add options to update and clear direct links

This commit is contained in:
2024-10-03 10:46:16 +02:00
parent 3ec94fa22d
commit 690355266c
10 changed files with 205 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
using ModpackUpdater.Apps.Manager.LangRes;
using ModpackUpdater.Apps.Manager.Ui;
using Pilz.Plugins.Advanced;
using Telerik.WinControls.UI;
namespace ModpackUpdater.Apps.Manager.Features.CM;
internal class ClearDirectLinkFeature : PluginFunction, IPluginFeatureProvider<ClearDirectLinkFeature>
{
public static ClearDirectLinkFeature Instance { get; } = new();
public ClearDirectLinkFeature() : base(FeatureTypes.ActionsContextMenu, "origin.cleardirectlink", FeatureNamesLangRes.ClearDirectLinkFeature)
{
}
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
{
if (@params is not MainApiParameters p
|| 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.ClearDirectLinks(p.Api, selectedAction);
return null;
}
}

View File

@@ -0,0 +1,29 @@
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
using ModpackUpdater.Apps.Manager.LangRes;
using ModpackUpdater.Apps.Manager.Ui;
using Pilz.Plugins.Advanced;
using Telerik.WinControls.UI;
namespace ModpackUpdater.Apps.Manager.Features.CM;
internal class UpdateDirectLinkFeature : PluginFunction, IPluginFeatureProvider<UpdateDirectLinkFeature>
{
public static UpdateDirectLinkFeature Instance { get; } = new();
public UpdateDirectLinkFeature() : base(FeatureTypes.ActionsContextMenu, "origin.updatedirectlink", FeatureNamesLangRes.UpdateDirectLinkFeature)
{
}
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
{
if (@params is not MainApiParameters p
|| 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.FindNewDirectLinks(p.Api, selectedAction);
return null;
}
}

View File

@@ -1,5 +1,4 @@
using ModpackUpdater.Apps.Manager.Api.Model;
using ModpackUpdater.Apps.Manager.Features.Tools;
using ModpackUpdater.Apps.Manager.Ui;
using ModpackUpdater.Manager;
using Pilz.UI.Extensions;
@@ -24,6 +23,7 @@ internal static class SharedFunctions
var failed = false;
var msg = default(string);
var factory = new ModpackFactory();
var rows = new Dictionary<GridViewRowInfo, InstallAction>();
for (var i = 0; i < selectedRows.Length; i++)
@@ -36,7 +36,6 @@ internal static class SharedFunctions
{
try
{
var factory = new ModpackFactory();
var result = await factory.ResolveSourceUrl(action);
failed = string.IsNullOrWhiteSpace(result);
}
@@ -107,4 +106,52 @@ internal static class SharedFunctions
return true;
}
public static void FindNewDirectLinks(IMainApi api, params InstallAction[] actions)
{
var mainForm = api.MainWindow as MainForm;
var gridView = mainForm?.Controls.Find("radGridView_Actions", true).FirstOrDefault() as RadGridView;
var rwb = mainForm?.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() as RadWaitingBar;
var factory = new ModpackFactory();
rwb?.StartWaiting();
gridView?.BeginUpdate();
foreach (var action in actions)
{
if (action.SourceType != SourceType.DirectLink)
{
Task.Run(async () =>
{
action.SourceUrl = await factory.ResolveSourceUrl(action);
}).Wait();
api.UpdateItem(action);
}
}
gridView?.EndUpdate();
rwb?.StopWaiting();
}
public static void ClearDirectLinks(IMainApi api, params InstallAction[] actions)
{
var mainForm = api.MainWindow as MainForm;
var gridView = mainForm?.Controls.Find("radGridView_Actions", true).FirstOrDefault() as RadGridView;
var rwb = mainForm?.Controls.Find("radWaitingBar_Actions", true).FirstOrDefault() as RadWaitingBar;
rwb?.StartWaiting();
gridView?.BeginUpdate();
foreach (var action in actions)
{
if (action.SourceType != SourceType.DirectLink)
{
action.SourceUrl = null;
api.UpdateItem(action);
}
}
gridView?.EndUpdate();
rwb?.StopWaiting();
}
}

View File

@@ -0,0 +1,24 @@
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
using ModpackUpdater.Apps.Manager.LangRes;
using Pilz.Plugins.Advanced;
namespace ModpackUpdater.Apps.Manager.Features.Tools;
internal class ClearDirectLinksFeature : PluginFunction, IPluginFeatureProvider<ClearDirectLinksFeature>
{
public static ClearDirectLinksFeature Instance { get; } = new();
public ClearDirectLinksFeature() : base(FeatureTypes.Tools, "origin.cleardirectlinks", FeatureNamesLangRes.ClearDirectLinksFeature)
{
}
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
{
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null)
return null;
SharedFunctions.ClearDirectLinks(p.Api, [.. p.Api.CurWorkspace.InstallInfos.Actions]);
return null;
}
}

View File

@@ -0,0 +1,24 @@
using ModpackUpdater.Apps.Manager.Api.Plugins.Params;
using ModpackUpdater.Apps.Manager.LangRes;
using Pilz.Plugins.Advanced;
namespace ModpackUpdater.Apps.Manager.Features.Tools;
internal class UpdateDirectLinksFeature : PluginFunction, IPluginFeatureProvider<UpdateDirectLinksFeature>
{
public static UpdateDirectLinksFeature Instance { get; } = new();
public UpdateDirectLinksFeature() : base(FeatureTypes.Tools, "origin.updatedirectlinks", FeatureNamesLangRes.UpdateDirectLinksFeature)
{
}
protected override object? ExecuteFunction(PluginFunctionParameter? @params)
{
if (@params is not MainApiParameters p || p.Api.CurWorkspace?.InstallInfos is null)
return null;
SharedFunctions.FindNewDirectLinks(p.Api, [.. p.Api.CurWorkspace.InstallInfos.Actions]);
return null;
}
}

View File

@@ -1,255 +0,0 @@
namespace ModpackUpdater.Apps.Manager.Features.Tools;
partial class UpdatesCollectorUi
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
var listViewDetailColumn1 = new Telerik.WinControls.UI.ListViewDetailColumn("Column 0", "Name");
var listViewDetailColumn2 = new Telerik.WinControls.UI.ListViewDetailColumn("Column 1", "Current version");
var listViewDetailColumn3 = new Telerik.WinControls.UI.ListViewDetailColumn("Column 2", "New version");
var resources = new System.ComponentModel.ComponentResourceManager(typeof(UpdatesCollectorUi));
tableLayoutPanel1 = new TableLayoutPanel();
radButton_Continue = new Telerik.WinControls.UI.RadButton();
radSplitContainer1 = new Telerik.WinControls.UI.RadSplitContainer();
splitPanel1 = new Telerik.WinControls.UI.SplitPanel();
tableLayoutPanel2 = new TableLayoutPanel();
radListView_Updates = new Telerik.WinControls.UI.RadListView();
splitPanel2 = new Telerik.WinControls.UI.SplitPanel();
tableLayoutPanel3 = new TableLayoutPanel();
radListControl_VersionTags = new Telerik.WinControls.UI.RadListControl();
radWaitingBar1 = new Telerik.WinControls.UI.RadWaitingBar();
dotsRingWaitingBarIndicatorElement1 = new Telerik.WinControls.UI.DotsRingWaitingBarIndicatorElement();
tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)radButton_Continue).BeginInit();
((System.ComponentModel.ISupportInitialize)radSplitContainer1).BeginInit();
radSplitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)splitPanel1).BeginInit();
splitPanel1.SuspendLayout();
tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)radListView_Updates).BeginInit();
((System.ComponentModel.ISupportInitialize)splitPanel2).BeginInit();
splitPanel2.SuspendLayout();
tableLayoutPanel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)radListControl_VersionTags).BeginInit();
((System.ComponentModel.ISupportInitialize)radWaitingBar1).BeginInit();
((System.ComponentModel.ISupportInitialize)this).BeginInit();
SuspendLayout();
//
// tableLayoutPanel1
//
tableLayoutPanel1.AutoSize = true;
tableLayoutPanel1.ColumnCount = 2;
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle());
tableLayoutPanel1.Controls.Add(radButton_Continue, 1, 0);
tableLayoutPanel1.Dock = DockStyle.Bottom;
tableLayoutPanel1.Location = new Point(0, 420);
tableLayoutPanel1.Name = "tableLayoutPanel1";
tableLayoutPanel1.RowCount = 1;
tableLayoutPanel1.RowStyles.Add(new RowStyle());
tableLayoutPanel1.Size = new Size(800, 30);
tableLayoutPanel1.TabIndex = 0;
//
// radButton_Continue
//
radButton_Continue.Anchor = AnchorStyles.Top | AnchorStyles.Right;
radButton_Continue.DialogResult = DialogResult.OK;
radButton_Continue.ImageAlignment = ContentAlignment.MiddleRight;
radButton_Continue.Location = new Point(647, 3);
radButton_Continue.Name = "radButton_Continue";
radButton_Continue.Size = new Size(150, 24);
radButton_Continue.TabIndex = 0;
radButton_Continue.Text = "Continue";
radButton_Continue.TextAlignment = ContentAlignment.MiddleLeft;
radButton_Continue.TextImageRelation = TextImageRelation.ImageBeforeText;
//
// radSplitContainer1
//
radSplitContainer1.Controls.Add(splitPanel1);
radSplitContainer1.Controls.Add(splitPanel2);
radSplitContainer1.Dock = DockStyle.Fill;
radSplitContainer1.Location = new Point(0, 0);
radSplitContainer1.Name = "radSplitContainer1";
//
//
//
radSplitContainer1.RootElement.MinSize = new Size(25, 25);
radSplitContainer1.Size = new Size(800, 420);
radSplitContainer1.TabIndex = 1;
radSplitContainer1.TabStop = false;
//
// splitPanel1
//
splitPanel1.Controls.Add(tableLayoutPanel2);
splitPanel1.Location = new Point(0, 0);
splitPanel1.Name = "splitPanel1";
//
//
//
splitPanel1.RootElement.MinSize = new Size(25, 25);
splitPanel1.Size = new Size(516, 420);
splitPanel1.SizeInfo.AutoSizeScale = new SizeF(0.148241222F, 0F);
splitPanel1.SizeInfo.SplitterCorrection = new Size(118, 0);
splitPanel1.TabIndex = 0;
splitPanel1.TabStop = false;
splitPanel1.Text = "splitPanel1";
//
// tableLayoutPanel2
//
tableLayoutPanel2.ColumnCount = 1;
tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20F));
tableLayoutPanel2.Controls.Add(radListView_Updates, 0, 0);
tableLayoutPanel2.Dock = DockStyle.Fill;
tableLayoutPanel2.Location = new Point(0, 0);
tableLayoutPanel2.Name = "tableLayoutPanel2";
tableLayoutPanel2.RowCount = 1;
tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel2.Size = new Size(516, 420);
tableLayoutPanel2.TabIndex = 1;
//
// radListView_Updates
//
radListView_Updates.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listViewDetailColumn1.HeaderText = "Name";
listViewDetailColumn2.HeaderText = "Current version";
listViewDetailColumn2.Width = 120F;
listViewDetailColumn3.HeaderText = "New version";
listViewDetailColumn3.Width = 120F;
radListView_Updates.Columns.AddRange(new Telerik.WinControls.UI.ListViewDetailColumn[] { listViewDetailColumn1, listViewDetailColumn2, listViewDetailColumn3 });
radListView_Updates.ItemSpacing = -1;
radListView_Updates.Location = new Point(3, 3);
radListView_Updates.Name = "radListView_Updates";
radListView_Updates.Size = new Size(510, 414);
radListView_Updates.TabIndex = 0;
radListView_Updates.ViewType = Telerik.WinControls.UI.ListViewType.DetailsView;
radListView_Updates.SelectedItemChanged += RadListView_Updates_SelectedItemChanged;
//
// splitPanel2
//
splitPanel2.Controls.Add(tableLayoutPanel3);
splitPanel2.Location = new Point(520, 0);
splitPanel2.Name = "splitPanel2";
//
//
//
splitPanel2.RootElement.MinSize = new Size(25, 25);
splitPanel2.Size = new Size(280, 420);
splitPanel2.SizeInfo.AutoSizeScale = new SizeF(-0.148241192F, 0F);
splitPanel2.SizeInfo.SplitterCorrection = new Size(-118, 0);
splitPanel2.TabIndex = 1;
splitPanel2.TabStop = false;
splitPanel2.Text = "splitPanel2";
//
// tableLayoutPanel3
//
tableLayoutPanel3.ColumnCount = 1;
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutPanel3.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 20F));
tableLayoutPanel3.Controls.Add(radListControl_VersionTags, 0, 0);
tableLayoutPanel3.Dock = DockStyle.Fill;
tableLayoutPanel3.Location = new Point(0, 0);
tableLayoutPanel3.Name = "tableLayoutPanel3";
tableLayoutPanel3.RowCount = 1;
tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
tableLayoutPanel3.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel3.Size = new Size(280, 420);
tableLayoutPanel3.TabIndex = 0;
//
// radListControl_VersionTags
//
radListControl_VersionTags.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
radListControl_VersionTags.ItemHeight = 24;
radListControl_VersionTags.Location = new Point(3, 3);
radListControl_VersionTags.Name = "radListControl_VersionTags";
radListControl_VersionTags.Size = new Size(274, 414);
radListControl_VersionTags.TabIndex = 0;
radListControl_VersionTags.SelectedValueChanged += RadListControl_VersionTags_SelectedValueChanged;
//
// radWaitingBar1
//
radWaitingBar1.AssociatedControl = radListView_Updates;
radWaitingBar1.Location = new Point(0, 0);
radWaitingBar1.Name = "radWaitingBar1";
radWaitingBar1.Size = new Size(70, 70);
radWaitingBar1.TabIndex = 2;
radWaitingBar1.Text = "radWaitingBar1";
radWaitingBar1.WaitingIndicators.Add(dotsRingWaitingBarIndicatorElement1);
radWaitingBar1.WaitingIndicatorSize = new Size(100, 14);
radWaitingBar1.WaitingSpeed = 50;
radWaitingBar1.WaitingStyle = Telerik.WinControls.Enumerations.WaitingBarStyles.DotsRing;
//
// dotsRingWaitingBarIndicatorElement1
//
dotsRingWaitingBarIndicatorElement1.Name = "dotsRingWaitingBarIndicatorElement1";
//
// UpdatesCollectorUi
//
AutoScaleBaseSize = new Size(7, 15);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(radWaitingBar1);
Controls.Add(radSplitContainer1);
Controls.Add(tableLayoutPanel1);
Icon = (Icon)resources.GetObject("$this.Icon");
Name = "UpdatesCollectorUi";
Text = "Find updates";
Shown += UpdatesCollectorUi_Shown;
tableLayoutPanel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)radButton_Continue).EndInit();
((System.ComponentModel.ISupportInitialize)radSplitContainer1).EndInit();
radSplitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)splitPanel1).EndInit();
splitPanel1.ResumeLayout(false);
tableLayoutPanel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)radListView_Updates).EndInit();
((System.ComponentModel.ISupportInitialize)splitPanel2).EndInit();
splitPanel2.ResumeLayout(false);
tableLayoutPanel3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)radListControl_VersionTags).EndInit();
((System.ComponentModel.ISupportInitialize)radWaitingBar1).EndInit();
((System.ComponentModel.ISupportInitialize)this).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private TableLayoutPanel tableLayoutPanel1;
private Telerik.WinControls.UI.RadButton radButton_Continue;
private Telerik.WinControls.UI.RadSplitContainer radSplitContainer1;
private Telerik.WinControls.UI.SplitPanel splitPanel1;
private TableLayoutPanel tableLayoutPanel2;
private Telerik.WinControls.UI.SplitPanel splitPanel2;
private TableLayoutPanel tableLayoutPanel3;
private Telerik.WinControls.UI.RadListView radListView_Updates;
private Telerik.WinControls.UI.RadListControl radListControl_VersionTags;
private Telerik.WinControls.UI.RadWaitingBar radWaitingBar1;
private Telerik.WinControls.UI.DotsRingWaitingBarIndicatorElement dotsRingWaitingBarIndicatorElement1;
}

View File

@@ -1,108 +0,0 @@
using ModpackUpdater.Manager;
using Telerik.WinControls.UI;
namespace ModpackUpdater.Apps.Manager.Features.Tools;
public partial class UpdatesCollectorUi : RadForm
{
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 InstallAction[] actions;
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(params InstallAction[] actions)
{
this.actions = actions;
InitializeComponent();
}
private async Task<ModUpdates> FindUpdates()
{
var list = new List<ModUpdateInfo>();
foreach (var action in 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(item);
}
radListView_Updates.EndUpdate();
}
private static 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].Value;
}
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)
{
radWaitingBar1.StartWaiting();
var updates = await FindUpdates();
LoadUpdates(updates);
radWaitingBar1.StopWaiting();
}
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);
}
}
}