add installation without gui & pass arguments to gui
This commit is contained in:
@@ -8,7 +8,7 @@ public class ModpackConfig
|
||||
public string UpdateUrl { get; set; }
|
||||
public string InstallUrl { get; set; }
|
||||
|
||||
public static object LoadFromUrl(string url)
|
||||
public static ModpackConfig LoadFromUrl(string url)
|
||||
{
|
||||
string result = new HttpClient().GetStringAsync(url).Result;
|
||||
return JsonConvert.DeserializeObject<ModpackConfig>(result);
|
||||
|
||||
@@ -13,6 +13,15 @@ public partial class Form1
|
||||
private bool currentUpdating = false;
|
||||
private UpdateCheckResult lastUpdateCheckResult = null;
|
||||
|
||||
public Form1(string modpackConfig, string profilePath) : this()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(modpackConfig))
|
||||
LoadUpdateConfigFile(modpackConfig);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(profilePath))
|
||||
LoadMinecraftProfile(profilePath);
|
||||
}
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -84,10 +93,11 @@ public partial class Form1
|
||||
private void LoadUpdateConfigFile(string filePath)
|
||||
{
|
||||
RadTextBoxControl_ModpackConfig.Text = filePath;
|
||||
|
||||
try
|
||||
{
|
||||
if (IsUpdateConfigLoaded())
|
||||
updateConfig = (ModpackConfig)ModpackConfig.LoadFromUrl(filePath);
|
||||
updateConfig = ModpackConfig.LoadFromUrl(filePath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -222,6 +232,7 @@ public partial class Form1
|
||||
{
|
||||
if (Directory.Exists(AppConfig.Instance.LastMinecraftProfilePath))
|
||||
LoadMinecraftProfile(AppConfig.Instance.LastMinecraftProfilePath);
|
||||
if (!string.IsNullOrWhiteSpace(AppConfig.Instance.LastConfigFilePath))
|
||||
LoadUpdateConfigFile(AppConfig.Instance.LastConfigFilePath);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ internal class Options
|
||||
private readonly List<string> additionals = [];
|
||||
|
||||
public IReadOnlyList<string> Additionals => additionals;
|
||||
public bool InstallWithoutUi { get; private set; }
|
||||
public bool Silent { get; private set; }
|
||||
public bool NoUi { get; private set; }
|
||||
public string ProfileFolder { get; private set; }
|
||||
public string ModpackConfig { get; private set; }
|
||||
|
||||
@@ -15,7 +16,8 @@ internal class Options
|
||||
{
|
||||
var options = new OptionSet
|
||||
{
|
||||
{ "i", "Install without user interface.", n => InstallWithoutUi = n != null },
|
||||
{ "s|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 },
|
||||
};
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Mono.Options;
|
||||
using ModpackUpdater.Manager;
|
||||
using ModpackUpdater.Model;
|
||||
using Mono.Options;
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Configuration;
|
||||
using Telerik.WinControls;
|
||||
@@ -21,13 +23,13 @@ public static class Program
|
||||
internal static void Main(string[] args)
|
||||
{
|
||||
var options = new Options(args);
|
||||
if (options.InstallWithoutUi)
|
||||
InstallWithoutGui(options.ProfileFolder, options.ModpackConfig);
|
||||
if (options.NoUi)
|
||||
InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent);
|
||||
else
|
||||
RunApp();
|
||||
RunApp(options.ModpackConfig, options.ProfileFolder);
|
||||
}
|
||||
|
||||
private static void RunApp()
|
||||
private static void RunApp(string modpackConfig, string profileFolder)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
@@ -36,7 +38,7 @@ public static class Program
|
||||
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
|
||||
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple";
|
||||
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new Form1(modpackConfig, profileFolder));
|
||||
}
|
||||
|
||||
private static string GetSettingsPath(int? settingsVersion = 2)
|
||||
@@ -70,8 +72,19 @@ public static class Program
|
||||
File.Delete(settingsPath);
|
||||
}
|
||||
|
||||
private static void InstallWithoutGui(string profileFolder, string modpackConfig)
|
||||
private static void InstallWithoutGui(string modpackConfig, string profileFolder, bool silent)
|
||||
{
|
||||
var config = ModpackConfig.LoadFromUrl(modpackConfig);
|
||||
var installer = new ModpackInstaller(config, profileFolder);
|
||||
var result = installer.Check().Result;
|
||||
|
||||
if (result.HasUpdates)
|
||||
{
|
||||
var success = installer.Install(result).Result;
|
||||
if (!silent)
|
||||
Console.WriteLine($"Installation {(success ?? false ? "completed successfully" : "failed")}!");
|
||||
}
|
||||
else if (!silent)
|
||||
Console.WriteLine("No updates available");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user