From a83d109f244893f6030fb9b45213416c41485407 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Thu, 5 Dec 2024 06:56:45 +0100 Subject: [PATCH] fix first install includes ALL updates --- ModpackUpdater.Manager/ModpackInstaller.cs | 57 ++++++++++++---------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index f2312ec..c8102e5 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -59,7 +59,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf } installInfos = await DownloadInstallInfos(); - result.CurrentVersion = modpackInfo.Version ?? new Version("0.0.0.0"); + result.CurrentVersion = modpackInfo.Version ?? installInfos.Version; var curVersion = result.CurrentVersion; // Check install actions @@ -223,35 +223,42 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf if (!isZip || localZipCache.FirstOrDefault(n => n.DownloadUrl == sourceUrl) is not LocalZipCacheEntry cachedZipInfo) { - // Download - var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath; - var sRemote = await http.GetStreamAsync(sourceUrl); - var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite); - await sRemote.CopyToAsync(fs); - await fs.FlushAsync(); - sRemote.Close(); - fs.Close(); - - // Extract - if (isZip) + try { - // Extract files - var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath)); - ZipFile.ExtractToDirectory(fsDestinationPath, zipDir); + // Download + var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath; + var sRemote = await http.GetStreamAsync(sourceUrl); + var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite); + await sRemote.CopyToAsync(fs); + await fs.FlushAsync(); + sRemote.Close(); + fs.Close(); - // Create cache entry - cachedZipInfo = new() + // Extract + if (isZip) { - DownloadUrl = sourceUrl, - ExtractedZipPath = zipDir - }; - localZipCache.Add(cachedZipInfo); + // Extract files + var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath)); + ZipFile.ExtractToDirectory(fsDestinationPath, zipDir); - // Remofe temp zip file - File.Delete(fsDestinationPath); + // Create cache entry + cachedZipInfo = new() + { + DownloadUrl = sourceUrl, + ExtractedZipPath = zipDir + }; + localZipCache.Add(cachedZipInfo); + + // Remofe temp zip file + File.Delete(fsDestinationPath); + } + else + cachedZipInfo = null; + } + catch (HttpRequestException ex) + { + throw; } - else - cachedZipInfo = null; } // Handle zip file content