public bool AddBuildFile( PBXBuildFile file )
		{
			if( !ContainsKey( FILES_KEY ) ){
				this.Add( FILES_KEY, new PBXList() );
			}
			((PBXList)_data[ FILES_KEY ]).Add( file.guid );
			
			return true;
		}
Пример #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);
        }
        public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, string[] compilerFlags = null)
        {
            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 + "/."));

                try {
                    filePath = rootURI.MakeRelativeUri(fileURI).ToString();
                } catch (UriFormatException exception) {
                    Debug.LogWarning(string.Format("Cannot create relative URI for path: {0}, error: {1}", filePath, exception));
                    absPath = filePath;
                }
            }

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

            // TODO: Aggiungere controllo se file già presente
            String filename = System.IO.Path.GetFileName(filePath);

            if (filename.Contains("+"))
            {
                filename = string.Format("\"{0}\"", filename);
            }

            PBXFileReference fileReference = GetFile(filename);

            if (fileReference != null)
            {
                //Weak references always taks precedence over strong reference
                if (weak)
                {
                    PBXBuildFile buildFile = GetBuildFile(fileReference.guid);
                    if (buildFile != null)
                    {
                        buildFile.SetWeakLink(weak);
                    }
                }

                // Dear future me: If they ever invent a time machine, please don't come back in time to hunt me down.
                // From Unity 5, AdSupport is loaded dinamically, meaning that there will be a reference to the
                // file in the project and it won't add it to the linking libraries. And we need that.
                // TODO: The correct solution would be to check inside each phase if that file is already present.
                if (filename.Contains("AdSupport.framework"))
                {
                    if (string.IsNullOrEmpty(fileReference.buildPhase))
                    {
                        fileReference.buildPhase = "PBXFrameworksBuildPhase";
                    }
                }
                else
                {
                    return(null);
                }
            }

            if (fileReference == null)
            {
                if (tree.CompareTo("SOURCE_ROOT") == 0)
                {
                    System.Uri projectRootURI = new System.Uri(Application.dataPath);
                    System.Uri fileURI        = new System.Uri(absPath);
                    String     relativePath   = projectRootURI.MakeRelativeUri(fileURI).ToString();
                    String     newFilePath    = Path.Combine(projectRootPath, relativePath);

                    Directory.CreateDirectory(Path.GetDirectoryName(newFilePath));
                    File.Copy(absPath, newFilePath);

                    filePath = relativePath;
                }

                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)
                    {
                        PBXBuildFile newBuildFile = GetBuildFile(fileReference.guid);
                        if (newBuildFile == null)
                        {
                            newBuildFile = new PBXBuildFile(fileReference, weak);
                            buildFiles.Add(newBuildFile);
                        }

                        if (currentObject.Value.HasBuildFile(newBuildFile.guid))
                        {
                            continue;
                        }
                        currentObject.Value.AddBuildFile(newBuildFile);
                    }
                    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);
                        foreach (string flag in compilerFlags)
                        {
                            buildFile.AddCompilerFlag(flag);
                        }
                        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("null value for build phase is not supported");
                    break;

                default:
                    Debug.LogWarning("default value for build phase is not supported");
                    return(null);
                }
            }

            return(results);
        }
Пример #4
0
		public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, string[] compilerFlags = null )
		{
			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);
			if (filename.Contains("+")) {
				filename = string.Format ("\"{0}\"", filename);
			}

			PBXFileReference fileReference = GetFile(filename); 

			if (fileReference != null) {
				//Weak references always taks precedence over strong reference
                if (weak) {
					PBXBuildFile buildFile = GetBuildFile(fileReference.guid);
					if(buildFile != null) {
						buildFile.SetWeakLink(weak);
					}
				}
				// Dear future me: If they ever invent a time machine, please don't come back in time to hunt me down.
				// From Unity 5, AdSupport is loaded dinamically, meaning that there will be a reference to the
				// file in the project and it won't add it to the linking libraries. And we need that.
				// TODO: The correct solution would be to check inside each phase if that file is already present.
				if (filename.Contains("AdSupport.framework")) {
					if (string.IsNullOrEmpty(fileReference.buildPhase)) {
						fileReference.buildPhase = "PBXFrameworksBuildPhase";
					}
				} else {
					return null;
				}

			}

			if (fileReference == 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 ) {
							PBXBuildFile newBuildFile = GetBuildFile(fileReference.guid);
							if (newBuildFile == null){
								newBuildFile = new PBXBuildFile( fileReference, weak );
								buildFiles.Add( newBuildFile );
							}

							if (currentObject.Value.HasBuildFile(newBuildFile.guid)) {
								continue;
							}
							currentObject.Value.AddBuildFile( newBuildFile );

						}
						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 );
							foreach (string flag in compilerFlags) {
								buildFile.AddCompilerFlag(flag);
							}
							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;
			
		}