Fixed models.txt download deleting old file if it fails to get a new one

This commit is contained in:
Julian Maier
2021-03-05 10:38:29 +01:00
parent 493a4f5975
commit e70d72bc5a

View File

@@ -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);
}
}