Files
MercuryConverter/UI/Dialogs/DataOpen.axaml.cs
T

95 lines
2.3 KiB
C#
Raw Normal View History

2025-08-13 20:13:40 -07:00
using System;
using System.Collections.Generic;
using System.IO;
2025-08-13 20:13:40 -07:00
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;
2025-08-13 20:13:40 -07:00
namespace MercuryConverter.UI.Dialogs;
public partial class DataOpen : UserControl
2025-08-13 20:13:40 -07:00
{
public static DataOpen? Instance { get; private set; }
2025-08-13 20:13:40 -07:00
public DataOpen()
{
Instance = this;
2025-08-13 20:13:40 -07:00
InitializeComponent();
if (!Design.IsDesignMode)
Run();
2025-08-13 20:13:40 -07:00
}
public void Run()
2025-08-13 20:13:40 -07:00
{
Task.Run(async () =>
2025-08-13 20:13:40 -07:00
{
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;
2025-08-13 20:13:40 -07:00
await Task.Delay(200);
dirSelection = await TopLevel.GetTopLevel(MainWindow.Instance)!.StorageProvider.OpenFolderPickerAsync
2025-08-13 20:13:40 -07:00
(
new FolderPickerOpenOptions
{
Title = "Locate Data Folder",
2025-08-13 20:13:40 -07:00
AllowMultiple = false,
}
);
});
2025-08-13 20:13:40 -07:00
if (dirSelection!.Count <= 0)
{
return "";
}
return dirSelection!.First().TryGetLocalPath()!;
}
2025-08-13 20:13:40 -07:00
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;
2025-08-13 20:13:40 -07:00
});
Database.SetupNew(dataPath);
2025-08-13 20:13:40 -07:00
}
}