new extras system
This commit is contained in:
@@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user