some fixes

This commit is contained in:
2024-09-29 09:58:32 +02:00
parent 31f557cc8d
commit 934b8db71b
4 changed files with 125 additions and 67 deletions

View File

@@ -25,8 +25,16 @@ internal class UpdatesCollectorFeature : PluginFunction, IPluginFeatureProvider<
if (!ucDialog.ShowDialog(p.Api.MainWindow).IsOk() || ucDialog.CurrentUpdates is null)
return null;
// Path install actions
// 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);
@@ -34,7 +42,7 @@ internal class UpdatesCollectorFeature : PluginFunction, IPluginFeatureProvider<
// Create update actions
var updateSet = new UpdateInfo();
foreach (var update in ucDialog.CurrentUpdates.List)
foreach (var update in updates)
{
updateSet.Actions.Add(new()
{

View File

@@ -33,26 +33,29 @@ partial class UpdatesCollectorUi
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();
tableLayoutPanel2 = new TableLayoutPanel();
radButton_Continue = new Telerik.WinControls.UI.RadButton();
radListView_Updates = new Telerik.WinControls.UI.RadListView();
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();
tableLayoutPanel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)radButton_Continue).BeginInit();
((System.ComponentModel.ISupportInitialize)radListView_Updates).BeginInit();
((System.ComponentModel.ISupportInitialize)radListControl_VersionTags).BeginInit();
((System.ComponentModel.ISupportInitialize)radWaitingBar1).BeginInit();
((System.ComponentModel.ISupportInitialize)this).BeginInit();
SuspendLayout();
//
@@ -71,6 +74,19 @@ partial class UpdatesCollectorUi
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);
@@ -102,6 +118,38 @@ partial class UpdatesCollectorUi
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);
@@ -133,51 +181,6 @@ partial class UpdatesCollectorUi
tableLayoutPanel3.Size = new Size(280, 420);
tableLayoutPanel3.TabIndex = 0;
//
// 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;
//
// 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;
//
// 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;
//
// radListControl_VersionTags
//
radListControl_VersionTags.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
@@ -188,12 +191,30 @@ partial class UpdatesCollectorUi
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");
@@ -201,17 +222,18 @@ partial class 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);
tableLayoutPanel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)radButton_Continue).EndInit();
((System.ComponentModel.ISupportInitialize)radListView_Updates).EndInit();
((System.ComponentModel.ISupportInitialize)radListControl_VersionTags).EndInit();
((System.ComponentModel.ISupportInitialize)radWaitingBar1).EndInit();
((System.ComponentModel.ISupportInitialize)this).EndInit();
ResumeLayout(false);
PerformLayout();
@@ -228,4 +250,6 @@ partial class UpdatesCollectorUi
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

@@ -53,20 +53,20 @@ public partial class UpdatesCollectorUi : RadForm
{
var item = new ListViewDataItem(update);
UpdateUpdatesItem(item);
radListView_Updates.Items.Add();
radListView_Updates.Items.Add(item);
}
radListView_Updates.EndUpdate();
}
private void UpdateUpdatesItem(ListViewDataItem? item)
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].Key;
item[2] = updates.AvailableVersions[updates.NewVersion].Value;
}
private void LoadVersions(ModUpdateInfo updates)
@@ -83,8 +83,10 @@ public partial class UpdatesCollectorUi : RadForm
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)

View File

@@ -1,4 +1,5 @@
using Modrinth;
using CurseForge.APIClient.Models.Mods;
using Modrinth;
using Octokit;
using System.Text.RegularExpressions;
@@ -6,8 +7,11 @@ namespace ModpackUpdater.Manager;
public class ModpackFactory
{
private readonly GitHubClient github = new(new ProductHeaderValue("MinecraftModpackUpdater"));
private readonly CurseForge.APIClient.ApiClient curseForge = new("$2a$10$pE4dD09gmr7IcOe8hjWhleWWjXopJcDNpq1P9FlrDMCBw05pCyAXa", "pilzinsel64@gmx.de"); // b67bd218-e011-4963-ac8a-ffd025e1091f
private readonly GitHubClient github = new(new ProductHeaderValue("MinecraftModpackUpdater"))
{
Credentials = new Credentials("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"),
};
private readonly CurseForge.APIClient.ApiClient curseForge = new("$2a$10$pE4dD09gmr7IcOe8hjWhleWWjXopJcDNpq1P9FlrDMCBw05pCyAXa", "pilzinsel64@gmx.de");
private readonly ModrinthClient modrinth = new(new ModrinthClientConfig
{
ModrinthToken = "mrp_zUlDSET5actMUdTU3FK242TXgvlWgaErSSEFuegNG7thLgkC50IiK2NCGOzW",
@@ -55,11 +59,16 @@ public class ModpackFactory
public async Task<KeyValuePair<string, string>[]> FindUpdates(InstallAction action, ModLoader modLoader = ModLoader.Any, string? gameVersion = null)
{
if (action.SourceType == SourceType.GitHub)
{
try
{
var repo = await github.Repository.Get(action.SourceOwner, action.SourceName);
var releases = await github.Repository.Release.GetAll(repo.Id);
return releases.Select(r => new KeyValuePair<string, string>(r.Name, r.TagName)).ToArray();
return releases.Select(r => new KeyValuePair<string, string>(r.Name ?? r.TagName, r.TagName)).ToArray();
}
catch (Exception ex)
{
}
}
else if (action.SourceType == SourceType.GitLab)
{
@@ -67,7 +76,7 @@ public class ModpackFactory
}
else if (action.SourceType == SourceType.CurseForge)
{
var res = await curseForge.GetModFilesAsync(Convert.ToInt32(action.SourceName), gameVersion: "1.7.10", modLoaderType: CurseForge.APIClient.Models.Mods.ModLoaderType.Forge);
var res = await curseForge.GetModFilesAsync(Convert.ToInt32(action.SourceName), gameVersion: gameVersion, modLoaderType: GetModLoaderForCurseForge(modLoader));
if (res.Data != null)
return res.Data.Select(n => new KeyValuePair<string, string>(n.DisplayName, n.Id.ToString())).ToArray();
}
@@ -79,4 +88,19 @@ public class ModpackFactory
return null;
}
private ModLoaderType? GetModLoaderForCurseForge(ModLoader modLoader)
{
return modLoader switch
{
ModLoader.Any => null,
ModLoader.Forge => ModLoaderType.Forge,
ModLoader.NeoForge => ModLoaderType.NeoForge,
ModLoader.Fabric => ModLoaderType.Fabric,
ModLoader.LiteLoader => ModLoaderType.LiteLoader,
ModLoader.Cauldron => ModLoaderType.Cauldron,
ModLoader.Quilt => ModLoaderType.Quilt,
_ => null,
};
}
}