some bugfixing & more

This commit is contained in:
2024-06-19 20:08:00 +02:00
parent 0f4ba96963
commit 6808f772c1
4 changed files with 48 additions and 25 deletions

View File

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

View File

@@ -1,10 +1,13 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ModpackUpdater.Model;
public class InstallInfos
{
public List<InstallAction> Actions { get; private set; } = [];
[JsonConverter(typeof(VersionConverter))]
public Version Version { get; set; }
public List<InstallAction> Actions { get; } = [];
public static InstallInfos Parse(string content)
{

View File

@@ -1,6 +1,7 @@
using ModpackUpdater.Manager;
using ModpackUpdater.Model;
using ModpackUpdater.My.Resources;
using System.Diagnostics;
using Telerik.WinControls;
using Telerik.WinControls.UI;
@@ -142,9 +143,11 @@ public partial class Form1
else
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px);
}
catch
catch(Exception)
{
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, MySymbols.icons8_delete_16px);
if (Debugger.IsAttached)
throw;
}
finally
{

View File

@@ -17,6 +17,7 @@ public static class Program
MigrateLegacySettings(GetSettingsPath(null));
}
[STAThread]
internal static void Main(string[] args)
{
var options = new Options(args);