From e70d72bc5aba7250aa9aac1a4232bb59ac5083fc Mon Sep 17 00:00:00 2001 From: Julian Maier Date: Fri, 5 Mar 2021 10:38:29 +0100 Subject: [PATCH] Fixed models.txt download deleting old file if it fails to get a new one --- Code/OS/Updater.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Code/OS/Updater.cs b/Code/OS/Updater.cs index caea138..257731e 100644 --- a/Code/OS/Updater.cs +++ b/Code/OS/Updater.cs @@ -134,19 +134,31 @@ namespace Flowframes.OS { try { - Networks.networks.ForEach(ai => + foreach(AI ai in Networks.networks) { var client = new WebClient(); string aiName = Path.GetFileNameWithoutExtension(ai.pkg.fileName); string url = $"https://raw.githubusercontent.com/n00mkrad/flowframes/main/Pkgs/{aiName}/models.txt"; - string savePath = Path.Combine(Paths.GetPkgPath(), aiName, "models.txt"); + string movePath = Path.Combine(Paths.GetPkgPath(), aiName, "models.txt"); + string savePath = movePath + ".tmp"; client.DownloadFile(url, savePath); + + if (IOUtils.GetFilesize(savePath) > 8) + { + File.Delete(movePath); + File.Move(savePath, movePath); + } + else + { + File.Delete(savePath); + } + Program.mainForm.UpdateAiModelCombox(); - }); + } } catch (Exception e) { - Logger.Log("Non-critical error while performing model list update. See logs for details."); + 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); } }