proper finish updates collector
This commit is contained in:
@@ -2,7 +2,13 @@
|
||||
|
||||
public interface IMainApi
|
||||
{
|
||||
public IWorkspace? CurWorkspace { get; }
|
||||
public IActionSetInfos? CurActionSet { get; }
|
||||
public Form MainWindow { get; }
|
||||
IWorkspace? CurWorkspace { get; }
|
||||
|
||||
IActionSetInfos? CurActionSet { get; }
|
||||
|
||||
Form MainWindow { get; }
|
||||
|
||||
void UpdateItem(InstallAction action);
|
||||
|
||||
void UpdateItem(IActionSetInfos actionSetInfos);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,33 @@ public partial class MainForm : RadForm, IMainApi
|
||||
item.SvgImage = AppGlobals.Symbols.GetSvgImage(infos.IsPublic ? AppSymbols.eye : AppSymbols.invisible, SymbolSize.Small);
|
||||
}
|
||||
|
||||
public void UpdateItem(IActionSetInfos actionSetInfos)
|
||||
{
|
||||
RadListDataItem? item = null;
|
||||
|
||||
foreach (var iitem in radListControl_Updates.Items)
|
||||
{
|
||||
if (item == null && iitem.Value == actionSetInfos)
|
||||
item = iitem;
|
||||
}
|
||||
|
||||
if (item == null)
|
||||
InsertUpdateItem(actionSetInfos);
|
||||
else if (wsInfo?.Workspace.UpdateInfos != null && !wsInfo.Workspace.UpdateInfos.Updates.Contains(actionSetInfos))
|
||||
radListControl_Updates.Items.Remove(item);
|
||||
else
|
||||
UpdateUpdateItem(item);
|
||||
}
|
||||
|
||||
public void UpdateItem(InstallAction action)
|
||||
{
|
||||
foreach (var row in radGridView_Actions.Rows)
|
||||
{
|
||||
if (row.Tag == action)
|
||||
UpdateActionRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadActionSet(IActionSetInfos infos)
|
||||
{
|
||||
radGridView_Actions.BeginUpdate();
|
||||
@@ -307,32 +334,40 @@ public partial class MainForm : RadForm, IMainApi
|
||||
{
|
||||
var row = radGridView_Actions.Rows.AddNew();
|
||||
row.Tag = action;
|
||||
row.Cells["id"].Value = action.Id;
|
||||
row.Cells["name"].Value = action.Name;
|
||||
row.Cells["iszip"].Value = action.IsZip;
|
||||
row.Cells["zippath"].Value = action.ZipPath;
|
||||
row.Cells["destpath"].Value = action.DestPath;
|
||||
row.Cells["srcurl"].Value = action.SourceUrl;
|
||||
row.Cells["srctype"].Value = action.SourceType;
|
||||
row.Cells["srcowner"].Value = action.SourceOwner;
|
||||
row.Cells["srcname"].Value = action.SourceName;
|
||||
row.Cells["srcregex"].Value = action.SourceRegex;
|
||||
row.Cells["srctag"].Value = action.SourceTag;
|
||||
row.Cells["side"].Value = action.Side;
|
||||
row.Cells["isextra"].Value = action.IsExtra;
|
||||
|
||||
if (action is UpdateAction uaction)
|
||||
{
|
||||
row.Cells["inherit"].Value = uaction.InheritFrom; // TODO: Find inherit action and put it in here!
|
||||
row.Cells["utype"].Value = uaction.Type;
|
||||
row.Cells["srcpath"].Value = uaction.SrcPath;
|
||||
row.Cells["isdir"].Value = uaction.IsDirectory;
|
||||
}
|
||||
UpdateActionRow(row);
|
||||
}
|
||||
|
||||
radGridView_Actions.EndUpdate();
|
||||
}
|
||||
|
||||
private void UpdateActionRow(GridViewRowInfo row)
|
||||
{
|
||||
if (row.Tag is not InstallAction action)
|
||||
return;
|
||||
|
||||
row.Cells["id"].Value = action.Id;
|
||||
row.Cells["name"].Value = action.Name;
|
||||
row.Cells["iszip"].Value = action.IsZip;
|
||||
row.Cells["zippath"].Value = action.ZipPath;
|
||||
row.Cells["destpath"].Value = action.DestPath;
|
||||
row.Cells["srcurl"].Value = action.SourceUrl;
|
||||
row.Cells["srctype"].Value = action.SourceType;
|
||||
row.Cells["srcowner"].Value = action.SourceOwner;
|
||||
row.Cells["srcname"].Value = action.SourceName;
|
||||
row.Cells["srcregex"].Value = action.SourceRegex;
|
||||
row.Cells["srctag"].Value = action.SourceTag;
|
||||
row.Cells["side"].Value = action.Side;
|
||||
row.Cells["isextra"].Value = action.IsExtra;
|
||||
|
||||
if (action is not UpdateAction uaction)
|
||||
return;
|
||||
|
||||
row.Cells["inherit"].Value = uaction.InheritFrom; // TODO: Find inherit action and put it in here!
|
||||
row.Cells["utype"].Value = uaction.Type;
|
||||
row.Cells["srcpath"].Value = uaction.SrcPath;
|
||||
row.Cells["isdir"].Value = uaction.IsDirectory;
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadRecentWorkspaces();
|
||||
|
||||
Reference in New Issue
Block a user