move actions to separated code & add sinlge update search action
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
using ModpackUpdater.Manager;
|
||||
using Pilz.Plugins.Advanced;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Features.Tools;
|
||||
namespace ModpackUpdater.Apps.Manager.Features.CM;
|
||||
|
||||
internal class CheckSingleActionHealthyFeature : PluginFunction, IPluginFeatureProvider<CheckSingleActionHealthyFeature>
|
||||
{
|
||||
@@ -22,36 +21,10 @@ internal class CheckSingleActionHealthyFeature : PluginFunction, IPluginFeatureP
|
||||
|| p.Api.MainWindow is not MainForm mainForm
|
||||
|| mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView
|
||||
|| gridView.SelectedRows.FirstOrDefault() is not GridViewRowInfo row
|
||||
|| row.Tag is not InstallAction action)
|
||||
|| row.Tag is not InstallAction)
|
||||
return null;
|
||||
|
||||
bool failed = true;
|
||||
string? msg = null;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var factory = new ModpackFactory();
|
||||
var result = await factory.ResolveSourceUrl(action);
|
||||
failed = string.IsNullOrWhiteSpace(result);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
}
|
||||
}).Wait();
|
||||
|
||||
gridView.BeginUpdate();
|
||||
foreach (var c in row.Cells)
|
||||
{
|
||||
c.Style.CustomizeFill = true;
|
||||
c.Style.BackColor = failed ? Color.IndianRed : Color.ForestGreen;
|
||||
}
|
||||
gridView.EndUpdate();
|
||||
|
||||
if (failed && !string.IsNullOrWhiteSpace(msg))
|
||||
MessageBox.Show(msg);
|
||||
SharedFunctions.CheckActionHealthy(p.Api, row);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
using Pilz.Plugins.Advanced;
|
||||
using Pilz.UI.Symbols;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Features.CM;
|
||||
internal class UpdateCollectorFeature : PluginFunction, IPluginFeatureProvider<UpdateCollectorFeature>
|
||||
{
|
||||
public static UpdateCollectorFeature Instance { get; } = new();
|
||||
|
||||
public UpdateCollectorFeature() : base(FeatureTypes.ActionsContextMenu, "origin.updatecollector", FeatureNamesLangRes.UpdateCollectorFeature)
|
||||
{
|
||||
Icon = AppGlobals.Symbols.GetSvgImage(AppSymbols.search, SymbolSize.Small);
|
||||
}
|
||||
|
||||
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
|
||||
{
|
||||
if (@params is not MainApiParameters p
|
||||
|| p.Api.CurWorkspace?.UpdateInfos is null
|
||||
|| p.Api.MainWindow is not MainForm mainForm
|
||||
|| mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView
|
||||
|| gridView.SelectedRows.FirstOrDefault()?.Tag is not InstallAction selectedAction)
|
||||
return null;
|
||||
|
||||
SharedFunctions.CollectUpdates(p.Api, selectedAction);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
110
ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs
Normal file
110
ModpackUpdater.Apps.Manager/Features/SharedFunctions.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||
using ModpackUpdater.Apps.Manager.Features.Tools;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
using ModpackUpdater.Manager;
|
||||
using Pilz.UI.Extensions;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Features;
|
||||
|
||||
internal static class SharedFunctions
|
||||
{
|
||||
public static bool CheckActionHealthy(IMainApi api, params GridViewRowInfo[] selectedRows)
|
||||
{
|
||||
if (api.MainWindow is not MainForm mainForm
|
||||
|| mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView
|
||||
|| mainForm.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() is not RadWaitingBar rwb)
|
||||
return false;
|
||||
|
||||
rwb.StartWaiting();
|
||||
rwb.ShowText = true;
|
||||
var rowsCount = selectedRows.Length;
|
||||
rwb.Text = "0 / " + rowsCount;
|
||||
gridView.BeginUpdate();
|
||||
|
||||
var failed = false;
|
||||
var msg = default(string);
|
||||
|
||||
var rows = new Dictionary<GridViewRowInfo, InstallAction>();
|
||||
for (var i = 0; i < selectedRows.Length; i++)
|
||||
{
|
||||
var row = selectedRows[i];
|
||||
|
||||
if (row.Tag is InstallAction action)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var factory = new ModpackFactory();
|
||||
var result = await factory.ResolveSourceUrl(action);
|
||||
failed = string.IsNullOrWhiteSpace(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
}
|
||||
}).Wait();
|
||||
}
|
||||
|
||||
foreach (var c in row.Cells)
|
||||
{
|
||||
c.Style.CustomizeFill = true;
|
||||
c.Style.BackColor = failed ? Color.IndianRed : Color.ForestGreen;
|
||||
}
|
||||
|
||||
rwb.Text = $"{i} / {rowsCount}";
|
||||
|
||||
Application.DoEvents();
|
||||
}
|
||||
|
||||
gridView.EndUpdate();
|
||||
rwb.ShowText = false;
|
||||
rwb.StopWaiting();
|
||||
|
||||
if (rowsCount == 1 && failed && !string.IsNullOrWhiteSpace(msg))
|
||||
MessageBox.Show(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool CollectUpdates(IMainApi api, params InstallAction[] actions)
|
||||
{
|
||||
if (api.CurWorkspace?.UpdateInfos is null)
|
||||
return false;
|
||||
|
||||
// Collect updates
|
||||
var ucDialog = new UpdatesCollectorUi(actions);
|
||||
if (!ucDialog.ShowDialog(api.MainWindow).IsOk() || ucDialog.CurrentUpdates is null)
|
||||
return false;
|
||||
|
||||
// Collect versions with changes
|
||||
var updates = new List<UpdatesCollectorUi.ModUpdateInfo>();
|
||||
foreach (var update in ucDialog.CurrentUpdates.List)
|
||||
{
|
||||
if (update.Origin.SourceTag != update.AvailableVersions[update.NewVersion].Value)
|
||||
updates.Add(update);
|
||||
}
|
||||
|
||||
// Path install actions
|
||||
foreach (var update in updates)
|
||||
{
|
||||
update.Origin.SourceTag = update.AvailableVersions[update.NewVersion].Value;
|
||||
api.UpdateItem(update.Origin);
|
||||
}
|
||||
|
||||
// Create update actions
|
||||
var updateSet = new UpdateInfo();
|
||||
foreach (var update in updates)
|
||||
{
|
||||
updateSet.Actions.Add(new()
|
||||
{
|
||||
InheritFrom = update.Origin.Id,
|
||||
});
|
||||
}
|
||||
api.CurWorkspace.UpdateInfos.Updates.Insert(0, updateSet);
|
||||
api.UpdateItem(updateSet);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
using ModpackUpdater.Manager;
|
||||
using Pilz.Plugins.Advanced;
|
||||
using Telerik.WinControls.UI;
|
||||
|
||||
@@ -20,52 +19,10 @@ internal class CheckAllActionsHealthyFeature : PluginFunction, IPluginFeaturePro
|
||||
{
|
||||
if (@params is not MainApiParameters p
|
||||
|| p.Api.MainWindow is not MainForm mainForm
|
||||
|| mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView
|
||||
|| mainForm.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() is not RadWaitingBar rwb)
|
||||
|| mainForm.Controls.Find("radGridView_Actions", true).FirstOrDefault() is not RadGridView gridView)
|
||||
return null;
|
||||
|
||||
rwb.StartWaiting();
|
||||
rwb.ShowText = true;
|
||||
var rowsCount = gridView.Rows.Count;
|
||||
rwb.Text = "0 / " + rowsCount;
|
||||
gridView.BeginUpdate();
|
||||
|
||||
var rows = new Dictionary<GridViewRowInfo, InstallAction>();
|
||||
for (var i = 0; i < gridView.Rows.Count; i++)
|
||||
{
|
||||
var row = gridView.Rows[i];
|
||||
var failed = false;
|
||||
|
||||
if (row.Tag is InstallAction action)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var factory = new ModpackFactory();
|
||||
var result = await factory.ResolveSourceUrl(action);
|
||||
failed = string.IsNullOrWhiteSpace(result);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}).Wait();
|
||||
}
|
||||
|
||||
foreach (var c in row.Cells)
|
||||
{
|
||||
c.Style.CustomizeFill = true;
|
||||
c.Style.BackColor = failed ? Color.IndianRed : Color.ForestGreen;
|
||||
}
|
||||
|
||||
rwb.Text = $"{i} / {rowsCount}";
|
||||
|
||||
Application.DoEvents();
|
||||
}
|
||||
|
||||
gridView.EndUpdate();
|
||||
rwb.ShowText = false;
|
||||
rwb.StopWaiting();
|
||||
SharedFunctions.CheckActionHealthy(p.Api, [.. gridView.Rows]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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;
|
||||
@@ -17,40 +16,10 @@ internal class UpdatesCollectorFeature : PluginFunction, IPluginFeatureProvider<
|
||||
|
||||
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
|
||||
{
|
||||
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null || p.Api.CurWorkspace.UpdateInfos is null)
|
||||
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos 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;
|
||||
|
||||
// Collect versions with changes
|
||||
var updates = new List<UpdatesCollectorUi.ModUpdateInfo>();
|
||||
foreach (var update in ucDialog.CurrentUpdates.List)
|
||||
{
|
||||
if (update.Origin.SourceTag != update.AvailableVersions[update.NewVersion].Value)
|
||||
updates.Add(update);
|
||||
}
|
||||
|
||||
// Path install actions
|
||||
foreach (var update in updates)
|
||||
{
|
||||
update.Origin.SourceTag = update.AvailableVersions[update.NewVersion].Value;
|
||||
p.Api.UpdateItem(update.Origin);
|
||||
}
|
||||
|
||||
// Create update actions
|
||||
var updateSet = new UpdateInfo();
|
||||
foreach (var update in updates)
|
||||
{
|
||||
updateSet.Actions.Add(new()
|
||||
{
|
||||
InheritFrom = update.Origin.Id,
|
||||
});
|
||||
}
|
||||
p.Api.CurWorkspace.UpdateInfos.Updates.Insert(0, updateSet);
|
||||
p.Api.UpdateItem(updateSet);
|
||||
SharedFunctions.CollectUpdates(p.Api, [.. p.Api.CurWorkspace.InstallInfos.Actions]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public partial class UpdatesCollectorUi : RadForm
|
||||
public record ModUpdates(IEnumerable<ModUpdateInfo> List);
|
||||
|
||||
private readonly ModpackFactory factory = new();
|
||||
private readonly InstallInfos infos;
|
||||
private readonly InstallAction[] actions;
|
||||
|
||||
public ModUpdates? CurrentUpdates { get; private set; }
|
||||
|
||||
@@ -21,9 +21,9 @@ public partial class UpdatesCollectorUi : RadForm
|
||||
|
||||
public int SelectedVersion => radListControl_VersionTags.SelectedValue as int? ?? -1;
|
||||
|
||||
public UpdatesCollectorUi(InstallInfos infos)
|
||||
public UpdatesCollectorUi(params InstallAction[] actions)
|
||||
{
|
||||
this.infos = infos;
|
||||
this.actions = actions;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public partial class UpdatesCollectorUi : RadForm
|
||||
{
|
||||
var list = new List<ModUpdateInfo>();
|
||||
|
||||
foreach (var action in infos.Actions)
|
||||
foreach (var action in actions)
|
||||
{
|
||||
var updates = await factory.FindUpdates(action);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user