proper finish updates collector
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using Pilz.Plugins.Advanced;
|
||||
using Pilz.UI.Extensions;
|
||||
using Pilz.UI.Symbols;
|
||||
using Pilz.UI.Telerik.Dialogs;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Features.Tools;
|
||||
|
||||
@@ -15,8 +15,33 @@ internal class UpdatesCollectorFeature : PluginFunction
|
||||
|
||||
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
|
||||
{
|
||||
if (@params is MainApiParameters p)
|
||||
new UpdatesCollectorUi().Show(p.Api.MainWindow);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,25 +5,102 @@ namespace ModpackUpdater.Apps.Manager.Features.Tools;
|
||||
|
||||
public partial class UpdatesCollectorUi : RadForm
|
||||
{
|
||||
private readonly ModpackFactory factory = new();
|
||||
|
||||
public UpdatesCollectorUi()
|
||||
public record ModUpdateInfo(KeyValuePair<string, string>[] AvailableVersions, InstallAction Origin)
|
||||
{
|
||||
public int NewVersion { get; set; } = 0;
|
||||
}
|
||||
|
||||
public record ModUpdates(IEnumerable<ModUpdateInfo> List);
|
||||
|
||||
private readonly ModpackFactory factory = new();
|
||||
private readonly InstallInfos infos;
|
||||
|
||||
public ModUpdates? CurrentUpdates { get; private set; }
|
||||
|
||||
public ModUpdateInfo? SelectedUpdate => radListView_Updates.SelectedItem?.Value as ModUpdateInfo;
|
||||
|
||||
public int SelectedVersion => radListControl_VersionTags.SelectedValue as int? ?? -1;
|
||||
|
||||
public UpdatesCollectorUi(InstallInfos infos)
|
||||
{
|
||||
this.infos = infos;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void UpdatesCollectorUi_Shown(object sender, EventArgs e)
|
||||
private async Task<ModUpdates> FindUpdates()
|
||||
{
|
||||
var list = new List<ModUpdateInfo>();
|
||||
|
||||
foreach (var action in infos.Actions)
|
||||
{
|
||||
var updates = await factory.FindUpdates(action);
|
||||
|
||||
if (updates == null || updates.Length == 0 || updates[0].Value == action.SourceTag)
|
||||
continue;
|
||||
|
||||
list.Add(new(updates, action));
|
||||
}
|
||||
|
||||
return new ModUpdates(list);
|
||||
}
|
||||
|
||||
private void LoadUpdates(ModUpdates updates)
|
||||
{
|
||||
radListView_Updates.BeginUpdate();
|
||||
radListView_Updates.Items.Clear();
|
||||
|
||||
foreach (var update in updates.List)
|
||||
{
|
||||
var item = new ListViewDataItem(update);
|
||||
UpdateUpdatesItem(item);
|
||||
radListView_Updates.Items.Add();
|
||||
}
|
||||
|
||||
radListView_Updates.EndUpdate();
|
||||
}
|
||||
|
||||
private void UpdateUpdatesItem(ListViewDataItem? item)
|
||||
{
|
||||
if (item?.Value is not ModUpdateInfo updates)
|
||||
return;
|
||||
|
||||
item[0] = updates.Origin.Name;
|
||||
item[1] = updates.Origin.SourceTag;
|
||||
item[2] = updates.AvailableVersions[updates.NewVersion].Key;
|
||||
}
|
||||
|
||||
private void LoadVersions(ModUpdateInfo updates)
|
||||
{
|
||||
radListControl_VersionTags.BeginUpdate();
|
||||
radListControl_VersionTags.Items.Clear();
|
||||
|
||||
foreach (var kvp in updates.AvailableVersions)
|
||||
radListControl_VersionTags.Items.Add(new RadListDataItem($"{kvp.Key} | ({kvp.Value})", kvp.Value));
|
||||
|
||||
radListControl_VersionTags.SelectedValue = updates.NewVersion;
|
||||
radListControl_VersionTags.EndUpdate();
|
||||
}
|
||||
|
||||
private async void UpdatesCollectorUi_Shown(object sender, EventArgs e)
|
||||
{
|
||||
var updates = await FindUpdates();
|
||||
LoadUpdates(updates);
|
||||
}
|
||||
|
||||
private void RadListView_Updates_SelectedItemChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (SelectedUpdate is ModUpdateInfo updates)
|
||||
LoadVersions(updates);
|
||||
}
|
||||
|
||||
private void RadListControl_VersionTags_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
var newIndex = SelectedVersion;
|
||||
|
||||
if (newIndex != -1 && SelectedUpdate is ModUpdateInfo updates)
|
||||
{
|
||||
updates.NewVersion = newIndex;
|
||||
UpdateUpdatesItem(radListView_Updates.SelectedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user