public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false) { PBXDictionary results = new PBXDictionary(); string absPath = string.Empty; if (Path.IsPathRooted(filePath)) { 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) { System.Uri fileURI = new System.Uri(absPath); System.Uri rootURI = new System.Uri((projectRootPath + "/.")); filePath = rootURI.MakeRelativeUri(fileURI).ToString(); } if (parent == null) { parent = _rootGroup; } //Check if there is already a file PBXFileReference fileReference = GetFile(Path.GetFileName(filePath)); if (fileReference != null) { Debug.LogWarning("File is already exists: " + filePath); 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) && File.Exists(absPath)) { string libraryPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath)); AddLibrarySearchPaths(new PBXList(libraryPath)); } break; case "PBXResourcesBuildPhase": foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases) { BuildAddFile(fileReference, currentObject, weak); } break; case "PBXShellScriptBuildPhase": foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases) { BuildAddFile(fileReference, currentObject, weak); } break; case "PBXSourcesBuildPhase": foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases) { BuildAddFile(fileReference, currentObject, weak); } break; case "PBXCopyFilesBuildPhase": foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases) { BuildAddFile(fileReference, currentObject, weak); } break; case null: Debug.LogWarning("File Not Support: " + filePath); break; default: Debug.LogWarning("File Not Support."); return(null); } } return(results); }
// public PBXDictionary<PBXBuildPhase> GetBuildPhase( string buildPhase ) // { // switch( buildPhase ) { // case "PBXFrameworksBuildPhase": // return (PBXDictionary<PBXBuildPhase>)frameworkBuildPhases; // case "PBXResourcesBuildPhase": // return (PBXDictionary<PBXBuildPhase>)resourcesBuildPhases; // case "PBXShellScriptBuildPhase": // return (PBXDictionary<PBXBuildPhase>)shellScriptBuildPhases; // case "PBXSourcesBuildPhase": // return (PBXDictionary<PBXBuildPhase>)sourcesBuildPhases; // case "PBXCopyFilesBuildPhase": // return (PBXDictionary<PBXBuildPhase>)copyBuildPhases; // default: // return default(T); // } // } public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, string compileFlag = " ") { PBXDictionary results = new PBXDictionary(); string absPath = string.Empty; if (Path.IsPathRooted(filePath)) { absPath = filePath; // Debug.Log( "Is rooted: " + absPath ); } else if (tree.CompareTo("SDKROOT") != 0) { absPath = Path.Combine(Application.dataPath.Replace("Assets", ""), filePath); // Debug.Log( "RElative: " + absPath ); } if (!(File.Exists(absPath) || Directory.Exists(absPath)) && tree.CompareTo("SDKROOT") != 0) { Debug.Log("Missing file: " + absPath + " > " + filePath); return(results); } else if (tree.CompareTo("SOURCE_ROOT") == 0 || tree.CompareTo("GROUP") == 0) { System.Uri fileURI = new System.Uri(absPath); System.Uri rootURI = new System.Uri((projectRootPath + "/.")); filePath = rootURI.MakeRelativeUri(fileURI).ToString(); } // else { // tree = "<absolute>"; // Debug.Log( "3: " + filePath ); // } // Debug.Log( "Add file result path: " + filePath ); if (parent == null) { parent = _rootGroup; } // TODO: Aggiungere controllo se file già presente PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath)); if (fileReference != null) { // Debug.Log( "File già presente." ); 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) { // PBXDictionary<PBXBuildPhase> currentPhase = GetBuildPhase( fileReference.buildPhase ); PBXBuildFile buildFile; switch (fileReference.buildPhase) { case "PBXFrameworksBuildPhase": foreach (KeyValuePair <string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } if (!string.IsNullOrEmpty(absPath) && File.Exists(absPath) && tree.CompareTo("SOURCE_ROOT") == 0) { //Debug.LogError(absPath); string libraryPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath)); this.AddLibrarySearchPaths(new PBXList(libraryPath)); } else if (!string.IsNullOrEmpty(absPath) && Directory.Exists(absPath) && absPath.EndsWith(".framework") && tree.CompareTo("GROUP") == 0) // Annt: Add framework search path for FacebookSDK { string frameworkPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath)); this.AddFrameworkSearchPaths(new PBXList(frameworkPath)); } break; case "PBXResourcesBuildPhase": foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case "PBXShellScriptBuildPhase": foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case "PBXSourcesBuildPhase": foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); //add by suyuancheng if (!compileFlag.Equals(" ")) { buildFile.AddCompilerFlag(compileFlag); } buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case "PBXCopyFilesBuildPhase": foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case null: Debug.LogWarning("fase non supportata null"); break; default: Debug.LogWarning("fase non supportata def"); return(null); } } // Debug.Log( "Results " + results.Count + " - " ); // foreach( KeyValuePair<string, object> obj in results ){ // Debug.Log( obj.Key + " - " + obj.Value.GetType().Name ); // } return(results); // def add_file(self, f_path, parent=None, tree='SOURCE_ROOT', create_build_files=True, weak=False): // results = [] // // abs_path = '' // // if os.path.isabs(f_path): // abs_path = f_path // // if not os.path.exists(f_path): // return results // elif tree == 'SOURCE_ROOT': // f_path = os.path.relpath(f_path, self.source_root) // else: // tree = '<absolute>' // // if not parent: // parent = self.root_group // elif not isinstance(parent, PBXGroup): // # assume it's an id // parent = self.objects.get(parent, self.root_group) // // file_ref = PBXFileReference.Create(f_path, tree) // parent.add_child(file_ref) // results.append(file_ref) // # create a build file for the file ref // if file_ref.build_phase and create_build_files: // phases = self.get_build_phases(file_ref.build_phase) // // for phase in phases: // build_file = PBXBuildFile.Create(file_ref, weak=weak) // // phase.add_build_file(build_file) // results.append(build_file) // // if abs_path and tree == 'SOURCE_ROOT' and os.path.isfile(abs_path)\ // and file_ref.build_phase == 'PBXFrameworksBuildPhase': // // library_path = os.path.join('$(SRCROOT)', os.path.split(f_path)[0]) // // self.add_library_search_paths([library_path], recursive=False) // // for r in results: // self.objects[r.id] = r // // if results: // self.modified = True // // return results }
public PBXDictionary AddFile( string filePath, string compilerFlags ,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( filePath + " Path is Rooted" ); absPath = filePath; } else if( tree.CompareTo( "SDKROOT" ) != 0) { absPath = Path.Combine( Application.dataPath, filePath ); } Debug.Log ("XCProject AddFile absPath: " + absPath); if( !( File.Exists( absPath ) || Directory.Exists( absPath ) ) && tree.CompareTo( "SDKROOT" ) != 0 ) { Debug.Log( "XCProject AddFile Missing file: " + filePath ); return results; } else if( tree.CompareTo( "SOURCE_ROOT" ) == 0 ) { Debug.Log( "XCProject AddFile 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( "XCProject AddFile Group File" ); filePath = System.IO.Path.GetFileName( filePath ); } if( parent == null ) { parent = _rootGroup; } Debug.Log ("XCProject AddFile filePath1 : " + filePath); //Check if there is already a file string fileName = System.IO.Path.GetFileName( filePath ); Debug.Log ("XCProject AddFile filePath2 : " + filePath); PBXFileReference fileReference = GetFile(fileName); if( fileReference != null ) { Debug.Log("File already exists: " + filePath); //not a warning, because this is normal for most builds! if (System.IO.Path.GetExtension(filePath) == ".mm") { DetachRefFile(fileName); } else { return null; } } fileReference = new PBXFileReference( filePath, (TreeEnum)System.Enum.Parse( typeof(TreeEnum), tree ) ) { compilerFlags = compilerFlags }; Debug.Log("fileReference: " + fileReference.path); parent.AddChild( fileReference ); fileReferences.Add( fileReference ); results.Add( fileReference.guid, fileReference ); //Create a build file for reference if( !string.IsNullOrEmpty( fileReference.buildPhase ) && createBuildFiles ) { Debug.Log("XCProject AddFile 3" + fileReference.buildPhase); 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 PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false) { PBXDictionary results = new PBXDictionary(); string absPath = string.Empty; if (Path.IsPathRooted(filePath)) { absPath = filePath; } else if (tree.CompareTo("SDKROOT") != 0) { absPath = Path.Combine(Application.dataPath, filePath); } if (tree.CompareTo("SOURCE_ROOT") == 0) { System.Uri fileURI = new System.Uri(absPath); System.Uri rootURI = new System.Uri((projectRootPath + "/.")); filePath = rootURI.MakeRelativeUri(fileURI).ToString(); } if (parent == null) { parent = _rootGroup; } // TODO: Aggiungere controllo se file già presente String filename = System.IO.Path.GetFileName(filePath); PBXFileReference fileReference = GetFile(filename); if (fileReference != null) { //Srong reference always taks precedence over weak reference if (!weak) { PBXBuildFile buildFile = GetBuildFile(fileReference.guid); if (buildFile != null) { buildFile.SetWeakLink(weak); } } 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) { PBXBuildFile buildFile; switch (fileReference.buildPhase) { case "PBXFrameworksBuildPhase": foreach (KeyValuePair <string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } if (!string.IsNullOrEmpty(absPath) && (tree.CompareTo("SOURCE_ROOT") == 0) && File.Exists(absPath)) { string libraryPath = Path.Combine("$(SRCROOT)", Path.GetDirectoryName(filePath)); this.AddLibrarySearchPaths(new PBXList(libraryPath)); } break; case "PBXResourcesBuildPhase": foreach (KeyValuePair <string, PBXResourcesBuildPhase> currentObject in resourcesBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case "PBXShellScriptBuildPhase": foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case "PBXSourcesBuildPhase": foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case "PBXCopyFilesBuildPhase": foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases) { buildFile = new PBXBuildFile(fileReference, weak); buildFiles.Add(buildFile); currentObject.Value.AddBuildFile(buildFile); } break; case null: Debug.LogWarning("fase non supportata null"); break; default: Debug.LogWarning("fase non supportata def"); return(null); } } return(results); }