fix: open folder pickers at current paths

This commit is contained in:
2026-07-27 01:25:09 +09:00
parent ee82f0be42
commit 8cad072cf0
3 changed files with 273 additions and 24 deletions

View File

@@ -2,8 +2,6 @@ using MBN_STOCK_WEBVIEW.Infrastructure;
using MBN_STOCK_WEBVIEW.LegacyApplication;
using MBN_STOCK_WEBVIEW.LegacyBridge;
using MMoneyCoderSharp.Data;
using Windows.Storage.Pickers;
using WinRT.Interop;
namespace MBN_STOCK_WEBVIEW.LegacyParityApp;
@@ -85,18 +83,11 @@ public sealed partial class MainWindow
cancellationToken.ThrowIfCancellationRequested();
try
{
var picker = new FolderPicker
{
SuggestedStartLocation = PickerLocationId.ComputerFolder,
ViewMode = PickerViewMode.List
};
picker.FileTypeFilter.Add("*");
var owner = _windowHandle != 0
? _windowHandle
: WindowNative.GetWindowHandle(this);
InitializeWithWindow.Initialize(picker, owner);
var selected = await picker.PickSingleFolderAsync();
if (selected is null)
var initialDirectory = ResolveOperatorFolderPickerStartDirectory(kind);
var selectedPath = await PickOperatorFolderAsync(
initialDirectory,
ResolveOperatorFolderPickerTitle(kind));
if (selectedPath is null)
{
return;
}
@@ -105,7 +96,7 @@ public sealed partial class MainWindow
var validationKind = ToSettingsFolderKind(kind);
if (!LegacyOperatorFolderValidator.TryValidate(
validationKind,
selected.Path,
selectedPath,
out var validated,
out var warningMessage) ||
validated is null)
@@ -156,6 +147,81 @@ public sealed partial class MainWindow
}
}
private string? ResolveOperatorFolderPickerStartDirectory(
LegacyOperatorFolderKind kind)
{
var preferredPath = kind switch
{
LegacyOperatorFolderKind.Design =>
_operatorSettings.SceneDirectory ??
Path.Combine(AppContext.BaseDirectory, "Cuts"),
LegacyOperatorFolderKind.Resource =>
_operatorSettings.ResourceDirectory ??
Path.Combine(AppContext.BaseDirectory, "Res"),
LegacyOperatorFolderKind.Background =>
_operatorSettings.BackgroundDirectory ??
ResolveAutomaticBackgroundDirectory(),
_ => throw new ArgumentOutOfRangeException(nameof(kind))
};
return FindNearestExistingDirectory(preferredPath) ??
FindNearestExistingDirectory(AppContext.BaseDirectory);
}
private string ResolveAutomaticBackgroundDirectory()
{
var sceneDirectory = _operatorSettings.SceneDirectory ??
Path.Combine(AppContext.BaseDirectory, "Cuts");
var canonicalSceneDirectory = Path.TrimEndingDirectorySeparator(
Path.GetFullPath(sceneDirectory));
var sceneParent = Path.GetDirectoryName(canonicalSceneDirectory);
return Path.Combine(
sceneParent ?? AppContext.BaseDirectory,
"배경");
}
private static string? FindNearestExistingDirectory(string? path)
{
if (string.IsNullOrWhiteSpace(path) ||
!Path.IsPathFullyQualified(path))
{
return null;
}
try
{
for (var candidate = new DirectoryInfo(Path.GetFullPath(path));
candidate is not null;
candidate = candidate.Parent)
{
if (candidate.Exists)
{
return candidate.FullName;
}
}
}
catch (Exception exception) when (
exception is ArgumentException or
IOException or
NotSupportedException or
System.Security.SecurityException or
UnauthorizedAccessException)
{
return null;
}
return null;
}
private static string ResolveOperatorFolderPickerTitle(
LegacyOperatorFolderKind kind) => kind switch
{
LegacyOperatorFolderKind.Design => "폴더 선택 - 디자인",
LegacyOperatorFolderKind.Resource => "폴더 선택 - 설정",
LegacyOperatorFolderKind.Background => "폴더 선택 - 배경",
_ => throw new ArgumentOutOfRangeException(nameof(kind))
};
private void ResetOperatorFolder(LegacyOperatorFolderKind kind)
{
var next = kind switch