public PBXNativeTarget GetUnityNativeTarget()
        {
            string name = "Unity-iPhone";

#if UNITY_2019_3_OR_NEWER
            name = "UnityFramework";
#endif

            PBXNativeTarget naviTarget = null;
            foreach (KeyValuePair <string, PBXNativeTarget> currentObject in nativeTargets)
            {
                string targetName = (string)currentObject.Value.data["name"];
                if (targetName == name)
                {
                    naviTarget = currentObject.Value;
                    break;
                }
            }
            return(naviTarget);
        }
Exemple #2
0
        public string ResolveName(string guid)
        {
            if (!this.objects.ContainsKey(guid))
            {
                Debug.LogWarning(this + " ResolveName could not resolve " + guid);
                return(string.Empty);                //"UNRESOLVED GUID:" + guid;
            }

            object entity = this.objects[guid];

            if (entity is PBXBuildFile)
            {
                return(ResolveName(((PBXBuildFile)entity).fileRef));
            }
            else if (entity is PBXFileReference)
            {
                PBXFileReference casted = (PBXFileReference)entity;
                return(casted.name != null ? casted.name : casted.path);
            }
            else if (entity is PBXGroup)
            {
                PBXGroup casted = (PBXGroup)entity;
                return(casted.name != null ? casted.name : casted.path);
            }
            else if (entity is PBXProject || guid == this.rootObject)
            {
                return("Project object");
            }
            else if (entity is PBXFrameworksBuildPhase)
            {
                return("Frameworks");
            }
            else if (entity is PBXResourcesBuildPhase)
            {
                return("Resources");
            }
            else if (entity is PBXShellScriptBuildPhase)
            {
                return("ShellScript");
            }
            else if (entity is PBXSourcesBuildPhase)
            {
                return("Sources");
            }
            else if (entity is PBXCopyFilesBuildPhase)
            {
                return("CopyFiles");
            }
            else if (entity is XCConfigurationList)
            {
                XCConfigurationList casted = (XCConfigurationList)entity;
                //Debug.LogWarning ("XCConfigurationList " + guid + " " + casted.ToString());

                if (casted.data.ContainsKey("defaultConfigurationName"))
                {
                    //Debug.Log ("XCConfigurationList " + (string)casted.data[ "defaultConfigurationName" ] + " " + guid);
                    return((string)casted.data["defaultConfigurationName"]);
                }

                return(null);
            }
            else if (entity is PBXNativeTarget)
            {
                PBXNativeTarget obj = (PBXNativeTarget)entity;
                //Debug.LogWarning ("PBXNativeTarget " + guid + " " + obj.ToString());

                if (obj.data.ContainsKey("name"))
                {
                    //Debug.Log ("PBXNativeTarget " + (string)obj.data[ "name" ] + " " + guid);
                    return((string)obj.data["name"]);
                }

                return(null);
            }
            else if (entity is XCBuildConfiguration)
            {
                XCBuildConfiguration obj = (XCBuildConfiguration)entity;
                //Debug.LogWarning ("XCBuildConfiguration UNRESOLVED GUID:" + guid + " " + (obj==null?"":obj.ToString()));

                if (obj.data.ContainsKey("name"))
                {
                    //Debug.Log ("XCBuildConfiguration " + (string)obj.data[ "name" ] + " " + guid + " " + (obj==null?"":obj.ToString()));
                    return((string)obj.data["name"]);
                }
            }
            else if (entity is PBXObject)
            {
                PBXObject obj = (PBXObject)entity;

                if (obj.data.ContainsKey("name"))
                {
                    Debug.Log("PBXObject " + (string)obj.data["name"] + " " + guid + " " + (obj == null?"":obj.ToString()));
                }
                return((string)obj.data["name"]);
            }

            //return "UNRESOLVED GUID:" + guid;
            Debug.LogWarning("UNRESOLVED GUID:" + guid);
            return(null);
        }
        public XCProject(string filePath) : this()
        {
            if (!Directory.Exists(filePath))
            {
                Debug.LogWarning("XCode project path does not exist: " + filePath);
                return;
            }

            if (filePath.EndsWith(".xcodeproj"))
            {
//				Debug.Log( "Opening project " + filePath );
                this.projectRootPath = Path.GetDirectoryName(filePath);
                this.filePath        = filePath;
            }
            else
            {
//				Debug.Log( "Looking for xcodeproj files in " + filePath );
                string[] projects = Directory.GetDirectories(filePath, "*.xcodeproj");
                if (projects.Length == 0)
                {
                    Debug.LogWarning("Error: missing xcodeproj file");
                    return;
                }

                this.projectRootPath = filePath;
                //if the path is relative to the project, we need to make it absolute
                if (!Path.IsPathRooted(projectRootPath))
                {
                    projectRootPath = Application.dataPath.Replace("Assets", "") + projectRootPath;
                }
//				Debug.Log ("projectRootPath adjusted to " + projectRootPath);
                this.filePath = projects[0];
            }

            projectFileInfo = new FileInfo(Path.Combine(this.filePath, "project.pbxproj"));

            StreamReader streamReader = projectFileInfo.OpenText();
            string       contents     = streamReader.ReadToEnd();

            streamReader.Close();


            // Get xcode project
            xcodeProject = GetXcodeProject(filePath);
            targetGUID   = GetUnityTargetGUID();


            PBXParser parser = new PBXParser();

            _datastore = parser.Decode(contents);
            if (_datastore == null)
            {
                throw new System.Exception("Project file not found at file path " + filePath);
            }

            if (!_datastore.ContainsKey("objects"))
            {
                Debug.Log("Error " + _datastore.Count);
                return;
            }

            _objects = (PBXDictionary)_datastore["objects"];
            modified = false;

            _rootObjectKey = (string)_datastore["rootObject"];
            if (!string.IsNullOrEmpty(_rootObjectKey))
            {
                _project   = new PBXProject(_rootObjectKey, (PBXDictionary)_objects[_rootObjectKey]);
                _rootGroup = new PBXGroup(_rootObjectKey, (PBXDictionary)_objects[_project.mainGroupID]);

                PBXNativeTarget _unityNativeTarget = GetUnityNativeTarget();
                _targetBuildPhases = (PBXList)_unityNativeTarget.data["buildPhases"];
            }
            else
            {
                Debug.LogWarning("error: project has no root object");
                _project   = null;
                _rootGroup = null;
            }
        }