some bugfixing & more
This commit is contained in:
@@ -81,7 +81,10 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
||||
var infos = await DownloadInstallInfos();
|
||||
|
||||
if (infos is not null && infos.Actions.Count != 0)
|
||||
{
|
||||
result.Actions.AddRange(infos.Actions);
|
||||
result.LatestVersion = infos.Version;
|
||||
}
|
||||
else
|
||||
result.HasError = true;
|
||||
}
|
||||
@@ -176,32 +179,45 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
|
||||
|
||||
// Download
|
||||
var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
|
||||
var sRemote = await httpClient.GetStreamAsync(sourceUrl);
|
||||
var fs = new FileStream(destFilePath, FileMode.Create, FileAccess.ReadWrite);
|
||||
await sRemote.CopyToAsync(fs);
|
||||
sRemote.Close();
|
||||
fs.Close();
|
||||
|
||||
// Handle zip file
|
||||
if (isZip)
|
||||
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 httpClient.GetStreamAsync(sourceUrl);
|
||||
var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite);
|
||||
await sRemote.CopyToAsync(fs);
|
||||
await fs.FlushAsync();
|
||||
sRemote.Close();
|
||||
fs.Close();
|
||||
|
||||
// Extract
|
||||
var zipDir = $"{Path.GetFileNameWithoutExtension(fsDestinationPath)}_extracted";
|
||||
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
|
||||
|
||||
// Copy content
|
||||
var zipSrc = Path.Combine(zipDir, zipPath);
|
||||
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
||||
|
||||
// Delete/cache temporary files
|
||||
File.Delete(fsDestinationPath);
|
||||
localZipCache?.Add(new LocalZipCacheEntry
|
||||
if (isZip)
|
||||
{
|
||||
DownloadUrl = sourceUrl,
|
||||
ExtractedZipPath = zipDir
|
||||
});
|
||||
// Extract files
|
||||
var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath));
|
||||
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
|
||||
|
||||
// Create cache entry
|
||||
cachedZipInfo = new()
|
||||
{
|
||||
DownloadUrl = sourceUrl,
|
||||
ExtractedZipPath = zipDir
|
||||
};
|
||||
localZipCache.Add(cachedZipInfo);
|
||||
|
||||
// Remofe temp zip file
|
||||
File.Delete(fsDestinationPath);
|
||||
}
|
||||
else
|
||||
cachedZipInfo = null;
|
||||
}
|
||||
|
||||
// Handle zip file content
|
||||
if (cachedZipInfo != null)
|
||||
{
|
||||
// Copy content
|
||||
var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath);
|
||||
Extensions.CopyDirectory(zipSrc, destFilePath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user