Example #1
0
        public PBXVariantGroup GetVariantGroup(string name, string path = null, PBXGroup parent = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

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

            foreach (KeyValuePair <string, PBXVariantGroup> current in variantGroups)
            {
                if (string.IsNullOrEmpty(current.Value.name))
                {
                    if (current.Value.path.CompareTo(name) == 0)
                    {
                        return(current.Value);
                    }
                }
                else if (current.Value.name.CompareTo(name) == 0)
                {
                    return(current.Value);
                }
            }

            PBXVariantGroup result = new PBXVariantGroup(name, path);

            variantGroups.Add(result);
            parent.AddChild(result);

            modified = true;
            return(result);
        }
        // We support neither recursing into nor bundles contained inside loc folders
        public bool AddLocFolder(string folderPath, string compilerFlags, 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 (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);
                AddFile(file, compilerFlags, variant, "GROUP", createBuildFile);
            }

            modified = true;
            return(modified);
        }
Example #3
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( 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;
        }
Example #4
0
        public void ApplyMod(XCMod mod)
        {
            PBXGroup modGroup = this.GetGroup(mod.group);

            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);
            }

            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);
            }

            Debug.Log("Adding files...");
            foreach (string filePath in mod.files)
            {
                string absoluteFilePath = System.IO.Path.Combine(mod.path, filePath);
                this.AddFile(absoluteFilePath, modGroup);
            }

            Debug.Log("Adding embed binaries...");
            if (mod.embed_binaries != null)
            {
                //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);
                }
            }

            Debug.Log("Adding folders...");
            foreach (string folderPath in mod.folders)
            {
                string absoluteFolderPath = System.IO.Path.Combine(Application.dataPath, folderPath);
                Debug.Log("Adding folder " + absoluteFolderPath);
                this.AddFolder(absoluteFolderPath, modGroup, (string[])mod.excludes.ToArray(typeof(string)));
            }

            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);
                }
            }

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

            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);

            Debug.Log("Adding I18N name...");
            if (mod.i18n_name != null && mod.i18n_name.Count > 0)
            {
                Dictionary <string, object> dict = (Dictionary <string, object>)PlistCS.Plist.readPlist(plistPath);
                if (dict.ContainsKey("CFBundleDisplayName"))
                {
                    dict.Remove("CFBundleDisplayName");
                }
                dict["LSHasLocalizedDisplayName"] = true;
                PlistCS.Plist.writeXml(dict, plistPath);

                var variant = new PBXVariantGroup("InfoPlist.strings", null, "GROUP");
                // mark variants
                variantGroups.Add(variant);
                // add variant to project
                _rootGroup.AddChild(variant);

                foreach (string entry in mod.i18n_name)
                {
                    string[] filename = entry.Split(':');
                    string   folder   = this.projectRootPath + "/" + filename[0] + ".lproj";
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    string filePath = folder + "/InfoPlist.strings";
                    string content  = "\"CFBundleDisplayName\" = \"" + filename[1] + "\";\n";
                    content += "\"CFBundleName\" = \"" + filename[1] + "\";\n";
                    File.WriteAllText(filePath, content);

                    var result = AddFile(filePath, variant, "GROUP", true, false, true);
                    foreach (var item in result.Keys)
                    {
                        PBXFileReference fileReference = (PBXFileReference)result[item];
                        fileReference.Remove("name");
                        fileReference.Add("name", filename[1]);
                    }
                }
            }

            this.Consolidate();
        }
 // Kanglai
 public PBXBuildFile(PBXVariantGroup variantRef) : base()
 {
     this.Add(FILE_REF_KEY, variantRef.guid);
     SetWeakLink(false);
 }
Example #6
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();
        }