flesh out the data scan UI, tweak selection table

This commit is contained in:
Alex
2025-08-19 00:27:53 -07:00
parent f4a091dfa4
commit 09de9cc0a7
11 changed files with 237 additions and 130 deletions
-95
View File
@@ -1,95 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using MercuryConverter.Data;
using UAssetAPI;
using UAssetAPI.UnrealTypes;
namespace MercuryConverter.UI.Dialogs;
public partial class DataOpen : UserControl
{
public static DataOpen? Instance { get; private set; }
public DataOpen()
{
Instance = this;
InitializeComponent();
if (!Design.IsDesignMode)
Run();
}
public void Run()
{
Task.Run(async () =>
{
var path = ""; // TODO: set to current data path
// Content selection
while (true)
{
var selectedPath = await BeginDirSelection();
Console.WriteLine($"selectedPath={selectedPath}");
if (selectedPath != "" && Directory.Exists(selectedPath))
{
path = selectedPath;
break;
}
// Display error message
}
BeginDataScan(path);
});
}
private async Task<string> BeginDirSelection()
{
IReadOnlyList<IStorageFolder>? dirSelection = null;
await Dispatcher.UIThread.Invoke(async () =>
{
// Update UI
ScanView.IsVisible = false;
SelectView.IsVisible = true;
await Task.Delay(200);
dirSelection = await TopLevel.GetTopLevel(MainWindow.Instance)!.StorageProvider.OpenFolderPickerAsync
(
new FolderPickerOpenOptions
{
Title = "Locate Data Folder",
AllowMultiple = false,
}
);
});
if (dirSelection!.Count <= 0)
{
return "";
}
return dirSelection!.First().TryGetLocalPath()!;
}
private void BeginDataScan(string dataPath)
{
Console.WriteLine(dataPath);
// Update UI
Dispatcher.UIThread.Invoke(() =>
{
SelectView.IsVisible = false;
ScanStatus.Text = "scanning...";
ScanPath.Text = dataPath;
ScanView.IsVisible = true;
});
Database.SetupNew(dataPath);
}
}
@@ -4,33 +4,39 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MercuryConverter.UI.Dialogs"
xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
x:Class="MercuryConverter.UI.Dialogs.DataOpen"
x:Class="MercuryConverter.UI.Dialogs.DataScanning"
>
<Panel Margin="12">
<StackPanel Name="SelectView" IsVisible="false">
<TextBlock FontSize="24" FontWeight="Light" Text="select your data folder..."/>
<progRing:ProgressRing Foreground="{DynamicResource SystemBaseMediumColor}"
Width="36"
Height="36"
IsActive="True"
HorizontalAlignment="Center"
Margin="0,15,0,0"/>
</StackPanel>
<StackPanel Name="ScanView" IsVisible="true">
<TextBlock Name="ScanStatus" FontSize="24" FontWeight="Light" Text="scanning..."/>
<TextBlock Name="ScanPath" Text="/there/is/a/path/here or whatever it is askljdhflksahdfliuahleifhu"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<StackPanel>
<TextBlock Name="ScanStatus" FontSize="24" FontWeight="Light" Text="select your data folder..."/>
<TextBlock Name="ScanPath" Text="/there/is/a/path/here" IsVisible="false"/>
<StackPanel Margin="0 6 0 0" Name="ScanError" IsVisible="False">
<TextBlock>
<Run FontWeight="DemiBold" Text="ERROR" Foreground="Red"/>
<LineBreak/>
<Run Name="ErrorText" Text="Data pooped its pants"/>
</TextBlock>
</StackPanel>
<StackPanel Name="ScanInfo">
</StackPanel>
<Grid ColumnDefinitions="Auto, *" HorizontalAlignment="Stretch">
<progRing:ProgressRing Foreground="{DynamicResource SystemBaseMediumColor}"
Name="ProgressAnimation"
Grid.Column="0"
Width="36"
Height="36"
IsActive="True"
HorizontalAlignment="Left"
Margin="0,15,0,0"/>
<StackPanel Margin="0 12 0 0" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Margin="6 0 0 0" Content="Cancel" />
<Button Margin="6 0 0 0" Content="Open Data Folder" />
<StackPanel Margin="0 12 0 0" Name="ButtonGroup" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right" IsVisible="false">
<Button Name="BtnClose" Margin="6 0 0 0" Content="Close" Click="CloseHandler"/>
<Button Name="BtnSelectFolder" Margin="6 0 0 0" Content="Open Data Folder" Click="OpenDataHandler"/>
</StackPanel>
</StackPanel>
</Grid>
</StackPanel>
<!-- <StackPanel Name="SelectErrorView" IsVisible="true">
<TextBlock FontSize="24" FontWeight="Light" Text="couldn't fully open data folder"/>
+170
View File
@@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using MercuryConverter.Data;
using UAssetAPI;
using UAssetAPI.UnrealTypes;
namespace MercuryConverter.UI.Dialogs;
public partial class DataScanning : UserControl
{
public static DataScanning? Instance { get; private set; }
public DataScanning()
{
Instance = this;
InitializeComponent();
ScanPath.Text = "";
if (!Design.IsDesignMode)
RunFlow();
}
public void RunFlow()
{
Task.Run(async () =>
{
var path = ""; // TODO: set to current/saved data path
// Content selection
var selectedPath = await BeginDirSelection();
Console.WriteLine($"selectedPath=[{selectedPath}]");
if (selectedPath == "") // cancelled opening folder
{
// TODO:
// return and go to completed mode if scan already completed
// continue if no scan has been completed
// break if we already have a path but somehow not scanned
UISetError("No data folder provided.");
return;
}
if (!Directory.Exists(selectedPath))
{
UISetError("Folder does not exist.");
return;
}
if (!(File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uasset")) && File.Exists(Path.Combine(selectedPath, "MusicParameterTable.uexp"))))
{
UISetError("Missing MusicParameterTable asset files. Without them, we have nothing to work with.");
return;
}
path = selectedPath;
UIScanningMode(path);
Database.SetupNew(path);
UIScanCompletedMode();
});
}
private void UISelectMode()
{
UISetError();
Dispatcher.UIThread.Post(() =>
{
ScanStatus.Text = "select your data folder...";
ScanPath.IsVisible = false;
ButtonGroup.IsVisible = false;
ProgressAnimation.IsVisible = true;
});
}
private void UIScanningMode(string path)
{
UISetError();
Dispatcher.UIThread.Post(() =>
{
ScanStatus.Text = "scanning...";
ScanPath.IsVisible = true;
ScanPath.Text = path;
ScanInfo.IsVisible = true;
ButtonGroup.IsVisible = false;
ProgressAnimation.IsVisible = true;
});
}
private void UIScanCompletedMode()
{
Dispatcher.UIThread.Post(() =>
{
ScanStatus.Text = "scan complete";
ScanPath.IsVisible = true;
ScanInfo.IsVisible = true;
ButtonGroup.IsVisible = true;
ProgressAnimation.IsVisible = false;
});
}
/// <summary>
/// Use only when no other processes are running.
/// </summary>
/// <param name="error"></param>
private void UISetError(string? error = null)
{
Dispatcher.UIThread.Post(() =>
{
if (error == null)
{
ScanError.IsVisible = false;
return;
}
ScanError.IsVisible = true;
ErrorText.Text = error;
ProgressAnimation.IsVisible = false;
ButtonGroup.IsVisible = true;
ScanStatus.Text = "an error has occurred";
});
}
private async Task<string> BeginDirSelection(string? startDir = null)
{
IReadOnlyList<IStorageFolder>? dirSelection = null;
UISelectMode();
await Dispatcher.UIThread.Invoke(async () =>
{
await Task.Delay(250);
var tl = TopLevel.GetTopLevel(MainWindow.Instance)!;
dirSelection = await tl.StorageProvider.OpenFolderPickerAsync
(
new FolderPickerOpenOptions
{
Title = "Locate Data Folder",
AllowMultiple = false,
SuggestedStartLocation = startDir == null ? null : await tl.StorageProvider.TryGetFolderFromPathAsync(startDir),
}
);
});
if (dirSelection!.Count <= 0)
{
return "";
}
return dirSelection!.First().TryGetLocalPath()!;
}
private void CloseHandler(object sender, RoutedEventArgs args)
{
Dispatcher.UIThread.Post(() =>
{
MainWindow.Instance!.Dialog.IsOpen = false;
});
}
private void OpenDataHandler(object sender, RoutedEventArgs args)
{
RunFlow();
}
}
+1 -1
View File
@@ -14,6 +14,6 @@ public partial class Welcome : Window
private void ClickHandler(object sender, RoutedEventArgs args)
{
MainWindow.Instance!.Dialog.DialogContent = new DataOpen().Content;
MainWindow.Instance!.Dialog.DialogContent = new DataScanning().Content;
}
}