new extras system
This commit is contained in:
@@ -24,7 +24,6 @@ public partial class MainViewModel : ObservableObject
|
|||||||
private readonly UpdateCheckOptions updateOptions = new();
|
private readonly UpdateCheckOptions updateOptions = new();
|
||||||
private ModpackInfo modpackInfo = new();
|
private ModpackInfo modpackInfo = new();
|
||||||
private ModpackConfig updateConfig = new();
|
private ModpackConfig updateConfig = new();
|
||||||
private ModpackFeatures? features;
|
|
||||||
private UpdateCheckResult? lastUpdateCheckResult;
|
private UpdateCheckResult? lastUpdateCheckResult;
|
||||||
|
|
||||||
[ObservableProperty] private string? minecraftProfileFolder;
|
[ObservableProperty] private string? minecraftProfileFolder;
|
||||||
@@ -99,7 +98,7 @@ public partial class MainViewModel : ObservableObject
|
|||||||
|
|
||||||
private bool AllowExtras()
|
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()
|
public void LoadProfileToUi()
|
||||||
@@ -191,15 +190,14 @@ public partial class MainViewModel : ObservableObject
|
|||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
features = new(updateConfig);
|
|
||||||
modpackInfo.ExtrasKey = InstallKey?.Trim();
|
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));
|
SetStatus(GeneralLangRes.InstallationKeyNotValid, AppGlobals.Symbols.GetImageSource(AppSymbols.general_warning_sign));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CanUseExtrasKey = CanUseExtrasKey = !string.IsNullOrWhiteSpace(updateConfig.UnleashApiUrl);
|
CanUseExtrasKey = updateConfig.ExtrasKeys.Count > 0;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(MinecraftProfileFolder) /*|| modpackInfo.Valid*/)
|
if (string.IsNullOrWhiteSpace(MinecraftProfileFolder) /*|| modpackInfo.Valid*/)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,13 +39,12 @@ public static class Program
|
|||||||
{
|
{
|
||||||
var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder);
|
var info = ModpackInfo.TryLoad(updateOptions.ProfileFolder);
|
||||||
var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig!, info));
|
var config = ModpackConfig.LoadFromUrl(CheckModpackConfigUrl(updateOptions.ModpackConfig!, info));
|
||||||
var features = new ModpackFeatures(config);
|
|
||||||
|
|
||||||
// Check features
|
// Check features
|
||||||
if (!string.IsNullOrWhiteSpace(updateOptions.ExtrasKey))
|
if (!string.IsNullOrWhiteSpace(updateOptions.ExtrasKey))
|
||||||
info.ExtrasKey = updateOptions.ExtrasKey;
|
info.ExtrasKey = updateOptions.ExtrasKey;
|
||||||
if (!string.IsNullOrWhiteSpace(info.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
|
// Check for update
|
||||||
var installer = new ModpackInstaller(config, info)
|
var installer = new ModpackInstaller(config, info)
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -169,9 +169,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
foreach (InstallAction iaction in checkResult.Actions)
|
foreach (InstallAction iaction in checkResult.Actions)
|
||||||
{
|
{
|
||||||
var destFilePath = iaction.GetDestPath(modpackInfo.LocalPath);
|
var destFilePath = iaction.GetDestPath(modpackInfo.LocalPath);
|
||||||
var sourceUrl = updateConfig.PreferDirectLinks && !string.IsNullOrWhiteSpace(iaction.SourceUrl)
|
var sourceUrl = iaction.GetSourceUrl(checkResult.LatestVersion, overwriteVersion: OverwriteVersion);
|
||||||
? iaction.GetSourceUrl(checkResult.LatestVersion, overwriteVersion: OverwriteVersion)
|
|
||||||
: await factory.ResolveSourceUrl(iaction, targetVersion: checkResult.LatestVersion, overwriteVersion: OverwriteVersion);
|
|
||||||
|
|
||||||
if (iaction is UpdateAction uaction)
|
if (iaction is UpdateAction uaction)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ public class ModpackConfig
|
|||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
public string? UpdateUrl { get; set; }
|
public string? UpdateUrl { get; set; }
|
||||||
public string? InstallUrl { get; set; }
|
public string? InstallUrl { get; set; }
|
||||||
public string? UnleashApiUrl { get; set; }
|
public List<string> ExtrasKeys { get; } = [];
|
||||||
public string? UnleashInstanceId { get; set; }
|
|
||||||
public bool PreferDirectLinks { get; set; }
|
|
||||||
public string? MinecraftVersion { get; set; }
|
public string? MinecraftVersion { get; set; }
|
||||||
public string? RefTag { get; set; }
|
public string? RefTag { get; set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user