add data reading & selection table population

This commit is contained in:
Alex
2025-08-18 00:32:10 -07:00
parent 7c407a7a84
commit f4a091dfa4
10 changed files with 249 additions and 191 deletions
+68 -13
View File
@@ -1,40 +1,95 @@
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 : Window
public partial class DataOpen : UserControl
{
public static DataOpen? Instance { get; private set; }
public DataOpen()
{
Instance = this;
InitializeComponent();
BeginDirSelection();
if (!Design.IsDesignMode)
Run();
}
private void BeginDirSelection()
public void Run()
{
Dispatcher.UIThread.Invoke(async () =>
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);
var dirSelection = await GetTopLevel(this)!.StorageProvider.OpenFolderPickerAsync
dirSelection = await TopLevel.GetTopLevel(MainWindow.Instance)!.StorageProvider.OpenFolderPickerAsync
(
new FolderPickerOpenOptions
{
Title = "Open Data Folder",
Title = "Locate Data Folder",
AllowMultiple = false,
}
);
if (dirSelection.Count <= 0)
{
return;
}
var d = dirSelection!.First().TryGetLocalPath()!;
});
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);
}
}