From 3e1ab721623df7afa418d950a0eddda697a7ed4f Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Thu, 5 Dec 2024 07:06:06 +0100 Subject: [PATCH] update deps & enable console logging --- .../ModpackUpdater.Apps.Client.csproj | 6 ++--- ModpackUpdater.Apps.Client/Program.cs | 10 +++++--- .../ModpackUpdater.Apps.Manager.csproj | 14 +++++------ .../ModpackUpdater.Apps.csproj | 4 ++-- ModpackUpdater.Manager/ModpackInstaller.cs | 24 ++++++++++++++----- .../ModpackUpdater.Manager.csproj | 3 ++- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/ModpackUpdater.Apps.Client/ModpackUpdater.Apps.Client.csproj b/ModpackUpdater.Apps.Client/ModpackUpdater.Apps.Client.csproj index eb43388..a2916c8 100644 --- a/ModpackUpdater.Apps.Client/ModpackUpdater.Apps.Client.csproj +++ b/ModpackUpdater.Apps.Client/ModpackUpdater.Apps.Client.csproj @@ -39,11 +39,11 @@ - + - - + + diff --git a/ModpackUpdater.Apps.Client/Program.cs b/ModpackUpdater.Apps.Client/Program.cs index c95c002..109e37d 100644 --- a/ModpackUpdater.Apps.Client/Program.cs +++ b/ModpackUpdater.Apps.Client/Program.cs @@ -1,10 +1,11 @@ -using ModpackUpdater.Manager; +using Castle.Core.Logging; +using ModpackUpdater.Manager; using Newtonsoft.Json; using Pilz; using Pilz.Configuration; using System.Runtime.InteropServices; -[assembly: AssemblyAppVersion("1.6.2.0")] +[assembly: AssemblyAppVersion("1.6.3.0")] namespace ModpackUpdater.Apps.Client; @@ -97,7 +98,10 @@ public static class Program updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(info)); // Check for update - var installer = new ModpackInstaller(config, info); + var installer = new ModpackInstaller(config, info) + { + Log = new ConsoleLogger(), + }; var result = installer.Check(updateOptions).Result; if (!silent && !updateOptions.NoUpdate && new AppUpdater().Check().Result) diff --git a/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj b/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj index 19148f4..c05e9e9 100644 --- a/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj +++ b/ModpackUpdater.Apps.Manager/ModpackUpdater.Apps.Manager.csproj @@ -11,13 +11,13 @@ - - - - - - - + + + + + + + diff --git a/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj b/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj index 38b6ff8..18a1c00 100644 --- a/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj +++ b/ModpackUpdater.Apps/ModpackUpdater.Apps.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index c8102e5..9aab986 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Castle.Core.Logging; +using Newtonsoft.Json; using System.IO.Compression; using FileMode = System.IO.FileMode; @@ -19,6 +20,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf public delegate void CheckingProgressUpdatedEventHandler(int toCheck, int processed); + public ILogger Log { get; set; } = NullLogger.Instance; + private readonly HttpClient http = new(); private readonly ModpackFactory factory = new(); @@ -153,7 +156,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf switch (uaction.Type) { case UpdateActionType.Update: - await InstallFile(destFilePath, sourceUrl, uaction.IsZip, uaction.ZipPath, localZipCache); + if (!await InstallFile(destFilePath, sourceUrl, uaction.IsZip, uaction.ZipPath, localZipCache)) + return false; break; case UpdateActionType.Delete: { @@ -198,8 +202,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf break; } } - else - await InstallFile(destFilePath, sourceUrl, iaction.IsZip, iaction.ZipPath, localZipCache); + else if (!await InstallFile(destFilePath, sourceUrl, iaction.IsZip, iaction.ZipPath, localZipCache)) + return false; processed += 1; InstallProgessUpdated?.Invoke(checkResult, processed); @@ -217,7 +221,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf return true; } - private async Task InstallFile(string destFilePath, string sourceUrl, bool isZip, string zipPath, List localZipCache) + private async Task InstallFile(string destFilePath, string sourceUrl, bool isZip, string zipPath, List localZipCache) { Directory.CreateDirectory(Path.GetDirectoryName(destFilePath)); @@ -257,7 +261,13 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf } catch (HttpRequestException ex) { - throw; + Log.Error("Could not download file: " + sourceUrl, ex); + return false; + } + catch (Exception ex) + { + Log.Error("Could not install file: " + sourceUrl, ex); + return false; } } @@ -268,5 +278,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf var zipSrc = Path.Combine(cachedZipInfo.ExtractedZipPath, zipPath); Extensions.CopyDirectory(zipSrc, destFilePath, true); } + + return true; } } \ No newline at end of file diff --git a/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj b/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj index e74a348..7531847 100644 --- a/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj +++ b/ModpackUpdater.Manager/ModpackUpdater.Manager.csproj @@ -7,11 +7,12 @@ + - +