diff --git a/ModpackUpdater.Apps.Client.Gui/MainViewModel.cs b/ModpackUpdater.Apps.Client.Gui/MainViewModel.cs index 61a1a6e..c64ca6c 100644 --- a/ModpackUpdater.Apps.Client.Gui/MainViewModel.cs +++ b/ModpackUpdater.Apps.Client.Gui/MainViewModel.cs @@ -24,7 +24,6 @@ public partial class MainViewModel : ObservableObject private readonly UpdateCheckOptions updateOptions = new(); private ModpackInfo modpackInfo = new(); private ModpackConfig updateConfig = new(); - private ModpackFeatures? features; private UpdateCheckResult? lastUpdateCheckResult; [ObservableProperty] private string? minecraftProfileFolder; @@ -99,7 +98,7 @@ public partial class MainViewModel : ObservableObject private bool AllowExtras() { - return features != null && features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(modpackInfo)); + return !string.IsNullOrWhiteSpace(modpackInfo.ExtrasKey) && updateConfig.ExtrasKeys.Contains(modpackInfo.ExtrasKey); } public void LoadProfileToUi() @@ -191,15 +190,14 @@ public partial class MainViewModel : ObservableObject // Ignore } - features = new(updateConfig); modpackInfo.ExtrasKey = InstallKey?.Trim(); - if (!features.IsInvalid() && !string.IsNullOrWhiteSpace(modpackInfo.ExtrasKey) && !AllowExtras()) + if (!string.IsNullOrWhiteSpace(modpackInfo.ExtrasKey) && !AllowExtras()) { SetStatus(GeneralLangRes.InstallationKeyNotValid, AppGlobals.Symbols.GetImageSource(AppSymbols.general_warning_sign)); return false; } - CanUseExtrasKey = CanUseExtrasKey = !string.IsNullOrWhiteSpace(updateConfig.UnleashApiUrl); + CanUseExtrasKey = updateConfig.ExtrasKeys.Count > 0; if (string.IsNullOrWhiteSpace(MinecraftProfileFolder) /*|| modpackInfo.Valid*/) { diff --git a/ModpackUpdater.Apps.Client/Program.cs b/ModpackUpdater.Apps.Client/Program.cs index 3075dd8..051538b 100644 --- a/ModpackUpdater.Apps.Client/Program.cs +++ b/ModpackUpdater.Apps.Client/Program.cs @@ -39,13 +39,12 @@ 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 = features.IsEnabled(ModpackFeatures.FeatureAllowExtas, new AllowExtrasFeatureContext(info)); + updateOptions.IncludeExtras = !string.IsNullOrWhiteSpace(info.ExtrasKey) && config.ExtrasKeys.Contains(info.ExtrasKey); // Check for update var installer = new ModpackInstaller(config, info) diff --git a/ModpackUpdater.Manager/ModpackFeatures.cs b/ModpackUpdater.Manager/ModpackFeatures.cs deleted file mode 100644 index b0291f9..0000000 --- a/ModpackUpdater.Manager/ModpackFeatures.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using Unleash; -using Unleash.ClientFactory; - -namespace ModpackUpdater.Manager; - -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); - } - - public bool IsInvalid() - { - return string.IsNullOrWhiteSpace(modpackConfig.UnleashApiUrl) || string.IsNullOrWhiteSpace(modpackConfig.UnleashInstanceId); - } - - [MemberNotNullWhen(true, nameof(api))] - private bool InitializeApi() - { - if (api != null - || string.IsNullOrWhiteSpace(modpackConfig.UnleashApiUrl) - || string.IsNullOrWhiteSpace(modpackConfig.UnleashInstanceId)) - return api != null; - - settings = new UnleashSettings - { - AppName = "Modpack Updater", - UnleashApi = new Uri(modpackConfig.UnleashApiUrl), - FetchTogglesInterval = TimeSpan.FromSeconds(0), - 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; - } -} \ No newline at end of file diff --git a/ModpackUpdater.Manager/ModpackInstaller.cs b/ModpackUpdater.Manager/ModpackInstaller.cs index 1999a99..ca9d3c8 100644 --- a/ModpackUpdater.Manager/ModpackInstaller.cs +++ b/ModpackUpdater.Manager/ModpackInstaller.cs @@ -169,9 +169,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf foreach (InstallAction iaction in checkResult.Actions) { var destFilePath = iaction.GetDestPath(modpackInfo.LocalPath); - var sourceUrl = updateConfig.PreferDirectLinks && !string.IsNullOrWhiteSpace(iaction.SourceUrl) - ? iaction.GetSourceUrl(checkResult.LatestVersion, overwriteVersion: OverwriteVersion) - : await factory.ResolveSourceUrl(iaction, targetVersion: checkResult.LatestVersion, overwriteVersion: OverwriteVersion); + var sourceUrl = iaction.GetSourceUrl(checkResult.LatestVersion, overwriteVersion: OverwriteVersion); if (iaction is UpdateAction uaction) { diff --git a/ModpackUpdater/ModpackConfig.cs b/ModpackUpdater/ModpackConfig.cs index c95841e..f87699c 100644 --- a/ModpackUpdater/ModpackConfig.cs +++ b/ModpackUpdater/ModpackConfig.cs @@ -9,9 +9,7 @@ public class ModpackConfig public string? Name { get; set; } public string? UpdateUrl { get; set; } public string? InstallUrl { get; set; } - public string? UnleashApiUrl { get; set; } - public string? UnleashInstanceId { get; set; } - public bool PreferDirectLinks { get; set; } + public List ExtrasKeys { get; } = []; public string? MinecraftVersion { get; set; } public string? RefTag { get; set; }