/// <summary> /// Removes the group. /// </summary> /// <param name = "groups">The groups.</param> /// <returns></returns> public PBXGroup RemoveGroup(String groups) { lock (this.syncRoot) { // Only keep the n-1 groups List <String> parts = groups.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList(); String last = parts.Last(); parts.RemoveAt(parts.Count - 1); // Go to the parent group PBXGroup g, group = this.Document.Project.MainGroup; foreach (String part in parts) { g = group.FindGroup(part); if (g == null) { // For each group not found, create it g = new PBXGroup(part); group.AddChild(g); } group = g; } // If the group to delete exists, remove it g = group.FindGroup(last); if (g != null) { group.RemoveChild(g); } return(g); } }
/// <summary> /// Adds the group. /// </summary> /// <param name = "groups">The group path.</param> /// <returns></returns> public PBXGroup AddGroup(String groups) { lock (this.syncRoot) { // Split the group paths List <string> parts = groups.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList(); PBXGroup group = this.Document.Project.MainGroup; foreach (String part in parts) { PBXGroup g = group.FindGroup(part); if (g == null) { // For each group not found, create it g = new PBXGroup(part); group.AddChild(g); } group = g; } return(group); } }
/// <summary> /// Adds the dependant project. /// </summary> /// <param name = "project">The project.</param> /// <param name = "targetName">Name of the target.</param> public void AddDependantProject(XcodeProject project, String targetName) { lock (this.syncRoot) { // Get the native target PBXNativeTarget target = project.GetDefaultTarget() as PBXNativeTarget; if (target == null) { return; } // Get the product reference PBXFileReference productReference = target.ProductReference; // Add a dummy group for references PBXGroup referecenGroup = this.AddGroup("References"); // Add file reference PBXFileReference fileReference = this.AddFile(String.Empty, project.ProjectFolder) as PBXFileReference; // Add proxy PBXContainerItemProxy itemProxy = new PBXContainerItemProxy(); itemProxy.ContainerPortal = fileReference; itemProxy.ProxyType = 2; // TODO: Find other values itemProxy.RemoteInfo = Path.GetFileNameWithoutExtension(fileReference.Name); itemProxy.RemoteGlobalIDString = project.Document.Mapping [productReference]; // Add reference proxy PBXReferenceProxy referenceProxy = new PBXReferenceProxy(); referenceProxy.RemoteRef = itemProxy; referenceProxy.SourceTree = PBXSourceTree.BuildProductDir; referenceProxy.FileType = productReference.ExplicitFileType; referenceProxy.Path = Path.GetFileName(productReference.Path); // Add reference proxy referecenGroup.AddChild(referenceProxy); // Add association this.Project.AddProjectReference(referecenGroup, fileReference); } }
public void TestProjectGeneration001() { // Create the document PBXDocument document = new PBXDocument(); PBXProject project = document.Project; PBXFileReference file1 = new PBXFileReference(); file1.LastKnownFileType = PBXFileType.WrapperFramework; file1.Name = "Cocoa.framework"; file1.Path = "/System/Library/Frameworks/Cocoa.framework"; file1.LastKnownFileType = PBXFileType.WrapperFramework; file1.SourceTree = PBXSourceTree.SdkRoot; PBXFileReference file2 = new PBXFileReference(); file2.LastKnownFileType = PBXFileType.WrapperFramework; file2.Name = "SurrogateTestAppDelegate.h"; file2.Path = "SurrogateTestAppDelegate.h"; file2.LastKnownFileType = PBXFileType.SourcecodeCH; file2.SourceTree = PBXSourceTree.Group; PBXFileReference file3 = new PBXFileReference(); file3.LastKnownFileType = PBXFileType.WrapperFramework; file3.Name = "en"; file3.Path = "en.lproj/MainMenu.xib"; file3.LastKnownFileType = PBXFileType.FileXib; file3.SourceTree = PBXSourceTree.Group; PBXFileReference file4 = new PBXFileReference(); file4.LastKnownFileType = PBXFileType.WrapperFramework; file4.Name = "fr"; file4.Path = "fr.lproj/MainMenu.xib"; file4.LastKnownFileType = PBXFileType.FileXib; file4.SourceTree = PBXSourceTree.Group; PBXVariantGroup variantGroup = new PBXVariantGroup("MainMenu.xib"); variantGroup.SourceTree = PBXSourceTree.Group; variantGroup.AddChild(file3); variantGroup.AddChild(file4); PBXGroup group1 = new PBXGroup("Products"); group1.SourceTree = PBXSourceTree.Group; PBXGroup group2 = new PBXGroup("Frameworks"); group2.SourceTree = PBXSourceTree.Group; group2.AddChild(file1); PBXGroup group3 = new PBXGroup("Classes"); group3.SourceTree = PBXSourceTree.Group; group3.AddChild(file2); PBXGroup group4 = new PBXGroup("Resources"); group4.SourceTree = PBXSourceTree.Group; group4.AddChild(variantGroup); PBXGroup group5 = document.Project.MainGroup; group5.SourceTree = PBXSourceTree.Group; group5.AddChild(group3); group5.AddChild(group4); group5.AddChild(group2); group5.AddChild(group1); document.Project.ProductRefGroup = group1; // Add build configuration "Release" XCBuildConfiguration releaseConfiguration = new XCBuildConfiguration(); releaseConfiguration.Name = "Release"; project.BuildConfigurationList.AddBuildConfiguration(releaseConfiguration); project.BuildConfigurationList.DefaultConfigurationName = "Release"; document.WriteToFile("project-001.pbxproj"); }
/// <summary> /// Adds the file. /// </summary> /// <param name = "groups">The groups.</param> /// <param name = "file">The file.</param> /// <param name = "sourceTree">The source tree.</param> /// <returns></returns> public PBXFileElement AddFile(String groups, String file, PBXSourceTree sourceTree) { lock (this.syncRoot) { // Prepare the group that will contain the file PBXGroup group = this.GetGroup(groups); PBXFileReference fileReference = null; PBXFileElement result = null; // Extract information String name = Path.GetFileName(file); String path = Path.GetFullPath(file); String rootDir = Path.GetFullPath(this.Dir); if (!String.IsNullOrEmpty(this.BaseDir)) { rootDir = Path.Combine(rootDir, this.BaseDir); rootDir = Path.GetFullPath(rootDir); } String parentDir = Path.GetDirectoryName(file); // If the file is localized, then add it to a variant group if (Path.GetExtension(parentDir).Equals(".lproj")) { // The variant group may exists to search for it PBXVariantGroup variantGroup = group.FindVariantGroup(name); if (variantGroup == null) { variantGroup = new PBXVariantGroup(name); group.AddChild(variantGroup); } // The file is named like the language name = Path.GetFileNameWithoutExtension(parentDir); group = variantGroup; result = variantGroup; } // Check if the file already exists fileReference = group.FindFileReference(name); if (fileReference == null) { // Create a file reference fileReference = new PBXFileReference(name); // Set the source tree if none specified if (sourceTree != PBXSourceTree.None) { fileReference.SourceTree = sourceTree; } else { if (path.StartsWith(rootDir)) { path = path.Substring(rootDir.Length + 1); fileReference.SourceTree = PBXSourceTree.Group; } else { fileReference.SourceTree = PBXSourceTree.Absolute; } } fileReference.Path = path; fileReference.LastKnownFileType = GetFileType(file); // Add it to the group group.AddChild(fileReference); } return(result ?? fileReference); } }