// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Flax.Build.Projects { /// /// Project generator for XCode. /// public class XCodeProjectGenerator : ProjectGenerator { private Random _rand = new Random(1995); private byte[] _randBytes = new byte[12]; /// /// Initializes a new instance of the class. /// public XCodeProjectGenerator() { } /// public override string ProjectFileExtension => "pbxproj"; /// public override string SolutionFileExtension => "xcodeproj"; /// public override TargetType? Type => null; /// public override Project CreateProject() { return new Project { Generator = this, }; } /// public override void GenerateProject(Project project) { Console.WriteLine(project.Path); var contents = new StringBuilder(); contents.AppendLine("// !$*UTF8*$!"); contents.AppendLine("{"); contents.AppendLine("\tarchiveVersion = 1;"); contents.AppendLine("\tclasses = {"); contents.AppendLine("\t};"); contents.AppendLine("\tobjectVersion = 46;"); contents.AppendLine("\tobjects = {"); contents.AppendLine("\t};"); contents.AppendLine("\trootObject = " + GetRandomGuid() + " /* Project object */;"); contents.AppendLine("}"); Utilities.WriteFileIfChanged(Path.Combine(project.Path), contents.ToString()); } /// public override void GenerateSolution(Solution solution) { Directory.CreateDirectory(solution.Path); var contents = new StringBuilder(); contents.AppendLine(""); contents.AppendLine(""); foreach (var project in solution.Projects) { } contents.AppendLine(""); Utilities.WriteFileIfChanged(Path.Combine(solution.Path, solution.Name + ".xcworkspace", "contents.xcworkspacedata"), contents.ToString()); } private string GetRandomGuid() { _rand.NextBytes(_randBytes); string result = string.Empty; for (int i = 0; i < 12; i++) { result += _randBytes[i].ToString("X2"); } return result; } } }