From f918aedac952c5db34e09ef0e0f34831794a9922 Mon Sep 17 00:00:00 2001 From: g3gg0 Date: Mon, 12 Feb 2024 20:30:42 +0100 Subject: [PATCH] show status message when downloading tonies.json --- TeddyBench/TeddyMain.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/TeddyBench/TeddyMain.cs b/TeddyBench/TeddyMain.cs index 7846ad7..da047f3 100644 --- a/TeddyBench/TeddyMain.cs +++ b/TeddyBench/TeddyMain.cs @@ -45,6 +45,7 @@ public partial class TeddyMain : Form private static object TonieInfoLock = new object(); private static TonieTools.TonieData[] TonieInfo = new TonieTools.TonieData[0]; private static Dictionary TonieInfoCustom = new Dictionary(); + private static string TonieInfoString = ""; private Dictionary> CachedAudios = new Dictionary>(); private ListViewItem LastSelectediItem = null; @@ -142,6 +143,7 @@ public void LoadJson(bool force = false) { if (Settings.DownloadJson || force) { + TonieInfoString = "| Downloading..."; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.revvox.de/tonies.json?source=TeddyBench&version=" + ThisAssembly.Git.BaseTag); @@ -149,10 +151,13 @@ public void LoadJson(bool force = false) TextReader reader = new StreamReader(response.GetResponseStream()); string content = reader.ReadToEnd(); File.WriteAllText("tonies.json", content); + TonieInfoString = "| Downloaded"; } catch (Exception e) { + TonieInfoString = "| Download Failed"; ReportException("Downloader Thread", e); + return; } } @@ -160,10 +165,13 @@ public void LoadJson(bool force = false) { try { + TonieInfoString = "| Parsing..."; TonieInfo = JsonConvert.DeserializeObject(File.ReadAllText("tonies.json")); + TonieInfoString = ""; } catch (Exception e) { + TonieInfoString = "| Parsing Failed"; TonieInfo = new TonieTools.TonieData[0]; ReportException("Parse tonies.json", e); } @@ -244,7 +252,7 @@ public TeddyMain() StatusBarTimer = new System.Windows.Forms.Timer(); StatusBarTimer.Tick += (object sender, EventArgs e) => { UpdateStatusBar(); }; - StatusBarTimer.Interval = 500; + StatusBarTimer.Interval = 250; StatusBarTimer.Start(); } @@ -377,11 +385,15 @@ private void UpdateStatusBar() { if (TonieInfo.Length == 0) { - text += " | No tonies.json, consider downloading it"; + text += " | No tonies.json loaded, consider downloading it"; } else { - text += " | tonies.json has " + TonieInfo.Length + " entries"; + text += " | Have " + TonieInfo.Length + " entries in tonies.json"; + } + if (!string.IsNullOrEmpty(TonieInfoString)) + { + text += " " + TonieInfoString; } }