Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9650c6118 | |||
| 2e467c0a96 | |||
| 69cd869cd1 | |||
| ef314ac227 | |||
| a30893e04c | |||
| 368948d277 | |||
| 60b11d949d | |||
| 1e41fa8b10 | |||
| d1f35676ee |
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
73
ModpackUpdater.Manager/ModpackFeatures.cs
Normal file
73
ModpackUpdater.Manager/ModpackFeatures.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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.1</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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -23,9 +30,17 @@ public static class Program
|
||||
{
|
||||
var options = new Options(args);
|
||||
if (options.NoUi)
|
||||
InstallWithoutGui(options.UpdateOptions, options.Silent);
|
||||
{
|
||||
if (options.Help)
|
||||
options.DrawHelp();
|
||||
else
|
||||
InstallWithoutGui(options.UpdateOptions, options.Silent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowWindow(GetConsoleWindow(), 0);
|
||||
RunApp(options.UpdateOptions);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunApp(UpdateCheckOptionsAdv updateOptions)
|
||||
@@ -81,12 +96,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);
|
||||
|
||||
Reference in New Issue
Block a user