public void RecalculateDisplayRootCategory() { if (ThingCategoryNodeDatabase.allThingCategoryNodes == null) { DisplayRootCategory = ThingCategoryNodeDatabase.RootNode; return; } int lastFoundCategory = -1; object lockObject = new object(); GenThreading.ParallelFor(0, ThingCategoryNodeDatabase.allThingCategoryNodes.Count, delegate(int index) { TreeNode_ThingCategory treeNode_ThingCategory = ThingCategoryNodeDatabase.allThingCategoryNodes[index]; bool flag = false; bool flag2 = false; foreach (ThingDef allowedDef in allowedDefs) { if (treeNode_ThingCategory.catDef.ContainedInThisOrDescendant(allowedDef)) { flag2 = true; } else { flag = true; } } if (!flag && flag2) { lock (lockObject) { if (index > lastFoundCategory) { lastFoundCategory = index; } } } }); if (lastFoundCategory == -1) { DisplayRootCategory = ThingCategoryNodeDatabase.RootNode; } else { DisplayRootCategory = ThingCategoryNodeDatabase.allThingCategoryNodes[lastFoundCategory]; } }
public static LoadableXmlAsset[] XmlAssetsInModFolder(ModContentPack mod, string folderPath, List <string> foldersToLoadDebug = null) { List <string> list = foldersToLoadDebug ?? mod.foldersToLoadDescendingOrder; Dictionary <string, FileInfo> dictionary = new Dictionary <string, FileInfo>(); for (int j = 0; j < list.Count; j++) { string text = list[j]; DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(text, folderPath)); if (!directoryInfo.Exists) { continue; } FileInfo[] files = directoryInfo.GetFiles("*.xml", SearchOption.AllDirectories); foreach (FileInfo fileInfo in files) { string key = fileInfo.FullName.Substring(text.Length + 1); if (!dictionary.ContainsKey(key)) { dictionary.Add(key, fileInfo); } } } if (dictionary.Count == 0) { return(emptyXmlAssetsArray); } List <FileInfo> fileList = dictionary.Values.ToList(); LoadableXmlAsset[] assets = new LoadableXmlAsset[fileList.Count]; GenThreading.ParallelFor(0, fileList.Count, delegate(int i) { FileInfo fileInfo2 = fileList[i]; LoadableXmlAsset loadableXmlAsset = new LoadableXmlAsset(fileInfo2.Name, fileInfo2.Directory.FullName, File.ReadAllText(fileInfo2.FullName)) { mod = mod }; assets[i] = loadableXmlAsset; }); return(assets); }