public static string getRelativePathTo(this string path, string basePath)
 {
     System.Uri uri1 = new System.Uri(path);
     System.Uri uri2 = new System.Uri(basePath);
     System.Uri relativeUri = uri2.MakeRelativeUri(uri1);
     return relativeUri.ToString();
 }
        static void DebugTest2()
        {
            string path1 = "/Users/Elyn/Projects/UnityPlugins/Unity Sandbox Project/Assets/Modules/GameCenter/Editor/iOS/GameCenterManager.m";
            string path2 = "/Users/Elyn/Projects/UnityPlugins/Unity Sandbox Project/XCode/.";

            System.Uri fileURI = new System.Uri( path1 );
            System.Uri rootURI = new System.Uri( path2 );
            Debug.Log( fileURI.MakeRelativeUri( rootURI ).ToString() );
            Debug.Log( rootURI.MakeRelativeUri( fileURI ).ToString() );

            //			string projectPath = Path.Combine( Directory.GetParent( Application.dataPath ).ToString(), "XCode" );

            //			string[] files = System.IO.Directory.GetFiles( projectPath, "Info.plist" );
            //			string contents = System.IO.File.OpenText( files[0] ).ReadToEnd();

            //			string[] projects = System.IO.Directory.GetDirectories( projectPath, "*.xcodeproj" );
            //			string projPath = System.IO.Path.Combine( projects[0], "project.pbxproj" );
            //			string contents = System.IO.File.OpenText( projPath ).ReadToEnd();
            //			Debug.Log( System.IO.File.OpenText( projPath ).ReadToEnd );

            //			PBXParser parser = new PBXParser();
            //			Hashtable test = (Hashtable)parser.Decode( contents );
            //			PBXDictionary test = parser.Decode( contents );
            //			Debug.Log( MiniJSON.jsonEncode( test ) );
            //			Debug.Log( test + " - " + test.Count );
            //			Debug.Log( parser.Encode( test ) );
        }
        private void SelectRDAFilesFolder(string path)
        {
            if (!System.IO.Directory.Exists(path))
            {
                MessageBox.Show(this, "The given path is not a directory.", "Error");
                return;
            }

            this.viewModel.RDAFilesFolder = path;
            System.Uri pathUri = new System.Uri(path);

            IEnumerable <string> containerPaths = System.IO.Directory.GetFiles(this.viewModel.RDAFilesFolder, @"data*.rda");

            containerPaths = AnnoRDA.Loader.ContainerDirectoryLoader.SortContainerPaths(containerPaths);
            this.viewModel.RDAFileList.Items.Clear();
            foreach (string filePath in containerPaths)
            {
                System.Uri filePathUri         = new System.Uri(filePath);
                System.Uri relativeFilePathUri = pathUri.MakeRelativeUri(filePathUri);

                this.viewModel.RDAFileList.Items.Add(new RDAFileListItem(true, filePath, relativeFilePathUri.OriginalString));
            }
        }
Beispiel #4
0
        private void DrawReferences()
        {
            if (query?.referencingPaths != null)
            {
                EditorGUILayout.BeginVertical("box");
                {
                    EditorGUILayout.LabelField("References", EditorStyles.boldLabel);

                    if (query.referencingPaths.Count == 0)
                    {
                        EditorGUILayout.LabelField("No references");
                    }
                    else
                    {
                        var currentDirectory = new System.Uri(System.Environment.CurrentDirectory + "/Assets");

                        foreach (var path in query.referencingPaths)
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                string relativePath = currentDirectory.MakeRelativeUri(new System.Uri(path)).ToString();
                                relativePath = System.Uri.UnescapeDataString(relativePath);
                                EditorGUILayout.LabelField(relativePath);

                                if (GUILayout.Button("Select", EditorStyles.miniButton, GUILayout.Width(60.0f)))
                                {
                                    Object obj = AssetDatabase.LoadAssetAtPath <Object>(relativePath);
                                    Selection.activeObject = obj;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                EditorGUILayout.EndVertical();
            }
        }
        public static System.Collections.Generic.List<string> ListAvailable(string basepath)
        {
            // instantiate
            System.Collections.Generic.List<string> availableConfigurationList = new System.Collections.Generic.List<string>();

            foreach (var cfgFile in System.IO.Directory.GetFiles(basepath, "ApollonInput.xml", System.IO.SearchOption.AllDirectories))
            {

                // get info
                System.IO.FileInfo cfgFileInfo = new System.IO.FileInfo(cfgFile);

                // build relative path

                System.Uri 
                    from = new System.Uri(cfgFileInfo.DirectoryName),
                    to   = new System.Uri(System.IO.Path.GetFullPath(basepath));

                availableConfigurationList.Add(
                    System.Uri.UnescapeDataString(
                        to.MakeRelativeUri(from).ToString()
                    )
                );

                // log
                UnityEngine.Debug.Log(
                    "<color=blue>Info: </color> ApollonExperimentExplorer.ListAvailable() : found ["
                    + System.Linq.Enumerable.Last(availableConfigurationList)
                    + "]"
                );

            } /* foreach() */

          
            // return 
            return availableConfigurationList;

        } /* ListAvailable */
Beispiel #6
0
        public PBXDictionary AddFile(string filePath, string fileName = null, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, string flag = null)
        {
            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();
            }

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

            //@since 3.9.2 Unity에서 lastKnownFileType를 text로 변경해버리는 이슈 해결
            PBXFileReference fileReference = GetFile(fileName == null ? System.IO.Path.GetFileName(filePath) : fileName);

            if (fileReference != null)
            {
//				Debug.Log( "File già presente." );
                string name = fileReference.name;
                string lastKnownFileType = fileReference.LastKnownFileType;
                string extension         = System.IO.Path.GetExtension(name);

                if (name.Equals("UIKit.framework"))
                {
                    Debug.Log("UIKit.framework");
                }

                if (extension.Equals(".tbd"))
                {
                    if (!lastKnownFileType.Equals("sourcecode.text-based-dylib-definition"))
                    {
                        Debug.Log(name + " LastKnownFileType changed");
                        fileReference.LastKnownFileType = "sourcecode.text-based-dylib-definition";
                    }
                }
                else if (extension.Equals(".mp3"))
                {
                    if (!lastKnownFileType.Equals("audio.mp3"))
                    {
                        Debug.Log(name + " LastKnownFileType changed");
                        fileReference.LastKnownFileType = "audio.mp3";
                    }
                }
                return(null);
            }

            fileReference = new PBXFileReference(filePath, fileName, (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, 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);
        }
        private void SelectRDAFilesFolder(string path)
        {
            if (!System.IO.Directory.Exists(path)) {
                MessageBox.Show(this, "The given path is not a directory.", "Error");
                return;
            }

            this.viewModel.RDAFilesFolder = path;
            System.Uri pathUri = new System.Uri(path);

            IEnumerable<string> containerPaths = System.IO.Directory.GetFiles(this.viewModel.RDAFilesFolder, @"data*.rda");
            containerPaths = AnnoRDA.Loader.ContainerDirectoryLoader.SortContainerPaths(containerPaths);
            this.viewModel.RDAFileList.Items.Clear();
            foreach (string filePath in containerPaths) {
                System.Uri filePathUri = new System.Uri(filePath);
                System.Uri relativeFilePathUri = pathUri.MakeRelativeUri(filePathUri);

                this.viewModel.RDAFileList.Items.Add(new RDAFileListItem(true, filePath, relativeFilePathUri.OriginalString));
            }
        }
Beispiel #8
0
    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
        PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath));
        if (fileReference != null)
        {
            return null;
        }

        fileReference = new PBXFileReference(filePath, (TreeEnum) System.Enum.Parse(typeof(TreeEnum), tree));
        parent.AddChild(fileReference);
        fileReferences.Add(fileReference);
        results.Add(fileReference.guid, fileReference);

        // Find test target
        PBXNativeTarget nativeTestTarget = null;
        foreach (KeyValuePair<string, PBXNativeTarget> currentObject in nativeTargets)
        {
            PBXNativeTarget nativeTargetObj = currentObject.Value;

            if (nativeTargetObj != null && nativeTargetObj.data.ContainsKey("name"))
            {
                string name = (string) nativeTargetObj.data["name"];

                if (name != null && name.Contains("Unity-iPhone Tests"))
                {
                    nativeTestTarget = nativeTargetObj;
                    break;
                }
            }
        }

        //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)
                {
                    if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                    {
                        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)
                {
                    if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                }
                break;
            case "PBXShellScriptBuildPhase":
                foreach (KeyValuePair<string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases)
                {
                    if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                }
                break;
            case "PBXSourcesBuildPhase":
                foreach (KeyValuePair<string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases)
                {
                    if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                    {
                        buildFile = new PBXBuildFile(fileReference, weak);
                        buildFiles.Add(buildFile);
                        currentObject.Value.AddBuildFile(buildFile);
                    }
                }
                break;
            case "PBXCopyFilesBuildPhase":
                foreach (KeyValuePair<string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                {
                    if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                    {
                        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;
    }
Beispiel #9
0
        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)
            {
                // zhiyuan.peng :
                // change "foler" root dir "Application.dataPath" to  "mod.path"
                // delet:
                absPath = Path.Combine(Application.dataPath, filePath);
                // add:
                // absPath = "/Users/zhiyuan.peng/Project/XUPorterTest/pp.xupemods/" + filePath;
                // end
            }

            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;
            }

            // zhiyuan.peng:
            // what a f*****g BUG!
            // code below used to check if the file reference is exsits, but olny check file name
            // file path should also be checked!
            // DELETE:
            //Check if there is already a file
//			PBXFileReference fileReference = GetFile( System.IO.Path.GetFileName( filePath ) );
//			if( fileReference != null) {
//				Debug.LogWarning(fileReference.path + "\n" + filePath + "\n" + tree);
//				Debug.LogWarning("File already exists: " + filePath); //not a warning, because this is normal for most builds!
//				return null;
//			}
            // ADD:
            //Check if there is already a file
            PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath));

            if (fileReference != null && fileReference.path.Equals(filePath))
            {
                Debug.LogWarning(fileReference.path + "\n" + filePath + "\n" + tree);
                Debug.LogWarning("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);

            //Debug.LogError("fileReference.path:"+fileReference.path+"            fileReference.buildPhase:"+fileReference.buildPhase);
            //Create a build file for reference
            if (!string.IsNullOrEmpty(fileReference.buildPhase) && createBuildFiles)
            {
                switch (fileReference.buildPhase)
                {
                case "PBXFrameworksBuildPhase":
                    //Debug.LogError("absPath:"+absPath+"tree.CompareTo( \"SOURCE_ROOT\" ) :"+tree.CompareTo( "SOURCE_ROOT" ) );
                    foreach (KeyValuePair <string, PBXFrameworksBuildPhase> currentObject in frameworkBuildPhases)
                    {
                        BuildAddFile(fileReference, currentObject, weak);
                    }
                    if (!string.IsNullOrEmpty(absPath) && (tree.CompareTo("SOURCE_ROOT") == 0))
                    {
                        string libraryPath = Path.Combine("$(PROJECT_DIR)", Path.GetDirectoryName(filePath));
                        //	Debug.LogError("libraryPath:"+libraryPath);
                        if (File.Exists(absPath))
                        {
                            this.AddLibrarySearchPaths(new PBXList(libraryPath));
                        }
                        else
                        {
                            this.AddFrameworkSearchPaths(new PBXList(libraryPath));
                        }
                    }
//						if(Path.GetExtension(fileReference.path).Equals(".tdb"))
//						{
//							string libraryPath = Path.Combine( "$(SRCROOT)", Path.GetDirectoryName( filePath ) );
//							Debug.LogError("libraryPath:"+libraryPath);
//							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);
        }
Beispiel #10
0
        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( System.IO.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 )) {
                            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 ) {
                            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;
        }
Beispiel #11
0
        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
            PBXFileReference fileReference = GetFile(System.IO.Path.GetFileName(filePath));

            if (fileReference != null)
            {
                return(null);
            }

            fileReference = new PBXFileReference(filePath, (TreeEnum)System.Enum.Parse(typeof(TreeEnum), tree));
            parent.AddChild(fileReference);
            fileReferences.Add(fileReference);
            results.Add(fileReference.guid, fileReference);

            // Find test target
            PBXNativeTarget nativeTestTarget = null;

            foreach (KeyValuePair <string, PBXNativeTarget> currentObject in nativeTargets)
            {
                PBXNativeTarget nativeTargetObj = currentObject.Value;

                if (nativeTargetObj != null && nativeTargetObj.data.ContainsKey("name"))
                {
                    string name = (string)nativeTargetObj.data["name"];

                    if (name != null && name.Contains("Unity-iPhone Tests"))
                    {
                        nativeTestTarget = nativeTargetObj;
                        break;
                    }
                }
            }

            //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)
                    {
                        if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                        {
                            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)
                    {
                        if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                        {
                            buildFile = new PBXBuildFile(fileReference, weak);
                            buildFiles.Add(buildFile);
                            currentObject.Value.AddBuildFile(buildFile);
                        }
                    }
                    break;

                case "PBXShellScriptBuildPhase":
                    foreach (KeyValuePair <string, PBXShellScriptBuildPhase> currentObject in shellScriptBuildPhases)
                    {
                        if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                        {
                            buildFile = new PBXBuildFile(fileReference, weak);
                            buildFiles.Add(buildFile);
                            currentObject.Value.AddBuildFile(buildFile);
                        }
                    }
                    break;

                case "PBXSourcesBuildPhase":
                    foreach (KeyValuePair <string, PBXSourcesBuildPhase> currentObject in sourcesBuildPhases)
                    {
                        if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                        {
                            buildFile = new PBXBuildFile(fileReference, weak);
                            buildFiles.Add(buildFile);
                            currentObject.Value.AddBuildFile(buildFile);
                        }
                    }
                    break;

                case "PBXCopyFilesBuildPhase":
                    foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                    {
                        if (nativeTestTarget == null || !nativeTestTarget.HasBuildphase(currentObject.Key.Split(' ')[0]))
                        {
                            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);
        }
Beispiel #12
0
 private static string GetRelativePath(string absolutePath, string basePath)
 {
     System.Uri absoluteUri = new System.Uri(Path.GetFullPath(absolutePath));
     System.Uri baseUri     = new System.Uri(Path.GetFullPath(basePath));
     return(System.Uri.UnescapeDataString(baseUri.MakeRelativeUri(absoluteUri).ToString()));
 }
Beispiel #13
0
//		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)
        {
//			Debug.Log ("========== Adding file " + filePath);
            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);
                        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
        }
Beispiel #14
0
		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.Replace("Assets", ""), filePath );
			}
			
			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();
			}
			
			if( parent == null ) {
				parent = _rootGroup;
			}
			
			// TODO: Aggiungere controllo se file già presente
			PBXFileReference fileReference = GetFile( System.IO.Path.GetFileName( filePath ) );	
			if( fileReference != null ) {
				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 ) && 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 );
							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;
		}
Beispiel #15
0
        public PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, string compilerFlags = null)
        {
            // Converting path to use Forward slashes
            filePath = filePath.Replace('\\', '/');

//			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 = Path.GetFileName(filePath);
            }

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

            //Check if there is already a file
            PBXFileReference fileReference = GetFile(Path.GetFileName(filePath));

            if (fileReference != null)
            {
                //Updating internal data with this call.
                fileReference.GuessFileType();
            }
            else
            {
                fileReference = new PBXFileReference(filePath, (TreeEnum)System.Enum.Parse(typeof(TreeEnum), tree));
            }

            // Adding compiler flag
            if (!string.IsNullOrEmpty(compilerFlags))
            {
                fileReference.compilerFlags = compilerFlags;
            }

            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("Build Phase Type : " + fileReference.buildPhase + " file path : " + filePath);
             *                  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":
             *          Debug.Log("PBXSourcesBuildPhase : " + fileReference.compilerFlags);
             *                                  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;
             *                  }
             *          }*/

            if (createBuildFiles)
            {
                switch (fileReference.buildPhase)
                {
                case "PBXFrameworksBuildPhase":
                    AddBuildFramework(fileReference, 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":
                    AddBuildFile(fileReference, weak);

                    break;

                case "PBXShellScriptBuildPhase":
                    AddBuildFile(fileReference, weak);

                    break;

                case "PBXSourcesBuildPhase":
                    AddBuildFile(fileReference, weak);

                    break;

                case "PBXCopyFilesBuildPhase":
                    AddBuildFile(fileReference, weak);

                    break;

                case null:
                    AddBuildFile(fileReference, weak);


                    //Debug.LogWarning("File Not Supported: " + filePath);
                    break;

                default:
                    Debug.LogWarning("File Not Supported.");
                    return(null);
                }
            }


            return(results);
        }
Beispiel #16
0
        /// <summary>
        /// 指定されたパスをソースにコンバート行う
        /// </summary>
        /// <param name="xlsxPath"></param>
        /// <param name="outputDir"></param>
        static void ImportFromXlsx(string xlsxPath, string outputDir = null)
        {
            string PATH          = xlsxPath;
            string OUTPUT_FORMAT = LanguageType.ASSET_NAME_FORMAT + ".asset";
            string OUTPUT_DIR    = outputDir;

            if (string.IsNullOrEmpty(outputDir))
            {
                OUTPUT_DIR = EditorUtility.SaveFolderPanel("Choose Output Folder", "Assets/", "Resources");
            }

            // OUTPUT_DIR: To relative path
            {
                System.Uri projectUri = new System.Uri(Path.GetFullPath("./"));
                System.Uri outputUri  = new System.Uri(OUTPUT_DIR);
                OUTPUT_DIR = projectUri.MakeRelativeUri(outputUri).ToString();
                Debug.Log(OUTPUT_DIR);
            }
            if (string.IsNullOrEmpty(OUTPUT_DIR))
            {
                return;
            }

            if (string.IsNullOrEmpty(xlsxPath) || xlsxPath.EndsWith(".xlsx") == false)
            {
                EditorUtility.DisplayDialog("Error", Path.GetFileName(xlsxPath) + " is not xlsx file", "OK");
                return;
            }

            const int COL_ID_POSITION         = 0;                              // ID値格納位置(列)※Excel上での管理用途。インポートでは使わない。
            const int COL_SYMBOL_POSITION     = 1;                              // シンボル名格納位置(列)
            const int COL_LANG_START_POSITION = 2;                              // 単語格納開始位置(列)
            const int COL_INDEX_NUM           = COL_LANG_START_POSITION - 1;    // 単語データが格納開始されるまでの列数

            const int ROW_START_DATA_POSITION = 1;                              // 単語データ格納開始行

            List <string> enumSymbols = new List <string>(128);
            List <string> defaultLang = new List <string>(128);

            System.Func <Worksheet, Row, int, Cell> ValidateCell = (sheet, row, col) =>
            {
                Cell cell = SpreadSheetUtil.GetCell(row, col);
                if (cell == null || cell.IsNullOrEmpty())
                {
                    return(null);
                }
                return(cell);
            };

            using (SpreadsheetDocument xlsx = SpreadsheetDocument.Open(PATH, false, new OpenSettings {
                AutoSave = false
            }))
            {
                WorkbookPart workbookpart = xlsx.WorkbookPart;
                Sheet        sheet        = workbookpart
                                            .Workbook
                                            .GetFirstChild <Sheets>()
                                            .Elements <Sheet>()
                                            .FirstOrDefault(s => s.Name == "List");

                WorksheetPart worksheetPart = (WorksheetPart)workbookpart.GetPartById(sheet.Id.Value);
                Worksheet     worksheet     = worksheetPart.Worksheet;

                foreach (var r in worksheet.GetFirstChild <SheetData>().Elements <Row>().Select((Value, Index) => new { Value, Index }))
                {
                    if (r.Index < ROW_START_DATA_POSITION)
                    {
                        continue;
                    }
                    Cell idCell     = ValidateCell(worksheet, r.Value, COL_ID_POSITION);
                    Cell symbolCell = ValidateCell(worksheet, r.Value, COL_SYMBOL_POSITION);

                    if (idCell == null || symbolCell == null)
                    {
                        continue;
                    }
                    enumSymbols.Add(SpreadSheetUtil.GetStringValue(workbookpart, symbolCell));
                }

                for (int langIndex = 0; langIndex < LanguageType.LANG_NUMS; langIndex++)
                {
                    Language lang  = ScriptableObject.CreateInstance <Language>();
                    bool     added = false;

                    foreach (var r in worksheet.GetFirstChild <SheetData>().Elements <Row>().Select((Value, Index) => new { Value, Index }))
                    {
                        if (r.Index < ROW_START_DATA_POSITION)
                        {
                            continue;
                        }
                        Cell idCell     = ValidateCell(worksheet, r.Value, COL_ID_POSITION);
                        Cell symbolCell = ValidateCell(worksheet, r.Value, COL_SYMBOL_POSITION);

                        if (idCell == null || symbolCell == null)
                        {
                            continue;
                        }

                        Cell   cell = SpreadSheetUtil.GetCell(r.Value, COL_LANG_START_POSITION + langIndex);
                        string word = "";

                        if (cell != null && !cell.IsNullOrEmpty())
                        {
                            word = SpreadSheetUtil.GetStringValue(workbookpart, cell);
                        }

                        lang.wordList.Add(word);

                        if (langIndex == (int)LanguageType.Language.Ja)
                        {
                            defaultLang.Add(word);
                        }

                        added = true;
                    }
                    AssetDatabase.CreateAsset(lang, Path.Combine(OUTPUT_DIR, string.Format(OUTPUT_FORMAT, LanguageType.LANG_LIST[langIndex])));
                }
            }

            GenerateIndexEnum(enumSymbols, defaultLang);
            AssetDatabase.Refresh();
            EditorUtility.DisplayDialog("Import", "Done.", "OK");
        }
 public static string GetProjectRelativePath(string path)
 {
     System.Uri pathUri     = new System.Uri(path, System.UriKind.Absolute);
     System.Uri dataPathUri = new System.Uri(Application.dataPath, System.UriKind.Absolute);
     return(dataPathUri.MakeRelativeUri(pathUri).ToString());
 }
Beispiel #18
0
        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.Replace("Assets", ""), filePath);
            }

            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();
            }


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

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

            if (fileReference != null)
            {
                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) && File.Exists(absPath) && tree.CompareTo("SOURCE_ROOT") == 0)
                    {
                        //CustomDebug.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);
                        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);
        }
Beispiel #19
0
        public bool AddFolder(string folderPath, PBXGroup parent = null, string[] exclude = null, bool recursive = true, bool createBuildFile = true, string flag = null)
        {
            if (!Directory.Exists(folderPath))
            {
                return(false);
            }
            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(folderPath);

            if (exclude == null)
            {
                exclude = new string[] { }
            }
            ;
            string regexExclude = string.Format(@"{0}", string.Join("|", exclude));

            //PBXDictionary results = new PBXDictionary();

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

            // Create group
            PBXGroup newGroup = GetGroup(sourceDirectoryInfo.Name, null /*relative path*/, parent);

//			groups.Add( newGroup );

            foreach (string directory in Directory.GetDirectories(folderPath))
            {
                if (Regex.IsMatch(directory, regexExclude))
                {
                    continue;
                }

                //@since 3.9.2 localization
                if (directory.EndsWith("language"))
                {
                    sourceDirectoryInfo = new DirectoryInfo(directory);
                    System.Uri fileURI  = new System.Uri(directory);
                    System.Uri rootURI  = new System.Uri((projectRootPath + "/."));
                    string     filePath = rootURI.MakeRelativeUri(fileURI).ToString();
                    AddLocalization(directory, GetGroup(sourceDirectoryInfo.Name, filePath, newGroup, "<group>"));
                    continue;
                }
                else
                {
                    if (directory.EndsWith(".bundle"))
                    {
                        // Treath it like a file and copy even if not recursive
//                      Debug.LogWarning( "This is a special folder: " + directory );
                        AddFile(directory, null, newGroup, "SOURCE_ROOT", createBuildFile, false, flag);
                        continue;
                    }

                    if (recursive)
                    {
//                      Debug.Log( "recursive" );
                        AddFolder(directory, newGroup, exclude, recursive, createBuildFile, flag);
                    }
                }
            }
            // Adding files.
            foreach (string file in Directory.GetFiles(folderPath))
            {
                if (Regex.IsMatch(file, regexExclude))
                {
                    continue;
                }
                //Debug.Log( "--> " + file + ", " + newGroup );
                AddFile(file, null, newGroup, "SOURCE_ROOT", createBuildFile, false, flag);
            }

            modified = true;
            return(modified);
        }
Beispiel #20
0
        // We support neither recursing into nor bundles contained inside loc folders
        public bool AddLocFolder( string folderPath, PBXGroup parent = null, string[] exclude = null, bool createBuildFile = true)
        {
            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo( folderPath );

            if( exclude == null )
                exclude = new string[] {};

            if( parent == null )
                parent = rootGroup;

            // Create group as needed
            System.Uri projectFolderURI = new System.Uri( projectFileInfo.DirectoryName );
            System.Uri locFolderURI = new System.Uri( folderPath );
            var relativePath = projectFolderURI.MakeRelativeUri( locFolderURI ).ToString();
            PBXGroup newGroup = GetGroup( sourceDirectoryInfo.Name, relativePath, parent );

            // Add loc region to project
            string nom = sourceDirectoryInfo.Name;
            string region = nom.Substring(0, nom.Length - ".lproj".Length);
            project.AddRegion(region);

            // Adding files.
            string regexExclude = string.Format( @"{0}", string.Join( "|", exclude ) );
            foreach( string file in Directory.GetFiles( folderPath ) ) {
                if( Regex.IsMatch( file, regexExclude ) ) {
                    continue;
                }

                // Add a variant group for the language as well
                var variant = new PBXVariantGroup(System.IO.Path.GetFileName( file ), null, "GROUP");
                variantGroups.Add(variant);

                // The group gets a reference to the variant, not to the file itself
                newGroup.AddChild(variant);

                AddFile( file, variant, "GROUP", createBuildFile );
            }

            modified = true;
            return modified;
        }
		public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, string compilerFlags = null)
		{
			//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 = Path.GetFileName( filePath );
			}

			if( parent == null ) {
				parent = _rootGroup;
			}
			
			//Check if there is already a file
			PBXFileReference fileReference = GetFile( Path.GetFileName( filePath ) );	
			if( fileReference != null ) 
			{
				//Updating internal data with this call.
				fileReference.GuessFileType();	
			}
			else
			{
				fileReference = new PBXFileReference( filePath, (TreeEnum)System.Enum.Parse( typeof(TreeEnum), tree ) );
			}

			// Adding compiler flag
			if (!string.IsNullOrEmpty(compilerFlags))
			{
				fileReference.compilerFlags	= compilerFlags;
			}

			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 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 )
		{
			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 );
							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
		}
Beispiel #23
0
 public IUri MakeRelativeUri(IUri uri) => new Uri(Inner.MakeRelativeUri(((Uri)uri).Inner));
Beispiel #24
0
        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 PBXDictionary AddFile(string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false, bool embed = 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.Replace("Assets", ""), filePath);
            }

            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();
            }

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

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

            if (fileReference != null)
            {
                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) && 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));
                    }

                    if (embed)
                    {
                        string ldRuntimePath = "$(inherited) @executable_path/Frameworks";
                        this.AddLDRuntimeSearchPaths(ldRuntimePath);

                        const string embedFrameworksName = "Embed Frameworks";

                        //Create a new copyBuildPhase for the embed framework
                        KeyValuePair <string, PBXCopyFilesBuildPhase>?copyPhaseKeyValue = null;
                        foreach (KeyValuePair <string, PBXCopyFilesBuildPhase> currentObject in copyBuildPhases)
                        {
                            // Search for a build phase named "Embed Frameworks".
                            // Unity 2019.3 adds one because of the new Unity as a Library
                            // project structure.
                            if (currentObject.Value.data.ContainsKey("name") &&
                                string.CompareOrdinal(currentObject.Value.data["name"] is string?(string)currentObject.Value.data["name"] : string.Empty, embedFrameworksName) == 0)
                            {
                                copyPhaseKeyValue = currentObject;
                                break;
                            }
                        }

                        // Didn't find a pre-existing "Embed Frameworks" build phase.
                        // We're likely on Unity 2019.2 or earlier, when Unity
                        // used to make an XCode project that had only a single build target.
                        if (!copyPhaseKeyValue.HasValue)
                        {
                            copyPhaseKeyValue = copyBuildPhases.Last();
                        }

                        buildFile = new PBXBuildFile(fileReference, weak, true);
                        buildFiles.Add(buildFile);

                        var embedFrameworksBuildPhase = copyPhaseKeyValue.Value.Value;
                        embedFrameworksBuildPhase.data["name"]             = embedFrameworksName;
                        embedFrameworksBuildPhase.data["dstSubfolderSpec"] = 10;
                        embedFrameworksBuildPhase.AddBuildFile(buildFile);

                        // This will add the "Code Sign On Copy" setting for the embedded framework
                        buildFile.SetEmbed(true);
                    }

                    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);
        }