repair manager project

This commit is contained in:
2025-06-26 18:53:00 +02:00
parent d85a41c158
commit 04848d4622
31 changed files with 129 additions and 122 deletions

View File

@@ -0,0 +1,17 @@
using Pilz.UI.Gtk.Symbols;
using System.Reflection;
namespace ModpackUpdater.Apps.Client;
internal class AppSymbolFactory : GtkSymbolFactory<AppSymbols>
{
public override Assembly GetImageResourceAssembly()
{
return typeof(AppSymbols).Assembly;
}
public override string GetImageRessourcePath(AppSymbols svgImage)
{
return $"{typeof(AppSymbols).Namespace}.Symbols.{svgImage}.svg";
}
}

View File

@@ -6,7 +6,6 @@ using Pilz.UI.Gtk.Dialogs;
using Pilz.UI.Symbols;
using System.Diagnostics;
using System.Reflection;
using System.Security.Cryptography;
using UI = Gtk.Builder.ObjectAttribute;
namespace ModpackUpdater.Apps.Client;
@@ -45,10 +44,10 @@ internal class MainWindow : Window
Title = $"{Title} (v{Assembly.GetExecutingAssembly().GetAppVersion()})";
button_CheckForUpdates.Image = AppGlobals.Symbols.GetImage(AppSymbols.update_done, SymbolSize.Small);
button_SearchMinecraftFolder.Image = AppGlobals.Symbols.GetImage(AppSymbols.opened_folder, SymbolSize.Small);
button_Install.Image = AppGlobals.Symbols.GetImage(AppSymbols.software_installer, SymbolSize.Small);
image_Repair.Pixbuf = AppGlobals.Symbols.GetPixbuf(AppSymbols.wrench, SymbolSize.Small);
button_CheckForUpdates.Image = Program.Symbols.GetImage(AppSymbols.update_done, SymbolSize.Small);
button_SearchMinecraftFolder.Image = Program.Symbols.GetImage(AppSymbols.opened_folder, SymbolSize.Small);
button_Install.Image = Program.Symbols.GetImage(AppSymbols.software_installer, SymbolSize.Small);
image_Repair.Pixbuf = Program.Symbols.GetPixbuf(AppSymbols.wrench, SymbolSize.Small);
LoadProfileToUi();
@@ -77,7 +76,7 @@ internal class MainWindow : Window
var updater = new AppUpdater();
if (!updateOptions.NoUpdate && await updater.Check() && MessageBox.Show(this, ButtonsType.YesNo, MessageType.Info, LangRes.MsgBox_UpdateAvailable) == ResponseType.Yes)
{
SetStatus(LangRes.StatusText_InstallingAppUpdate, AppGlobals.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
SetStatus(LangRes.StatusText_InstallingAppUpdate, Program.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
Sensitive = false;
await updater.Install();
Program.Restart();
@@ -203,21 +202,21 @@ internal class MainWindow : Window
if (modpackInfo == null || string.IsNullOrWhiteSpace(textBox_MinecraftFolder.Text) /*|| modpackInfo.Valid*/)
{
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppGlobals.Symbols.GetPixbuf(AppSymbols.general_warning_sign, SymbolSize.Small));
SetStatus(LangRes.StatusText_MinecraftProfileWarning, Program.Symbols.GetPixbuf(AppSymbols.general_warning_sign, SymbolSize.Small));
button_CheckForUpdates.Sensitive = false;
button_Install.Sensitive = false;
return false;
}
else if (updateConfig == null || string.IsNullOrWhiteSpace(textBox_ModpackUrl.Text))
{
SetStatus(LangRes.StatusText_ConfigIncompleteOrNotLoaded, AppGlobals.Symbols.GetPixbuf(AppSymbols.general_warning_sign, SymbolSize.Small));
SetStatus(LangRes.StatusText_ConfigIncompleteOrNotLoaded, Program.Symbols.GetPixbuf(AppSymbols.general_warning_sign, SymbolSize.Small));
button_CheckForUpdates.Sensitive = false;
button_Install.Sensitive = false;
return false;
}
else if (updateConfig.Maintenance && !updateOptions.IgnoreMaintenance)
{
SetStatus(LangRes.StatusText_Maintenance, AppGlobals.Symbols.GetPixbuf(AppSymbols.services, SymbolSize.Small));
SetStatus(LangRes.StatusText_Maintenance, Program.Symbols.GetPixbuf(AppSymbols.services, SymbolSize.Small));
button_CheckForUpdates.Sensitive = false;
button_Install.Sensitive = false;
return false;
@@ -243,28 +242,28 @@ internal class MainWindow : Window
void error()
{
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, AppGlobals.Symbols.GetPixbuf(AppSymbols.close, SymbolSize.Small));
SetStatus(LangRes.StatusText_ErrorWhileUpdateCheckOrUpdate, Program.Symbols.GetPixbuf(AppSymbols.close, SymbolSize.Small));
currentUpdating = false;
}
void installing()
{
SetStatus(LangRes.StatusText_Installing, AppGlobals.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
SetStatus(LangRes.StatusText_Installing, Program.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
currentUpdating = true;
}
void updatesAvailable()
{
SetStatus(LangRes.StatusText_UpdateAvailable, AppGlobals.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
SetStatus(LangRes.StatusText_UpdateAvailable, Program.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
}
void everythingOk()
{
SetStatus(LangRes.StatusTest_EverythingOk, AppGlobals.Symbols.GetPixbuf(AppSymbols.done, SymbolSize.Small));
SetStatus(LangRes.StatusTest_EverythingOk, Program.Symbols.GetPixbuf(AppSymbols.done, SymbolSize.Small));
currentUpdating = false;
}
// Check only if not pressed "install", not really needed otherwise.
if (lastUpdateCheckResult is null || !doInstall || repair)
{
SetStatus(LangRes.StatusText_CheckingForUpdates, AppGlobals.Symbols.GetPixbuf(AppSymbols.update_done, SymbolSize.Small));
SetStatus(LangRes.StatusText_CheckingForUpdates, Program.Symbols.GetPixbuf(AppSymbols.update_done, SymbolSize.Small));
// Check for extras once again
updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(modpackInfo));
@@ -335,13 +334,13 @@ internal class MainWindow : Window
private void Updated_CheckingProgresssUpdated(int toCheck, int processed)
{
SetStatus(Math.Round(processed / (double)toCheck * 100d, 1) + "%", AppGlobals.Symbols.GetPixbuf(AppSymbols.update_done, SymbolSize.Small));
SetStatus(Math.Round(processed / (double)toCheck * 100d, 1) + "%", Program.Symbols.GetPixbuf(AppSymbols.update_done, SymbolSize.Small));
}
private void Update_InstallProgessUpdated(UpdateCheckResult result, int processedSyncs)
{
int actionCount = result.Actions.Count;
SetStatus(Math.Round(processedSyncs / (double)actionCount * 100d, 1) + "%", AppGlobals.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
SetStatus(Math.Round(processedSyncs / (double)actionCount * 100d, 1) + "%", Program.Symbols.GetPixbuf(AppSymbols.software_installer, SymbolSize.Small));
}
#endregion

View File

@@ -48,7 +48,7 @@
<PackageReference Include="Pilz.Configuration" Version="3.2.2" />
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
<PackageReference Include="Pilz.IO" Version="2.1.0" />
<PackageReference Include="Pilz.UI.Gtk" Version="1.0.1" />
<PackageReference Include="Pilz.UI.Gtk" Version="1.0.2" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,9 +1,11 @@
using Castle.Core.Logging;
using Gtk;
using Microsoft.Win32;
using ModpackUpdater.Manager;
using Newtonsoft.Json;
using Pilz;
using Pilz.Configuration;
using Pilz.UI.Gtk.Symbols;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
@@ -18,10 +20,9 @@ public static class Program
private static readonly ILogger log = new ConsoleLogger();
private static Application uiApp;
public static IGtkSymbolFactory<AppSymbols> Symbols { get; } = new AppSymbolFactory();
public static ISettings Settings => settingsManager.Instance;
public static ILogger Log => log;
internal static Options Options { get; private set; }
[DllImport("kernel32.dll")]
@@ -54,6 +55,9 @@ public static class Program
private static void RunApp(UpdateCheckOptionsAdv updateOptions)
{
if (UsesWindowsDarkTheme())
Environment.SetEnvironmentVariable("GTK_THEME", "Adwaita:dark");
Application.Init();
uiApp = new Application("ModpackUpdater.Apps.Client", GLib.ApplicationFlags.None);
@@ -170,4 +174,19 @@ public static class Program
return info.ConfigUrl;
return configUrl;
}
private static bool UsesWindowsDarkTheme()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
try
{
return Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize")?.GetValue("AppsUseLightTheme") as bool? ?? default;
}
catch (Exception)
{
}
}
return default;
}
}