add maintenance mode & improve & bugfixing
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
namespace ModpackUpdater.Manager;
|
||||
using ModpackUpdater.Model;
|
||||
|
||||
namespace ModpackUpdater.Manager;
|
||||
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static bool IsSide(this Side @this, Side side)
|
||||
{
|
||||
return @this.HasFlag(side) || side.HasFlag(@this);
|
||||
}
|
||||
|
||||
|
||||
public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive)
|
||||
{
|
||||
|
||||
@@ -37,32 +37,38 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
||||
return InstallInfos.Parse(content);
|
||||
}
|
||||
|
||||
public Task<UpdateCheckResult> Check()
|
||||
{
|
||||
return Check(Side.Client, true);
|
||||
}
|
||||
|
||||
public async Task<UpdateCheckResult> Check(Side side, bool allowUpdaterAfterInstall)
|
||||
public async Task<UpdateCheckResult> Check(UpdateCheckOptions options)
|
||||
{
|
||||
var result = new UpdateCheckResult();
|
||||
var hasConfig = ModpackInfo.HasModpackInfo(localPath);
|
||||
InstallInfos installInfos = null;
|
||||
UpdateInfos updateInfos = null;
|
||||
|
||||
if (updateConfig.Maintenance && !options.IgnoreMaintenance)
|
||||
{
|
||||
result.IsInMaintenance = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!hasConfig)
|
||||
{
|
||||
installInfos = await DownloadInstallInfos();
|
||||
|
||||
if (installInfos is not null && installInfos.Actions.Count != 0)
|
||||
{
|
||||
result.Actions.AddRange(installInfos.Actions);
|
||||
result.LatestVersion = installInfos.Version;
|
||||
var actions = installInfos.Actions.Where(n => n.Side.IsSide(options.Side));
|
||||
if (actions.Any())
|
||||
{
|
||||
result.Actions.AddRange(installInfos.Actions);
|
||||
result.LatestVersion = installInfos.Version;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (result.Actions.Count == 0)
|
||||
result.HasError = true;
|
||||
}
|
||||
|
||||
if (allowUpdaterAfterInstall)
|
||||
if (options.AllowUpdaterAfterInstall)
|
||||
{
|
||||
updateInfos = await DownloadUpdateInfos();
|
||||
var modpackInfo = ModpackInfo.HasModpackInfo(localPath) ? ModpackInfo.Load(localPath) : new();
|
||||
@@ -83,7 +89,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, string localPath)
|
||||
|
||||
foreach (var action in checkingVersion.Actions)
|
||||
{
|
||||
if (!result.Actions.Any(n => n.DestPath == action.DestPath))
|
||||
if (action.Side.IsSide(options.Side) && !result.Actions.Any(n => n.DestPath == action.DestPath))
|
||||
actionsToAdd.Add(action);
|
||||
}
|
||||
|
||||
|
||||
10
ModpackUpdater.Manager/UpdateCheckOptions.cs
Normal file
10
ModpackUpdater.Manager/UpdateCheckOptions.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using ModpackUpdater.Model;
|
||||
|
||||
namespace ModpackUpdater.Manager;
|
||||
|
||||
public class UpdateCheckOptions
|
||||
{
|
||||
public bool IgnoreMaintenance { get; set; }
|
||||
public bool AllowUpdaterAfterInstall { get; set; } = true;
|
||||
public Side Side { get; set; } = Side.Client;
|
||||
}
|
||||
@@ -9,5 +9,6 @@ public class UpdateCheckResult
|
||||
public List<InstallAction> Actions { get; private set; } = [];
|
||||
public bool IsInstalled { get; set; }
|
||||
public bool HasError { get; set; }
|
||||
public bool IsInMaintenance { get; set; }
|
||||
public bool HasUpdates => !IsInstalled || CurrentVersion < LatestVersion;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace ModpackUpdater.Model;
|
||||
|
||||
public class ModpackConfig
|
||||
{
|
||||
public bool Maintenance { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string UpdateUrl { get; set; }
|
||||
public string InstallUrl { get; set; }
|
||||
|
||||
@@ -12,20 +12,17 @@ public partial class Form1
|
||||
private ModpackConfig updateConfig = new();
|
||||
private bool currentUpdating = false;
|
||||
private UpdateCheckResult lastUpdateCheckResult = null;
|
||||
private readonly bool allowUpdateCheck;
|
||||
private readonly bool allowUpdaterAfterInstall;
|
||||
private readonly Side side;
|
||||
private readonly UpdateCheckOptionsAdv updateOptions;
|
||||
|
||||
public Form1(string modpackConfig, string profilePath, Side side, bool allowUpdaterAfterInstall, bool allowUpdateCheck) : this()
|
||||
public Form1(UpdateCheckOptionsAdv updateOptions) : this()
|
||||
{
|
||||
this.allowUpdaterAfterInstall = allowUpdaterAfterInstall;
|
||||
this.side = side;
|
||||
this.updateOptions = updateOptions;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(modpackConfig))
|
||||
LoadUpdateConfigFile(modpackConfig);
|
||||
if (!string.IsNullOrWhiteSpace(updateOptions.ModpackConfig))
|
||||
LoadUpdateConfigFile(updateOptions.ModpackConfig);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(profilePath))
|
||||
LoadMinecraftProfile(profilePath);
|
||||
if (!string.IsNullOrWhiteSpace(updateOptions.ProfileFolder))
|
||||
LoadMinecraftProfile(updateOptions.ProfileFolder);
|
||||
}
|
||||
|
||||
public Form1()
|
||||
@@ -129,7 +126,7 @@ public partial class Form1
|
||||
|
||||
try
|
||||
{
|
||||
lastUpdateCheckResult = await updater.Check(side, allowUpdaterAfterInstall);
|
||||
lastUpdateCheckResult = await updater.Check(updateOptions);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -245,7 +242,7 @@ public partial class Form1
|
||||
private async void Form1_Shown(object sender, EventArgs e)
|
||||
{
|
||||
var updater = new AppUpdater();
|
||||
if (allowUpdateCheck && await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info) == DialogResult.Yes)
|
||||
if (!updateOptions.NoUpdate && await updater.Check() && RadMessageBox.Show(LangRes.MsgBox_UpdateAvailable, LangRes.MsgBox_UpdateAvailable_Title, MessageBoxButtons.YesNo, RadMessageIcon.Info) == DialogResult.Yes)
|
||||
{
|
||||
SetStatus(LangRes.StatusText_InstallingAppUpdate, MySymbols.icons8_software_installer_16px);
|
||||
Enabled = false;
|
||||
|
||||
@@ -10,11 +10,7 @@ internal class Options
|
||||
public IReadOnlyList<string> Additionals => additionals;
|
||||
public bool Silent { get; private set; }
|
||||
public bool NoUi { get; private set; }
|
||||
public bool NoUpdate { get; private set; };
|
||||
public bool AllowUpdaterAfterInstall { get; private set; } = true;
|
||||
public Side Side { get; private set; } = Side.Client;
|
||||
public string ProfileFolder { get; private set; }
|
||||
public string ModpackConfig { get; private set; }
|
||||
public UpdateCheckOptionsAdv UpdateOptions { get; } = new();
|
||||
|
||||
public Options(string[] args)
|
||||
{
|
||||
@@ -22,13 +18,14 @@ internal class Options
|
||||
{
|
||||
{ "silent", "Do not output anything.", s => Silent = s != null },
|
||||
{ "n|noui", "Install without user interface.", n => NoUi = n != null },
|
||||
{ "p|profile=", "Sets the minecraft profile folder.", p => ProfileFolder = p },
|
||||
{ "c|config=", "Sets the minecraft profile folder.", c => ModpackConfig = c },
|
||||
{ "s|side=", "Sets the minecraft profile folder.\nDefault side is Client.\nAvailable: Client, Server", s => Side = Enum.Parse<Side>(s)},
|
||||
{ "uai", "Allow an update directly after install. This only has affect if there is no existing installation.", uai => AllowUpdaterAfterInstall = uai != null},
|
||||
{ "noupdate", "Skip the update check wich happens when opening the user interface.", noupdate => NoUpdate = noupdate != null},
|
||||
{ "p|profile=", "Sets the minecraft profile folder.", p => UpdateOptions.ProfileFolder = p },
|
||||
{ "c|config=", "Sets the minecraft profile folder.", c => UpdateOptions.ModpackConfig = c },
|
||||
{ "s|side=", "Sets the minecraft profile folder.\nDefault side is Client.\nAvailable: Client, Server", s => UpdateOptions.Side = Enum.Parse<Side>(s)},
|
||||
{ "uai", "Allow an update directly after install. This only has affect if there is no existing installation.", uai => UpdateOptions.AllowUpdaterAfterInstall = uai != null},
|
||||
{ "noupdate", "Skip the update check.", noupdate => UpdateOptions.NoUpdate = noupdate != null},
|
||||
{ "m|maintenance", "Ignores the maintenance mode.", m => UpdateOptions.IgnoreMaintenance = m != null},
|
||||
};
|
||||
|
||||
var additional = options.Parse(args);
|
||||
additionals.AddRange(options.Parse(args));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using ModpackUpdater.Manager;
|
||||
using ModpackUpdater.Model;
|
||||
using Mono.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Configuration;
|
||||
using Telerik.WinControls;
|
||||
@@ -24,12 +23,12 @@ public static class Program
|
||||
{
|
||||
var options = new Options(args);
|
||||
if (options.NoUi)
|
||||
InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent, options.Side, options.AllowUpdaterAfterInstall);
|
||||
InstallWithoutGui(options.UpdateOptions, options.Silent);
|
||||
else
|
||||
RunApp(options.ModpackConfig, options.ProfileFolder, options.Side, options.AllowUpdaterAfterInstall, !options.NoUpdate);
|
||||
RunApp(options.UpdateOptions);
|
||||
}
|
||||
|
||||
private static void RunApp(string modpackConfig, string profileFolder, Side side, bool allowUpdaterAfterInstall, bool allowUpdateCheck)
|
||||
private static void RunApp(UpdateCheckOptionsAdv updateOptions)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
@@ -38,7 +37,7 @@ public static class Program
|
||||
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
|
||||
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple";
|
||||
|
||||
Application.Run(new Form1(modpackConfig, profileFolder, side, allowUpdaterAfterInstall, allowUpdateCheck));
|
||||
Application.Run(new Form1(updateOptions));
|
||||
}
|
||||
|
||||
private static string GetSettingsPath(int? settingsVersion = 2)
|
||||
@@ -72,11 +71,14 @@ public static class Program
|
||||
File.Delete(settingsPath);
|
||||
}
|
||||
|
||||
private static void InstallWithoutGui(string modpackConfig, string profileFolder, bool silent, Side side, bool allowUpdaterAfterInstall)
|
||||
private static void InstallWithoutGui(UpdateCheckOptionsAdv updateOptions, bool silent)
|
||||
{
|
||||
var config = ModpackConfig.LoadFromUrl(modpackConfig);
|
||||
var installer = new ModpackInstaller(config, profileFolder);
|
||||
var result = installer.Check(side, allowUpdaterAfterInstall).Result;
|
||||
var config = ModpackConfig.LoadFromUrl(updateOptions.ModpackConfig);
|
||||
var installer = new ModpackInstaller(config, updateOptions.ProfileFolder);
|
||||
var result = installer.Check(updateOptions).Result;
|
||||
|
||||
if (!silent && !updateOptions.NoUpdate && new AppUpdater().Check().Result)
|
||||
Console.WriteLine("A new version is available!");
|
||||
|
||||
if (result.HasUpdates)
|
||||
{
|
||||
|
||||
10
ModpackUpdater/UpdateCheckOptionsAdv.cs
Normal file
10
ModpackUpdater/UpdateCheckOptionsAdv.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using ModpackUpdater.Manager;
|
||||
|
||||
namespace ModpackUpdater;
|
||||
|
||||
public class UpdateCheckOptionsAdv : UpdateCheckOptions
|
||||
{
|
||||
public string ProfileFolder { get; set; }
|
||||
public string ModpackConfig { get; set; }
|
||||
public bool NoUpdate { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user