public static void CheckForManualInstalledMods() { ModFile[] mods = ModParsing.GetAllMods(); ModFile[] instmods = InstalledMods.GetInstalledMods(); string addedmods = ""; for (int i = 0; i < mods.Length; i++) { if (!string.IsNullOrEmpty(mods[i].DelInfo)) { if (File.Exists(Path.Combine(Utilities.GameDirectory, mods[i].DelInfo))) { bool IsInstalled = false; for (int x = 0; x < instmods.Length; x++) { if (mods[i].ModId == instmods[x].ModId) { IsInstalled = true; break; } } if (!IsInstalled) { addedmods += mods[i].ModId + ", "; InstalledMods.AddInstalledMod(mods[i].ModId); } } } } if (!String.IsNullOrEmpty(addedmods)) { var conf = MessageBox.Show($"Some manually installed mods have been detected, adding it to database. Detected mods: {addedmods.Split(',').Length} \n" + addedmods, "Installed mods detected!", MessageBoxButtons.OK); } }
public static Tuple <ModFile[], ModFile[]> GetRelevantMods(string category) { relevantCategory = category; //set new relevantcat ModFile[] DLmods = new ModFile[0]; //get downloadable mods, all or select category if (category == "" || category == "all") { DLmods = ModParsing.GetAllMods(); } else { DLmods = JsonModList.GetDeserializedModListFormatOnline(category).Modlist; } ModFile[] ILmods = InstalledMods.GetInstalledMods(); //get all installed mods List <ModFile> resultDLmods = new List <ModFile>(); //i've never actually used a List before! --potatoes List <ModFile> resultILmods = new List <ModFile>(); //that's why 95% of my array code uses resize. oh well, who needs speed! for (int i = 0; i < DLmods.Length; i++) { bool inILmods = false; for (int x = 0; x < ILmods.Length; x++) { if (DLmods[i].ModId == ILmods[i].ModId) { inILmods = true; break; } //if in ilmods, set to true } if (inILmods) { resultILmods.Add(ILmods[i]); } //if overlap btwn dl&il, put to il else { resultDLmods.Add(DLmods[i]); } //otherwise, put to dl //this also means that if there is an il but no dl, it is discarded. } return(new Tuple <ModFile[], ModFile[]>(resultDLmods.ToArray(), resultILmods.ToArray())); }
public void UpdateModList(string dispcat = "n/a", string filter = "") { Program.CheckForManuallyUninstalledMods(); DownloadableModsList.Items.Clear(); InstalledModsList.Items.Clear(); if (dispcat == "n/a") { dispcat = publicdispcat; } publicdispcat = dispcat; var totalmods = ModParsing.GetAllMods(); if (dispcat == "n/a") { dispcat = "dependencies"; } Console.WriteLine(dispcat); var dispmods = JsonModList.GetDeserializedModListFormatOnline(dispcat).Modlist; var installedMods = InstalledMods.GetInstalledMods(); //f**k you ModFile[] list = null; var relevantint = 0; for (var i = 0; i < totalmods.Length; i++) { //this just checks if the mod we're working with is an installedmod, or a dl mod in isinstldmod var isinstldmod = false; var x = 0; for (x = 0; x < installedMods.Length; x++) { if (totalmods[i].ModId == installedMods[x].ModId) { isinstldmod = true; break; } } var isdispmod = false; for (var y = 0; y < dispmods.Length; y++) { if (totalmods[i].ModId == dispmods[y].ModId) { isdispmod = true; break; } } //sets vars to installedmods or input if (isinstldmod) { list = installedMods; relevantint = x; } else { if (publicdispcat == "n/a") { goto Finish; } list = totalmods; relevantint = i; } var mod = new ListViewItem(list[relevantint].Name, 0); //0 mod.SubItems.Add(list[relevantint].Version); //1 mod.SubItems.Add(string.Join(", ", list[relevantint].Author)); //2 mod.SubItems.Add(list[relevantint].Description); //3 mod.SubItems.Add(list[relevantint].ModId); //4 if (String.IsNullOrEmpty(filter)) { if (!isinstldmod && isdispmod) { DownloadableModsList.Items.Add(mod); } if (isinstldmod) { InstalledModsList.Items.Add(mod); } } else { //search bar functionality filter = filter.ToLower(); var modname = list[relevantint].Name.ToLower(); var authorString = string.Join("", list[relevantint].Author).ToLower(); if (modname.Contains(filter) || authorString.Contains(filter)) { Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Console.WriteLine(""); switch (isinstldmod) { case false when isdispmod: DownloadableModsList.Items.Add(mod); break; case true: InstalledModsList.Items.Add(mod); break; } } } Finish :; } for (var i = 0; i < InstalledModsList.Items.Count; i++) { //if cached installed mod is a older version than the database if (new Version(InstalledModsList.Items[i].SubItems[1].Text).CompareTo( new Version(ModParsing.GetSpecificMod(InstalledModsList.Items[i].SubItems[4].Text).Version)) < 0) { InstalledModsList.Items[i].BackColor = Color.Yellow; } string delinfo = ModParsing.GetSpecificMod(InstalledModsList.Items[i].SubItems[4].Text).DelInfo; //if cached mod is disabled if (!String.IsNullOrEmpty(delinfo)) { string path = Path.Combine(Utilities.GameDirectory, delinfo.Split('?')[0]); //split to get the first delinfo arg string path2 = Path.Combine(Utilities.DisableCache, new DirectoryInfo(delinfo.Split('?')[0]).Name); //basically loc of the cache area if ((!File.Exists(path) && !Directory.Exists(path)) && (File.Exists(path2) || Directory.Exists(path2))) //if it is not disabled { InstalledModsList.Items[i].BackColor = Color.Gray; UpdateButton.Hide(); } else { UpdateButton.Show(); } } } }