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(); installInfos = await DownloadInstallInfos();
result.CurrentVersion = modpackInfo.Version ?? new Version("0.0.0.0"); result.CurrentVersion = modpackInfo.Version ?? installInfos.Version;
var curVersion = result.CurrentVersion; var curVersion = result.CurrentVersion;
// Check install actions // 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) if (!isZip || localZipCache.FirstOrDefault(n => n.DownloadUrl == sourceUrl) is not LocalZipCacheEntry cachedZipInfo)
{ {
// Download try
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)
{ {
// Extract files // Download
var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath)); var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir); 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 // Extract
cachedZipInfo = new() if (isZip)
{ {
DownloadUrl = sourceUrl, // Extract files
ExtractedZipPath = zipDir var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath));
}; ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
localZipCache.Add(cachedZipInfo);
// Remofe temp zip file // Create cache entry
File.Delete(fsDestinationPath); 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 // Handle zip file content