public PBXBuildFile( PBXFileReference fileRef, bool weak = false ) : base() { this.Add( FILE_REF_KEY, fileRef.guid ); SetWeakLink( weak ); if (!string.IsNullOrEmpty(fileRef.compilerFlags)) { foreach (var flag in fileRef.compilerFlags.Split(',')) AddCompilerFlag(flag); } }
/// <summary> /// Visits the specified element. /// </summary> /// <param name = "element">The element.</param> public void Visit(PBXFileReference element) { this.Add (element); }
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 PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false ) { //Debug.Log("AddFile " + filePath + ", " + parent + ", " + tree + ", " + (createBuildFiles? "TRUE":"FALSE") + ", " + (weak? "TRUE":"FALSE") ); PBXDictionary results = new PBXDictionary(); if (filePath == null) { Debug.LogError ("AddFile called with null filePath"); return results; } string absPath = string.Empty; if( Path.IsPathRooted( filePath ) ) { Debug.Log( "Path is Rooted" ); absPath = filePath; } else if( tree.CompareTo( "SDKROOT" ) != 0) { absPath = Path.Combine( Application.dataPath, filePath ); } if( !( File.Exists( absPath ) || Directory.Exists( absPath ) ) && tree.CompareTo( "SDKROOT" ) != 0 ) { Debug.Log( "Missing file: " + filePath ); return results; } else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) { Debug.Log( "Source Root File" ); System.Uri fileURI = new System.Uri( absPath ); System.Uri rootURI = new System.Uri( ( projectRootPath + "/." ) ); filePath = rootURI.MakeRelativeUri( fileURI ).ToString(); } else if( tree.CompareTo("GROUP") == 0) { Debug.Log( "Group File" ); filePath = System.IO.Path.GetFileName( filePath ); } if( parent == null ) { parent = _rootGroup; } //Check if there is already a file PBXFileReference fileReference = GetFile( System.IO.Path.GetFileName( filePath ) ); if( fileReference != null ) { Debug.Log("File already exists: " + filePath); //not a warning, because this is normal for most builds! return null; } fileReference = new PBXFileReference( filePath, (TreeEnum)System.Enum.Parse( typeof(TreeEnum), tree ) ); parent.AddChild( fileReference ); fileReferences.Add( fileReference ); results.Add( fileReference.guid, fileReference ); //Create a build file for reference if( !string.IsNullOrEmpty( fileReference.buildPhase ) && createBuildFiles ) { switch( fileReference.buildPhase ) { case "PBXFrameworksBuildPhase": foreach( KeyValuePair<string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases ) { BuildAddFile(fileReference,currentObject,weak); } if ( !string.IsNullOrEmpty( absPath ) && ( tree.CompareTo( "SOURCE_ROOT" ) == 0 )) { string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) ); if (File.Exists(absPath)) { this.AddLibrarySearchPaths( new PBXList( libraryPath ) ); } else { this.AddFrameworkSearchPaths( new PBXList( libraryPath ) ); } } break; case "PBXResourcesBuildPhase": foreach( KeyValuePair<string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases ) { Debug.Log( "Adding Resources Build File" ); BuildAddFile(fileReference,currentObject,weak); } break; case "PBXShellScriptBuildPhase": foreach( KeyValuePair<string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases ) { Debug.Log( "Adding Script Build File" ); BuildAddFile(fileReference,currentObject,weak); } break; case "PBXSourcesBuildPhase": foreach( KeyValuePair<string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases ) { Debug.Log( "Adding Source Build File" ); BuildAddFile(fileReference,currentObject,weak); } break; case "PBXCopyFilesBuildPhase": foreach( KeyValuePair<string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases ) { Debug.Log( "Adding Copy Files Build Phase" ); BuildAddFile(fileReference,currentObject,weak); } break; case null: Debug.LogWarning( "File Not Supported: " + filePath ); break; default: Debug.LogWarning( "File Not Supported." ); return null; } } return results; }
public void TestProjectGeneration001() { // Create the document PBXDocument document = new PBXDocument(); PBXProject project = document.Project; PBXFileReference file1 = new PBXFileReference(); file1.LastKnownFileType = PBXFileType.WrapperFramework; file1.Name = "Cocoa.framework"; file1.Path = "/System/Library/Frameworks/Cocoa.framework"; file1.LastKnownFileType = PBXFileType.WrapperFramework; file1.SourceTree = PBXSourceTree.SdkRoot; PBXFileReference file2 = new PBXFileReference(); file2.LastKnownFileType = PBXFileType.WrapperFramework; file2.Name = "SurrogateTestAppDelegate.h"; file2.Path = "SurrogateTestAppDelegate.h"; file2.LastKnownFileType = PBXFileType.SourcecodeCH; file2.SourceTree = PBXSourceTree.Group; PBXFileReference file3 = new PBXFileReference(); file3.LastKnownFileType = PBXFileType.WrapperFramework; file3.Name = "en"; file3.Path = "en.lproj/MainMenu.xib"; file3.LastKnownFileType = PBXFileType.FileXib; file3.SourceTree = PBXSourceTree.Group; PBXFileReference file4 = new PBXFileReference(); file4.LastKnownFileType = PBXFileType.WrapperFramework; file4.Name = "fr"; file4.Path = "fr.lproj/MainMenu.xib"; file4.LastKnownFileType = PBXFileType.FileXib; file4.SourceTree = PBXSourceTree.Group; PBXVariantGroup variantGroup = new PBXVariantGroup("MainMenu.xib"); variantGroup.SourceTree = PBXSourceTree.Group; variantGroup.AddChild(file3); variantGroup.AddChild(file4); PBXGroup group1 = new PBXGroup("Products"); group1.SourceTree = PBXSourceTree.Group; PBXGroup group2 = new PBXGroup("Frameworks"); group2.SourceTree = PBXSourceTree.Group; group2.AddChild(file1); PBXGroup group3 = new PBXGroup("Classes"); group3.SourceTree = PBXSourceTree.Group; group3.AddChild(file2); PBXGroup group4 = new PBXGroup("Resources"); group4.SourceTree = PBXSourceTree.Group; group4.AddChild(variantGroup); PBXGroup group5 = document.Project.MainGroup; group5.SourceTree = PBXSourceTree.Group; group5.AddChild(group3); group5.AddChild(group4); group5.AddChild(group2); group5.AddChild(group1); document.Project.ProductRefGroup = group1; // Add build configuration "Release" XCBuildConfiguration releaseConfiguration = new XCBuildConfiguration(); releaseConfiguration.Name = "Release"; project.BuildConfigurationList.AddBuildConfiguration(releaseConfiguration); project.BuildConfigurationList.DefaultConfigurationName = "Release"; document.WriteToFile("project-001.pbxproj"); }
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 }
public static string AddNewFileReference(IIgorModule ModuleInst, string ProjectPath, string Filename, TreeEnum TreeBase, string Path = "", int FileEncoding = -1, string LastKnownFileType = "", string Name = "") { if (IgorAssert.EnsureTrue(ModuleInst, Directory.Exists(ProjectPath), "XCodeProj doesn't exist at path " + ProjectPath)) { XCProject CurrentProject = new XCProject(ProjectPath); CurrentProject.Backup(); foreach (KeyValuePair <string, PBXFileReference> CurrentFileRef in CurrentProject.fileReferences) { if (CurrentFileRef.Value.name == Filename) { IgorDebug.Log(ModuleInst, "The file " + Filename + " is already referenced in the XCodeProj."); return(CurrentFileRef.Value.guid); } } PBXFileReference NewFile = new PBXFileReference(Filename, TreeBase); if (Path != "") { if (NewFile.ContainsKey("path")) { NewFile.Remove("path"); } NewFile.Add("path", Path); } if (FileEncoding != -1) { if (NewFile.ContainsKey("fileEncoding")) { NewFile.Remove("fileEncoding"); } NewFile.Add("fileEncoding", FileEncoding); } if (LastKnownFileType != "") { if (NewFile.ContainsKey("lastKnownFileType")) { NewFile.Remove("lastKnownFileType"); } NewFile.Add("lastKnownFileType", LastKnownFileType); } if (Name != "") { if (NewFile.ContainsKey("name")) { NewFile.Remove("name"); } NewFile.Add("name", Name); } CurrentProject.fileReferences.Add(NewFile); IgorDebug.Log(ModuleInst, "File " + Filename + " has been added to the XCodeProj."); CurrentProject.Save(); return(NewFile.guid); } return(""); }
public PBXBuildFile(PBXFileReference fileRef, bool weak = false) : base() { this.Add(FILE_REF_KEY, fileRef.guid); SetWeakLink(weak); }
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 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 }