manager: add proper support for options
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Castle.Core.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Extensions.Collections;
|
||||
using System.IO.Compression;
|
||||
using FileMode = System.IO.FileMode;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
||||
|
||||
if (installInfos is not null && installInfos.IsPublic && installInfos.Actions.Count != 0)
|
||||
{
|
||||
var actions = installInfos.Actions.Where(n => n.Side.IsSide(options.Side) && (!n.IsExtra || options.IncludeExtras));
|
||||
var actions = installInfos.Actions.Where(n => n.Side.IsSide(options.Side) && (!n.IsExtra || options.IncludeExtras) && GetOptionValue(options, installInfos, n.TargetOption));
|
||||
if (actions.Any())
|
||||
{
|
||||
result.Actions.AddRange(actions);
|
||||
@@ -101,7 +102,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
||||
var updatesOrderes = updateInfos.Updates.Where(n => n.IsPublic || options.IncludeNonPublic).OrderByDescending(n => n.Version);
|
||||
var checkingVersionIndex = 0;
|
||||
var checkingVersion = updatesOrderes.ElementAtOrDefault(checkingVersionIndex);
|
||||
var actionsZeroIndex = result.Actions.Count; // Ensure we insert update actions behind install actions
|
||||
var actionsZeroIndex = result.Actions.Count; // Ensure we insert update actions BEHIND install actions
|
||||
|
||||
while (checkingVersion is not null && checkingVersion.Version > result.CurrentVersion)
|
||||
{
|
||||
@@ -113,10 +114,8 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
||||
ResolveInherit(action, installInfos);
|
||||
|
||||
// Check & add
|
||||
if (action.Side.IsSide(options.Side) && (!action.IsExtra || options.IncludeExtras) && !result.Actions.Any(n => n.DestPath == action.DestPath))
|
||||
{
|
||||
if (action.Side.IsSide(options.Side) && (!action.IsExtra || options.IncludeExtras) && GetOptionValue(options, installInfos, action.TargetOption) && !result.Actions.Any(n => n.DestPath == action.DestPath))
|
||||
actionsToAdd.Add(action);
|
||||
}
|
||||
}
|
||||
|
||||
result.Actions.InsertRange(actionsZeroIndex, actionsToAdd);
|
||||
@@ -132,6 +131,22 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
||||
result.HasError = true;
|
||||
}
|
||||
|
||||
// Check option uninstall actions
|
||||
result.OptionsAvailable.AddRange(installInfos.OptionSets); // Find used options
|
||||
result.OptionsEnabled.AddRange(installInfos.OptionSets
|
||||
.Where(set => set.Side.IsSide(options.Side))
|
||||
.SelectMany(set => set.Options
|
||||
.Where(opt => opt.Side.IsSide(options.Side) && options.Options.GetOptionValue(set, opt))
|
||||
.Select(opt => $"{set.Id}.{opt.Id}"))); // Find used options
|
||||
var uninstallOptionActions = installInfos.OptionSets
|
||||
.Where(set => set.Side.IsSide(options.Side))
|
||||
.SelectMany(set => set.Options
|
||||
.Where(opt => opt.Side.IsSide(options.Side) && !result.OptionsEnabled.Contains($"{set.Id}.{opt.Id}") && modpackInfo.Options.ContainsKey($"{set.Id}.{opt.Id}"))
|
||||
.SelectMany(opt => opt.UninstallActions))
|
||||
.ForEach(action => ResolveInherit(action, installInfos))
|
||||
.Where(action => !result.Actions.Any(n => n.DestPath == action.DestPath)); // Find actions that are not already there
|
||||
result.Actions.InsertRange(0, uninstallOptionActions); // Add uninstall update actions BEFORE install actions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -217,6 +232,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
||||
}
|
||||
|
||||
// Save new modpack info
|
||||
modpackInfo.Options.Clear();
|
||||
modpackInfo.Version = checkResult.LatestVersion;
|
||||
modpackInfo.ConfigUrl = updateConfig.ConfigUrl;
|
||||
modpackInfo.Save();
|
||||
@@ -293,4 +309,23 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool GetOptionValue(UpdateCheckOptions options, InstallInfos installInfos, string optionStr)
|
||||
{
|
||||
var optionsStr = optionStr.Split(',');
|
||||
|
||||
foreach (var set in installInfos.OptionSets)
|
||||
{
|
||||
if (!set.Side.IsSide(options.Side))
|
||||
continue;
|
||||
|
||||
foreach (var opt in set.Options)
|
||||
{
|
||||
if (opt.Side.IsSide(options.Side) && optionsStr.Contains($"{set.Id}.{opt.Id}") && options.Options.GetOptionValue(set, opt))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,5 @@ public class UpdateCheckOptions
|
||||
public Side Side { get; set; } = Side.Client;
|
||||
public bool IncludeExtras { get; set; }
|
||||
public bool IgnoreInstalledVersion { get; set; }
|
||||
public InstallOptionValueDictionary Options { get; } = [];
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ public class UpdateCheckResult
|
||||
public Version CurrentVersion { get; set; }
|
||||
public Version LatestVersion { get; set; }
|
||||
public List<InstallAction> Actions { get; private set; } = [];
|
||||
public List<InstallOptionSet> OptionsAvailable { get; } = [];
|
||||
public List<string> OptionsEnabled { get; } = [];
|
||||
public bool IsInstalled { get; set; }
|
||||
public bool HasError { get; set; }
|
||||
public bool IsInMaintenance { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user