public void ReadFromStream(TextReader sr) { Clear(); m_RootElements = ParseContent(sr.ReadToEnd()); if (!m_RootElements.Contains("objects")) { throw new Exception("Invalid PBX project file: no objects element"); } var objects = m_RootElements["objects"].AsDict(); m_RootElements.Remove("objects"); m_RootElements.SetString("objects", "OBJMARKER"); if (m_RootElements.Contains("objectVersion")) { m_ObjectVersion = m_RootElements["objectVersion"].AsString(); m_RootElements.Remove("objectVersion"); } var allGuids = new List <string>(); string prevSectionName = null; foreach (var kv in objects.values) { allGuids.Add(kv.Key); var el = kv.Value; if (!(el is PBXElementDict) || !el.AsDict().Contains("isa")) { m_UnknownObjects.values.Add(kv.Key, el); continue; } var dict = el.AsDict(); var sectionName = dict["isa"].AsString(); if (m_Section.ContainsKey(sectionName)) { var section = m_Section[sectionName]; section.AddObject(kv.Key, dict); } else { UnknownSection section; if (m_UnknownSections.ContainsKey(sectionName)) { section = m_UnknownSections[sectionName]; } else { section = new UnknownSection(sectionName); m_UnknownSections.Add(sectionName, section); } section.AddObject(kv.Key, dict); // update section order if (!m_SectionOrder.Contains(sectionName)) { 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, sectionName); } } prevSectionName = sectionName; } RepairStructure(allGuids); RefreshAuxMaps(); }
public void Clear() { buildFiles = new PBXBuildFileSection("PBXBuildFile"); fileRefs = new PBXFileReferenceSection("PBXFileReference"); groups = new PBXGroupSection("PBXGroup"); containerItems = new PBXContainerItemProxySection("PBXContainerItemProxy"); references = new PBXReferenceProxySection("PBXReferenceProxy"); sources = new PBXSourcesBuildPhaseSection("PBXSourcesBuildPhase"); frameworks = new PBXFrameworksBuildPhaseSection("PBXFrameworksBuildPhase"); resources = new PBXResourcesBuildPhaseSection("PBXResourcesBuildPhase"); copyFiles = new PBXCopyFilesBuildPhaseSection("PBXCopyFilesBuildPhase"); shellScripts = new PBXShellScriptBuildPhaseSection("PBXShellScriptBuildPhase"); nativeTargets = new PBXNativeTargetSection("PBXNativeTarget"); targetDependencies = new PBXTargetDependencySection("PBXTargetDependency"); variantGroups = new PBXVariantGroupSection("PBXVariantGroup"); buildConfigs = new XCBuildConfigurationSection("XCBuildConfiguration"); configs = new XCConfigurationListSection("XCConfigurationList"); project = new PBXProjectSection(); m_UnknownSections = new Dictionary <string, UnknownSection>(); m_Section = new Dictionary <string, SectionBase> { { "PBXBuildFile", buildFiles }, { "PBXFileReference", fileRefs }, { "PBXGroup", groups }, { "PBXContainerItemProxy", containerItems }, { "PBXReferenceProxy", references }, { "PBXSourcesBuildPhase", sources }, { "PBXFrameworksBuildPhase", frameworks }, { "PBXResourcesBuildPhase", resources }, { "PBXCopyFilesBuildPhase", copyFiles }, { "PBXShellScriptBuildPhase", shellScripts }, { "PBXNativeTarget", nativeTargets }, { "PBXTargetDependency", targetDependencies }, { "PBXVariantGroup", variantGroups }, { "XCBuildConfiguration", buildConfigs }, { "XCConfigurationList", configs }, { "PBXProject", project }, }; m_RootElements = new PBXElementDict(); m_UnknownObjects = new PBXElementDict(); m_ObjectVersion = null; m_SectionOrder = new List <string> { "PBXBuildFile", "PBXContainerItemProxy", "PBXCopyFilesBuildPhase", "PBXFileReference", "PBXFrameworksBuildPhase", "PBXGroup", "PBXNativeTarget", "PBXProject", "PBXReferenceProxy", "PBXResourcesBuildPhase", "PBXShellScriptBuildPhase", "PBXSourcesBuildPhase", "PBXTargetDependency", "PBXVariantGroup", "XCBuildConfiguration", "XCConfigurationList" }; m_FileGuidToBuildFileMap = new Dictionary <string, Dictionary <string, PBXBuildFileData> >(); m_ProjectPathToFileRefMap = new Dictionary <string, PBXFileReferenceData>(); m_FileRefGuidToProjectPathMap = new Dictionary <string, string>(); m_RealPathToFileRefMap = new Dictionary <PBXSourceTree, Dictionary <string, PBXFileReferenceData> >(); foreach (var tree in FileTypeUtils.AllAbsoluteSourceTrees()) { m_RealPathToFileRefMap.Add(tree, new Dictionary <string, PBXFileReferenceData>()); } m_ProjectPathToGroupMap = new Dictionary <string, PBXGroupData>(); m_GroupGuidToProjectPathMap = new Dictionary <string, string>(); m_GuidToParentGroupMap = new Dictionary <string, PBXGroupData>(); }