Inheritance: PBXFileElement
Example #1
0
 /// <summary>
 ///   Removes the project reference.
 /// </summary>
 /// <param name = "file">The file.</param>
 public void RemoveProjectReference(PBXFileReference file)
 {
     Dictionary<String, IPBXElement> reference = (from pr in this.projectReferences
                                                  where pr["ProjectRef"] == file
                                                  select pr).FirstOrDefault();
     if (reference == null)
     {
         return;
     }
     this.projectReferences.Remove(reference);
 }
Example #2
0
 /// <summary>
 ///   Adds the project reference.
 /// </summary>
 /// <param name = "group">The group.</param>
 /// <param name = "file">The file.</param>
 public void AddProjectReference(PBXGroup group, PBXFileReference file)
 {
     Dictionary<String, IPBXElement> reference = (from pr in this.projectReferences
                                                  where pr["ProjectRef"] == file
                                                  select pr).FirstOrDefault();
     if (reference != null)
     {
         return;
     }
     reference = new Dictionary<String, IPBXElement>();
     reference["ProductGroup"] = group;
     reference["ProjectRef"] = file;
     this.projectReferences.Add(reference);
 }
        /// <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;
            }
        }
        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");
        }
Example #5
0
        /// <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);
            }
        }