/* Removes objects from the given @a section for which @a checker returns true. * Also removes the guids of the removed elements from allGuids dictionary. * Returns true if any objects were removed. */ static bool RemoveObjectsFromSection <T>(KnownSectionBase <T> section, Dictionary <string, bool> allGuids, Func <T, bool> checker) where T : PBXObjectData, new() { List <string> guidsToRemove = null; foreach (var kv in section.GetEntries()) { if (checker(kv.Value)) { if (guidsToRemove == null) { guidsToRemove = new List <string>(); } guidsToRemove.Add(kv.Key); } } if (guidsToRemove != null) { foreach (var guid in guidsToRemove) { section.RemoveEntry(guid); allGuids.Remove(guid); } return(true); } return(false); }
private static bool RemoveObjectsFromSection <T>(KnownSectionBase <T> section, Dictionary <string, bool> allGuids, Func <T, bool> checker) where T : PBXObjectData, new() { List <string> list = (List <string>)null; foreach (KeyValuePair <string, T> keyValuePair in section.GetEntries()) { if (checker(keyValuePair.Value)) { if (list == null) { list = new List <string>(); } list.Add(keyValuePair.Key); } } if (list == null) { return(false); } foreach (string str in list) { section.RemoveEntry(str); allGuids.Remove(str); } return(true); }
public void ReadFromStream(TextReader sr) { this.Clear(); this.m_RootElements = PBXProjectData.ParseContent(sr.ReadToEnd()); if (!this.m_RootElements.Contains("objects")) { throw new Exception("Invalid PBX project file: no objects element"); } PBXElementDict pbxElementDict1 = this.m_RootElements["objects"].AsDict(); this.m_RootElements.Remove("objects"); this.m_RootElements.SetString("objects", "OBJMARKER"); if (this.m_RootElements.Contains("objectVersion")) { this.m_ObjectVersion = this.m_RootElements["objectVersion"].AsString(); this.m_RootElements.Remove("objectVersion"); } List <string> allGuids = new List <string>(); string prevSectionName = (string)null; foreach (KeyValuePair <string, PBXElement> keyValuePair in (IEnumerable <KeyValuePair <string, PBXElement> >)pbxElementDict1.values) { allGuids.Add(keyValuePair.Key); PBXElement pbxElement = keyValuePair.Value; if (!(pbxElement is PBXElementDict) || !pbxElement.AsDict().Contains("isa")) { this.m_UnknownObjects.values.Add(keyValuePair.Key, pbxElement); } else { PBXElementDict pbxElementDict2 = pbxElement.AsDict(); string index1 = pbxElementDict2["isa"].AsString(); if (this.m_Section.ContainsKey(index1)) { this.m_Section[index1].AddObject(keyValuePair.Key, pbxElementDict2); } else { KnownSectionBase <PBXObjectData> knownSectionBase; if (this.m_UnknownSections.ContainsKey(index1)) { knownSectionBase = this.m_UnknownSections[index1]; } else { knownSectionBase = new KnownSectionBase <PBXObjectData>(index1); this.m_UnknownSections.Add(index1, knownSectionBase); } knownSectionBase.AddObject(keyValuePair.Key, pbxElementDict2); if (!this.m_SectionOrder.Contains(index1)) { int index2 = 0; if (prevSectionName != null) { index2 = this.m_SectionOrder.FindIndex((Predicate <string>)(x => x == prevSectionName)) + 1; } this.m_SectionOrder.Insert(index2, index1); } } prevSectionName = index1; } } this.RepairStructure(allGuids); this.RefreshAuxMaps(); }
public void Clear() { this.buildFiles = new KnownSectionBase <PBXBuildFileData>("PBXBuildFile"); this.fileRefs = new KnownSectionBase <PBXFileReferenceData>("PBXFileReference"); this.groups = new KnownSectionBase <PBXGroupData>("PBXGroup"); this.containerItems = new KnownSectionBase <PBXContainerItemProxyData>("PBXContainerItemProxy"); this.references = new KnownSectionBase <PBXReferenceProxyData>("PBXReferenceProxy"); this.sources = new KnownSectionBase <PBXSourcesBuildPhaseData>("PBXSourcesBuildPhase"); this.headers = new KnownSectionBase <PBXHeadersBuildPhaseData>("PBXHeadersBuildPhase"); this.frameworks = new KnownSectionBase <PBXFrameworksBuildPhaseData>("PBXFrameworksBuildPhase"); this.resources = new KnownSectionBase <PBXResourcesBuildPhaseData>("PBXResourcesBuildPhase"); this.copyFiles = new KnownSectionBase <PBXCopyFilesBuildPhaseData>("PBXCopyFilesBuildPhase"); this.shellScripts = new KnownSectionBase <PBXShellScriptBuildPhaseData>("PBXShellScriptBuildPhase"); this.nativeTargets = new KnownSectionBase <PBXNativeTargetData>("PBXNativeTarget"); this.targetDependencies = new KnownSectionBase <PBXTargetDependencyData>("PBXTargetDependency"); this.variantGroups = new KnownSectionBase <PBXVariantGroupData>("PBXVariantGroup"); this.buildConfigs = new KnownSectionBase <XCBuildConfigurationData>("XCBuildConfiguration"); this.buildConfigLists = new KnownSectionBase <XCConfigurationListData>("XCConfigurationList"); this.project = new PBXProjectSection(); this.m_UnknownSections = new Dictionary <string, KnownSectionBase <PBXObjectData> >(); Dictionary <string, SectionBase> dictionary = new Dictionary <string, SectionBase>(); string key1 = "PBXBuildFile"; KnownSectionBase <PBXBuildFileData> knownSectionBase1 = this.buildFiles; dictionary.Add(key1, (SectionBase)knownSectionBase1); string key2 = "PBXFileReference"; KnownSectionBase <PBXFileReferenceData> knownSectionBase2 = this.fileRefs; dictionary.Add(key2, (SectionBase)knownSectionBase2); string key3 = "PBXGroup"; KnownSectionBase <PBXGroupData> knownSectionBase3 = this.groups; dictionary.Add(key3, (SectionBase)knownSectionBase3); string key4 = "PBXContainerItemProxy"; KnownSectionBase <PBXContainerItemProxyData> knownSectionBase4 = this.containerItems; dictionary.Add(key4, (SectionBase)knownSectionBase4); string key5 = "PBXReferenceProxy"; KnownSectionBase <PBXReferenceProxyData> knownSectionBase5 = this.references; dictionary.Add(key5, (SectionBase)knownSectionBase5); string key6 = "PBXSourcesBuildPhase"; KnownSectionBase <PBXSourcesBuildPhaseData> knownSectionBase6 = this.sources; dictionary.Add(key6, (SectionBase)knownSectionBase6); string key7 = "PBXHeadersBuildPhase"; KnownSectionBase <PBXHeadersBuildPhaseData> knownSectionBase7 = this.headers; dictionary.Add(key7, (SectionBase)knownSectionBase7); string key8 = "PBXFrameworksBuildPhase"; KnownSectionBase <PBXFrameworksBuildPhaseData> knownSectionBase8 = this.frameworks; dictionary.Add(key8, (SectionBase)knownSectionBase8); string key9 = "PBXResourcesBuildPhase"; KnownSectionBase <PBXResourcesBuildPhaseData> knownSectionBase9 = this.resources; dictionary.Add(key9, (SectionBase)knownSectionBase9); string key10 = "PBXCopyFilesBuildPhase"; KnownSectionBase <PBXCopyFilesBuildPhaseData> knownSectionBase10 = this.copyFiles; dictionary.Add(key10, (SectionBase)knownSectionBase10); string key11 = "PBXShellScriptBuildPhase"; KnownSectionBase <PBXShellScriptBuildPhaseData> knownSectionBase11 = this.shellScripts; dictionary.Add(key11, (SectionBase)knownSectionBase11); string key12 = "PBXNativeTarget"; KnownSectionBase <PBXNativeTargetData> knownSectionBase12 = this.nativeTargets; dictionary.Add(key12, (SectionBase)knownSectionBase12); string key13 = "PBXTargetDependency"; KnownSectionBase <PBXTargetDependencyData> knownSectionBase13 = this.targetDependencies; dictionary.Add(key13, (SectionBase)knownSectionBase13); string key14 = "PBXVariantGroup"; KnownSectionBase <PBXVariantGroupData> knownSectionBase14 = this.variantGroups; dictionary.Add(key14, (SectionBase)knownSectionBase14); string key15 = "XCBuildConfiguration"; KnownSectionBase <XCBuildConfigurationData> knownSectionBase15 = this.buildConfigs; dictionary.Add(key15, (SectionBase)knownSectionBase15); string key16 = "XCConfigurationList"; KnownSectionBase <XCConfigurationListData> knownSectionBase16 = this.buildConfigLists; dictionary.Add(key16, (SectionBase)knownSectionBase16); string key17 = "PBXProject"; PBXProjectSection pbxProjectSection = this.project; dictionary.Add(key17, (SectionBase)pbxProjectSection); this.m_Section = dictionary; this.m_RootElements = new PBXElementDict(); this.m_UnknownObjects = new PBXElementDict(); this.m_ObjectVersion = (string)null; List <string> list = new List <string>(); string str1 = "PBXBuildFile"; list.Add(str1); string str2 = "PBXContainerItemProxy"; list.Add(str2); string str3 = "PBXCopyFilesBuildPhase"; list.Add(str3); string str4 = "PBXFileReference"; list.Add(str4); string str5 = "PBXFrameworksBuildPhase"; list.Add(str5); string str6 = "PBXGroup"; list.Add(str6); string str7 = "PBXHeadersBuildPhase"; list.Add(str7); string str8 = "PBXNativeTarget"; list.Add(str8); string str9 = "PBXProject"; list.Add(str9); string str10 = "PBXReferenceProxy"; list.Add(str10); string str11 = "PBXResourcesBuildPhase"; list.Add(str11); string str12 = "PBXShellScriptBuildPhase"; list.Add(str12); string str13 = "PBXSourcesBuildPhase"; list.Add(str13); string str14 = "PBXTargetDependency"; list.Add(str14); string str15 = "PBXVariantGroup"; list.Add(str15); string str16 = "XCBuildConfiguration"; list.Add(str16); string str17 = "XCConfigurationList"; list.Add(str17); this.m_SectionOrder = list; this.m_FileGuidToBuildFileMap = new Dictionary <string, Dictionary <string, PBXBuildFileData> >(); this.m_ProjectPathToFileRefMap = new Dictionary <string, PBXFileReferenceData>(); this.m_FileRefGuidToProjectPathMap = new Dictionary <string, string>(); this.m_RealPathToFileRefMap = new Dictionary <PBXSourceTree, Dictionary <string, PBXFileReferenceData> >(); foreach (PBXSourceTree key18 in FileTypeUtils.AllAbsoluteSourceTrees()) { this.m_RealPathToFileRefMap.Add(key18, new Dictionary <string, PBXFileReferenceData>()); } this.m_ProjectPathToGroupMap = new Dictionary <string, PBXGroupData>(); this.m_GroupGuidToProjectPathMap = new Dictionary <string, string>(); this.m_GuidToParentGroupMap = new Dictionary <string, PBXGroupData>(); }
public void Clear() { this.buildFiles = new KnownSectionBase <PBXBuildFileData>("PBXBuildFile"); this.fileRefs = new KnownSectionBase <PBXFileReferenceData>("PBXFileReference"); this.groups = new KnownSectionBase <PBXGroupData>("PBXGroup"); this.containerItems = new KnownSectionBase <PBXContainerItemProxyData>("PBXContainerItemProxy"); this.references = new KnownSectionBase <PBXReferenceProxyData>("PBXReferenceProxy"); this.sources = new KnownSectionBase <PBXSourcesBuildPhaseData>("PBXSourcesBuildPhase"); this.frameworks = new KnownSectionBase <PBXFrameworksBuildPhaseData>("PBXFrameworksBuildPhase"); this.resources = new KnownSectionBase <PBXResourcesBuildPhaseData>("PBXResourcesBuildPhase"); this.copyFiles = new KnownSectionBase <PBXCopyFilesBuildPhaseData>("PBXCopyFilesBuildPhase"); this.shellScripts = new KnownSectionBase <PBXShellScriptBuildPhaseData>("PBXShellScriptBuildPhase"); this.nativeTargets = new KnownSectionBase <PBXNativeTargetData>("PBXNativeTarget"); this.targetDependencies = new KnownSectionBase <PBXTargetDependencyData>("PBXTargetDependency"); this.variantGroups = new KnownSectionBase <PBXVariantGroupData>("PBXVariantGroup"); this.buildConfigs = new KnownSectionBase <XCBuildConfigurationData>("XCBuildConfiguration"); this.configs = new KnownSectionBase <XCConfigurationListData>("XCConfigurationList"); this.project = new PBXProjectSection(); this.m_UnknownSections = new Dictionary <string, KnownSectionBase <PBXObjectData> >(); Dictionary <string, SectionBase> dictionary = new Dictionary <string, SectionBase> { { "PBXBuildFile", this.buildFiles }, { "PBXFileReference", this.fileRefs }, { "PBXGroup", this.groups }, { "PBXContainerItemProxy", this.containerItems }, { "PBXReferenceProxy", this.references }, { "PBXSourcesBuildPhase", this.sources }, { "PBXFrameworksBuildPhase", this.frameworks }, { "PBXResourcesBuildPhase", this.resources }, { "PBXCopyFilesBuildPhase", this.copyFiles }, { "PBXShellScriptBuildPhase", this.shellScripts }, { "PBXNativeTarget", this.nativeTargets }, { "PBXTargetDependency", this.targetDependencies }, { "PBXVariantGroup", this.variantGroups }, { "XCBuildConfiguration", this.buildConfigs }, { "XCConfigurationList", this.configs }, { "PBXProject", this.project } }; this.m_Section = dictionary; this.m_RootElements = new PBXElementDict(); this.m_UnknownObjects = new PBXElementDict(); this.m_ObjectVersion = null; List <string> list = new List <string> { "PBXBuildFile", "PBXContainerItemProxy", "PBXCopyFilesBuildPhase", "PBXFileReference", "PBXFrameworksBuildPhase", "PBXGroup", "PBXNativeTarget", "PBXProject", "PBXReferenceProxy", "PBXResourcesBuildPhase", "PBXShellScriptBuildPhase", "PBXSourcesBuildPhase", "PBXTargetDependency", "PBXVariantGroup", "XCBuildConfiguration", "XCConfigurationList" }; this.m_SectionOrder = list; this.m_FileGuidToBuildFileMap = new Dictionary <string, Dictionary <string, PBXBuildFileData> >(); this.m_ProjectPathToFileRefMap = new Dictionary <string, PBXFileReferenceData>(); this.m_FileRefGuidToProjectPathMap = new Dictionary <string, string>(); this.m_RealPathToFileRefMap = new Dictionary <PBXSourceTree, Dictionary <string, PBXFileReferenceData> >(); foreach (PBXSourceTree tree in FileTypeUtils.AllAbsoluteSourceTrees()) { this.m_RealPathToFileRefMap.Add(tree, new Dictionary <string, PBXFileReferenceData>()); } this.m_ProjectPathToGroupMap = new Dictionary <string, PBXGroupData>(); this.m_GroupGuidToProjectPathMap = new Dictionary <string, string>(); this.m_GuidToParentGroupMap = new Dictionary <string, PBXGroupData>(); }
public void ReadFromStream(TextReader sr) { this.Clear(); this.m_RootElements = PBXProjectData.ParseContent(sr.ReadToEnd()); if (!this.m_RootElements.Contains("objects")) { throw new Exception("Invalid PBX project file: no objects element"); } PBXElementDict pbxElementDict1 = this.m_RootElements["objects"].AsDict(); this.m_RootElements.Remove("objects"); this.m_RootElements.SetString("objects", "OBJMARKER"); if (this.m_RootElements.Contains("objectVersion")) { this.m_ObjectVersion = this.m_RootElements["objectVersion"].AsString(); this.m_RootElements.Remove("objectVersion"); } List <string> allGuids = new List <string>(); // ISSUE: reference to a compiler-generated field string prevSectionName = null; foreach (KeyValuePair <string, PBXElement> keyValuePair in (IEnumerable <KeyValuePair <string, PBXElement> >)pbxElementDict1.values) { allGuids.Add(keyValuePair.Key); PBXElement pbxElement = keyValuePair.Value; if (!(pbxElement is PBXElementDict) || !pbxElement.AsDict().Contains("isa")) { this.m_UnknownObjects.values.Add(keyValuePair.Key, pbxElement); } else { PBXElementDict pbxElementDict2 = pbxElement.AsDict(); string index1 = pbxElementDict2["isa"].AsString(); if (this.m_Section.ContainsKey(index1)) { this.m_Section[index1].AddObject(keyValuePair.Key, pbxElementDict2); } else { KnownSectionBase <PBXObjectData> knownSectionBase; if (this.m_UnknownSections.ContainsKey(index1)) { knownSectionBase = this.m_UnknownSections[index1]; } else { knownSectionBase = new KnownSectionBase <PBXObjectData>(index1); this.m_UnknownSections.Add(index1, knownSectionBase); } knownSectionBase.AddObject(keyValuePair.Key, pbxElementDict2); if (!this.m_SectionOrder.Contains(index1)) { int pos = 0; if (prevSectionName != null) { // this never fails, because we already added any previous unknown sections // to m_SectionOrder pos = m_SectionOrder.FindIndex(x => x == prevSectionName); pos += 1; } m_SectionOrder.Insert(pos, index1); } } // ISSUE: reference to a compiler-generated field prevSectionName = index1; } } this.RepairStructure(allGuids); this.RefreshAuxMaps(); }