ui(manager)+manager: improve display version
This commit is contained in:
@@ -6,7 +6,6 @@ using ModpackUpdater.Apps.Manager.Ui;
|
||||
using ModpackUpdater.Apps.Manager.Ui.Models.MainWindow;
|
||||
using ModpackUpdater.Apps.Manager.Ui.Models.UpdatesCollectorViewMode;
|
||||
using ModpackUpdater.Manager;
|
||||
using MsBox.Avalonia;
|
||||
using OfficeOpenXml;
|
||||
using OfficeOpenXml.Table;
|
||||
using Pilz.UI.AvaloniaUI.Dialogs;
|
||||
@@ -39,7 +38,7 @@ internal static class SharedFunctions
|
||||
var result = await factory.ResolveSourceUrl(row.Action);
|
||||
failed = string.IsNullOrWhiteSpace(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
@@ -65,12 +64,12 @@ internal static class SharedFunctions
|
||||
return false;
|
||||
|
||||
// Collect versions with changes
|
||||
var updates = resultUpdates.List.Where(update => update.Origin.SourceTag != update.AvailableVersions[update.NewVersion].Key).ToList();
|
||||
var updates = resultUpdates.List.Where(update => update.Origin.SourceTag != update.AvailableVersions[update.NewVersion].Tag).ToList();
|
||||
|
||||
// Path install actions
|
||||
foreach (var update in updates)
|
||||
{
|
||||
var sourceTag = update.AvailableVersions[update.NewVersion].Key;
|
||||
var sourceTag = update.AvailableVersions[update.NewVersion].Tag;
|
||||
if (api.Model.CurrentGridRows?.FirstOrDefault(n => n.Action == update.Origin) is { } row)
|
||||
row.SourceTag = sourceTag;
|
||||
else
|
||||
|
||||
@@ -1,18 +1,30 @@
|
||||
using System.ComponentModel;
|
||||
using ModpackUpdater.Manager;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models.UpdatesCollectorViewMode;
|
||||
|
||||
public record ModUpdateInfo(KeyValuePair<string, string>[] AvailableVersions, InstallAction Origin) : INotifyPropertyChanged
|
||||
public record ModUpdateInfo(ModVersionInfo[] AvailableVersions, InstallAction Origin) : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public int NewVersion { get; set; }
|
||||
public bool Visible { get; set; } = true;
|
||||
|
||||
public string? OldVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (AvailableVersions.FirstOrDefault(n => n.Tag.Equals(Origin.SourceTag)) is { } old
|
||||
&& !old.Name.Equals(old.Tag, StringComparison.InvariantCulture))
|
||||
return $"{old.Name} ({old.Tag})";
|
||||
return Origin.SourceTag;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> DisplayVersions { get; } = AvailableVersions.Select(n =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(n.Value) || n.Value.Equals(n.Key, StringComparison.InvariantCulture))
|
||||
return n.Key;
|
||||
return $"{n.Value} ({n.Value})";
|
||||
if (string.IsNullOrWhiteSpace(n.Tag) || n.Tag.Equals(n.Name, StringComparison.InvariantCulture))
|
||||
return n.Name;
|
||||
return $"{n.Name} ({n.Tag})";
|
||||
});
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Origin.SourceTag}"/>
|
||||
Text="{Binding OldVersion}"/>
|
||||
|
||||
<!-- ComboBox: Version (new) -->
|
||||
<ComboBox
|
||||
|
||||
@@ -33,7 +33,7 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase
|
||||
|
||||
Model.Progress.Increment();
|
||||
|
||||
if (updates == null || updates.Length == 0 || updates[0].Value == action.SourceTag)
|
||||
if (updates == null || updates.Length == 0 || updates[0].Tag == action.SourceTag)
|
||||
continue;
|
||||
|
||||
Model.Updates.Add(new(updates, action));
|
||||
|
||||
3
ModpackUpdater.Manager/ModVersionInfo.cs
Normal file
3
ModpackUpdater.Manager/ModVersionInfo.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace ModpackUpdater.Manager;
|
||||
|
||||
public record ModVersionInfo(string Name, string Tag);
|
||||
@@ -1,7 +1,8 @@
|
||||
using CurseForge.APIClient.Models.Mods;
|
||||
using System.Text.RegularExpressions;
|
||||
using CurseForge.APIClient.Models.Mods;
|
||||
using Modrinth;
|
||||
using Octokit;
|
||||
using System.Text.RegularExpressions;
|
||||
using ApiClient = CurseForge.APIClient.ApiClient;
|
||||
|
||||
namespace ModpackUpdater.Manager;
|
||||
|
||||
@@ -11,7 +12,7 @@ public class ModpackFactory
|
||||
{
|
||||
Credentials = new Credentials("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"),
|
||||
};
|
||||
private readonly CurseForge.APIClient.ApiClient curseForge = new("$2a$10$pE4dD09gmr7IcOe8hjWhleWWjXopJcDNpq1P9FlrDMCBw05pCyAXa", "pilzinsel64@gmx.de");
|
||||
private readonly ApiClient curseForge = new("$2a$10$pE4dD09gmr7IcOe8hjWhleWWjXopJcDNpq1P9FlrDMCBw05pCyAXa", "pilzinsel64@gmx.de");
|
||||
private readonly ModrinthClient modrinth = new(new ModrinthClientConfig
|
||||
{
|
||||
ModrinthToken = "mrp_zUlDSET5actMUdTU3FK242TXgvlWgaErSSEFuegNG7thLgkC50IiK2NCGOzW",
|
||||
@@ -26,37 +27,41 @@ public class ModpackFactory
|
||||
|
||||
public async Task<string> ResolveSourceUrl(InstallAction action, Version? targetVersion = null, string? overwriteVersion = null)
|
||||
{
|
||||
if (action.SourceType == SourceType.GitHub)
|
||||
switch (action.SourceType)
|
||||
{
|
||||
case SourceType.GitHub:
|
||||
{
|
||||
var repo = await github.Repository.Get(action.SourceOwner, action.SourceName);
|
||||
var release = await github.Repository.Release.Get(repo.Id, action.SourceTag);
|
||||
var assets = await github.Repository.Release.GetAllAssets(repo.Id, release.Id);
|
||||
|
||||
if (assets.LastOrDefault(asset => Regex.IsMatch(asset.Name, action.SourceRegex)) is ReleaseAsset asset)
|
||||
if (assets.LastOrDefault(a => Regex.IsMatch(a.Name, action.SourceRegex)) is ReleaseAsset asset)
|
||||
return asset.BrowserDownloadUrl;
|
||||
break;
|
||||
}
|
||||
else if (action.SourceType == SourceType.GitLab)
|
||||
{
|
||||
throw new NotImplementedException("To be implemented soon.");
|
||||
}
|
||||
else if (action.SourceType == SourceType.CurseForge)
|
||||
case SourceType.GitLab:
|
||||
throw new NotSupportedException("To be implemented soon.");
|
||||
case SourceType.CurseForge:
|
||||
{
|
||||
var res = await curseForge.GetModFileDownloadUrlAsync(Convert.ToInt32(action.SourceName), Convert.ToInt32(action.SourceTag));
|
||||
if (!string.IsNullOrWhiteSpace(res.Data))
|
||||
return res.Data;
|
||||
break;
|
||||
}
|
||||
else if (action.SourceType == SourceType.Modrinth)
|
||||
case SourceType.Modrinth:
|
||||
{
|
||||
var res = await modrinth.VersionFile.GetVersionByHashAsync(action.SourceTag);
|
||||
var file = res.Files.Length == 1 ? res.Files[0] : res.Files.FirstOrDefault(n => Regex.IsMatch(n.FileName, action.SourceRegex));
|
||||
if (file != null)
|
||||
return file.Url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return action.GetSourceUrl(targetVersion, overwriteVersion: overwriteVersion);
|
||||
}
|
||||
|
||||
public async Task<KeyValuePair<string, string>[]?> FindUpdates(InstallAction action, string? gameVersion, ModLoader modLoader)
|
||||
public async Task<ModVersionInfo[]?> FindUpdates(InstallAction action, string? gameVersion, ModLoader modLoader)
|
||||
{
|
||||
switch (action.SourceType)
|
||||
{
|
||||
@@ -65,7 +70,7 @@ public class ModpackFactory
|
||||
{
|
||||
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.TagName, r.Name ?? r.TagName)).ToArray();
|
||||
return releases.Select(r => new ModVersionInfo(r.TagName, r.Name ?? r.TagName)).ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -73,18 +78,18 @@ public class ModpackFactory
|
||||
}
|
||||
break;
|
||||
case SourceType.GitLab:
|
||||
throw new NotImplementedException("To be implemented soon.");
|
||||
throw new NotSupportedException("To be implemented soon.");
|
||||
case SourceType.CurseForge:
|
||||
{
|
||||
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();
|
||||
return res.Data.Select(n => new ModVersionInfo(n.DisplayName, n.Id.ToString())).ToArray();
|
||||
break;
|
||||
}
|
||||
case SourceType.Modrinth:
|
||||
{
|
||||
var res = await modrinth.Version.GetProjectVersionListAsync(action.SourceName, gameVersions: GetGameVersionForModrinth(gameVersion), loaders: GetModLoaderForModrinth(modLoader));
|
||||
return res.Select(v => new KeyValuePair<string, string>($"{v.VersionNumber} {v.ProjectVersionType} {v.Name}", v.Id)).ToArray();
|
||||
return res.Select(v => new ModVersionInfo(v.VersionNumber, v.Id)).ToArray();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -116,7 +121,7 @@ public class ModpackFactory
|
||||
ModLoader.LiteLoader => ["liteloader"],
|
||||
ModLoader.Cauldron => ["cauldron"],
|
||||
ModLoader.Quilt => ["quilt"],
|
||||
_ => null,
|
||||
_ => [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user