seperated cli & some work for options

This commit is contained in:
2025-08-20 08:17:33 +02:00
parent b434ddf480
commit 582752c987
26 changed files with 254 additions and 166 deletions

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
<PackageReference Include="Pilz.IO" Version="2.1.0" />
</ItemGroup>
</Project>

View File

@@ -1,9 +1,9 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Pilz.Configuration; using Pilz.Configuration;
namespace ModpackUpdater.Apps.Client; namespace ModpackUpdater.Apps.Client.Gui;
public class AppConfig : IChildSettings, ISettingsIdentifier public class AppConfig : ISettingsNode, ISettingsIdentifier
{ {
public static string Identifier => "pilz.appconfig"; public static string Identifier => "pilz.appconfig";

View File

@@ -2,11 +2,10 @@
using Newtonsoft.Json.Converters; using Newtonsoft.Json.Converters;
using Pilz.Extensions; using Pilz.Extensions;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
namespace ModpackUpdater.Apps.Client; namespace ModpackUpdater.Apps.Client.Gui;
public class AppUpdater public class AppUpdater(string updateUrl)
{ {
private class UpdateInfo private class UpdateInfo
{ {
@@ -15,7 +14,6 @@ public class AppUpdater
public string DownloadUrl { get; set; } public string DownloadUrl { get; set; }
} }
private const string UPDATE_URL = "https://git.pilzinsel64.de/litw-refined/minecraft-modpack-updater/-/snippets/3/raw/main/updates.json";
private readonly HttpClient httpClient = new(); private readonly HttpClient httpClient = new();
private UpdateInfo info; private UpdateInfo info;
@@ -26,7 +24,7 @@ public class AppUpdater
try try
{ {
var appVersion = Assembly.GetExecutingAssembly().GetAppVersion().Version; var appVersion = Assembly.GetExecutingAssembly().GetAppVersion().Version;
var result = await httpClient.GetStringAsync(UPDATE_URL); var result = await httpClient.GetStringAsync(updateUrl);
info = JsonConvert.DeserializeObject<UpdateInfo>(result); info = JsonConvert.DeserializeObject<UpdateInfo>(result);
if (info is not null && info.Version > appVersion) if (info is not null && info.Version > appVersion)
@@ -58,10 +56,10 @@ public class AppUpdater
// Download the new file // Download the new file
using (var tempFileStream = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)) using (var tempFileStream = new FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite))
{ {
Stream downloadStream = null; Stream? downloadStream = null;
try try
{ {
var url = info.DownloadUrl; var url = info?.DownloadUrl;
downloadStream = await client.GetStreamAsync(url); downloadStream = await client.GetStreamAsync(url);
await downloadStream.CopyToAsync(tempFileStream); await downloadStream.CopyToAsync(tempFileStream);
} }
@@ -75,7 +73,10 @@ public class AppUpdater
} }
// Replace current application file with new file // Replace current application file with new file
if (!string.IsNullOrWhiteSpace(appFileName))
{
File.Move(appFileName, oldFileName, true); File.Move(appFileName, oldFileName, true);
File.Move(tempFileName, appFileName); File.Move(tempFileName, appFileName);
} }
}
} }

View File

@@ -39,7 +39,7 @@ namespace ModpackUpdater.My.Resources {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModpackUpdater.Apps.Client.FiledialogFilters", typeof(FiledialogFilters).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModpackUpdater.Apps.Client.Gui.FiledialogFilters", typeof(FiledialogFilters).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;

View File

@@ -39,7 +39,7 @@ namespace ModpackUpdater.My.Resources {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModpackUpdater.Apps.Client.LangRes", typeof(LangRes).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ModpackUpdater.Apps.Client.Gui.LangRes", typeof(LangRes).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;

View File

@@ -3,7 +3,7 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace ModpackUpdater.Apps.Client namespace ModpackUpdater.Apps.Client.Gui
{ {
[Microsoft.VisualBasic.CompilerServices.DesignerGenerated()] [Microsoft.VisualBasic.CompilerServices.DesignerGenerated()]

View File

@@ -8,11 +8,11 @@ using System.Reflection;
using Telerik.WinControls; using Telerik.WinControls;
using Telerik.WinControls.UI; using Telerik.WinControls.UI;
namespace ModpackUpdater.Apps.Client; namespace ModpackUpdater.Apps.Client.Gui;
public partial class MainForm public partial class MainForm
{ {
private readonly UpdateCheckOptionsAdv updateOptions; private readonly UpdateCheckOptions updateOptions = new();
private ModpackInfo modpackInfo = new(); private ModpackInfo modpackInfo = new();
private ModpackConfig updateConfig = new(); private ModpackConfig updateConfig = new();
private ModpackFeatures features; private ModpackFeatures features;
@@ -21,14 +21,8 @@ public partial class MainForm
private bool loadingData; private bool loadingData;
private int curOptionsRow = 3; private int curOptionsRow = 3;
public MainForm() : this(new()) public MainForm()
{ {
}
public MainForm(UpdateCheckOptionsAdv updateOptions)
{
this.updateOptions = updateOptions;
InitializeComponent(); InitializeComponent();
Text = $"{Text} (v{Assembly.GetExecutingAssembly().GetAppVersion()})"; Text = $"{Text} (v{Assembly.GetExecutingAssembly().GetAppVersion()})";
@@ -60,14 +54,24 @@ public partial class MainForm
private void LoadProfileToUi() private void LoadProfileToUi()
{ {
loadingData = true; loadingData = true;
tableLayoutPanel1.SuspendLayout();
RadTextBox_MinecraftProfileFolder.Text = modpackInfo?.LocaLPath ?? updateOptions.ProfileFolder ?? AppConfig.Instance.LastMinecraftProfilePath ?? RadTextBox_MinecraftProfileFolder.Text; RadTextBox_MinecraftProfileFolder.Text = modpackInfo?.LocaLPath ?? AppConfig.Instance.LastMinecraftProfilePath ?? RadTextBox_MinecraftProfileFolder.Text;
RadTextBox_ModpackConfig.Text = modpackInfo?.ConfigUrl ?? updateOptions.ModpackConfig ?? RadTextBox_ModpackConfig.Text; RadTextBox_ModpackConfig.Text = modpackInfo?.ConfigUrl ?? RadTextBox_ModpackConfig.Text;
radTextBox_InstallKey.Text = modpackInfo?.ExtrasKey ?? updateOptions.ExtrasKey ?? radTextBox_InstallKey.Text; radTextBox_InstallKey.Text = modpackInfo?.ExtrasKey ?? radTextBox_InstallKey.Text;
tableLayoutPanel1.ResumeLayout();
loadingData = false; loadingData = false;
} }
private void LoadOptionsToUi()
{
//foreach (var set in )
//{
// // ...
//}
}
private async void CheckStatusAndUpdate(bool loadProfileToUi) private async void CheckStatusAndUpdate(bool loadProfileToUi)
{ {
if (CheckStatus(loadProfileToUi)) if (CheckStatus(loadProfileToUi))
@@ -121,6 +125,7 @@ public partial class MainForm
RadButton_Install.Enabled = false; RadButton_Install.Enabled = false;
return false; return false;
} }
LoadOptionsToUi();
RadButton_CheckForUpdates.Enabled = true; RadButton_CheckForUpdates.Enabled = true;
RadButton_Install.Enabled = true; RadButton_Install.Enabled = true;
return true; return true;
@@ -131,11 +136,7 @@ public partial class MainForm
// Ensure set extras key // Ensure set extras key
modpackInfo.ExtrasKey = radTextBox_InstallKey.Text.Trim(); modpackInfo.ExtrasKey = radTextBox_InstallKey.Text.Trim();
var updater = new ModpackInstaller(updateConfig, modpackInfo) var updater = new ModpackInstaller(updateConfig, modpackInfo);
{
OverwriteRefTag = Program.Options.RefTag,
OverwriteVersion = Program.Options.Version,
};
updater.InstallProgessUpdated += Update_InstallProgessUpdated; updater.InstallProgessUpdated += Update_InstallProgessUpdated;
updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated; updater.CheckingProgressUpdated += Updated_CheckingProgresssUpdated;
@@ -192,6 +193,10 @@ public partial class MainForm
return; return;
} }
// Load options
// lastUpdateCheckResult.OptionsAvailable...
// lastUpdateCheckResult.OptionsEnabled...
// No updates available // No updates available
if (!lastUpdateCheckResult.HasUpdates) if (!lastUpdateCheckResult.HasUpdates)
{ {
@@ -257,8 +262,8 @@ public partial class MainForm
private async void Form1_Shown(object sender, EventArgs e) private async void Form1_Shown(object sender, EventArgs e)
{ {
var updater = new AppUpdater(); var updater = new AppUpdater(Program.UPDATE_URL);
if (!updateOptions.NoUpdate && await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info).IsYes()) if (await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info).IsYes())
{ {
SetStatus(LangRes.StatusText_InstallingAppUpdate, AppGlobals.Symbols.GetSvgImage(AppSymbols.software_installer, SymbolSize.Small)); SetStatus(LangRes.StatusText_InstallingAppUpdate, AppGlobals.Symbols.GetSvgImage(AppSymbols.software_installer, SymbolSize.Small));
Enabled = false; Enabled = false;

View File

@@ -0,0 +1,64 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<ApplicationIcon>minecraft modpack updater.ico</ApplicationIcon>
<AssemblyName>Minecraft Modpack Updater</AssemblyName>
<ImplicitUsings>true</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Version.cs" />
</ItemGroup>
<ItemGroup>
<Compile Update="FiledialogFilters.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>FiledialogFilters.resx</DependentUpon>
</Compile>
<Compile Update="LangRes.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>LangRes.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="FiledialogFilters.resx">
<Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>ModpackUpdater.My.Resources</CustomToolNamespace>
<LastGenOutput>FiledialogFilters.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="LangRes.resx">
<Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>ModpackUpdater.My.Resources</CustomToolNamespace>
<LastGenOutput>LangRes.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pilz.Configuration" Version="3.2.6" />
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
<PackageReference Include="Pilz.IO" Version="2.1.0" />
<PackageReference Include="Pilz.UI" Version="3.0.0" />
<PackageReference Include="Pilz.UI.WinForms" Version="2.6.2" />
<PackageReference Include="Pilz.UI.WinForms.Telerik" Version="2.13.3" />
<PackageReference Include="Pilz.UI.WinForms.Telerik.Symbols" Version="1.2.1" />
<PackageReference Include="UI.for.WinForms.Common" Version="2025.2.612-preview" />
<PackageReference Include="UI.for.WinForms.Themes" Version="2025.2.612-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ModpackUpdater.Apps.AppUpdates\ModpackUpdater.Apps.AppUpdates.csproj" />
<ProjectReference Include="..\ModpackUpdater.Apps\ModpackUpdater.Apps.csproj" />
<ProjectReference Include="..\ModpackUpdater.Manager\ModpackUpdater.Manager.csproj" />
<ProjectReference Include="..\ModpackUpdater\ModpackUpdater.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,64 @@
using Castle.Core.Logging;
using Newtonsoft.Json;
using Pilz.Configuration;
namespace ModpackUpdater.Apps.Client.Gui;
public static class Program
{
public const string UPDATE_URL = "https://git.pilzinsel64.de/litw-refined/minecraft-modpack-updater/-/snippets/3/raw/main/updates.json";
private static readonly SettingsManager settingsManager;
private static readonly ILogger log = new ConsoleLogger();
public static ISettings Settings => settingsManager.Instance;
public static ILogger Log => log;
static Program()
{
settingsManager = new(GetSettingsPath(2), true);
MigrateLegacySettings(GetSettingsPath(null));
}
[STAThread]
internal static void Main(string[] args)
{
ApplicationConfiguration.Initialize();
AppGlobals.Initialize();
Application.Run(new MainForm());
}
private static string GetSettingsPath(int? settingsVersion = 3)
{
const string AppDataDirectoryName = "MinecraftModpackUpdater";
var fileNamePostfix = settingsVersion == null ? string.Empty : $"V{settingsVersion}";
var SettingsFileName = $"Settings{fileNamePostfix}.json";
var settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataDirectoryName);
Directory.CreateDirectory(settingsPath);
settingsPath = Path.Combine(settingsPath, SettingsFileName);
return settingsPath;
}
private static void MigrateLegacySettings(string settingsPath)
{
// Try load legacy config file
if (!File.Exists(settingsPath) || JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(settingsPath)) is not AppConfig legacyConfig)
return;
// Migrate
var newConfig = Settings.Get<AppConfig>();
newConfig.LastMinecraftProfilePath = legacyConfig.LastMinecraftProfilePath;
if (ModpackInfo.TryLoad(legacyConfig.LastMinecraftProfilePath) is ModpackInfo info)
#pragma warning disable CS0612 // Typ oder Element ist veraltet
info.ConfigUrl = legacyConfig.ConfigFilePath;
// Ensure save settings
settingsManager.Save();
// Delete legacy config file
File.Delete(settingsPath);
}
}

View File

@@ -6,12 +6,12 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PropertyGroup> <PropertyGroup>
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Any CPU</Platform> <Platform>Any CPU</Platform>
<PublishDir>bin\publish\windows\</PublishDir> <PublishDir>..\publish\ui\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId> <_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier> <RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>false</SelfContained> <SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile> <PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun> <PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup> </PropertyGroup>

View File

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -2,56 +2,24 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ApplicationIcon>minecraft modpack updater.ico</ApplicationIcon> <ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>Minecraft Modpack Updater</AssemblyName> <Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Update="FiledialogFilters.Designer.cs"> <Compile Include="..\Version.cs" />
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>FiledialogFilters.resx</DependentUpon>
</Compile>
<Compile Update="LangRes.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>LangRes.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="FiledialogFilters.resx">
<Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>ModpackUpdater.My.Resources</CustomToolNamespace>
<LastGenOutput>FiledialogFilters.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="LangRes.resx">
<Generator>ResXFileCodeGenerator</Generator>
<CustomToolNamespace>ModpackUpdater.My.Resources</CustomToolNamespace>
<LastGenOutput>LangRes.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Mono.Options" Version="6.12.0.148" /> <PackageReference Include="Mono.Options" Version="6.12.0.148" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pilz.Configuration" Version="3.2.6" />
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" /> <PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
<PackageReference Include="Pilz.IO" Version="2.1.0" /> <PackageReference Include="Pilz.IO" Version="2.1.0" />
<PackageReference Include="Pilz.UI" Version="3.0.0" />
<PackageReference Include="Pilz.UI.WinForms" Version="2.6.2" />
<PackageReference Include="Pilz.UI.WinForms.Telerik" Version="2.13.3" />
<PackageReference Include="Pilz.UI.WinForms.Telerik.Symbols" Version="1.2.1" />
<PackageReference Include="UI.for.WinForms.Common" Version="2025.2.612-preview" />
<PackageReference Include="UI.for.WinForms.Themes" Version="2025.2.612-preview" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ModpackUpdater.Apps\ModpackUpdater.Apps.csproj" /> <ProjectReference Include="..\ModpackUpdater.Apps.AppUpdates\ModpackUpdater.Apps.AppUpdates.csproj" />
<ProjectReference Include="..\ModpackUpdater.Manager\ModpackUpdater.Manager.csproj" /> <ProjectReference Include="..\ModpackUpdater.Manager\ModpackUpdater.Manager.csproj" />
<ProjectReference Include="..\ModpackUpdater\ModpackUpdater.csproj" /> <ProjectReference Include="..\ModpackUpdater\ModpackUpdater.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -10,9 +10,8 @@ internal class Options
public IReadOnlyList<string> Additionals => additionals; public IReadOnlyList<string> Additionals => additionals;
public bool Help { get; private set; } public bool Help { get; private set; }
public bool Silent { get; private set; } public bool Silent { get; private set; }
public bool NoUi { get; private set; } public string? RefTag { get; private set; }
public string RefTag { get; private set; } public string? Version { get; private set; }
public string Version { get; private set; }
public UpdateCheckOptionsAdv UpdateOptions { get; } = new(); public UpdateCheckOptionsAdv UpdateOptions { get; } = new();
public Options(string[] args) public Options(string[] args)
@@ -21,12 +20,10 @@ internal class Options
{ {
{ "silent", "Do not output anything.", s => Silent = true }, { "silent", "Do not output anything.", s => Silent = true },
{ "h|help", "Writes the help text as output.", h => Help = true }, { "h|help", "Writes the help text as output.", h => Help = true },
{ "n|noui", "Install without user interface.", n => NoUi = true },
{ "p|profile=", "Sets the minecraft profile folder.", p => UpdateOptions.ProfileFolder = p }, { "p|profile=", "Sets the minecraft profile folder.", p => UpdateOptions.ProfileFolder = p },
{ "c|config=", "Sets the modpack update info url.", c => UpdateOptions.ModpackConfig = c }, { "c|config=", "Sets the modpack update info url.", c => UpdateOptions.ModpackConfig = c },
{ "s|side=", "Sets the installation side.\nDefault side is Client.\nAvailable: Client, Server", s => UpdateOptions.Side = Enum.Parse<Side>(s)}, { "s|side=", "Sets the installation side.\nDefault side is Client.\nAvailable: Client, Server", s => UpdateOptions.Side = Enum.Parse<Side>(s)},
{ "u|uai", "Disallow an update directly after install. This only has effect if there is no existing installation.", uai => UpdateOptions.AllowUpdaterAfterInstall = false}, { "u|uai", "Disallow an update directly after install. This only has effect if there is no existing installation.", uai => UpdateOptions.AllowUpdaterAfterInstall = false},
{ "noupdate", "Skip the update check.", noupdate => UpdateOptions.NoUpdate = true},
{ "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = true}, { "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = true},
{ "i|nonpublic", "Include non public (currently hidden) updates.", i => UpdateOptions.IncludeNonPublic = true}, { "i|nonpublic", "Include non public (currently hidden) updates.", i => UpdateOptions.IncludeNonPublic = true},
{ "k|key=", "An key for retriving extra files on updates.", k => UpdateOptions.ExtrasKey = k}, { "k|key=", "An key for retriving extra files on updates.", k => UpdateOptions.ExtrasKey = k},

View File

@@ -1,34 +1,14 @@
using Castle.Core.Logging; using Castle.Core.Logging;
using ModpackUpdater.Manager; using ModpackUpdater.Manager;
using Newtonsoft.Json;
using Pilz;
using Pilz.Configuration;
using System.Runtime.InteropServices;
[assembly: AssemblyAppVersion("1.9.2.0")]
namespace ModpackUpdater.Apps.Client; namespace ModpackUpdater.Apps.Client;
public static class Program public static class Program
{ {
private static readonly SettingsManager settingsManager;
private static readonly ILogger log = new ConsoleLogger(); private static readonly ILogger log = new ConsoleLogger();
public static ISettings Settings => settingsManager.Instance;
public static ILogger Log => log; public static ILogger Log => log;
internal static Options Options { get; private set; } internal static Options Options { get; private set; } = null!;
[DllImport("kernel32.dll")]
static extern nint GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(nint hWnd, int nCmdShow);
static Program()
{
settingsManager = new(GetSettingsPath(2), true);
MigrateLegacySettings(GetSettingsPath(null));
}
[STAThread] [STAThread]
internal static void Main(string[] args) internal static void Main(string[] args)
@@ -36,61 +16,14 @@ public static class Program
Options = new Options(args); Options = new Options(args);
if (Options.Help) if (Options.Help)
Options.DrawHelp(); Options.DrawHelp();
else if (Options.NoUi)
InstallWithoutGui(Options.UpdateOptions, Options.Silent);
else else
{ InstallWithoutGui(Options.UpdateOptions, Options.Silent);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
ShowWindow(GetConsoleWindow(), 0);
RunApp(Options.UpdateOptions);
}
}
private static void RunApp(UpdateCheckOptionsAdv updateOptions)
{
ApplicationConfiguration.Initialize();
AppGlobals.Initialize();
Application.Run(new MainForm(updateOptions));
}
private static string GetSettingsPath(int? settingsVersion = 3)
{
const string AppDataDirectoryName = "MinecraftModpackUpdater";
var fileNamePostfix = settingsVersion == null ? string.Empty : $"V{settingsVersion}";
var SettingsFileName = $"Settings{fileNamePostfix}.json";
var settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataDirectoryName);
Directory.CreateDirectory(settingsPath);
settingsPath = Path.Combine(settingsPath, SettingsFileName);
return settingsPath;
}
private static void MigrateLegacySettings(string settingsPath)
{
// Try load legacy config file
if (!File.Exists(settingsPath) || JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(settingsPath)) is not AppConfig legacyConfig)
return;
// Migrate
var newConfig = Settings.Get<AppConfig>();
newConfig.LastMinecraftProfilePath = legacyConfig.LastMinecraftProfilePath;
if (ModpackInfo.TryLoad(legacyConfig.LastMinecraftProfilePath) is ModpackInfo info)
#pragma warning disable CS0612 // Typ oder Element ist veraltet
info.ConfigUrl = legacyConfig.ConfigFilePath;
// Ensure save settings
settingsManager.Save();
// Delete legacy config file
File.Delete(settingsPath);
} }
private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent) private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent)
{ {
var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder); var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder);
var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig, info)); var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig!, info));
var features = new ModpackFeatures(config); var features = new ModpackFeatures(config);
// Check features // Check features
@@ -108,9 +41,6 @@ public static class Program
}; };
var result = installer.Check(updateOptions).Result; var result = installer.Check(updateOptions).Result;
if (!silent && !updateOptions.NoUpdate && new AppUpdater().Check().Result)
Log.Info("A new version is available!");
if (result.HasUpdates) if (result.HasUpdates)
{ {
var success = installer.Install(result).Result; var success = installer.Install(result).Result;

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\publish\cli\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project>

View File

@@ -4,8 +4,7 @@ namespace ModpackUpdater.Apps.Client;
public class UpdateCheckOptionsAdv : UpdateCheckOptions public class UpdateCheckOptionsAdv : UpdateCheckOptions
{ {
public string ProfileFolder { get; set; } public string? ProfileFolder { get; set; }
public string ModpackConfig { get; set; } public string? ModpackConfig { get; set; }
public bool NoUpdate { get; set; } public string? ExtrasKey { get; set; }
public string ExtrasKey { get; set; }
} }

View File

@@ -3,8 +3,6 @@ using Pilz;
using Pilz.Configuration; using Pilz.Configuration;
using Pilz.Plugins.Advanced; using Pilz.Plugins.Advanced;
[assembly: AssemblyAppVersion("1.0.0.0")]
namespace ModpackUpdater.Apps.Manager; namespace ModpackUpdater.Apps.Manager;
public static class Program public static class Program

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>H:\Applications\Minecraft Modpack Manager</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net8.0-windows</TargetFramework>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>

View File

@@ -33,13 +33,13 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
http.Dispose(); http.Dispose();
} }
private async Task<UpdateInfos> DownloadUpdateInfos() public async Task<UpdateInfos> DownloadUpdateInfos()
{ {
var content = await http.GetStringAsync(updateConfig.GetUpdateUrl(overwriteRefTag: OverwriteRefTag)); var content = await http.GetStringAsync(updateConfig.GetUpdateUrl(overwriteRefTag: OverwriteRefTag));
return UpdateInfos.Parse(content); return UpdateInfos.Parse(content);
} }
private async Task<InstallInfos> DownloadInstallInfos() public async Task<InstallInfos> DownloadInstallInfos()
{ {
var content = await http.GetStringAsync(updateConfig.GetInstallUrl(overwriteRefTag: OverwriteRefTag)); var content = await http.GetStringAsync(updateConfig.GetInstallUrl(overwriteRefTag: OverwriteRefTag));
return InstallInfos.Parse(content); return InstallInfos.Parse(content);

View File

@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.2.32526.322 VisualStudioVersion = 17.2.32526.322
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModpackUpdater.Apps.Client", "ModpackUpdater.Apps.Client\ModpackUpdater.Apps.Client.csproj", "{81F9A2F7-D36B-0F08-12D7-9EC2606C9080}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModpackUpdater.Apps.Client.Gui", "ModpackUpdater.Apps.Client.Gui\ModpackUpdater.Apps.Client.Gui.csproj", "{81F9A2F7-D36B-0F08-12D7-9EC2606C9080}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModpackUpdater", "ModpackUpdater\ModpackUpdater.csproj", "{0E6B6470-8C1D-0CDD-3681-461297A01960}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModpackUpdater", "ModpackUpdater\ModpackUpdater.csproj", "{0E6B6470-8C1D-0CDD-3681-461297A01960}"
EndProject EndProject
@@ -17,6 +17,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModpackUpdater.Apps.Manager
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModpackUpdater.Apps", "ModpackUpdater.Apps\ModpackUpdater.Apps.csproj", "{EF2EAFAF-01CD-46BD-BE45-0125B51316A4}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModpackUpdater.Apps", "ModpackUpdater.Apps\ModpackUpdater.Apps.csproj", "{EF2EAFAF-01CD-46BD-BE45-0125B51316A4}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModpackUpdater.Apps.Client", "ModpackUpdater.Apps.Client\ModpackUpdater.Apps.Client.csproj", "{415A7854-C358-4DCD-8C9E-D8413097A06D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModpackUpdater.Apps.AppUpdates", "ModpackUpdater.Apps.AppUpdates\ModpackUpdater.Apps.AppUpdates.csproj", "{7D8F9265-7BAC-4541-A6A8-168F45D0EA56}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -43,6 +47,14 @@ Global
{EF2EAFAF-01CD-46BD-BE45-0125B51316A4}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF2EAFAF-01CD-46BD-BE45-0125B51316A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF2EAFAF-01CD-46BD-BE45-0125B51316A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF2EAFAF-01CD-46BD-BE45-0125B51316A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF2EAFAF-01CD-46BD-BE45-0125B51316A4}.Release|Any CPU.Build.0 = Release|Any CPU {EF2EAFAF-01CD-46BD-BE45-0125B51316A4}.Release|Any CPU.Build.0 = Release|Any CPU
{415A7854-C358-4DCD-8C9E-D8413097A06D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{415A7854-C358-4DCD-8C9E-D8413097A06D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{415A7854-C358-4DCD-8C9E-D8413097A06D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{415A7854-C358-4DCD-8C9E-D8413097A06D}.Release|Any CPU.Build.0 = Release|Any CPU
{7D8F9265-7BAC-4541-A6A8-168F45D0EA56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D8F9265-7BAC-4541-A6A8-168F45D0EA56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D8F9265-7BAC-4541-A6A8-168F45D0EA56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D8F9265-7BAC-4541-A6A8-168F45D0EA56}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -53,6 +65,8 @@ Global
{D3A92EBD-FF6E-09D0-00A1-20221AAA198E} = {96B711FA-1AF2-469B-BC02-6D1E540E8E9D} {D3A92EBD-FF6E-09D0-00A1-20221AAA198E} = {96B711FA-1AF2-469B-BC02-6D1E540E8E9D}
{227A37AA-73F0-431D-B976-B9B3A8ADD8C2} = {743892CF-E482-4FBD-9BAB-02920C140F2B} {227A37AA-73F0-431D-B976-B9B3A8ADD8C2} = {743892CF-E482-4FBD-9BAB-02920C140F2B}
{EF2EAFAF-01CD-46BD-BE45-0125B51316A4} = {743892CF-E482-4FBD-9BAB-02920C140F2B} {EF2EAFAF-01CD-46BD-BE45-0125B51316A4} = {743892CF-E482-4FBD-9BAB-02920C140F2B}
{415A7854-C358-4DCD-8C9E-D8413097A06D} = {743892CF-E482-4FBD-9BAB-02920C140F2B}
{7D8F9265-7BAC-4541-A6A8-168F45D0EA56} = {743892CF-E482-4FBD-9BAB-02920C140F2B}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {322E6A6B-9F3E-4E88-8945-C98A9EF613BF} SolutionGuid = {322E6A6B-9F3E-4E88-8945-C98A9EF613BF}

3
Version.cs Normal file
View File

@@ -0,0 +1,3 @@
using Pilz;
[assembly: AssemblyAppVersion("1.9.3.0")]