Esempio n. 1
0
        public void ApplyMod(string pbxmod)
        {
            XCMod mod = new XCMod(pbxmod);

            foreach (var lib in mod.libs)
            {
                Debug.Log("Library: " + lib);
            }
            ApplyMod(mod);
        }
Esempio n. 2
0
        public void ApplyMod(XCMod mod)
        {
            PBXGroup modGroup = this.GetGroup(mod.group);

            Debug.Log("Adding libraries...");
            PBXGroup frameworkGroup = this.GetGroup("Frameworks");

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

            Debug.Log("Adding 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[] path             = filePath.Split(':');
                string   absoluteFilePath = "";
                if (path.Length > 1)
                {
                    absoluteFilePath = System.IO.Path.Combine(mod.path, path [0]);
                                        #if UNITY_5
                    if (absoluteFilePath.Contains("C98"))
                    {
                        absoluteFilePath = absoluteFilePath.Replace("C98", "C11");
                    }
                                        #else
                    if (absoluteFilePath.Contains("C11"))
                    {
                        absoluteFilePath = absoluteFilePath.Replace("C11", "C98");
                    }
                                        #endif

                    this.AddFile(absoluteFilePath, modGroup);
                    PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(absoluteFilePath));
                    string           compilerFlags = path [1];

                    foreach (KeyValuePair <string, PBXBuildFile> source in buildFiles)
                    {
                        if (string.Equals(source.Value.fileRef, fileReference.guid))
                        {
                            source.Value.AddCompilerFlag(compilerFlags);
                        }
                    }
                }
                else
                {
                    absoluteFilePath = System.IO.Path.Combine(mod.path, filePath);
                    //兼容相对路径和绝对路径 Exist
                    if ((!File.Exists(absoluteFilePath)) && (!Directory.Exists(absoluteFilePath)))
                    {
                        string oldAbsoluteFilePath = absoluteFilePath;
                        absoluteFilePath = System.IO.Path.Combine(Application.dataPath, filePath);
                        Debug.Log("change file path from " + oldAbsoluteFilePath + " to dataPath2:" + absoluteFilePath);
                    }

                                        #if UNITY_5
                    if (absoluteFilePath.Contains("C98"))
                    {
                        absoluteFilePath = absoluteFilePath.Replace("C98", "C11");
                    }
                                        #else
                    if (absoluteFilePath.Contains("C11"))
                    {
                        absoluteFilePath = absoluteFilePath.Replace("C11", "C98");
                    }
                                        #endif
                    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");
                this.overwriteBuildSetting("LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks", "ReleaseForProfiling");
                this.overwriteBuildSetting("LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks", "ReleaseForRunning");

                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(mod.path, folderPath);
                Debug.Log("Adding folder " + absoluteFolderPath);
                //兼容相对路径和绝对路径
                if (!Directory.Exists(absoluteFolderPath))
                {
                    string oldAbsoluteFolderPath = absoluteFolderPath;
                    absoluteFolderPath = System.IO.Path.Combine(Application.dataPath, folderPath);
                    Debug.Log("change dir path from " + oldAbsoluteFolderPath + " to dataPath2:" + 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 build setting...");
            Hashtable buildSetting = mod.build_settigs;
            if (buildSetting != null)
            {
                foreach (DictionaryEntry item in buildSetting)
                {
                    if (item.Value is ArrayList)
                    {
                        ArrayList valueList = item.Value as ArrayList;
                        overwriteBuildSetting(item.Key.ToString(), valueList);
                    }
                    else if (item.Value is string)
                    {
                        if (item.Value.ToString() == "TRUE" || item.Value.ToString() == "FALSE")
                        {
                            overwriteBuildSetting(item.Key.ToString(), Convert.ToBoolean(item.Value) ? "YES" : "NO");
                        }
                        else
                        {
                            overwriteBuildSetting(item.Key.ToString(), item.Value.ToString());
                        }
                    }
                }
            }
            Debug.Log("Adding system capability...");
            var systemCapabilities = mod.system_capabilities;
            if (systemCapabilities != null)
            {
                foreach (DictionaryEntry item in systemCapabilities)
                {
                    AddSystemCapabilities(item.Key.ToString(), Convert.ToBoolean(item.Value));
                }
            }

            Debug.Log("Adding info_plist...");
            if (mod.info_plist != null)
            {
                string  infoPlistPath = Path.Combine(projectRootPath, "Info.plist");
                XCPlist infoPlist     = new XCPlist(infoPlistPath);
                infoPlist.Process(mod.info_plist);
            }
            this.Consolidate();
        }