manager: add proper support for options
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Castle.Core.Logging;
|
using Castle.Core.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Pilz.Extensions.Collections;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using FileMode = System.IO.FileMode;
|
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)
|
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())
|
if (actions.Any())
|
||||||
{
|
{
|
||||||
result.Actions.AddRange(actions);
|
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 updatesOrderes = updateInfos.Updates.Where(n => n.IsPublic || options.IncludeNonPublic).OrderByDescending(n => n.Version);
|
||||||
var checkingVersionIndex = 0;
|
var checkingVersionIndex = 0;
|
||||||
var checkingVersion = updatesOrderes.ElementAtOrDefault(checkingVersionIndex);
|
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)
|
while (checkingVersion is not null && checkingVersion.Version > result.CurrentVersion)
|
||||||
{
|
{
|
||||||
@@ -113,11 +114,9 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
ResolveInherit(action, installInfos);
|
ResolveInherit(action, installInfos);
|
||||||
|
|
||||||
// Check & add
|
// 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);
|
actionsToAdd.Add(action);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result.Actions.InsertRange(actionsZeroIndex, actionsToAdd);
|
result.Actions.InsertRange(actionsZeroIndex, actionsToAdd);
|
||||||
|
|
||||||
@@ -132,6 +131,22 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
result.HasError = true;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +232,7 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save new modpack info
|
// Save new modpack info
|
||||||
|
modpackInfo.Options.Clear();
|
||||||
modpackInfo.Version = checkResult.LatestVersion;
|
modpackInfo.Version = checkResult.LatestVersion;
|
||||||
modpackInfo.ConfigUrl = updateConfig.ConfigUrl;
|
modpackInfo.ConfigUrl = updateConfig.ConfigUrl;
|
||||||
modpackInfo.Save();
|
modpackInfo.Save();
|
||||||
@@ -293,4 +309,23 @@ public class ModpackInstaller(ModpackConfig updateConfig, ModpackInfo modpackInf
|
|||||||
|
|
||||||
return true;
|
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 Side Side { get; set; } = Side.Client;
|
||||||
public bool IncludeExtras { get; set; }
|
public bool IncludeExtras { get; set; }
|
||||||
public bool IgnoreInstalledVersion { 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 CurrentVersion { get; set; }
|
||||||
public Version LatestVersion { get; set; }
|
public Version LatestVersion { get; set; }
|
||||||
public List<InstallAction> Actions { get; private 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 IsInstalled { get; set; }
|
||||||
public bool HasError { get; set; }
|
public bool HasError { get; set; }
|
||||||
public bool IsInMaintenance { get; set; }
|
public bool IsInMaintenance { get; set; }
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ public class InstallOption : IActionSet
|
|||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public Side Side { get; set; } = Side.Both;
|
public Side Side { get; set; } = Side.Both;
|
||||||
|
|
||||||
|
[DefaultValue(false)]
|
||||||
|
public bool Default { get; }
|
||||||
|
|
||||||
public List<UpdateAction> UninstallActions { get; } = [];
|
public List<UpdateAction> UninstallActions { get; } = [];
|
||||||
|
|
||||||
IEnumerable<InstallAction> IActionSet.Actions => UninstallActions.Cast<InstallAction>();
|
IEnumerable<InstallAction> IActionSet.Actions => UninstallActions.Cast<InstallAction>();
|
||||||
|
|||||||
@@ -18,7 +18,5 @@ public class InstallOptionSet
|
|||||||
[DefaultValue(false)]
|
[DefaultValue(false)]
|
||||||
public bool Multiselect { get; set; }
|
public bool Multiselect { get; set; }
|
||||||
|
|
||||||
public List<int> Defaults { get; } = [];
|
|
||||||
|
|
||||||
public List<InstallOption> Options { get; } = [];
|
public List<InstallOption> Options { get; } = [];
|
||||||
}
|
}
|
||||||
|
|||||||
28
ModpackUpdater/InstallOptionValueDictionary.cs
Normal file
28
ModpackUpdater/InstallOptionValueDictionary.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
namespace ModpackUpdater;
|
||||||
|
|
||||||
|
public class InstallOptionValueDictionary : Dictionary<string, bool>
|
||||||
|
{
|
||||||
|
public void SetOption(InstallOptionSet set, InstallOption option, bool value)
|
||||||
|
{
|
||||||
|
if (!set.Options.Contains(option))
|
||||||
|
throw new KeyNotFoundException("Options seems to be not a part of the option set.");
|
||||||
|
if (option.Default == value)
|
||||||
|
UnsetOption(set, option);
|
||||||
|
else
|
||||||
|
this[$"{set.Id}.{option.Id}"] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnsetOption(InstallOptionSet set, InstallOption option)
|
||||||
|
{
|
||||||
|
if (!set.Options.Contains(option))
|
||||||
|
throw new KeyNotFoundException("Options seems to be not a part of the option set.");
|
||||||
|
Remove($"{set.Id}.{option.Id}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetOptionValue(InstallOptionSet set, InstallOption option)
|
||||||
|
{
|
||||||
|
if (TryGetValue($"{set.Id}.{option.Id}", out var value))
|
||||||
|
return value;
|
||||||
|
return option.Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ public class ModpackInfo
|
|||||||
public Version Version { get; set; }
|
public Version Version { get; set; }
|
||||||
public string ConfigUrl { get; set; }
|
public string ConfigUrl { get; set; }
|
||||||
public string ExtrasKey { get; set; }
|
public string ExtrasKey { get; set; }
|
||||||
|
public InstallOptionValueDictionary Options { get; } = [];
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string LocaLPath { get; private set; }
|
public string LocaLPath { get; private set; }
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
|
<PackageReference Include="Pilz.Cryptography" Version="2.1.2" />
|
||||||
|
<PackageReference Include="Pilz.Extensions" Version="2.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user