From 2822dc7d322fddd61ddd6aed238960444edbc916 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Fri, 9 Apr 2021 15:31:42 +0200 Subject: [PATCH] Better error handling for fetching models.txt, news, patrons --- Code/OS/Updater.cs | 32 ++++++++++++++++++++------------ Code/UI/GetWebInfo.cs | 30 ++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Code/OS/Updater.cs b/Code/OS/Updater.cs index 06522e5..2f3e1c1 100644 --- a/Code/OS/Updater.cs +++ b/Code/OS/Updater.cs @@ -14,7 +14,7 @@ namespace Flowframes.OS public enum VersionCompareResult { Older, Newer, Equal }; public static string latestVerUrl = "https://dl.nmkd.de/flowframes/exe/ver.ini"; - public static string GetInstalledVerStr () + public static string GetInstalledVerStr() { Version ver = GetInstalledVer(); if (ver.Major == 0 && ver.Minor == 0 && ver.Minor == 0) return ""; @@ -36,7 +36,7 @@ namespace Flowframes.OS } } - public static VersionCompareResult CompareVersions (Version currentVersion, Version newVersion) + public static VersionCompareResult CompareVersions(Version currentVersion, Version newVersion) { Logger.Log($"Checking if {newVersion} > {currentVersion}", true); int result = newVersion.CompareTo(currentVersion); @@ -57,7 +57,7 @@ namespace Flowframes.OS return VersionCompareResult.Equal; } - public static Version GetLatestVer (bool patreon) + public static Version GetLatestVer(bool patreon) { var client = new WebClient(); int line = patreon ? 0 : 2; @@ -79,7 +79,7 @@ namespace Flowframes.OS } } - public static async Task UpdateTo (int version, UpdaterForm form = null) + public static async Task UpdateTo(int version, UpdaterForm form = null) { Logger.Log("Updating to " + version, true); string savePath = Path.Combine(Paths.GetExeDir(), $"FlowframesV{version}"); @@ -128,7 +128,7 @@ namespace Flowframes.OS Application.Exit(); } - public static async Task AsyncUpdateCheck () + public static async Task AsyncUpdateCheck() { Version installed = GetInstalledVer(); Version latestPat = GetLatestVer(true); @@ -139,15 +139,23 @@ namespace Flowframes.OS public static async Task UpdateModelList() { - try + foreach (AI ai in Networks.networks) { - foreach(AI ai in Networks.networks) + try { var client = new WebClient(); string aiName = ai.pkgDir; string url = $"https://raw.githubusercontent.com/n00mkrad/flowframes/main/Pkgs/{aiName}/models.txt"; string movePath = Path.Combine(Paths.GetPkgPath(), aiName, "models.txt"); string savePath = movePath + ".tmp"; + + if (!Directory.Exists(savePath.GetParentDir())) + { + Logger.Log($"Skipping {ai.pkgDir} models file download as '{savePath.GetParentDir()}' does not exist!", true); + continue; + } + + Logger.Log($"Saving models file from '{url}' to '{savePath}'", true); client.DownloadFile(url, savePath); if (IOUtils.GetFilesize(savePath) > 8) @@ -162,11 +170,11 @@ namespace Flowframes.OS Program.mainForm.UpdateAiModelCombox(); } - } - catch (Exception e) - { - Logger.Log("Failed to fetch models file. Ignore this if you are not connected to the internet."); - Logger.Log($"{e.Message}\n{e.StackTrace}", true); + catch (Exception e) + { + Logger.Log($"Failed to fetch models file for {ai.friendlyName}. Ignore this if you are not connected to the internet."); + Logger.Log($"{e.Message}\n{e.StackTrace}", true); + } } } } diff --git a/Code/UI/GetWebInfo.cs b/Code/UI/GetWebInfo.cs index 199c4b8..a8e2e9c 100644 --- a/Code/UI/GetWebInfo.cs +++ b/Code/UI/GetWebInfo.cs @@ -13,18 +13,32 @@ namespace Flowframes.UI { public static async Task LoadNews (Label newsLabel) { - string url = $"https://raw.githubusercontent.com/n00mkrad/flowframes/main/changelog.txt"; - var client = new WebClient(); - var str = await client.DownloadStringTaskAsync(new Uri(url)); - newsLabel.Text = str; + try + { + string url = $"https://raw.githubusercontent.com/n00mkrad/flowframes/main/changelog.txt"; + var client = new WebClient(); + var str = await client.DownloadStringTaskAsync(new Uri(url)); + newsLabel.Text = str; + } + catch(Exception e) + { + Logger.Log($"Failed to load news: {e.Message}"); + } } public static async Task LoadPatronListCsv(Label patronsLabel) { - string url = $"https://raw.githubusercontent.com/n00mkrad/flowframes/main/patrons.csv"; - var client = new WebClient(); - var csvData = await client.DownloadStringTaskAsync(new Uri(url)); - patronsLabel.Text = ParsePatreonCsv(csvData); + try + { + string url = $"https://raw.githubusercontent.com/n00mkrad/flowframes/main/patrons.csv"; + var client = new WebClient(); + var csvData = await client.DownloadStringTaskAsync(new Uri(url)); + patronsLabel.Text = ParsePatreonCsv(csvData); + } + catch (Exception e) + { + Logger.Log($"Failed to load patreon CSV: {e.Message}"); + } } public static string ParsePatreonCsv(string csvData)