11 Commits

Author SHA1 Message Date
deeee34f87 v1.5.2.2 2024-08-10 09:27:13 +02:00
f254ac03e1 draw help always even if not noui is set 2024-08-10 09:27:09 +02:00
c9650c6118 v1.5.2.1 2024-08-10 09:24:07 +02:00
2e467c0a96 draw help 2024-08-10 09:23:57 +02:00
69cd869cd1 v1.5.2 2024-08-09 15:37:45 +02:00
ef314ac227 show console on cmd 2024-08-09 15:37:36 +02:00
a30893e04c fix: also check side for initial install 2024-08-09 15:37:21 +02:00
368948d277 fail safe when no unleash api endpoint configured 2024-07-10 18:49:25 +02:00
60b11d949d remove modpack key 2024-07-10 18:45:22 +02:00
1e41fa8b10 v1.5.1.0 2024-07-10 18:25:17 +02:00
d1f35676ee unleash api via modpack config 2024-07-10 18:24:55 +02:00
10 changed files with 109 additions and 91 deletions

View File

@@ -6,7 +6,7 @@ public static class Extensions
{
public static bool IsSide(this Side @this, Side side)
{
return @this.HasFlag(side) || side.HasFlag(@this);
return @this.HasFlag(side);
}

View File

@@ -0,0 +1,73 @@
using ModpackUpdater.Model;
using Unleash;
using Unleash.ClientFactory;
namespace ModpackUpdater;
public class ModpackFeatures(ModpackConfig modpackConfig)
{
private IUnleash api;
private UnleashContext context;
private UnleashSettings settings;
public static string FeatureAllowExtas => "allow-extras";
~ModpackFeatures()
{
api?.Dispose();
}
public bool IsEnabled(string feature)
{
return IsEnabled(feature, null);
}
public bool IsEnabled(string feature, AppFeatureContext context)
{
return CheckFeature(feature, context);
}
private bool InitializeApi()
{
if (api == null && !string.IsNullOrWhiteSpace(modpackConfig.UnleashApiUrl) && !string.IsNullOrWhiteSpace(modpackConfig.UnleashInstanceId))
{
settings = new UnleashSettings
{
AppName = "Modpack Updater",
UnleashApi = new Uri(modpackConfig.UnleashApiUrl),
FetchTogglesInterval = TimeSpan.FromSeconds(60 * 5),
InstanceTag = modpackConfig.UnleashInstanceId,
};
api = new UnleashClientFactory().CreateClient(settings, synchronousInitialization: true);
}
return api != null;
}
private bool CheckFeature(string name, AppFeatureContext context)
{
return InitializeApi() && api.IsEnabled(name, GetContext(context));
}
private UnleashContext GetContext(AppFeatureContext ccontext)
{
context ??= new();
context.CurrentTime = DateTime.Now;
ccontext?.Apply(context);
return context;
}
}
public abstract class AppFeatureContext
{
public abstract void Apply(UnleashContext context);
}
public class AllowExtrasFeatureContext(ModpackInfo info) : AppFeatureContext
{
public override void Apply(UnleashContext context)
{
context.UserId = info.ExtrasKey;
}
}

View File

@@ -65,7 +65,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
var actions = installInfos.Actions.Where(n => n.Side.IsSide(options.Side) && (!n.IsExtra || options.IncludeExtras));
if (actions.Any())
{
result.Actions.AddRange(installInfos.Actions);
result.Actions.AddRange(actions);
result.LatestVersion = installInfos.Version;
result.CurrentVersion = installInfos.Version;
}

View File

@@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="Unleash.Client" Version="4.1.9" />
</ItemGroup>
<ItemGroup>

View File

@@ -6,9 +6,10 @@ public class ModpackConfig
{
public bool Maintenance { get; set; }
public string Name { get; set; }
public string Key { get; set; }
public string UpdateUrl { get; set; }
public string InstallUrl { get; set; }
public string UnleashApiUrl { get; set; }
public string UnleashInstanceId { get; set; }
[JsonIgnore]
public string ConfigUrl { get; set; }

View File

@@ -1,81 +0,0 @@
using ModpackUpdater.Model;
using Unleash;
namespace ModpackUpdater;
public enum AppFeatures
{
AllowExtras
}
public static class AppFeaturesExtensions
{
private const string apiUrl = "https://git.pilzinsel64.de/api/v4/feature_flags/unleash/2";
private const string instanceId = "glffct-3vCzJXChAnxjsgvoHijR";
private static IUnleash api;
private static UnleashContext context;
private static UnleashSettings settings;
public static bool IsEnabled(this AppFeatures feature, AppFeatureContext context)
{
return feature switch
{
AppFeatures.AllowExtras => CheckFeature("allow-extras", false, context),
_ => throw new NotSupportedException(),
};
}
public static bool IsEnabled(this AppFeatures feature)
{
return feature switch
{
_ => throw new NotSupportedException(),
};
}
private static bool InitializeApi()
{
if (api == null)
{
settings = new UnleashSettings
{
AppName = "Modpack Updater",
UnleashApi = new Uri(apiUrl),
FetchTogglesInterval = TimeSpan.FromSeconds(60 * 5),
InstanceTag = instanceId,
};
api = new DefaultUnleash(settings);
}
return api != null;
}
private static bool CheckFeature(string name, bool defaultValue, AppFeatureContext context)
{
return InitializeApi() && api.IsEnabled(name, GetContext(context), defaultValue);
}
private static UnleashContext GetContext(AppFeatureContext ccontext)
{
context ??= new();
context.CurrentTime = DateTime.Now;
ccontext?.Apply(context);
return context;
}
}
public abstract class AppFeatureContext
{
public abstract void Apply(UnleashContext context);
}
public class AllowExtrasFeatureContext(ModpackInfo info, ModpackConfig config) : AppFeatureContext
{
public override void Apply(UnleashContext context)
{
context.UserId = info.ExtrasKey;
context.Environment = config.Key;
}
}

View File

@@ -13,6 +13,7 @@ public partial class Form1
{
private ModpackInfo modpackInfo = new();
private ModpackConfig updateConfig = new();
private ModpackFeatures features;
private bool currentUpdating = false;
private UpdateCheckResult lastUpdateCheckResult = null;
private readonly UpdateCheckOptionsAdv updateOptions;
@@ -101,6 +102,9 @@ public partial class Form1
{
}
if (modpackInfo != null)
features = new(updateConfig);
if (modpackInfo == null || string.IsNullOrWhiteSpace(RadTextBoxControl_MinecraftProfileFolder.Text) /*|| modpackInfo.Valid*/)
{
SetStatus(LangRes.StatusText_MinecraftProfileWarning, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.general_warning_sign, SvgImageSize.Small));
@@ -168,7 +172,7 @@ public partial class Form1
SetStatus(LangRes.StatusText_CheckingForUpdates, AppSymbolFactory.Instance.GetSvgImage(AppSymbols.update_done, SvgImageSize.Small));
// Check for extras once again
updateOptions.IncludeExtras = AppFeatures.AllowExtras.IsEnabled(new AllowExtrasFeatureContext(modpackInfo, updateConfig));
updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(modpackInfo));
try
{

View File

@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>icons8_download_from_ftp.ico</ApplicationIcon>
<AssemblyName>Minecraft Modpack Updater</AssemblyName>
<ImplicitUsings>true</ImplicitUsings>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>1.5.0.6</Version>
<Version>1.5.2.2</Version>
</PropertyGroup>
<ItemGroup>
@@ -54,7 +54,6 @@
<PackageReference Include="Pilz.UI.Telerik.SymbolFactory" Version="2.0.3" />
<PackageReference Include="Pilz.Win32" Version="2.0.0" />
<PackageReference Include="UI.for.WinForms.Common" Version="2024.2.514" />
<PackageReference Include="Unleash.Client" Version="4.1.9" />
</ItemGroup>
<ItemGroup>

View File

@@ -6,17 +6,20 @@ namespace ModpackUpdater;
internal class Options
{
private readonly List<string> additionals = [];
private readonly OptionSet options;
public IReadOnlyList<string> Additionals => additionals;
public bool Help { get; private set; }
public bool Silent { get; private set; }
public bool NoUi { get; private set; }
public UpdateCheckOptionsAdv UpdateOptions { get; } = new();
public Options(string[] args)
{
var options = new OptionSet
options = new OptionSet
{
{ "silent", "Do not output anything.", s => Silent = s != null },
{ "h|help", "Writes the help text as output.", h => Help = h != null },
{ "n|noui", "Install without user interface.", n => NoUi = n != null },
{ "p|profile=", "Sets the minecraft profile folder.", p => UpdateOptions.ProfileFolder = p },
{ "c|config=", "Sets the minecraft profile folder.", c => UpdateOptions.ModpackConfig = c },
@@ -29,4 +32,9 @@ internal class Options
additionals.AddRange(options.Parse(args));
}
public void DrawHelp()
{
options.WriteOptionDescriptions(Console.Out);
}
}

View File

@@ -2,6 +2,7 @@
using ModpackUpdater.Model;
using Newtonsoft.Json;
using Pilz.Configuration;
using System.Runtime.InteropServices;
using Telerik.WinControls;
namespace ModpackUpdater;
@@ -12,6 +13,12 @@ public static class Program
public static ISettings Settings => settingsManager.Instance;
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static Program()
{
settingsManager = new(GetSettingsPath(2), true);
@@ -22,10 +29,15 @@ public static class Program
internal static void Main(string[] args)
{
var options = new Options(args);
if (options.NoUi)
if (options.Help)
options.DrawHelp();
else if (options.NoUi)
InstallWithoutGui(options.UpdateOptions, options.Silent);
else
{
ShowWindow(GetConsoleWindow(), 0);
RunApp(options.UpdateOptions);
}
}
private static void RunApp(UpdateCheckOptionsAdv updateOptions)
@@ -81,12 +93,13 @@ public static class Program
{
var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder);
var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig, info));
var features = new ModpackFeatures(config);
// Check features
if (!string.IsNullOrWhiteSpace(updateOptions.ExtrasKey))
info.ExtrasKey = updateOptions.ExtrasKey;
if (!string.IsNullOrWhiteSpace(info.ExtrasKey))
updateOptions.IncludeExtras = AppFeatures.AllowExtras.IsEnabled(new AllowExtrasFeatureContext(info, config));
updateOptions.IncludeExtras = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(info));
// Check for update
var installer = new ModpackInstaller(config, info);