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 UpdateUrl { get; set; }
|
||||||
public string InstallUrl { 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;
|
string result = new HttpClient().GetStringAsync(url).Result;
|
||||||
return JsonConvert.DeserializeObject<ModpackConfig>(result);
|
return JsonConvert.DeserializeObject<ModpackConfig>(result);
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ public partial class Form1
|
|||||||
private bool currentUpdating = false;
|
private bool currentUpdating = false;
|
||||||
private UpdateCheckResult lastUpdateCheckResult = null;
|
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()
|
public Form1()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -84,10 +93,11 @@ public partial class Form1
|
|||||||
private void LoadUpdateConfigFile(string filePath)
|
private void LoadUpdateConfigFile(string filePath)
|
||||||
{
|
{
|
||||||
RadTextBoxControl_ModpackConfig.Text = filePath;
|
RadTextBoxControl_ModpackConfig.Text = filePath;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (IsUpdateConfigLoaded())
|
if (IsUpdateConfigLoaded())
|
||||||
updateConfig = (ModpackConfig)ModpackConfig.LoadFromUrl(filePath);
|
updateConfig = ModpackConfig.LoadFromUrl(filePath);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -222,7 +232,8 @@ public partial class Form1
|
|||||||
{
|
{
|
||||||
if (Directory.Exists(AppConfig.Instance.LastMinecraftProfilePath))
|
if (Directory.Exists(AppConfig.Instance.LastMinecraftProfilePath))
|
||||||
LoadMinecraftProfile(AppConfig.Instance.LastMinecraftProfilePath);
|
LoadMinecraftProfile(AppConfig.Instance.LastMinecraftProfilePath);
|
||||||
LoadUpdateConfigFile(AppConfig.Instance.LastConfigFilePath);
|
if (!string.IsNullOrWhiteSpace(AppConfig.Instance.LastConfigFilePath))
|
||||||
|
LoadUpdateConfigFile(AppConfig.Instance.LastConfigFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void Form1_Shown(object sender, EventArgs e)
|
private async void Form1_Shown(object sender, EventArgs e)
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ internal class Options
|
|||||||
private readonly List<string> additionals = [];
|
private readonly List<string> additionals = [];
|
||||||
|
|
||||||
public IReadOnlyList<string> Additionals => 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 ProfileFolder { get; private set; }
|
||||||
public string ModpackConfig { get; private set; }
|
public string ModpackConfig { get; private set; }
|
||||||
|
|
||||||
@@ -15,7 +16,8 @@ internal class Options
|
|||||||
{
|
{
|
||||||
var options = new OptionSet
|
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 },
|
{ "p|profile=", "Sets the minecraft profile folder.", p => ProfileFolder = p },
|
||||||
{ "c|config=", "Sets the minecraft profile folder.", c => ModpackConfig = c },
|
{ "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 Newtonsoft.Json;
|
||||||
using Pilz.Configuration;
|
using Pilz.Configuration;
|
||||||
using Telerik.WinControls;
|
using Telerik.WinControls;
|
||||||
@@ -21,13 +23,13 @@ public static class Program
|
|||||||
internal static void Main(string[] args)
|
internal static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var options = new Options(args);
|
var options = new Options(args);
|
||||||
if (options.InstallWithoutUi)
|
if (options.NoUi)
|
||||||
InstallWithoutGui(options.ProfileFolder, options.ModpackConfig);
|
InstallWithoutGui(options.ModpackConfig, options.ProfileFolder, options.Silent);
|
||||||
else
|
else
|
||||||
RunApp();
|
RunApp(options.ModpackConfig, options.ProfileFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RunApp()
|
private static void RunApp(string modpackConfig, string profileFolder)
|
||||||
{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
@@ -36,7 +38,7 @@ public static class Program
|
|||||||
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
|
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
|
||||||
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple";
|
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple";
|
||||||
|
|
||||||
Application.Run(new Form1());
|
Application.Run(new Form1(modpackConfig, profileFolder));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetSettingsPath(int? settingsVersion = 2)
|
private static string GetSettingsPath(int? settingsVersion = 2)
|
||||||
@@ -70,8 +72,19 @@ public static class Program
|
|||||||
File.Delete(settingsPath);
|
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