complete
This commit is contained in:
@@ -8,4 +8,5 @@ public interface IMainApi
|
||||
{
|
||||
Window MainWindow { get; }
|
||||
MainWindowViewModel Model { get; }
|
||||
bool HasClosed { get; }
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ internal class ClearDirectLinkFeature : PluginFunction, IPluginFeatureProvider<C
|
||||
protected override Task<object?> ExecuteFunctionAsync(PluginFunctionParameter? @params)
|
||||
{
|
||||
if (@params is MainApiParameters p && p.Api.Model.SelectedGridRow is { } row)
|
||||
SharedFunctions.ClearDirectLinks(row);
|
||||
SharedFunctions.ClearDirectLinks(p.Api, row);
|
||||
return Task.FromResult<object?>(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ internal class UpdateDirectLinkFeature : PluginFunction, IPluginFeatureProvider<
|
||||
if (@params is not MainApiParameters p || p.Api.Model.SelectedGridRow is not MainWindowGridRow row)
|
||||
return null;
|
||||
|
||||
await SharedFunctions.FindNewDirectLinks(row);
|
||||
await SharedFunctions.FindNewDirectLinks(p.Api, row);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using Avalonia.Media;
|
||||
using ModpackUpdater.Apps.Manager.Api.Model;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Ui;
|
||||
@@ -14,16 +15,26 @@ namespace ModpackUpdater.Apps.Manager.Features;
|
||||
|
||||
internal static class SharedFunctions
|
||||
{
|
||||
public static async Task<bool> CheckActionHealthy(IMainApi api, params MainWindowGridRow[] rows)
|
||||
private static readonly IImage? imageSourceSuccess = AppGlobals.Symbols.GetImageSource(AppSymbols.done);
|
||||
private static readonly IImage? imageSourceWorking = AppGlobals.Symbols.GetImageSource(AppSymbols.hourglass);
|
||||
private static readonly IImage? imageSourceFailed = AppGlobals.Symbols.GetImageSource(AppSymbols.close);
|
||||
|
||||
public static async Task CheckActionHealthy(IMainApi api, params MainWindowGridRow[] rows)
|
||||
{
|
||||
var rowsCount = rows.Length;
|
||||
var failed = false;
|
||||
var msg = default(string);
|
||||
var factory = new ModpackFactory();
|
||||
|
||||
for (var i = 0; i < rows.Length; i++)
|
||||
api.Model.Progress.Value = 0;
|
||||
api.Model.Progress.MaxValue = rowsCount;
|
||||
api.Model.Progress.Visible = true;
|
||||
|
||||
for (var i = 0; i < rowsCount; i++)
|
||||
{
|
||||
var row = rows[i];
|
||||
if (row.SourceType == SourceType.DirectLink)
|
||||
continue;
|
||||
row.StateImage = imageSourceWorking;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -32,18 +43,17 @@ internal static class SharedFunctions
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
// Ignore
|
||||
}
|
||||
|
||||
row.IsValid = !failed;
|
||||
if (api.HasClosed)
|
||||
return;
|
||||
|
||||
// rwb.Text = $"{i} / {rowsCount}";
|
||||
row.StateImage = failed ? imageSourceFailed : imageSourceSuccess;
|
||||
api.Model.Progress.Value = i;
|
||||
}
|
||||
|
||||
if (rowsCount == 1 && failed && !string.IsNullOrWhiteSpace(msg))
|
||||
_ = MessageBoxManager.GetMessageBoxStandard(string.Empty, msg).ShowAsPopupAsync(api.MainWindow);
|
||||
|
||||
return true;
|
||||
api.Model.Progress.Visible = false;
|
||||
}
|
||||
|
||||
public static async Task<bool> CollectUpdates(IMainApi api, params InstallAction[] actions)
|
||||
@@ -53,7 +63,7 @@ internal static class SharedFunctions
|
||||
|
||||
// Collect updates
|
||||
var result = await AvaloniaFlyoutBase.Show(new UpdatesCollectorView(api.Model.CurrentWorkspace, actions), api.MainWindow);
|
||||
if (result.Result is not ModUpdates resultUpdates)
|
||||
if (api.HasClosed || result.Result is not ModUpdates resultUpdates)
|
||||
return false;
|
||||
|
||||
// Collect versions with changes
|
||||
@@ -86,33 +96,55 @@ internal static class SharedFunctions
|
||||
return true;
|
||||
}
|
||||
|
||||
public static async Task FindNewDirectLinks(params MainWindowGridRow[] rows)
|
||||
public static async Task FindNewDirectLinks(IMainApi api, params MainWindowGridRow[] rows)
|
||||
{
|
||||
var factory = new ModpackFactory();
|
||||
|
||||
foreach (var row in rows)
|
||||
api.Model.Progress.Value = 0;
|
||||
api.Model.Progress.MaxValue = rows.Length;
|
||||
api.Model.Progress.Visible = true;
|
||||
|
||||
for (var i = 0; i < rows.Length; i++)
|
||||
{
|
||||
var row = rows[i];
|
||||
if (row.SourceType == SourceType.DirectLink)
|
||||
continue;
|
||||
row.StateImage = imageSourceWorking;
|
||||
|
||||
try
|
||||
{
|
||||
row.SourceUrl = await factory.ResolveSourceUrl(row.Action);
|
||||
row.StateImage = imageSourceSuccess;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Fail silently
|
||||
}
|
||||
}
|
||||
row.StateImage = imageSourceFailed;
|
||||
}
|
||||
|
||||
public static void ClearDirectLinks(params MainWindowGridRow[] rows)
|
||||
if (api.HasClosed)
|
||||
return;
|
||||
api.Model.Progress.Value = i;
|
||||
}
|
||||
|
||||
api.Model.Progress.Visible = false;
|
||||
}
|
||||
|
||||
public static void ClearDirectLinks(IMainApi api, params MainWindowGridRow[] rows)
|
||||
{
|
||||
foreach (var row in rows)
|
||||
api.Model.Progress.Value = 0;
|
||||
api.Model.Progress.MaxValue = rows.Length;
|
||||
api.Model.Progress.Visible = true;
|
||||
|
||||
for (var i = 0; i < rows.Length; i++)
|
||||
{
|
||||
var row = rows[i];
|
||||
if (row.SourceType != SourceType.DirectLink)
|
||||
row.SourceUrl = null;
|
||||
row.StateImage = null;
|
||||
api.Model.Progress.Value = i;
|
||||
}
|
||||
|
||||
api.Model.Progress.Visible = false;
|
||||
}
|
||||
|
||||
public static string GenerateChangelog(InstallInfos installInfos, UpdateInfo updateInfos)
|
||||
|
||||
@@ -18,7 +18,7 @@ internal class ClearDirectLinksFeature : PluginFunction, IPluginFeatureProvider<
|
||||
protected override Task<object?> ExecuteFunctionAsync(PluginFunctionParameter? @params)
|
||||
{
|
||||
if (@params is MainApiParameters p && p.Api.Model.CurrentGridRows is not null)
|
||||
SharedFunctions.ClearDirectLinks([.. p.Api.Model.CurrentGridRows]);
|
||||
SharedFunctions.ClearDirectLinks(p.Api, [.. p.Api.Model.CurrentGridRows]);
|
||||
return Task.FromResult<object?>(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ internal class UpdateDirectLinksFeature : PluginFunction, IPluginFeatureProvider
|
||||
if (@params is not MainApiParameters p || p.Api.Model.CurrentGridRows is null)
|
||||
return null;
|
||||
|
||||
await SharedFunctions.FindNewDirectLinks([.. p.Api.Model.CurrentGridRows]);
|
||||
await SharedFunctions.FindNewDirectLinks(p.Api, [.. p.Api.Model.CurrentGridRows]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -195,6 +195,12 @@ namespace ModpackUpdater.Apps.Manager.LangRes {
|
||||
}
|
||||
}
|
||||
|
||||
public static string State {
|
||||
get {
|
||||
return ResourceManager.GetString("State", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
public static string InheritFrom {
|
||||
get {
|
||||
return ResourceManager.GetString("InheritFrom", resourceCulture);
|
||||
|
||||
@@ -192,6 +192,9 @@
|
||||
<data name="DestinationPath" xml:space="preserve">
|
||||
<value>Destination path</value>
|
||||
</data>
|
||||
<data name="State" xml:space="preserve">
|
||||
<value>State</value>
|
||||
</data>
|
||||
<data name="InheritFrom" xml:space="preserve">
|
||||
<value>Inherit from</value>
|
||||
</data>
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
x:DataType="mainWindow:MainWindowViewModel"
|
||||
Title="Minecraft Modpack Manager"
|
||||
WindowState="Maximized"
|
||||
Loaded="Window_OnLoaded">
|
||||
Loaded="Window_OnLoaded"
|
||||
Closed="Window_OnClosed">
|
||||
|
||||
<Grid
|
||||
x:Name="GridMain"
|
||||
@@ -100,9 +101,15 @@
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- Panel: List header -->
|
||||
<ContentControl
|
||||
<StackPanel
|
||||
Grid.Column="1"
|
||||
Grid.Row="0"
|
||||
Spacing="6"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center">
|
||||
|
||||
<!-- Panel: Menu -->
|
||||
<ContentControl
|
||||
Content="{Binding SelectedTreeNode}">
|
||||
|
||||
<ContentControl.DataTemplates>
|
||||
@@ -147,6 +154,28 @@
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
|
||||
<!-- Progress -->
|
||||
<Panel
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
IsVisible="{Binding Progress.Visible}">
|
||||
|
||||
<!-- ProgressBar: Status -->
|
||||
<ProgressBar
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Maximum="{Binding Progress.MaxValue}"
|
||||
Value="{Binding Progress.Value}"/>
|
||||
|
||||
<!-- TextBox: Status -->
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
TextAlignment="Center"
|
||||
Text="{Binding Progress.Text}"/>
|
||||
</Panel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- DataGrid -->
|
||||
<DataGrid
|
||||
Grid.Column="1"
|
||||
@@ -177,6 +206,18 @@
|
||||
<DataGridTextColumn
|
||||
Header="{x:Static langRes:GeneralLangRes.DestinationPath}"
|
||||
Binding="{Binding InheritedDestPath}"/>
|
||||
|
||||
<DataGridTemplateColumn
|
||||
Header="{x:Static langRes:GeneralLangRes.State}">
|
||||
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Image
|
||||
Width="{x:Static symbols:SymbolGlobals.DefaultImageSmallSize}"
|
||||
Source="{Binding StateImage}"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using ModpackUpdater.Apps.Manager.Api;
|
||||
@@ -22,6 +23,7 @@ public partial class MainWindow : Window, IMainApi
|
||||
public MainWindowViewModel Model { get; } = new();
|
||||
Window IMainApi.MainWindow => this;
|
||||
public IMainApi MainApi => this;
|
||||
public bool HasClosed { get; private set; }
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
@@ -110,6 +112,11 @@ public partial class MainWindow : Window, IMainApi
|
||||
LoadRecentWorkspaces();
|
||||
}
|
||||
|
||||
private void Window_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
HasClosed = true;
|
||||
}
|
||||
|
||||
private async void MenuItemNewWorkspaceItem_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not MenuItem item || item.Tag is not WorkspaceFeature feature)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using Avalonia.Media;
|
||||
using ModpackUpdater.Apps.Manager.LangRes;
|
||||
using ModpackUpdater.Apps.Manager.Utils;
|
||||
using PropertyChanged;
|
||||
@@ -18,7 +19,7 @@ public class MainWindowGridRow(InstallAction action, IActionSet baseActions) : I
|
||||
private InstallAction Inherited => Base ?? action;
|
||||
|
||||
public bool IsUpdate => action is UpdateAction;
|
||||
public bool? IsValid { get; set; } = null;
|
||||
public IImage? StateImage { get; set; }
|
||||
|
||||
[DependsOn(nameof(Id), nameof(InheritFrom))]
|
||||
public string? InheritedId => action is UpdateAction ua && !string.IsNullOrWhiteSpace(ua.InheritFrom) ? ua.InheritFrom : action.Id;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class MainWindowViewModel : INotifyPropertyChanged
|
||||
private IWorkspace? currentWorkspace;
|
||||
|
||||
public bool IsUpdate => selectedTreeNode is ActionSetTreeNode node && node.Infos is UpdateInfo;
|
||||
|
||||
public ProgressInfos Progress { get; } = new();
|
||||
public MainWindowGridRow? SelectedGridRow { get; set; }
|
||||
|
||||
[AlsoNotifyFor(nameof(CurrentTreeNodes))]
|
||||
|
||||
15
ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs
Normal file
15
ModpackUpdater.Apps.Manager/Ui/Models/ProgressInfos.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.ComponentModel;
|
||||
using PropertyChanged;
|
||||
|
||||
namespace ModpackUpdater.Apps.Manager.Ui.Models;
|
||||
|
||||
public class ProgressInfos : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public bool Visible { get; set; }
|
||||
public double MaxValue { get; set; }
|
||||
public double Value { get; set; }
|
||||
[DependsOn(nameof(Value), nameof(MaxValue))]
|
||||
public string? Text => $"{Math.Round(Value / MaxValue * 100)}%";
|
||||
}
|
||||
@@ -8,11 +8,7 @@ public class UpdatesCollectorViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public bool ProgressVisible { get; set; }
|
||||
public double ProgressMaxValue { get; set; }
|
||||
public double ProgressValue { get; set; }
|
||||
[DependsOn(nameof(ProgressValue), nameof(ProgressMaxValue))]
|
||||
public string? ProgressText => $"{Math.Round(ProgressValue / ProgressMaxValue * 100)}%";
|
||||
public ProgressInfos Progress { get; } = new();
|
||||
public string? SearchText { get; set; }
|
||||
public ObservableCollection<ModUpdateInfo> Updates { get; } = [];
|
||||
}
|
||||
@@ -85,20 +85,20 @@
|
||||
<Panel
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
IsVisible="{Binding ProgressVisible}">
|
||||
IsVisible="{Binding Progress.Visible}">
|
||||
|
||||
<!-- ProgressBar: Status -->
|
||||
<ProgressBar
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Maximum="{Binding ProgressMaxValue}"
|
||||
Value="{Binding ProgressValue}"/>
|
||||
Maximum="{Binding Progress.MaxValue}"
|
||||
Value="{Binding Progress.Value}"/>
|
||||
|
||||
<!-- TextBox: Status -->
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding ProgressText}"/>
|
||||
Text="{Binding Progress.Text}"/>
|
||||
</Panel>
|
||||
</dialogs:AvaloniaFlyoutBase.FooterContent>
|
||||
</dialogs:AvaloniaFlyoutBase>
|
||||
@@ -25,14 +25,15 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase
|
||||
|
||||
private async Task FindUpdates()
|
||||
{
|
||||
Model.ProgressVisible = true;
|
||||
Model.ProgressMaxValue = actions.Length;
|
||||
Model.Progress.Value = 0;
|
||||
Model.Progress.MaxValue = actions.Length;
|
||||
Model.Progress.Visible = true;
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
var updates = await factory.FindUpdates(action, workspace.ModpackConfig?.MinecraftVersion, workspace.ModpackConfig?.ModLoader ?? ModLoader.Any);
|
||||
|
||||
Model.ProgressValue += 1;
|
||||
Model.Progress.Value += 1;
|
||||
|
||||
if (updates == null || updates.Length == 0 || updates[0].Value == action.SourceTag)
|
||||
continue;
|
||||
@@ -43,7 +44,7 @@ public partial class UpdatesCollectorView : AvaloniaFlyoutBase
|
||||
break;
|
||||
}
|
||||
|
||||
Model.ProgressVisible = false;
|
||||
Model.Progress.Visible = false;
|
||||
}
|
||||
|
||||
protected override object GetResult()
|
||||
|
||||
@@ -41,4 +41,5 @@ public enum AppSymbols
|
||||
input,
|
||||
output,
|
||||
git,
|
||||
hourglass,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user