Example #1
0
        public void visitAddSystemTargetTeamID(string teamid)
        {
            if (weakProject == null)
            {
                Debug.Log("weakProject must not be null");
                return;
            }

            PBXDictionary _Attributes       = (PBXDictionary)weakProject.data ["attributes"];
            PBXDictionary _TargetAttributes = (PBXDictionary)_Attributes ["TargetAttributes"];
            PBXList       _targets          = (PBXList)weakProject.data ["targets"];
            PBXDictionary targetDict        = null;

            if (_TargetAttributes.ContainsKey((string)_targets [0]))
            {
                targetDict = (PBXDictionary)_TargetAttributes [(string)_targets [0]];
            }
            else
            {
                //不会发生
                //return;
                targetDict = new PBXDictionary();
            }

            if (targetDict != null && targetDict.ContainsKey("DevelopmentTeam"))
            {
                targetDict.Remove("DevelopmentTeam");
            }
            targetDict.Add("DevelopmentTeam", teamid);

            if (!_TargetAttributes.ContainsKey((string)_targets [0]))
            {
                _TargetAttributes.Add((string)_targets [0], targetDict);
            }
        }
        public void visitAddSystemCapabilities(XCProjectSystemCapabilitiesType type, bool enabled)
        {
            if (weakProject == null)
            {
                Debug.Log("weakProject must not be null");
                return;
            }
            string destributeType = getEnumType(type);

            Debug.Log("Add System Capabilities " + destributeType);

            PBXDictionary _Attributes       = (PBXDictionary)weakProject.data ["attributes"];
            PBXDictionary _TargetAttributes = (PBXDictionary)_Attributes ["TargetAttributes"];
            PBXList       _targets          = (PBXList)weakProject.data ["targets"];
            PBXDictionary targetDict        = null;

            if (_TargetAttributes.ContainsKey((string)_targets [0]))
            {
                targetDict = (PBXDictionary)_TargetAttributes [(string)_targets [0]];
            }
            else
            {
                //不会发生
                //return;
                targetDict = new PBXDictionary();
            }
            //			Debug.Log ("targetDict:" + targetDict);

            PBXDictionary SystemCapabilities = null;

            if (targetDict != null && targetDict.ContainsKey("SystemCapabilities"))
            {
                //				Debug.Log ("xxxxxxxxxxxxxxxxxxx");
                SystemCapabilities = (PBXDictionary)targetDict ["SystemCapabilities"];
            }
            else
            {
                SystemCapabilities = new PBXDictionary();
            }

            Debug.Log("before SystemCapabilities:" + SystemCapabilities);
            if (SystemCapabilities != null && SystemCapabilities.ContainsKey(destributeType))
            {
                SystemCapabilities.Remove(destributeType);
            }
            Debug.Log("after SystemCapabilities:" + SystemCapabilities);
            PBXDictionary enableDict = new PBXDictionary();

            enableDict.Add("enabled", enabled?"1":"0");
            SystemCapabilities.Add(destributeType, enableDict);

            if (!targetDict.ContainsKey("SystemCapabilities"))
            {
                targetDict.Add("SystemCapabilities", SystemCapabilities);
            }
            if (!_TargetAttributes.ContainsKey((string)_targets [0]))
            {
                _TargetAttributes.Add((string)_targets [0], targetDict);
            }
        }
Example #3
0
        public PBXBuildFile(string guid, PBXDictionary dictionary) : base(guid, dictionary)
        {
            if (!this.data.ContainsKey(SETTINGS_KEY))
            {
                return;
            }
            object settingsObj = this.data[SETTINGS_KEY];

            if (!(settingsObj is PBXDictionary))
            {
                return;
            }
            PBXDictionary settingsDict = (PBXDictionary)settingsObj;

            settingsDict.internalNewlines = false;

            if (!settingsDict.ContainsKey(ATTRIBUTES_KEY))
            {
                return;
            }
            object attributesObj = settingsDict[ATTRIBUTES_KEY];

            if (!(attributesObj is PBXList))
            {
                return;
            }

            PBXList attributesCast = (PBXList)attributesObj;

            attributesCast.internalNewlines = false;
        }
Example #4
0
        void SetSystemAttributeValue(string attrName, int value)
        {
            string TargetAttrKey = "TargetAttributes";

            if (attributes.ContainsKey(TargetAttrKey))
            {
                PBXDictionary targetAttrs = (PBXDictionary)attributes[TargetAttrKey];

                foreach (object target in targets)
                {
                    string id = target.ToString();
                    if (!targetAttrs.ContainsKey(id))
                    {
                        PBXDictionary targetAttr = new PBXDictionary();
                        targetAttr["SystemCapabilities"] = new PBXDictionary();
                        targetAttrs[id] = targetAttr;
                    }
                }

                PBXDictionary.ValueCollection.Enumerator it = targetAttrs.Values.GetEnumerator();
                while (it.MoveNext())
                {
                    PBXDictionary subAttrs = it.Current as PBXDictionary;
                    if (subAttrs != null && subAttrs.ContainsKey("SystemCapabilities"))
                    {
                        PBXDictionary capabilities = (PBXDictionary)subAttrs["SystemCapabilities"];
                        PBXDictionary attrValue    = new PBXDictionary();
                        attrValue["enabled"]   = value;
                        capabilities[attrName] = attrValue;
                    }
                }
            }
        }
Example #5
0
        public XCProject(string filePath) : this()
        {
            if (!Directory.Exists(filePath))
            {
                Debug.LogWarning("Path does not exists.");
                return;
            }
            if (filePath.EndsWith(".xcodeproj"))
            {
                Debug.Log("Opening project " + filePath);
                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;
                this.filePath        = projects[0];
            }

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

            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("Errore " + _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]);
            }
            else
            {
                Debug.LogWarning("error: project has no root object");
                _project   = null;
                _rootGroup = null;
            }
        }
Example #6
0
        public PBXObject(string guid, PBXDictionary dictionary) : this( guid )
        {
            if (!dictionary.ContainsKey(ISA_KEY) || ((string)dictionary[ISA_KEY]).CompareTo(this.GetType().Name) != 0)
            {
                Debug.LogError("PBXDictionary is not a valid ISA object");
            }

            foreach (KeyValuePair <string, object> item in dictionary)
            {
                _data[item.Key] = item.Value;
            }
        }
Example #7
0
//		private T Convert<T>( PBXDictionary dictionary )
//		{
//			if( dictionary.ContainsKey( "isa" ) ){
////				((string)dictionary["isa"]).CompareTo(
//				Type targetType = Type.GetType( (string)dictionary["isa"] );
//				if( targetType.IsSubclassOf( typeof(PBXObject) ) ) {
//					Debug.Log( "ok" );
//					T converted = (T)Activator.CreateInstance( targetType );
//					return converted;
//				}
//				else {
//					Debug.Log( "Warning: unknown PBX type: " + targetType.Name );
//					return default(T);
//				}
//
//			}
//			return default(T);
//
//		}

        private PBXDictionary ParseDictionary()
        {
            SkipWhitespaces();
            PBXDictionary dictionary  = new PBXDictionary();
            string        keyString   = string.Empty;
            object        valueObject = null;

            bool complete = false;

            while (!complete)
            {
                switch (NextToken())
                {
                case END_OF_FILE:
                    CustomDebug.Log("Error: reached end of file inside a dictionary: " + index);
                    complete = true;
                    break;

                case DICTIONARY_ITEM_DELIMITER_TOKEN:
                    keyString   = string.Empty;
                    valueObject = null;
                    break;

                case DICTIONARY_END_TOKEN:
                    keyString   = string.Empty;
                    valueObject = null;
                    complete    = true;
                    break;

                case DICTIONARY_ASSIGN_TOKEN:
                    if (!dictionary.ContainsKey(keyString))
                    {
                        valueObject = ParseValue();
                        dictionary.Add(keyString, valueObject);
                    }
                    else
                    {
                        CustomDebug.LogError("ParseDictionary , keys allready exist = " + keyString);
                    }
                    break;

                default:
                    StepBackward();
                    keyString = ParseValue() as string;
                    break;
                }
            }
            return(dictionary);
        }
Example #8
0
        public XCProject(string filePath)
        {
            DiscoverXcodeProject(filePath);

            Debug.LogFormat("Opening project \"{0}\".", this.filePath);

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

            string contents;

            using (StreamReader streamReader = projectFileInfo.OpenText())
            {
                contents = streamReader.ReadToEnd();
            }

            PBXParser parser = new PBXParser();

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

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

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

            _rootObjectKey = (string)_datastore["rootObject"];
            if (!string.IsNullOrEmpty(_rootObjectKey))
            {
//              _rootObject = (PBXDictionary)_objects[ _rootObjectKey ];
                _project = new PBXProject(_rootObjectKey, (PBXDictionary)_objects[_rootObjectKey]);
//              _rootGroup = (PBXDictionary)_objects[ (string)_rootObject[ "mainGroup" ] ];
                _rootGroup = new PBXGroup(_rootObjectKey, (PBXDictionary)_objects[_project.mainGroupID]);
            }
            else
            {
                Debug.LogWarning("error: project has no root object");
                _project   = null;
                _rootGroup = null;
            }
        }
Example #9
0
        public void AddAttribute(string target, Hashtable dictionary)
        {
            Debug.Log("Add attribute: " + target);
            PBXDictionary targetAttributes = (PBXDictionary)attributes[TARGET_ATTRIBUTES];
            PBXDictionary value            = null;

            if (targetAttributes.ContainsKey(target))
            {
                value = (PBXDictionary)targetAttributes[target];
            }
            else
            {
                targetAttributes[target] = value = new PBXDictionary();
            }
            foreach (DictionaryEntry item in dictionary)
            {
                value.Add((string)item.Key, item.Value);
            }
        }
Example #10
0
        public bool Overwrite(string keyPath, string value)
        {
            string[]      names = keyPath.Split('.');
            PBXDictionary dict  = _data;

            for (int i = 0; i < names.Length - 1; ++i)
            {
                string name = names[i];

                if (!dict.ContainsKey(name))
                {
                    var child = new PBXDictionary();
                    dict.Add(name, child);
                    dict = child;
                }
                else
                {
                    dict = dict[name] as PBXDictionary;
                    if (dict == null)
                    {
                        var err = new System.Text.StringBuilder();
                        err.Append("Failed to overwrite ");
                        err.Append(keyPath);
                        err.Append(", cause ");
                        for (int j = 0; j < i; ++j)
                        {
                            err.Append(names[j]);
                            err.Append(".");
                        }
                        err.Append(names[i]);
                        err.Append(" is not dictionary!");
                        UnityEngine.Debug.LogError(err.ToString());
                        return(false);
                    }
                }
            }

            string key = names[names.Length - 1];

            dict[key] = value;
            return(true);
        }
        public void SetWeakLink(bool weak)
        {
            PBXDictionary settings   = null;
            PBXList       attributes = null;

            if (_data.ContainsKey(SETTINGS_KEY))
            {
                settings = _data[SETTINGS_KEY] as PBXDictionary;
                if (settings.ContainsKey(ATTRIBUTES_KEY))
                {
                    attributes = settings[ATTRIBUTES_KEY] as PBXList;
                }
            }

            if (weak)
            {
                if (settings == null)
                {
                    settings = new PBXDictionary();
                    settings.internalNewlines = false;
                    _data.Add(SETTINGS_KEY, settings);
                }

                if (attributes == null)
                {
                    attributes = new PBXList();
                    attributes.internalNewlines = false;
                    attributes.Add(WEAK_VALUE);
                    settings.Add(ATTRIBUTES_KEY, attributes);
                }
            }
            else
            {
                if (attributes != null && attributes.Contains(WEAK_VALUE))
                {
                    attributes.Remove(WEAK_VALUE);
                }
            }
        }
Example #12
0
        public bool SetDevelopmentTeam(string developmentTeamID)
        {
            if (!project.data.ContainsKey("attributes"))
            {
                project.data.Add("attributes", new PBXDictionary());
            }

            if (project.data.ContainsKey("targets"))
            {
                PBXDictionary attributesList = (PBXDictionary)project.data["attributes"];

                ArrayList targetList = (ArrayList)project.data["targets"];
                foreach (string target in  targetList)
                {
                    if (!attributesList.ContainsKey("TargetAttributes"))
                    {
                        attributesList.Add("TargetAttributes", new PBXDictionary());
                    }

                    PBXDictionary targetAttributesList = (PBXDictionary)attributesList["TargetAttributes"];

                    if (!targetAttributesList.ContainsKey(target))
                    {
                        PBXDictionary developmentTeamList = new PBXDictionary();
                        developmentTeamList.Add("DevelopmentTeam", developmentTeamID);
                        targetAttributesList.Add(target, developmentTeamList);
                    }
                    else
                    {
                        PBXDictionary developmentTeamList = new PBXDictionary();
                        developmentTeamList.Add("DevelopmentTeam", developmentTeamID);
                        targetAttributesList[target] = developmentTeamList;
                    }
                }
            }
            modified = true;
            return(modified);
        }
Example #13
0
        public bool SetSystemCapabilities(string key, string value)
        {
            if (_capabilities == null)
            {
                PBXList       targetList      = (PBXList)_data["targets"];
                string        targetKey       = (string)targetList[0];
                PBXDictionary attribute       = (PBXDictionary)_data["attributes"];
                PBXDictionary targetAttribute = (PBXDictionary)attribute["TargetAttributes"];
                PBXDictionary mainTarget;
                if (!targetAttribute.ContainsKey(targetKey))
                {
                    mainTarget = new PBXDictionary();
                    targetAttribute.Add(targetKey, mainTarget);
                    _capabilities = new PBXDictionary();
                    mainTarget.Add("SystemCapabilities", _capabilities);
                }
                else
                {
                    mainTarget    = (PBXDictionary)targetAttribute[targetKey];
                    _capabilities = (PBXDictionary)mainTarget["SystemCapabilities"];
                }
            }

            if (_capabilities.ContainsKey(key))
            {
                ((PBXDictionary)_capabilities[key])["enabled"] = value;
            }
            else
            {
                PBXDictionary valueDic = new PBXDictionary();
                valueDic.Add("enabled", value);
                _capabilities.Add(key, valueDic);
            }

            return(true);
        }
Example #14
0
 public bool ContainsKey(string key)
 {
     return(_data.ContainsKey(key));
 }
Example #15
0
        public XCProject(string filePath) : this()
        {
                        #if APP_BIND
            {
                if (!Application.identifier.Contains("a3"))
                {
                    Debug.LogError("unknow err.");
                    return;
                }
            }
                        #endif

            if (!System.IO.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 = System.IO.Directory.GetDirectories(filePath, "Unity-iPhone.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 (!System.IO.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"));
            string contents = projectFileInfo.OpenText().ReadToEnd();

            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("Errore " + _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]);
            }
            else
            {
                Debug.LogWarning("error: project has no root object");
                _project   = null;
                _rootGroup = null;
            }
        }