fix first install includes ALL updates

This commit is contained in:
2024-12-05 06:56:45 +01:00
parent e50d5f4874
commit a83d109f24

View File

@@ -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