private string AddFileImpl(string path, string projectPath, PBXSourceTree tree, bool isFolderReference)
        {
            PBXFileReferenceData data;

            path        = PBXPath.FixSlashes(path);
            projectPath = PBXPath.FixSlashes(projectPath);
            if (!isFolderReference && (Path.GetExtension(path) != Path.GetExtension(projectPath)))
            {
                throw new Exception("Project and real path extensions do not match");
            }
            string str = this.FindFileGuidByProjectPath(projectPath);

            if (str == null)
            {
                str = this.FindFileGuidByRealPath(path);
            }
            if (str != null)
            {
                return(str);
            }
            if (isFolderReference)
            {
                data = PBXFileReferenceData.CreateFromFolderReference(path, PBXPath.GetFilename(projectPath), tree);
            }
            else
            {
                data = PBXFileReferenceData.CreateFromFile(path, PBXPath.GetFilename(projectPath), tree);
            }
            PBXGroupData parent = this.CreateSourceGroup(PBXPath.GetDirectory(projectPath));

            parent.children.AddGUID(data.guid);
            this.FileRefsAdd(path, projectPath, parent, data);
            return(data.guid);
        }
Exemple #2
0
        // The same file can be referred to by more than one project path.
        private string AddFileImpl(string path, string projectPath, PBXSourceTree tree, bool isFolderReference)
        {
            path        = PBXPath.FixSlashes(path);
            projectPath = PBXPath.FixSlashes(projectPath);

            if (!isFolderReference && Path.GetExtension(path) != Path.GetExtension(projectPath))
            {
                throw new Exception("Project and real path extensions do not match");
            }

            string guid = FindFileGuidByProjectPath(projectPath);

            if (guid == null)
            {
                guid = FindFileGuidByRealPath(path);
            }
            if (guid == null)
            {
                PBXFileReferenceData fileRef;
                if (isFolderReference)
                {
                    fileRef = PBXFileReferenceData.CreateFromFolderReference(path, PBXPath.GetFilename(projectPath), tree);
                }
                else
                {
                    fileRef = PBXFileReferenceData.CreateFromFile(path, PBXPath.GetFilename(projectPath), tree);
                }
                PBXGroupData parent = CreateSourceGroup(PBXPath.GetDirectory(projectPath));
                parent.children.AddGUID(fileRef.guid);
                FileRefsAdd(path, projectPath, parent, fileRef);
                guid = fileRef.guid;
            }
            return(guid);
        }
Exemple #3
0
        public string FindFileGuidByProjectPath(string path)
        {
            path = PBXPath.FixSlashes(path);
            var fileRef = FileRefsGetByProjectPath(path);

            if (fileRef != null)
            {
                return(fileRef.guid);
            }
            return(null);
        }
        public string FindFileGuidByProjectPath(string path)
        {
            path = PBXPath.FixSlashes(path);
            PBXFileReferenceData data = this.FileRefsGetByProjectPath(path);

            if (data != null)
            {
                return(data.guid);
            }
            return(null);
        }
        internal void RemoveFilesByProjectPathRecursive(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData parent = this.GroupsGetByProjectPath(projectPath);

            if (parent != null)
            {
                this.RemoveGroupChildrenRecursive(parent);
                this.RemoveGroupIfEmpty(parent);
            }
        }
Exemple #6
0
        internal void RemoveFilesByProjectPathRecursive(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData gr = GroupsGetByProjectPath(projectPath);

            if (gr == null)
            {
                return;
            }
            RemoveGroupChildrenRecursive(gr);
            RemoveGroupIfEmpty(gr);
        }
 public string FindFileGuidByRealPath(string path)
 {
     path = PBXPath.FixSlashes(path);
     foreach (PBXSourceTree tree in FileTypeUtils.AllAbsoluteSourceTrees())
     {
         string str = this.FindFileGuidByRealPath(path, tree);
         if (str != null)
         {
             return(str);
         }
     }
     return(null);
 }
Exemple #8
0
        public string FindFileGuidByRealPath(string path)
        {
            path = PBXPath.FixSlashes(path);

            foreach (var tree in FileTypeUtils.AllAbsoluteSourceTrees())
            {
                string res = FindFileGuidByRealPath(path, tree);
                if (res != null)
                {
                    return(res);
                }
            }
            return(null);
        }
Exemple #9
0
        public static string GetCurrentDirectory()
        {
            if (Environment.OSVersion.Platform != PlatformID.MacOSX && Environment.OSVersion.Platform != PlatformID.Unix)
            {
                throw new Exception("PBX project compatible current directory can only obtained on OSX");
            }
            string path = PBXPath.FixSlashes(Directory.GetCurrentDirectory());

            if (!PBXPath.IsPathRooted(path))
            {
                return("/" + path);
            }
            return(path);
        }
Exemple #10
0
        // sourceTree must not be PBXSourceTree.Group
        public string FindFileGuidByRealPath(string path, PBXSourceTree sourceTree)
        {
            if (sourceTree == PBXSourceTree.Group)
            {
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            }
            path = PBXPath.FixSlashes(path);
            var fileRef = FileRefsGetByRealPath(path, sourceTree);

            if (fileRef != null)
            {
                return(fileRef.guid);
            }
            return(null);
        }
        public string FindFileGuidByRealPath(string path, PBXSourceTree sourceTree)
        {
            if (sourceTree == PBXSourceTree.Group)
            {
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            }
            path = PBXPath.FixSlashes(path);
            PBXFileReferenceData data = this.FileRefsGetByRealPath(path, sourceTree);

            if (data != null)
            {
                return(data.guid);
            }
            return(null);
        }
Exemple #12
0
        /// Creates source group identified by sourceGroup, if needed, and returns it.
        /// If sourceGroup is empty or null, root group is returned
        private PBXGroupData CreateSourceGroup(string sourceGroup)
        {
            sourceGroup = PBXPath.FixSlashes(sourceGroup);

            if (sourceGroup == null || sourceGroup == "")
            {
                return(GroupsGetMainGroup());
            }

            PBXGroupData gr = GroupsGetByProjectPath(sourceGroup);

            if (gr != null)
            {
                return(gr);
            }

            // the group does not exist -- create new
            gr = GroupsGetMainGroup();

            var    elements    = PBXPath.Split(sourceGroup);
            string projectPath = null;

            foreach (string pathEl in elements)
            {
                if (projectPath == null)
                {
                    projectPath = pathEl;
                }
                else
                {
                    projectPath += "/" + pathEl;
                }

                PBXGroupData child = GetPBXGroupChildByName(gr, pathEl);
                if (child != null)
                {
                    gr = child;
                }
                else
                {
                    PBXGroupData newGroup = PBXGroupData.Create(pathEl, pathEl, PBXSourceTree.Group);
                    gr.children.AddGUID(newGroup.guid);
                    GroupsAdd(projectPath, gr, newGroup);
                    gr = newGroup;
                }
            }
            return(gr);
        }
        public void AddExternalProjectDependency(string path, string projectPath, PBXSourceTree sourceTree)
        {
            if (sourceTree == PBXSourceTree.Group)
            {
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            }
            path        = PBXPath.FixSlashes(path);
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData gr = PBXGroupData.CreateRelative("Products");

            this.GroupsAddDuplicate(gr);
            PBXFileReferenceData fileRef = PBXFileReferenceData.CreateFromFile(path, Path.GetFileName(projectPath), sourceTree);

            this.FileRefsAdd(path, projectPath, null, fileRef);
            this.CreateSourceGroup(PBXPath.GetDirectory(projectPath)).children.AddGUID(fileRef.guid);
            this.project.project.AddReference(gr.guid, fileRef.guid);
        }
        public void AddExternalLibraryDependency(string targetGuid, string filename, string remoteFileGuid, string projectPath, string remoteInfo)
        {
            PBXNativeTargetData target = this.nativeTargets[targetGuid];

            filename    = PBXPath.FixSlashes(filename);
            projectPath = PBXPath.FixSlashes(projectPath);
            string containerRef = this.FindFileGuidByRealPath(projectPath);

            if (containerRef == null)
            {
                throw new Exception("No such project");
            }
            string guid = null;

            foreach (ProjectReference reference in this.project.project.projectReferences)
            {
                if (reference.projectRef == containerRef)
                {
                    guid = reference.group;
                    break;
                }
            }
            if (guid == null)
            {
                throw new Exception("Malformed project: no project in project references");
            }
            PBXGroupData data2     = this.GroupsGet(guid);
            string       extension = Path.GetExtension(filename);

            if (!FileTypeUtils.IsBuildableFile(extension))
            {
                throw new Exception("Wrong file extension");
            }
            PBXContainerItemProxyData data3 = PBXContainerItemProxyData.Create(containerRef, "2", remoteFileGuid, remoteInfo);

            this.containerItems.AddEntry(data3);
            string typeName             = FileTypeUtils.GetTypeName(extension);
            PBXReferenceProxyData data4 = PBXReferenceProxyData.Create(filename, typeName, data3.guid, "BUILT_PRODUCTS_DIR");

            this.references.AddEntry(data4);
            PBXBuildFileData buildFile = PBXBuildFileData.CreateFromFile(data4.guid, false, null);

            this.BuildFilesAdd(targetGuid, buildFile);
            this.BuildSectionAny(target, extension, false).files.AddGUID(buildFile.guid);
            data2.children.AddGUID(data4.guid);
        }
Exemple #15
0
        // Allow user to add a Capability
        public bool AddCapability(string targetGuid, PBXCapabilityType capability, string entitlementsFilePath = null, bool addOptionalFramework = false)
        {
            // If the capability requires entitlements then you have to provide the name of it or we don't add the capability.
            if (capability.requiresEntitlements && entitlementsFilePath == "")
            {
                throw new Exception("Couldn't add the Xcode Capability " + capability.id + " to the PBXProject file because this capability requires an entitlement file.");
            }
            var p = project.project;

            // If an entitlement with a different name was added for another capability
            // we don't add this capacity.
            if (p.entitlementsFile != null && entitlementsFilePath != null && p.entitlementsFile != entitlementsFilePath)
            {
                if (p.capabilities.Count > 0)
                {
                    throw new WarningException("Attention, it seems that you have multiple entitlements file. Only one will be added the Project : " + p.entitlementsFile);
                }

                return(false);
            }

            // Add the capability only if it doesn't already exist.
            if (p.capabilities.Contains(new PBXCapabilityType.TargetCapabilityPair(targetGuid, capability)))
            {
                throw new WarningException("This capability has already been added. Method ignored");
            }

            p.capabilities.Add(new PBXCapabilityType.TargetCapabilityPair(targetGuid, capability));

            // Add the required framework.
            if (capability.framework != "" && !capability.optionalFramework ||
                (capability.framework != "" && capability.optionalFramework && addOptionalFramework))
            {
                AddFrameworkToProject(targetGuid, capability.framework, false);
            }

            // Finally add the entitlement code signing if it wasn't added before.
            if (entitlementsFilePath != null && p.entitlementsFile == null)
            {
                p.entitlementsFile = entitlementsFilePath;
                AddFileImpl(entitlementsFilePath, entitlementsFilePath, PBXSourceTree.Source, false);
                SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", PBXPath.FixSlashes(entitlementsFilePath));
            }
            return(true);
        }
        internal List <string> GetGroupChildrenFiles(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData data = this.GroupsGetByProjectPath(projectPath);

            if (data == null)
            {
                return(null);
            }
            List <string> list2 = new List <string>();

            foreach (string str in (IEnumerable <string>)data.children)
            {
                PBXFileReferenceData data2 = this.FileRefsGet(str);
                if (data2 != null)
                {
                    list2.Add(data2.name);
                }
            }
            return(list2);
        }
Exemple #17
0
        // Returns null on error
        internal List <string> GetGroupChildrenFiles(string projectPath)
        {
            projectPath = PBXPath.FixSlashes(projectPath);
            PBXGroupData gr = GroupsGetByProjectPath(projectPath);

            if (gr == null)
            {
                return(null);
            }
            var res = new List <string>();

            foreach (var guid in gr.children)
            {
                var fileRef = FileRefsGet(guid);
                if (fileRef != null)
                {
                    res.Add(fileRef.name);
                }
            }
            return(res);
        }
        private PBXGroupData CreateSourceGroup(string sourceGroup)
        {
            sourceGroup = PBXPath.FixSlashes(sourceGroup);
            if ((sourceGroup == null) || (sourceGroup == ""))
            {
                return(this.GroupsGetMainGroup());
            }
            PBXGroupData group = this.GroupsGetByProjectPath(sourceGroup);

            if (group == null)
            {
                group = this.GroupsGetMainGroup();
                string[] strArray    = PBXPath.Split(sourceGroup);
                string   projectPath = null;
                foreach (string str2 in strArray)
                {
                    if (projectPath == null)
                    {
                        projectPath = str2;
                    }
                    else
                    {
                        projectPath = projectPath + "/" + str2;
                    }
                    PBXGroupData pBXGroupChildByName = this.GetPBXGroupChildByName(group, str2);
                    if (pBXGroupChildByName != null)
                    {
                        group = pBXGroupChildByName;
                    }
                    else
                    {
                        PBXGroupData gr = PBXGroupData.Create(str2, str2, PBXSourceTree.Group);
                        group.children.AddGUID(gr.guid);
                        this.GroupsAdd(projectPath, group, gr);
                        group = gr;
                    }
                }
            }
            return(group);
        }
Exemple #19
0
        // sourceTree must not be PBXSourceTree.Group
        public void AddExternalProjectDependency(string path, string projectPath, PBXSourceTree sourceTree)
        {
            if (sourceTree == PBXSourceTree.Group)
            {
                throw new Exception("sourceTree must not be PBXSourceTree.Group");
            }
            path        = PBXPath.FixSlashes(path);
            projectPath = PBXPath.FixSlashes(projectPath);

            // note: we are duplicating products group for the project reference. Otherwise Xcode crashes.
            PBXGroupData productGroup = PBXGroupData.CreateRelative("Products");

            GroupsAddDuplicate(productGroup); // don't use GroupsAdd here

            PBXFileReferenceData fileRef = PBXFileReferenceData.CreateFromFile(path, Path.GetFileName(projectPath),
                                                                               sourceTree);

            FileRefsAdd(path, projectPath, null, fileRef);
            CreateSourceGroup(PBXPath.GetDirectory(projectPath)).children.AddGUID(fileRef.guid);

            project.project.AddReference(productGroup.guid, fileRef.guid);
        }
Exemple #20
0
        /** This function must be called only after the project the library is in has
         *  been added as a dependency via AddExternalProjectDependency. projectPath must be
         *  the same as the 'path' parameter passed to the AddExternalProjectDependency.
         *  remoteFileGuid must be the guid of the referenced file as specified in
         *  PBXFileReference section of the external project
         *
         *  TODO: what. is remoteInfo entry in PBXContainerItemProxy? Is in referenced project name or
         *  referenced library name without extension?
         */
        public void AddExternalLibraryDependency(string targetGuid, string filename, string remoteFileGuid, string projectPath,
                                                 string remoteInfo)
        {
            PBXNativeTargetData target = nativeTargets[targetGuid];

            filename    = PBXPath.FixSlashes(filename);
            projectPath = PBXPath.FixSlashes(projectPath);

            // find the products group to put the new library in
            string projectGuid = FindFileGuidByRealPath(projectPath);

            if (projectGuid == null)
            {
                throw new Exception("No such project");
            }

            string productsGroupGuid = null;

            foreach (var proj in project.project.projectReferences)
            {
                if (proj.projectRef == projectGuid)
                {
                    productsGroupGuid = proj.group;
                    break;
                }
            }

            if (productsGroupGuid == null)
            {
                throw new Exception("Malformed project: no project in project references");
            }

            PBXGroupData productGroup = GroupsGet(productsGroupGuid);

            // verify file extension
            string ext = Path.GetExtension(filename);

            if (!FileTypeUtils.IsBuildableFile(ext))
            {
                throw new Exception("Wrong file extension");
            }

            // create ContainerItemProxy object
            var container = PBXContainerItemProxyData.Create(projectGuid, "2", remoteFileGuid, remoteInfo);

            containerItems.AddEntry(container);

            // create a reference and build file for the library
            string typeName = FileTypeUtils.GetTypeName(ext);

            var libRef = PBXReferenceProxyData.Create(filename, typeName, container.guid, "BUILT_PRODUCTS_DIR");

            references.AddEntry(libRef);
            PBXBuildFileData libBuildFile = PBXBuildFileData.CreateFromFile(libRef.guid, false, null);

            BuildFilesAdd(targetGuid, libBuildFile);
            BuildSectionAny(target, ext, false).files.AddGUID(libBuildFile.guid);

            // add to products folder
            productGroup.children.AddGUID(libRef.guid);
        }