Ejemplo n.º 1
0
 public bool AddBuildFile( PBXBuildFile file )
 {
     if( !ContainsKey( FILES_KEY ) ){
         this.Add( FILES_KEY, new PBXList() );
     }
     ((PBXList)_data[ FILES_KEY ]).Add( file.guid );
     return true;
 }
Ejemplo n.º 2
0
 public bool AddBuildFile(PBXBuildFile file)
 {
     if (!ContainsKey(FILES_KEY))
     {
         this.Add(FILES_KEY, new PBXList());
     }
     ((PBXList)_data[FILES_KEY]).Add(file.guid);
     return(true);
 }
Ejemplo n.º 3
0
        public bool AddBuildFile(PBXBuildFile file)
        {
//          if( ((string)file[ ISA_KEY ]).CompareTo( "PBXBuildFile" ) != 0 )
//              return false;

            if (!ContainsKey(FILES_KEY))
            {
                this.Add(FILES_KEY, new PBXList());
            }

            ((PBXList)_data[FILES_KEY]).Add(file.guid);

            return(true);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// projmods ファイルの設定値を XCode プロジェクト設定へ反映する
    /// </summary>
    /// <param name="path">出力先のパス(ビルド時に指定するパス)</param>
    private static void ProcessXCodeProject(string path)
    {
        XCProject project = new XCProject(path);

        string modsPath = System.IO.Path.Combine(path, "Lobi");

        string[] files = System.IO.Directory.GetFiles(modsPath, "*.projmods", System.IO.SearchOption.AllDirectories);

        foreach (string file in files)
        {
            project.ApplyMod(file);
        }

                #if UNITY_5
        // To need to add a `-fno-objc-arc` flag if building in Unity5.
        string   librariesPath = System.IO.Path.Combine(path, "Libraries/Plugins/iOS");
        string[] filePathList  = System.IO.Directory.GetFiles(librariesPath);

        PBXDictionary <PBXBuildFile> buildFiles = project.buildFiles;
        foreach (KeyValuePair <string, PBXBuildFile> kvp in buildFiles)
        {
            string fileName = kvp.Key;
            foreach (string targetPath in filePathList)
            {
                string extention = System.IO.Path.GetExtension(targetPath);
                if (!(extention == ".m" || extention == ".mm"))
                {
                    continue;
                }

                string targetName = System.IO.Path.GetFileName(targetPath);
                if (!fileName.Contains(targetName))
                {
                    continue;
                }

                PBXBuildFile file = kvp.Value;
                file.AddCompilerFlag("\"-fno-objc-arc\"");
            }
        }
                #endif

        project.Save();
    }
Ejemplo n.º 5
0
        public static string AddNewBuildFile(IIgorModule ModuleInst, string ProjectPath, string FileRefGUID)
        {
            if (IgorAssert.EnsureTrue(ModuleInst, Directory.Exists(ProjectPath), "XCodeProj doesn't exist at path " + ProjectPath))
            {
                XCProject CurrentProject = new XCProject(ProjectPath);

                CurrentProject.Backup();

                foreach (KeyValuePair <string, PBXBuildFile> CurrentBuildFile in CurrentProject.buildFiles)
                {
                    if (IgorAssert.EnsureTrue(ModuleInst, CurrentBuildFile.Value.ContainsKey("fileRef"), "PBXBuildFile doesn't contain a key for fileRef."))
                    {
                        if (CurrentBuildFile.Value.data["fileRef"] == FileRefGUID)
                        {
                            IgorDebug.Log(ModuleInst, "The file GUID " + FileRefGUID + " already has an associated BuildFile in the XCodeProj.");

                            return(CurrentBuildFile.Value.guid);
                        }
                    }
                }

                foreach (KeyValuePair <string, PBXFileReference> CurrentFileRef in CurrentProject.fileReferences)
                {
                    if (CurrentFileRef.Value.guid == FileRefGUID)
                    {
                        PBXBuildFile NewBuildFile = new PBXBuildFile(CurrentFileRef.Value);

                        CurrentProject.buildFiles.Add(NewBuildFile);

                        IgorDebug.Log(ModuleInst, "BuildFile for FileRefGUID " + FileRefGUID + " has been added to the XCodeProj.");

                        CurrentProject.Save();

                        return(NewBuildFile.guid);
                    }
                }
            }

            return("");
        }
Ejemplo n.º 6
0
 /// <summary>
 ///   Visits the specified element.
 /// </summary>
 /// <param name = "element">The element.</param>
 public void Visit(PBXBuildFile element)
 {
     this.Add (element);
 }
Ejemplo n.º 7
0
 /// <summary>
 ///   Visits the specified element.
 /// </summary>
 /// <param name = "element">The element.</param>
 public void Visit(PBXBuildFile element)
 {
     this.Add(element);
 }
Ejemplo n.º 8
0
        public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iOS)
            {
                Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
                return;
            }


            #region 写入Plist
            Debug.Log("Run mine ----------------------------------------------------------------- ");
            string plistPath = pathToBuiltProject + "/Info.Plist";
            Dictionary <string, object> dict = (Dictionary <string, object>)PlistCS.Plist.readPlist(plistPath);

            dict["LSHasLocalizedDisplayName"] = true;
            PlistCS.Plist.writeXml(dict, plistPath);
            #endregion

            var    permissionConfig  = PermissionDesEditorWindow.Load();
            string strPermissionName = "";
            if (null == permissionConfig || string.IsNullOrEmpty(permissionConfig.SelectedStamp))
            {
            }
            else
            {
                strPermissionName = permissionConfig.SelectedStamp;
            }

            Debug.Log(strPermissionName);

            if (strPermissionName.EndsWith(","))
            {
                strPermissionName = strPermissionName.Remove(strPermissionName.Length - 1);
            }
            Debug.Log(strPermissionName);

            string[]   strPermissionIndexes = strPermissionName.Split(',');
            List <int> permissionList       = new List <int> ();

            for (int i = 0; i < strPermissionIndexes.Length; i++)
            {
                if (!string.IsNullOrEmpty(strPermissionIndexes [i]))
                {
                    permissionList.Add(int.Parse(strPermissionIndexes [i]));
                }
            }
            int[] permissionIndexes = permissionList.ToArray();

            #region 生成资源文件

            // Create a new project object from build target
            XCProject project = new XCProject(pathToBuiltProject);

            var variantGroup         = project.variantGroups;
            var rootGroup            = project.rootGroup;
            var buildFiles           = project.buildFiles;
            var resourcesBuildPhases = project.resourcesBuildPhases;

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

            // add variant in build process

            var appNameConfigData = AppNameConfigData.Load();

            Dictionary <string, string> language = new Dictionary <string, string> ();
            foreach (var languageData in appNameConfigData.SupportedLanguageItems)
            {
                language.Add(appNameConfigData.LanguageDefiOS [languageData.Index], languageData.AppName);
            }
            // English  en    french fr

            foreach (KeyValuePair <string, string> entry in language)
            {
                string folder = project.projectRootPath + "/" + entry.Key + ".lproj";
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                string filePath = folder + "/InfoPlist.strings";
                string content  = "\"CFBundleDisplayName\" = \"" + entry.Value + "\";\n";

                List <PermissionDescription> permissionDescriptions = GetLanguagePermissionDescriptions(entry.Key, permissionIndexes);

                foreach (PermissionDescription permissionDescription in permissionDescriptions)
                {
                    content += "\"" + permissionDescription.PermissionName + "\" = \"" + permissionDescription.Description + "\";\n";
                }

                File.WriteAllText(filePath, content);

                var    result   = project.AddFile(filePath, (PBXGroup)variant, "SOURCE_ROOT", true, false);
                string firstKey = "";

                foreach (KeyValuePair <string, object> resultEntry in result)
                {
                    firstKey = resultEntry.Key;
                    break;
                }
                PBXFileReference fileReference = (PBXFileReference)result[firstKey];
                fileReference.Remove("name");
                fileReference.Add("name", entry.Key);

                PBXBuildFile buildFile = new PBXBuildFile(fileReference);
                buildFiles.Add(buildFile);
            }

            project.Save();
            #endregion
        }
Ejemplo n.º 9
0
 private void BuildAddFile(PBXFileReference fileReference, KeyValuePair<string, PBXCopyFilesBuildPhase> currentObject,bool weak)
 {
     PBXBuildFile buildFile = new PBXBuildFile( fileReference, weak );
     buildFiles.Add( buildFile );
     currentObject.Value.AddBuildFile( buildFile );
 }
        public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.iOS)
            {
                Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
                return;
            }


            #region 写入Plist
            Debug.Log("Run mine ----------------------------------------------------------------- ");
            //修改工程文件 内容
            //string projPath = PBXProject.GetPBXProjectPath(path);
            //PBXProject proj = new PBXProject();
            //proj.ReadFromString(File.ReadAllText(projPath));
            //string target = proj.TargetGuidByName("Unity-iPhone");

            // add extra framework(s) 添加额外的Framework
            //proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false);

            // set code sign identity & provisioning profile 设置证书签名等
            //proj.SetBuildProperty(target, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________");
            //proj.SetBuildProperty(target, "PROVISIONING_PROFILE", "********-****-****-****-************");

            // rewrite to file
            //File.WriteAllText(projPath, proj.WriteToString());

            //修改Info.plist
            // Get plist

            // Get root
            //读取配置文件
//			string _path = Application.dataPath +
//				"/PTGameData/Editor/config_ptgame/ptconfig_XCodePermission.xml";
//			XmlDocument xmlDoc = new XmlDocument();
//			xmlDoc.Load(_path);
//			//获取Config的所有子节点
//			XmlNodeList nodeList = xmlDoc.SelectSingleNode("Config").ChildNodes;
//			foreach (XmlElement _xmlele in nodeList)
//			{
//				if (_xmlele.GetAttribute("Choose") == "True")
//				{
//					//				rootDict.SetString(_xmlele.GetAttribute("PermissionKey"), _xmlele.GetAttribute("DescriptionString"));
//				}
//			}
            //		PlistElementDict _https = rootDict.CreateDict ("NSAppTransportSecurity");
            //		_https.SetBoolean ("NSAllowsArbitraryLoads",true);
            // Change value of CFBundleDevelopmentRegion in Xcode plist //设置语言为中文
            //rootDict.SetString("CFBundleDevelopmentRegion", "zh_CN");

            //PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");

            // add weixin url scheme
            //PlistElementDict wxUrl = urlTypes.AddDict();
            //wxUrl.SetString("CFBundleTypeRole", "Editor");
            //wxUrl.SetString("CFBundleURLName", "weixin");
            //PlistElementArray wxUrlScheme = wxUrl.CreateArray("CFBundleURLSchemes");
            //wxUrlScheme.AddString("____________");

            // Write to file
            //		File.WriteAllText(plistPath, plist.WriteToString());
            string plistPath = pathToBuiltProject + "/Info.Plist";
            Dictionary <string, object> dict = (Dictionary <string, object>)PlistCS.Plist.readPlist(plistPath);

            dict["LSHasLocalizedDisplayName"] = true;
            PlistCS.Plist.writeXml(dict, plistPath);
            #endregion

            string strPermissionName = EditorPrefs.GetString(PermissionDesEditorWindow.StrPermissionName, "");
            Debug.Log(strPermissionName);

            if (strPermissionName.EndsWith(","))
            {
                strPermissionName = strPermissionName.Remove(strPermissionName.Length - 1);
            }
            Debug.Log(strPermissionName);

            string[] strPermissionIndexes = strPermissionName.Split(',');
            int[]    permissionIndexes    = new int[strPermissionIndexes.Length];
            for (int i = 0; i < permissionIndexes.Length; i++)
            {
                permissionIndexes [i] = int.Parse(strPermissionIndexes [i]);
            }

            #region 生成资源文件

            // Create a new project object from build target
            XCProject project = new XCProject(pathToBuiltProject);

            var variantGroup         = project.variantGroups;
            var rootGroup            = project.rootGroup;
            var buildFiles           = project.buildFiles;
            var resourcesBuildPhases = project.resourcesBuildPhases;

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

            // add variant in build process

            var appNameConfigData = AppNameConfigData.Load();

            Dictionary <string, string> language = new Dictionary <string, string> ();
            foreach (var languageData in appNameConfigData.SupportedLanguageItems)
            {
                language.Add(appNameConfigData.LanguageDefiOS [languageData.Index], languageData.AppName);
            }
            // English  en    french fr

            foreach (KeyValuePair <string, string> entry in language)
            {
                string folder = project.projectRootPath + "/" + entry.Key + ".lproj";
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                string filePath = folder + "/InfoPlist.strings";
                string content  = "\"CFBundleDisplayName\" = \"" + entry.Value + "\";\n";

                List <PermissionDescription> permissionDescriptions = GetLanguagePermissionDescriptions(entry.Key, permissionIndexes);

                foreach (PermissionDescription permissionDescription in permissionDescriptions)
                {
                    content += "\"" + permissionDescription.PermissionName + "\" = \"" + permissionDescription.Description + "\";\n";
                }

                File.WriteAllText(filePath, content);
                var result = project.AddFile(filePath, (PBXGroup)variant, "SOURCE_ROOT", true, false);
//				var result = project.AddFile(filePath,"", (PBXGroup)variant,"SOURCE_ROOT",  true,  false);
                string firstKey = "";

                foreach (KeyValuePair <string, object> resultEntry in result)
                {
                    firstKey = resultEntry.Key;
                    break;
                }
                PBXFileReference fileReference = (PBXFileReference)result[firstKey];
                fileReference.Remove("name");
                fileReference.Add("name", entry.Key);

                PBXBuildFile buildFile = new PBXBuildFile(fileReference);
                buildFiles.Add(buildFile);
            }

            project.Save();
            #endregion
        }