mirror of
https://github.com/muskit/MercuryConverter.git
synced 2026-06-03 04:34:25 -07:00
flesh out the data scan UI, tweak selection table
This commit is contained in:
@@ -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"/>
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -30,8 +30,8 @@
|
||||
<DockPanel>
|
||||
|
||||
<Menu Name="MenuBar" DockPanel.Dock="Top">
|
||||
<MenuItem Header="File">
|
||||
<MenuItem Header="Open Data Folder..." />
|
||||
<MenuItem Header="_File">
|
||||
<MenuItem Name="DataFolderBtn" Header="_Open Data Folder..." Command="{Binding OpenDataHandler}" />
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
Instance = this;
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
|
||||
// Force dark mode in designer
|
||||
if (Design.IsDesignMode)
|
||||
@@ -39,4 +40,10 @@ public partial class MainWindow : Window
|
||||
Dialog.DialogContent = new Welcome().Content;
|
||||
Dialog.IsOpen = true;
|
||||
}
|
||||
|
||||
public void OpenDataHandler()
|
||||
{
|
||||
Dialog.IsOpen = true;
|
||||
Dialog.DialogContent = new DataScanning().Content;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,6 @@
|
||||
<!-- Song Listing Table -->
|
||||
<DockPanel>
|
||||
<DockPanel Margin="0 4 0 8" DockPanel.Dock="Top">
|
||||
<!-- <ComboBox DockPanel.Dock="Right" Width="160" PlaceholderText="Source filter" Name="SourceFilter"/> -->
|
||||
<TextBox Watermark="Search for title, artist, designer..."/>
|
||||
</DockPanel>
|
||||
<UserControl Background="{DynamicResource DataGridContentBackground}">
|
||||
@@ -48,7 +47,7 @@
|
||||
<DataGridTextColumn Header="ID" Width="90" Binding="{Binding Id}"/>
|
||||
<DataGridTextColumn Header="Title" Width="*" Binding="{Binding Name}"/>
|
||||
<DataGridTextColumn Header="Artist" Width="*" Binding="{Binding Artist}"/>
|
||||
<DataGridTextColumn Header="Source" Width="150" Binding="{Binding SourceName}"/>
|
||||
<DataGridTextColumn Header="Source" Width="150" Binding="{Binding SourceName}" SortMemberPath="Source"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</UserControl>
|
||||
|
||||
Reference in New Issue
Block a user