Skip to content

Commit

Permalink
show status message when downloading tonies.json
Browse files Browse the repository at this point in the history
  • Loading branch information
g3gg0 committed Feb 12, 2024
1 parent b71bb9c commit f918aed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions TeddyBench/TeddyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> TonieInfoCustom = new Dictionary<string, string>();
private static string TonieInfoString = "";

private Dictionary<string, Tuple<TonieAudio, DateTime>> CachedAudios = new Dictionary<string, Tuple<TonieAudio, DateTime>>();
private ListViewItem LastSelectediItem = null;
Expand Down Expand Up @@ -142,28 +143,35 @@ 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);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
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;
}
}

lock (TonieInfoLock)
{
try
{
TonieInfoString = "| Parsing...";
TonieInfo = JsonConvert.DeserializeObject<TonieTools.TonieData[]>(File.ReadAllText("tonies.json"));
TonieInfoString = "";
}
catch (Exception e)
{
TonieInfoString = "| Parsing Failed";
TonieInfo = new TonieTools.TonieData[0];
ReportException("Parse tonies.json", e);
}
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit f918aed

Please sign in to comment.