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(); var infos = await DownloadInstallInfos();
if (infos is not null && infos.Actions.Count != 0) if (infos is not null && infos.Actions.Count != 0)
{
result.Actions.AddRange(infos.Actions); result.Actions.AddRange(infos.Actions);
result.LatestVersion = infos.Version;
}
else else
result.HasError = true; result.HasError = true;
} }
@@ -176,32 +179,45 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
{ {
Directory.CreateDirectory(Path.GetDirectoryName(destFilePath)); Directory.CreateDirectory(Path.GetDirectoryName(destFilePath));
if (!isZip || localZipCache.FirstOrDefault(n => n.DownloadUrl == sourceUrl) is not LocalZipCacheEntry cachedZipInfo)
{
// Download // Download
var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath; var fsDestinationPath = isZip ? Path.Combine(Path.GetTempPath(), $"mc_update_file_{DateTime.Now.ToBinary()}.zip") : destFilePath;
var sRemote = await httpClient.GetStreamAsync(sourceUrl); var sRemote = await httpClient.GetStreamAsync(sourceUrl);
var fs = new FileStream(destFilePath, FileMode.Create, FileAccess.ReadWrite); var fs = new FileStream(fsDestinationPath, FileMode.Create, FileAccess.ReadWrite);
await sRemote.CopyToAsync(fs); await sRemote.CopyToAsync(fs);
await fs.FlushAsync();
sRemote.Close(); sRemote.Close();
fs.Close(); fs.Close();
// Handle zip file // Extract
if (isZip) if (isZip)
{ {
// Extract // Extract files
var zipDir = $"{Path.GetFileNameWithoutExtension(fsDestinationPath)}_extracted"; var zipDir = Path.Combine(Path.GetDirectoryName(fsDestinationPath), Path.GetFileNameWithoutExtension(fsDestinationPath));
ZipFile.ExtractToDirectory(fsDestinationPath, zipDir); ZipFile.ExtractToDirectory(fsDestinationPath, zipDir);
// Copy content // Create cache entry
var zipSrc = Path.Combine(zipDir, zipPath); cachedZipInfo = new()
Extensions.CopyDirectory(zipSrc, destFilePath, true);
// Delete/cache temporary files
File.Delete(fsDestinationPath);
localZipCache?.Add(new LocalZipCacheEntry
{ {
DownloadUrl = sourceUrl, DownloadUrl = sourceUrl,
ExtractedZipPath = zipDir 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;
using Newtonsoft.Json.Converters;
namespace ModpackUpdater.Model; namespace ModpackUpdater.Model;
public class InstallInfos 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) public static InstallInfos Parse(string content)
{ {

View File

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

View File

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