コード例 #1
0
        // We support neither recursing into nor bundles contained inside loc folders
        public bool AddLocFolder(string folderPath, PBXGroup parent = null, string[] exclude = null, bool createBuildFile = true)
        {
            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(folderPath);

            if (exclude == null)
            {
                exclude = new string[] {}
            }
            ;

            if (parent == null)
            {
                parent = rootGroup;
            }

            // Create group as needed
            System.Uri projectFolderURI = new System.Uri(projectFileInfo.DirectoryName);
            System.Uri locFolderURI     = new System.Uri(folderPath);
            var        relativePath     = projectFolderURI.MakeRelativeUri(locFolderURI).ToString();
            PBXGroup   newGroup         = GetGroup(sourceDirectoryInfo.Name, relativePath, parent);

            // Add loc region to project
            string nom    = sourceDirectoryInfo.Name;
            string region = nom.Substring(0, nom.Length - ".lproj".Length);

            project.AddRegion(region);

            // Adding files.
            string regexExclude = string.Format(@"{0}", string.Join("|", exclude));

            foreach (string file in Directory.GetFiles(folderPath))
            {
                if (regexExclude.Length > 0 && Regex.IsMatch(file, regexExclude))
                {
                    continue;
                }

                // Add a variant group for the language as well
                var variant = new PBXVariantGroup(System.IO.Path.GetFileName(file), null, "GROUP");
                variantGroups.Add(variant);

                // The group gets a reference to the variant, not to the file itself
                newGroup.AddChild(variant);

                AddFile(file, variant, "GROUP", createBuildFile);
            }

            modified = true;
            return(modified);
        }
コード例 #2
0
        public void ApplyMod(XCMod mod)
        {
            PBXGroup modGroup = this.GetGroup(mod.group);

            if (mod.libs != null)
            {
                Debug.Log("Adding libraries...");
                foreach (XCModFile libRef in mod.libs)
                {
                    string completeLibPath = System.IO.Path.Combine("usr/lib", libRef.filePath);
                    Debug.Log("Adding library " + completeLibPath);
                    this.AddFile(completeLibPath, modGroup, "SDKROOT", true, libRef.isWeak);
                }
            }

            if (mod.frameworks != null)
            {
                Debug.Log("Adding frameworks...");
                PBXGroup frameworkGroup = this.GetGroup("Frameworks");
                foreach (string framework in mod.frameworks)
                {
                    string[] filename     = framework.Split(':');
                    bool     isWeak       = (filename.Length > 1) ? true : false;
                    string   completePath = System.IO.Path.Combine("System/Library/Frameworks", filename[0]);
                    this.AddFile(completePath, frameworkGroup, "SDKROOT", true, isWeak);
                }
            }

            if (mod.files != null)
            {
                Debug.Log("Adding files...");
                foreach (string filePath in mod.files)
                {
                    string absoluteFilePath = combinePathWithCheck(mod.path, filePath);
                    this.AddFile(absoluteFilePath, modGroup);
                }
            }

            if (mod.embed_binaries != null)
            {
                Debug.Log("Adding embed binaries...");
                //1. Add LD_RUNPATH_SEARCH_PATHS for embed framework
                this.overwriteBuildSetting("LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks", "Release");
                this.overwriteBuildSetting("LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks", "Debug");

                foreach (string binary in mod.embed_binaries)
                {
                    string absoluteFilePath = System.IO.Path.Combine(mod.path, binary);
                    this.AddEmbedFramework(absoluteFilePath);
                }
            }

            if (mod.folders != null)
            {
                Debug.Log("Adding folders...");
                foreach (string folderPath in mod.folders)
                {
                    string parentPath = Application.dataPath;
                    parentPath = parentPath.Substring(0, parentPath.Length - 7);

                    string absoluteFolderPath = System.IO.Path.Combine(parentPath, System.IO.Path.Combine(mod.path, folderPath));
                    Debug.Log("Adding folder " + absoluteFolderPath);
                    this.AddFolder(absoluteFolderPath, modGroup, (string[])mod.excludes.ToArray(typeof(string)));
                }
            }

            if (mod.headerpaths != null)
            {
                Debug.Log("Adding headerpaths...");
                foreach (string headerpath in mod.headerpaths)
                {
                    if (headerpath.Contains("$(inherited)"))
                    {
                        Debug.Log("not prepending a path to " + headerpath);
                        this.AddHeaderSearchPaths(headerpath);
                    }
                    else
                    {
                        string absoluteHeaderPath = System.IO.Path.Combine(mod.path, headerpath);
                        this.AddHeaderSearchPaths(absoluteHeaderPath);
                    }
                }
            }

            if (mod.compiler_flags != null)
            {
                Debug.Log("Adding compiler flags...");
                foreach (string flag in mod.compiler_flags)
                {
                    this.AddOtherCFlags(flag);
                }
            }

            if (mod.linker_flags != null)
            {
                Debug.Log("Adding linker flags...");
                foreach (string flag in mod.linker_flags)
                {
                    this.AddOtherLinkerFlags(flag);
                }
            }

            Debug.Log("Adding plist items...");
            string  plistPath = this.projectRootPath + "/Info.plist";
            XCPlist plist     = new XCPlist(plistPath);

            plist.Process(mod.plist);

            // Kanglai: for localization
            if (mod.variants != null)
            {
                foreach (string variantPath in mod.variants)
                {
                    string absoluteFolderPath = System.IO.Path.Combine(mod.path, variantPath);
                    if (!Directory.Exists(absoluteFolderPath))
                    {
                        Debug.LogWarning("VariantGroup: folder not exists");
                        continue;
                    }
                    DirectoryInfo directory   = new DirectoryInfo(absoluteFolderPath);
                    string        variantName = directory.Name;

                    var variant = new PBXVariantGroup(variantName, null, "GROUP");
                    // mark variants
                    variantGroups.Add(variant);
                    // add variant to project
                    _rootGroup.AddChild(variant);
                    // add variant in build process
                    PBXBuildFile buildFile = new PBXBuildFile(variant);
                    buildFiles.Add(buildFile);
                    foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases)
                    {
                        currentObject.Value.AddBuildFile(buildFile);
                    }

                    foreach (var dir in directory.GetDirectories())
                    {
                        string dirName = dir.Name;
                        int    split   = dirName.Length - 6;
                        if (split <= 0 || !dirName.Substring(split).Equals(".lproj"))
                        {
                            Debug.LogWarning("VariantGroup: folder should end with .lproj");
                            continue;
                        }
                        string languangeName   = dirName.Substring(0, split);
                        string variantFilePath = System.IO.Path.Combine(dir.FullName, variantName);
                        if (!File.Exists(variantFilePath))
                        {
                            Debug.LogWarning("VariantGroup: file under folder not exists");
                            continue;
                        }

                        var result = AddFile(variantFilePath, variant, createBuildFiles: false, ignoreSameFilename: false);
                        PBXFileReference fileReference = (PBXFileReference)result.Values.First();
                        fileReference.Remove("name");
                        fileReference.Add("name", languangeName);
                    }
                }
            }

            this.Consolidate();
        }
コード例 #3
0
 // Kanglai
 public PBXBuildFile(PBXVariantGroup variantRef) : base()
 {
     this.Add(FILE_REF_KEY, variantRef.guid);
     SetWeakLink(false);
 }