50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
|
using ModpackUpdater.Apps.Manager.LangRes;
|
|
using Pilz.Plugins.Advanced;
|
|
using Pilz.UI.Extensions;
|
|
using Pilz.UI.Symbols;
|
|
|
|
namespace ModpackUpdater.Apps.Manager.Features.Tools;
|
|
|
|
internal class UpdatesCollectorFeature : PluginFunction, IPluginFeatureProvider<UpdatesCollectorFeature>
|
|
{
|
|
public static UpdatesCollectorFeature Instance { get; } = new();
|
|
|
|
public UpdatesCollectorFeature() : base(FeatureTypes.Tools, "origin.updatescollector", FeatureNamesLangRes.UpdatesCollectorFeature)
|
|
{
|
|
Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.search, SymbolSize.Small);
|
|
}
|
|
|
|
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
|
|
{
|
|
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null || p.Api.CurWorkspace.UpdateInfos is null)
|
|
return null;
|
|
|
|
// Collect updates
|
|
var ucDialog = new UpdatesCollectorUi(p.Api.CurWorkspace.InstallInfos);
|
|
if (!ucDialog.ShowDialog(p.Api.MainWindow).IsOk() || ucDialog.CurrentUpdates is null)
|
|
return null;
|
|
|
|
// Path install actions
|
|
foreach (var update in ucDialog.CurrentUpdates.List)
|
|
{
|
|
update.Origin.SourceTag = update.AvailableVersions[update.NewVersion].Value;
|
|
p.Api.UpdateItem(update.Origin);
|
|
}
|
|
|
|
// Create update actions
|
|
var updateSet = new UpdateInfo();
|
|
foreach (var update in ucDialog.CurrentUpdates.List)
|
|
{
|
|
updateSet.Actions.Add(new()
|
|
{
|
|
InheritFrom = update.Origin.Id,
|
|
});
|
|
}
|
|
p.Api.CurWorkspace.UpdateInfos.Updates.Insert(0, updateSet);
|
|
p.Api.UpdateItem(updateSet);
|
|
|
|
return null;
|
|
}
|
|
}
|