From 6f9d592f5a38d6ba0bc620d253a57193a9111055 Mon Sep 17 00:00:00 2001 From: rjtwins Date: Sun, 25 Jul 2021 22:37:22 +0200 Subject: [PATCH] bugfixes -Fixed a but where the program could crash if you highlight an entry. -Fixed a bug where the dependency and overriding check would be done in the wrong order when filtering. --- Form1.cs | 78 +++++++++++++++++++------------------ Program.cs | 110 +++++++++++++++++++++++++---------------------------- 2 files changed, 93 insertions(+), 95 deletions(-) diff --git a/Form1.cs b/Form1.cs index 111e178..4b0e8bc 100644 --- a/Form1.cs +++ b/Form1.cs @@ -79,6 +79,9 @@ private void Form1_Load(object sender, EventArgs e) this.rotatingLabel1.NewText = "<- Low Priority/Loaded First --- High Priority/Loaded Last ->"; // whatever you want to display this.rotatingLabel1.ForeColor = Color.Black; // color to display this.rotatingLabel1.RotateAngle = -90; // angle to rotate + + logic.CheckRequires(ListViewData); + logic.GetOverridingData(ListViewData); } //handling key presses for hotkeys. @@ -492,7 +495,6 @@ private void LoadAndFill(bool FromClipboard) ListViewData.Add(item1); } - logic.GetOverridingData(ListViewData); UpdateListView(); logic.SaveProgramData(); } @@ -505,7 +507,6 @@ private void LoadAndFill(bool FromClipboard) MessageBox.Show(message, caption, buttons); } this.LoadingAndFilling = false; - logic.CheckRequires(ListViewData); } //Fill list view from internal list of data. @@ -857,8 +858,6 @@ private void toolStripButton1_Click(object sender, EventArgs e) //Crude filter because to lazy to add a proper list as backup for the items. private void filterBox_TextChanged(object sender, EventArgs e) { - //Console.WriteLine("There are " + this.backupListView.Count() + " items in the backup"); - string filtertext = MainForm.filterBox.Text.ToLower(); if ( filtertext == "" @@ -866,12 +865,11 @@ private void filterBox_TextChanged(object sender, EventArgs e) || string.IsNullOrEmpty(filtertext) ) { - Console.WriteLine("No filter text"); + //Console.WriteLine("No filter text"); if (this.filtered) //we are returning from filtering { foreach (ListViewItem x in this.ListViewData) { - x.SubItems[0].BackColor = Color.White; x.SubItems[1].BackColor = Color.White; x.SubItems[2].BackColor = Color.White; x.SubItems[3].BackColor = Color.White; @@ -881,6 +879,7 @@ private void filterBox_TextChanged(object sender, EventArgs e) } else //We are not returning from a filter { + //This should never happen. We can't return from a filter we never entered. // do nothing } MainForm.button1.Enabled = true; @@ -889,37 +888,14 @@ private void filterBox_TextChanged(object sender, EventArgs e) } else { - Console.WriteLine("Filter Text: " + filtertext); - this.listView1.Items.Clear(); - - foreach (ListViewItem x in this.ListViewData) - { - x.SubItems[0].BackColor = Color.White; - x.SubItems[1].BackColor = Color.White; - x.SubItems[2].BackColor = Color.White; - x.SubItems[3].BackColor = Color.White; - x.SubItems[4].BackColor = Color.White; - } - - //Check if the items modname, foltername or author stars with or contains the filter text - foreach (ListViewItem item in this.ListViewData) + this.filtered = true; + //Console.WriteLine("Filter Text: " + filtertext); + if (MainForm.checkBox1.Checked) { - if ( - item.SubItems[1].Text.ToLower().StartsWith(filtertext) || - item.SubItems[2].Text.ToLower().StartsWith(filtertext) || - item.SubItems[3].Text.ToLower().StartsWith(filtertext) || - item.SubItems[1].Text.ToLower().Contains(filtertext) || - item.SubItems[2].Text.ToLower().Contains(filtertext) || - item.SubItems[3].Text.ToLower().Contains(filtertext) - ) + foreach (ListViewItem item in this.ListViewData) { - if (!MainForm.checkBox1.Checked) + if(MatchItemToText(filtertext, item)) { - MainForm.listView1.Items.Add(item); - } - else - { - item.SubItems[0].BackColor = Color.Yellow; item.SubItems[1].BackColor = Color.Yellow; item.SubItems[2].BackColor = Color.Yellow; item.SubItems[3].BackColor = Color.Yellow; @@ -927,16 +903,44 @@ private void filterBox_TextChanged(object sender, EventArgs e) } } } - if (MainForm.checkBox1.Checked) + else { - UpdateListView(); + this.listView1.Items.Clear(); + foreach (ListViewItem item in this.ListViewData) + { + if (MatchItemToText(filtertext, item)) + { + item.SubItems[1].BackColor = Color.White; + item.SubItems[2].BackColor = Color.White; + item.SubItems[3].BackColor = Color.White; + item.SubItems[4].BackColor = Color.White; + MainForm.listView1.Items.Add(item); + } + } } MainForm.button1.Enabled = false; MainForm.button2.Enabled = false; - this.filtered = true; } } + //Check all items in list view data and see if their content can be matched to a string. + private bool MatchItemToText(string filtertext, ListViewItem item) + { + if + ( + item.SubItems[1].Text.ToLower().StartsWith(filtertext) || + item.SubItems[2].Text.ToLower().StartsWith(filtertext) || + item.SubItems[3].Text.ToLower().StartsWith(filtertext) || + item.SubItems[1].Text.ToLower().Contains(filtertext) || + item.SubItems[2].Text.ToLower().Contains(filtertext) || + item.SubItems[3].Text.ToLower().Contains(filtertext) + ) + { + return true; + } + return false; + } + //Filter or Highlight checkbox on tick action private void checkBox1_CheckedChanged(object sender, EventArgs e) { diff --git a/Program.cs b/Program.cs index 5944690..945f998 100644 --- a/Program.cs +++ b/Program.cs @@ -188,10 +188,10 @@ public bool TryLoadProgramData() string json = File.ReadAllText(complete + @"\ProgramData.json"); this.ProgramData = JsonConvert.DeserializeObject(json); - Console.WriteLine("Finshed loading ProgramData.json:" - + " Vendor: " + this.ProgramData.vendor - + " Version: " + this.ProgramData.version - + " Installdir: " + this.ProgramData.installdir); + //Console.WriteLine("Finshed loading ProgramData.json:" + //+ " Vendor: " + this.ProgramData.vendor + //+ " Version: " + this.ProgramData.version + //+ " Installdir: " + this.ProgramData.installdir); if (this.ProgramData.installdir != null && this.ProgramData.installdir != "") { @@ -208,9 +208,9 @@ public bool TryLoadProgramData() } catch (Exception e) { - Console.WriteLine("ERROR: Something went wrong while loading ProgramData.json"); - Console.WriteLine(e.Message); - Console.WriteLine(e.StackTrace); + //Console.WriteLine("ERROR: Something went wrong while loading ProgramData.json"); + //Console.WriteLine(e.Message); + //Console.WriteLine(e.StackTrace); } if (this.BasePath != null && this.BasePath != "") @@ -235,8 +235,8 @@ public void WhipeInstallDirMemory() System.IO.File.WriteAllText(complete + @"\ProgramData.json", " "); }catch(Exception Ex) { - Console.WriteLine(Ex.Message); - Console.WriteLine(Ex.StackTrace); + //Console.WriteLine(Ex.Message); + //Console.WriteLine(Ex.StackTrace); return; } } @@ -256,12 +256,12 @@ public void ParseDirectories() //{ // if (WorkshopPath == "") // { - // Console.WriteLine("Found Steam version"); + // //Console.WriteLine("Found Steam version"); // string workshopPath = BasePath; // workshopPath = workshopPath.Remove(workshopPath.Length - 46, 46); - // Console.WriteLine($"trimmed path is {workshopPath}"); + // //Console.WriteLine($"trimmed path is {workshopPath}"); // workshopPath += ("workshop\\content\\784080"); - // Console.WriteLine($"full workshop path is {workshopPath}"); + // //Console.WriteLine($"full workshop path is {workshopPath}"); // WorkshopPath = workshopPath; // } // if (!Directory.Exists(WorkshopPath)) @@ -502,7 +502,7 @@ public void ThreadProc() public void PackModsToZip(BackgroundWorker worker, DoWorkEventArgs e) { - Console.WriteLine("Starting zip compression"); + //Console.WriteLine("Starting zip compression"); string parent = Directory.GetParent(Logic.BasePath).ToString(); Thread t = new Thread(new ThreadStart(ThreadProc)); @@ -543,7 +543,7 @@ public string Scramble(string input) chars[i] = temp; } string scrambled = new string(chars); - Console.WriteLine(scrambled); + //Console.WriteLine(scrambled); return scrambled; } @@ -563,7 +563,7 @@ public string UnScramble(string scrambled) scramChars[i] = temp; } string unscrambled = new string(scramChars); - Console.WriteLine(unscrambled); + //Console.WriteLine(unscrambled); return unscrambled; } */ @@ -608,8 +608,8 @@ public void ResetOverrdingBetweenMods(ModItem itemA, ModItem itemB) if (this.OverrridingData[modB].overriddenBy.Count == 0) this.OverrridingData[modB].isOverriden = false; } - Console.WriteLine("ResetOverrdingBetweenMods modA: " + modA + " " + this.OverrridingData[modA].isOverriding + " " + this.OverrridingData[modA].isOverriden); - Console.WriteLine("ResetOverrdingBetweenMods modB: " + modB + " " + this.OverrridingData[modB].isOverriding + " " + this.OverrridingData[modB].isOverriden); + //Console.WriteLine("ResetOverrdingBetweenMods modA: " + modA + " " + this.OverrridingData[modA].isOverriding + " " + this.OverrridingData[modA].isOverriden); + //Console.WriteLine("ResetOverrdingBetweenMods modB: " + modB + " " + this.OverrridingData[modB].isOverriding + " " + this.OverrridingData[modB].isOverriden); } @@ -622,7 +622,7 @@ internal void SavePresets() if (File.Exists(JsonFile)) File.Delete(JsonFile); - Console.WriteLine(JsonString); + //Console.WriteLine(JsonString); StreamWriter sw = File.CreateText(JsonFile); sw.WriteLine(JsonString); sw.Flush(); @@ -643,8 +643,8 @@ public void LoadPresets() { string json = File.ReadAllText(JsonFile); temp = JsonConvert.DeserializeObject>(json); - Console.WriteLine("OUTPUT HERE!"); - Console.WriteLine(JsonConvert.SerializeObject(temp, Formatting.Indented)); + //Console.WriteLine("OUTPUT HERE!"); + //Console.WriteLine(JsonConvert.SerializeObject(temp, Formatting.Indented)); } catch (Exception Ex) { @@ -661,12 +661,12 @@ public void LoadPresets() public void UpdateNewModOverrideData(List items, ModItem newItem) { string modA = newItem.SubItems[2].Text; - //Console.WriteLine("UpdateNewModOverrideData"); - //Console.WriteLine("Mod checked or unchecked: " + modA); + ////Console.WriteLine("UpdateNewModOverrideData"); + ////Console.WriteLine("Mod checked or unchecked: " + modA); if (!newItem.Checked) { - //Console.WriteLine("--Unchecked"); + ////Console.WriteLine("--Unchecked"); if (this.OverrridingData.ContainsKey(modA)) this.OverrridingData.Remove(modA); @@ -687,7 +687,7 @@ public void UpdateNewModOverrideData(List items, ModItem newItem) } else { - //Console.WriteLine("--Unchecked"); + ////Console.WriteLine("--Unchecked"); if (!this.OverrridingData.ContainsKey(modA)) { this.OverrridingData[modA] = new OverridingData @@ -728,8 +728,8 @@ public void UpdateModOverridingdata(List items, ModItem movedMod, bool { string modA = movedMod.SubItems[2].Text; - Console.WriteLine("UpdateModOverridingdata"); - Console.WriteLine("--" + modA); + //Console.WriteLine("UpdateModOverridingdata"); + //Console.WriteLine("--" + modA); int indexToCheck = 0; if (movedUp) @@ -739,7 +739,7 @@ public void UpdateModOverridingdata(List items, ModItem movedMod, bool ModItem itemB = items[indexToCheck]; string modB = itemB.SubItems[2].Text; - Console.WriteLine("++" + modB); + //Console.WriteLine("++" + modB); if (!this.OverrridingData.ContainsKey(modA)) { @@ -792,7 +792,7 @@ public void GetModOverridingData(ModItem itemA, ModItem itemB, int itemCount, Ov if (intersect.Count() == 0) return; - //Console.WriteLine("---Intersection: " + modB + " : " + priorityB.ToString()); + ////Console.WriteLine("---Intersection: " + modB + " : " + priorityB.ToString()); //If we are loaded after the mod we are looking at we are overriding it. if (priorityA > priorityB) @@ -829,8 +829,8 @@ public void GetModOverridingData(ModItem itemA, ModItem itemB, int itemCount, Ov //else returns an empty string. public void GetOverridingData(List items) { - //Console.WriteLine(Environment.StackTrace); - //Console.WriteLine("Starting Overriding data check"); + ////Console.WriteLine(Environment.StackTrace); + ////Console.WriteLine("Starting Overriding data check"); this.OverrridingData.Clear(); foreach (ModItem itemA in items) @@ -854,7 +854,7 @@ public void GetOverridingData(List items) } OverridingData A = this.OverrridingData[modA]; - Console.WriteLine("Checking: " + modA + " : " + priorityA.ToString()); + //Console.WriteLine("Checking: " + modA + " : " + priorityA.ToString()); foreach (ModItem itemB in items) { string modB = itemB.FolderName; @@ -871,7 +871,7 @@ public void GetOverridingData(List items) A.overrides.ContainsKey(modB) ) { - //Console.WriteLine("--" + modA + "has allready been compared to: " + modB); + ////Console.WriteLine("--" + modA + "has allready been compared to: " + modB); continue; } @@ -884,7 +884,7 @@ public void GetOverridingData(List items) this.OverrridingData[modB].overrides.ContainsKey(modA) ) { - //Console.WriteLine("--" + modB + "has allready been compared to: " + modA); + ////Console.WriteLine("--" + modB + "has allready been compared to: " + modA); continue; } } @@ -906,16 +906,16 @@ public void GetOverridingData(List items) //Debug output //foreach(string key in this.OverrridingData.Keys) //{ - // Console.WriteLine("MOD: " + key); - // Console.WriteLine("--Overriden:"); + // //Console.WriteLine("MOD: " + key); + // //Console.WriteLine("--Overriden:"); // foreach (string mod in OverrridingData[key].overriddenBy.Keys) // { - // Console.WriteLine("----" + OverrridingData[key].isOverriden); + // //Console.WriteLine("----" + OverrridingData[key].isOverriden); // } - // Console.WriteLine("--Overrides:"); + // //Console.WriteLine("--Overrides:"); // foreach (string mod in OverrridingData[key].overrides.Keys) // { - // Console.WriteLine("----" + OverrridingData[key].isOverriding); + // //Console.WriteLine("----" + OverrridingData[key].isOverriding); // } //} #endregion @@ -942,33 +942,33 @@ public void ColorItemsOnOverridingData(List items) continue; } - //Console.WriteLine("Coloring mod: " + mod); + ////Console.WriteLine("Coloring mod: " + mod); if (!this.OverrridingData.ContainsKey(mod)) { item.SubItems[1].ForeColor = Color.Black; - //Console.WriteLine("Black"); + ////Console.WriteLine("Black"); continue; } OverridingData A = OverrridingData[mod]; if (A.isOverriden) { - //Console.WriteLine("OrangeRed"); + ////Console.WriteLine("OrangeRed"); item.SubItems[1].ForeColor = Color.OrangeRed; } if (A.isOverriding) { - //Console.WriteLine("Green"); + ////Console.WriteLine("Green"); item.SubItems[1].ForeColor = Color.Green; } if (A.isOverriding && A.isOverriden) { - //Console.WriteLine("Orange"); + ////Console.WriteLine("Orange"); item.SubItems[1].ForeColor = Color.Orange; } if (!A.isOverriding && !A.isOverriden) { - //Console.WriteLine("Black"); + ////Console.WriteLine("Black"); item.SubItems[1].ForeColor = Color.Black; } } @@ -977,12 +977,13 @@ public void ColorItemsOnOverridingData(List items) //Check for all active mods in list provided if the mods in the required section are also active. public Dictionary> CheckRequires (List items) { - //Console.WriteLine("Checking mods Requires"); + ////Console.WriteLine("Checking mods Requires"); this.MissingModsDependenciesDict = new Dictionary>(); //For each mod check if their requires list is a sub list of the active mods list... aka see if the required mods are active. foreach(ModItem item in items) { + Console.WriteLine("---" + item.SubItems[1].Text); if (!item.Checked) { item.SubItems[5].BackColor = Color.White; @@ -1003,13 +1004,6 @@ public Dictionary> CheckRequires (List items) continue; } - Console.WriteLine(item.SubItems[1].Text); - Console.WriteLine("List of Requires"); - foreach (string mod in ModDetails[modFolderName].Requires) - { - Console.WriteLine("--" + mod); - } - List Requires = ModDetails[modFolderName].Requires; List activeMods = new List(); @@ -1019,7 +1013,7 @@ public Dictionary> CheckRequires (List items) continue; if (!(items.IndexOf(itemB) > items.IndexOf(item))) continue; - //Console.WriteLine(itemB.SubItems[1].Text); + ////Console.WriteLine(itemB.SubItems[1].Text); activeMods.Add(itemB.SubItems[1].Text); } @@ -1028,12 +1022,12 @@ public Dictionary> CheckRequires (List items) if (missingMods.Count == 0) { - Console.WriteLine("All subset items found!"); + ////Console.WriteLine("All subset items found!"); item.SubItems[5].BackColor = Color.Green; item.SubItems[5].Text = "FOUND"; continue; } - Console.WriteLine("Not all subset items found!"); + ////Console.WriteLine("Not all subset items found!"); item.SubItems[5].BackColor = Color.Red; item.SubItems[5].Text = "MISSING"; MissingModsDependenciesDict[modDisplayName] = missingMods; @@ -1058,7 +1052,7 @@ public void MonitorZipSize(BackgroundWorker worker, DoWorkEventArgs e) long folderSize = Utils.DirSize(new DirectoryInfo(BasePath)); //zip usually does about 60 percent but we dont wanna complete at like 85 or 90 lets overestimate long compressedFolderSize = (long)Math.Round(folderSize * 0.35); - Console.WriteLine("Starting file size monitor, FolderSize: " + compressedFolderSize.ToString()); + //Console.WriteLine("Starting file size monitor, FolderSize: " + compressedFolderSize.ToString()); while (!e.Cancel && !worker.CancellationPending) { while (!File.Exists(zipFile)) @@ -1067,8 +1061,8 @@ public void MonitorZipSize(BackgroundWorker worker, DoWorkEventArgs e) } long zipFileSize = new FileInfo(zipFile).Length; int progress = Math.Min((int)((zipFileSize * (long)100) / compressedFolderSize ), 100); - Console.WriteLine("--" + zipFileSize.ToString()); - Console.WriteLine("--" + progress.ToString()); + //Console.WriteLine("--" + zipFileSize.ToString()); + //Console.WriteLine("--" + progress.ToString()); worker.ReportProgress(progress); System.Threading.Thread.Sleep(500); }