2026-06-03 00:50:52 +08:00
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Input;
|
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
using Avalonia.Platform.Storage;
|
|
|
|
|
using LanDesktopPLONDS.Installer.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace LanDesktopPLONDS.Installer.Views;
|
|
|
|
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDataContextChanged(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnDataContextChanged(e);
|
|
|
|
|
if (DataContext is MainWindowViewModel viewModel)
|
|
|
|
|
{
|
|
|
|
|
viewModel.BrowseRequested = BrowseForFolderAsync;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<string?> BrowseForFolderAsync(string currentPath)
|
|
|
|
|
{
|
2026-06-03 12:32:56 +08:00
|
|
|
IStorageFolder? startFolder = null;
|
|
|
|
|
if (Directory.Exists(currentPath))
|
|
|
|
|
{
|
|
|
|
|
startFolder = await StorageProvider.TryGetFolderFromPathAsync(currentPath);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 00:50:52 +08:00
|
|
|
var result = await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
|
|
|
|
{
|
|
|
|
|
Title = "选择安装位置",
|
|
|
|
|
AllowMultiple = false,
|
|
|
|
|
SuggestedStartLocation = startFolder
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-03 12:32:56 +08:00
|
|
|
if (result.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var path = result[0].TryGetLocalPath();
|
|
|
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("请选择本机文件夹作为安装位置。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
2026-06-03 00:50:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnTitleBarPointerPressed(object? sender, PointerPressedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_ = sender;
|
2026-06-03 12:32:56 +08:00
|
|
|
if (e.Source is Button)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-03 00:50:52 +08:00
|
|
|
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
|
|
|
|
|
{
|
|
|
|
|
BeginMoveDrag(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMinimizeClick(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_ = sender;
|
|
|
|
|
_ = e;
|
|
|
|
|
WindowState = WindowState.Minimized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCloseClick(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_ = sender;
|
|
|
|
|
_ = e;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|