public bool LoadMods(string path) { var config = new INI(); // Mod list var mods = new List <ModViewModel>(); // Listing local mods (except Core) var LocalModDir = Path.Combine(config.Read("RimWorldDir", "Directories"), "Mods"); var LocalMods = Directory.GetDirectories(LocalModDir) .Select(x => Path.GetFileName(x)) .ToArray(); // Listing steam mods var SteamModDir = Path.Combine(config.Read("WorkshopDir", "Directories")); var SteamMods = Directory.GetDirectories(SteamModDir) .Select(x => Path.GetFileName(x)) .ToArray(); var mc = new ModsConfig(path); if (!mc.Loaded) { return(false); } var ActivatedMods = mc.activeMods(); var PlainList = new List <ModViewModel>(); var MissingList = new List <string>(); Action <RawMod, ModViewModel> explore = null; explore = new Action <RawMod, ModViewModel>((node, target) => { ModViewModel mod = null; if (node.Name != null && node.Name.Length > 0) { mod = new ModViewModel( node.Id, node.Name ) { Expanded = false }; } else { var isLocal = LocalMods.Contains(node.Id); mod = new ModViewModel( node.Id, Path.Combine(isLocal ? LocalModDir : SteamModDir, node.Id), isLocal ? ModType.Local : ModType.Steam ); } if (mod.Id != null) { if (node.Color != Colors.Transparent) { mod.Color = node.Color; } mod.Enabled = node.Enabled; if (target == null) { mods.Add(mod); } else { target.Childs.Add(mod); } PlainList.Add(mod); } else { if (node.Name == null || node.Name.Length == 0) { MissingList.Add(node.Id); } } if (node.Childs != null) { foreach (var y in node.Childs) { explore(y, mod.Id == null ? target : mod); } } }); foreach (var raw in ActivatedMods) { explore(raw, null); } var DeactivatedMods = LocalMods .Concat(SteamMods) .Where(x => !PlainList.Any(y => y.Id == x)) .ToArray(); foreach (var modName in DeactivatedMods) { var isLocal = LocalMods.Contains(modName); mods.Add(new ModViewModel( modName, Path.Combine(isLocal ? LocalModDir : SteamModDir, modName), isLocal ? ModType.Local : ModType.Steam ) { Enabled = false }); } this.ModList = new ObservableCollection <ModViewModel>( mods.Select(x => { if (x.Color == Colors.Transparent) { x.Color = ModColor.GetModColor(config.Read("ConfigurationDir", "Directories"), x.Id); } return(x); }) ); this.SelectedMod = this.ModList.FirstOrDefault(); if (MissingList.Count > 0) { File.WriteAllLines( Path.Combine( Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "MissingMods.txt" ), MissingList .Where(x => int.TryParse(x, out _)) .Select(x => "https://steamcommunity.com/sharedfiles/filedetails/?id=" + x) ); MessageBox.Show( "Failed to load all mod list, missing mods:" + Environment.NewLine + string.Join(Environment.NewLine, MissingList.Select(x => "- " + x)) + Environment.NewLine + Environment.NewLine + "Check 'MissingMods.txt' on RWMV directory.", "RimWorldModVisualizer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } return(true); }