From f0f68e54f51582e1fb6383f973e5ab5a0e46b764 Mon Sep 17 00:00:00 2001 From: matty <10895809+murrty@users.noreply.github.com> Date: Sat, 13 Jan 2024 23:42:53 -0600 Subject: [PATCH] handle un-reloadable threads --- src/YChanEx/Classes/ProgramSettings.cs | 15 ++++++++++----- src/YChanEx/Forms/frmMain.cs | 8 ++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/YChanEx/Classes/ProgramSettings.cs b/src/YChanEx/Classes/ProgramSettings.cs index 2e6da81..e828367 100644 --- a/src/YChanEx/Classes/ProgramSettings.cs +++ b/src/YChanEx/Classes/ProgramSettings.cs @@ -63,12 +63,17 @@ public static List LoadThreads() { if (SavedFiles.Count > 0) { for (int i = 0; i < SavedFiles.Count; i++) { - ThreadData Thread = File.ReadAllText(SavedFiles[i].FullName).JsonDeserialize(); - if (Thread == null) { - continue; + try { + ThreadData Thread = File.ReadAllText(SavedFiles[i].FullName).JsonDeserialize(); + if (Thread == null) { + continue; + } + Thread.FilePath = SavedFiles[i].FullName; + list.Add(Thread); + } + catch { + File.Move(SavedFiles[i].FullName, SavedFiles[i].FullName + ".broken"); } - Thread.FilePath = SavedFiles[i].FullName; - list.Add(Thread); } //list.Sort((x, y) => x.QueueIndex.CompareTo(y.QueueIndex)); } diff --git a/src/YChanEx/Forms/frmMain.cs b/src/YChanEx/Forms/frmMain.cs index ac9362a..988d882 100644 --- a/src/YChanEx/Forms/frmMain.cs +++ b/src/YChanEx/Forms/frmMain.cs @@ -157,8 +157,12 @@ private void CheckThreads() { var Thread = SavedThreads[i]; this.Invoke(() => LoadSavedThread(Thread, Thread.FilePath)); } - catch (Exception ex) { - murrty.classes.Log.ReportException(ex); + catch { + this.Invoke(() => { + MessageBox.Show("Could not load saved thread. It will need to be redownloaded."); + SavedThreads.RemoveAt(i); + lvThreads.Items.RemoveAt(i--); + }); } Thread.Sleep(500); }