移除winforms引用

This commit is contained in:
ww-rm
2025-05-29 20:10:15 +08:00
parent fffe69c49f
commit 42cb782a96
18 changed files with 111 additions and 146 deletions

View File

@@ -1,18 +0,0 @@
using SpineViewer.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Services
{
public static class AboutDialogService
{
public static bool ShowAboutDialog()
{
var dialog = new AboutDialog() { Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
}
}

View File

@@ -1,18 +0,0 @@
using SpineViewer.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Services
{
public static class DiagnosticsDialogService
{
public static bool ShowDiagnosticsDialog()
{
var dialog = new DiagnosticsDialog() { Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
}
}

View File

@@ -0,0 +1,85 @@
using Microsoft.Win32;
using SpineViewer.ViewModels.Exporters;
using SpineViewer.Views;
using SpineViewer.Views.ExporterDialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Services
{
/// <summary>
/// 用于弹出各种对话框的服务
/// </summary>
public static class DialogService
{
public static bool ShowDiagnosticsDialog()
{
var dialog = new DiagnosticsDialog() { Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowAboutDialog()
{
var dialog = new AboutDialog() { Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowFrameExporterDialog(FrameExporterViewModel vm)
{
var dialog = new FrameExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowFrameSequenceExporterDialog(FrameSequenceExporterViewModel vm)
{
var dialog = new FrameSequenceExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowFFmpegVideoExporterDialog(FFmpegVideoExporterViewModel vm)
{
var dialog = new FFmpegVideoExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowCustomFFmpegExporterDialog(CustomFFmpegExporterViewModel vm)
{
var dialog = new CustomFFmpegExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
/// <summary>
/// 获取用户选择的文件夹
/// </summary>
/// <param name="folderName"></param>
/// <returns>是否确认了选择</returns>
public static bool ShowOpenFolderDialog(out string? folderName)
{
// XXX: 此处使用了 System.Windows.Forms 的文件夹浏览对话框
var folderDialog = new OpenFolderDialog() { Multiselect = false };
if (folderDialog.ShowDialog() is true)
{
folderName = folderDialog.FolderName;
return true;
}
folderName = null;
return false;
}
/// <summary>
/// 获取用户选择的文件夹
/// </summary>
/// <param name="selectedPath"></param>
/// <returns>是否确认了选择</returns>
public static bool ShowSaveFileDialog(out string? selectedPath)
{
var dialog = new SaveFileDialog() { };
selectedPath = null;
// TODO
return false;
}
}
}

View File

@@ -1,38 +0,0 @@
using SpineViewer.ViewModels.Exporters;
using SpineViewer.Views;
using SpineViewer.Views.ExporterDialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Services
{
public static class ExporterDialogService
{
public static bool ShowFrameExporterDialog(FrameExporterViewModel vm)
{
var dialog = new FrameExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowFrameSequenceExporterDialog(FrameSequenceExporterViewModel vm)
{
var dialog = new FrameSequenceExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowFFmpegVideoExporterDialog(FFmpegVideoExporterViewModel vm)
{
var dialog = new FFmpegVideoExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
public static bool ShowCustomFFmpegExporterDialog(CustomFFmpegExporterViewModel vm)
{
var dialog = new CustomFFmpegExporterDialog() { DataContext = vm, Owner = App.Current.MainWindow };
return dialog.ShowDialog() ?? false;
}
}
}

View File

@@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Services
{
public static class OpenFolderService
{
/// <summary>
/// 获取用户选择的文件夹
/// </summary>
/// <param name="selectedPath"></param>
/// <returns>是否确认了选择</returns>
public static bool OpenFolder(out string? selectedPath)
{
// XXX: 此处使用了 System.Windows.Forms 的文件夹浏览对话框
using var folderDialog = new System.Windows.Forms.FolderBrowserDialog();
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
selectedPath = folderDialog.SelectedPath;
return true;
}
selectedPath = null;
return false;
}
}
}

View File

@@ -1,25 +0,0 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Services
{
public static class SaveService
{
/// <summary>
/// 获取用户选择的文件夹
/// </summary>
/// <param name="selectedPath"></param>
/// <returns>是否确认了选择</returns>
public static bool SaveFile(out string? selectedPath)
{
var dialog = new SaveFileDialog() { };
selectedPath = null;
// TODO
return false;
}
}
}

View File

@@ -10,7 +10,6 @@
<Version>0.15.0</Version>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<PropertyGroup>
@@ -19,11 +18,6 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Using Remove="System.Windows.Forms" />
<Using Remove="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Content Include="appicon.ico" />
</ItemGroup>

View File

@@ -12,6 +12,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace SpineViewer.ViewModels
{
public class DiagnosticsDialogViewModel : ObservableObject
@@ -31,7 +32,20 @@ namespace SpineViewer.ViewModels
}
}
public string Memory => $"{new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / 1024f / 1024f / 1024f:F1} GB";
public string Memory
{
get
{
var searcher = new ManagementObjectSearcher("SELECT TotalPhysicalMemory FROM Win32_ComputerSystem");
foreach (ManagementObject obj in searcher.Get())
{
ulong bytes = (ulong)obj["TotalPhysicalMemory"];
float gb = bytes / 1024f / 1024f / 1024f;
return $"{gb:F1} GB";
}
return "N/A";
}
}
public string WindowsVersion
{

View File

@@ -50,7 +50,7 @@ namespace SpineViewer.ViewModels.Exporters
protected override void Export_Execute(IList? args)
{
if (args is null || args.Count <= 0) return;
if (!ExporterDialogService.ShowCustomFFmpegExporterDialog(this)) return;
if (!DialogService.ShowCustomFFmpegExporterDialog(this)) return;
SpineObject[] spines = args.Cast<SpineObjectModel>().Select(m => m.GetSpineObject()).ToArray();
ProgressService.RunAsync((pr, ct) => ExportTask(spines, pr, ct), AppResource.Str_CustomFFmpegExporterTitle);
foreach (var sp in spines) sp.Dispose();

View File

@@ -37,7 +37,7 @@ namespace SpineViewer.ViewModels.Exporters
protected override void Export_Execute(IList? args)
{
if (args is null || args.Count <= 0) return;
if (!ExporterDialogService.ShowFFmpegVideoExporterDialog(this)) return;
if (!DialogService.ShowFFmpegVideoExporterDialog(this)) return;
SpineObject[] spines = args.Cast<SpineObjectModel>().Select(m => m.GetSpineObject()).ToArray();
ProgressService.RunAsync((pr, ct) => ExportTask(spines, pr, ct), AppResource.Str_FFmpegVideoExporterTitle);
foreach (var sp in spines) sp.Dispose();

View File

@@ -41,7 +41,7 @@ namespace SpineViewer.ViewModels.Exporters
protected override void Export_Execute(IList? args)
{
if (args is null || args.Count <= 0) return;
if (!ExporterDialogService.ShowFrameExporterDialog(this)) return;
if (!DialogService.ShowFrameExporterDialog(this)) return;
SpineObject[] spines = args.Cast<SpineObjectModel>().Select(m => m.GetSpineObject(true)).ToArray();
ProgressService.RunAsync((pr, ct) => ExportTask(spines, pr, ct), AppResource.Str_FrameExporterTitle);
foreach (var sp in spines) sp.Dispose();

View File

@@ -20,7 +20,7 @@ namespace SpineViewer.ViewModels.Exporters
protected override void Export_Execute(IList? args)
{
if (args is null || args.Count <= 0) return;
if (!ExporterDialogService.ShowFrameSequenceExporterDialog(this)) return;
if (!DialogService.ShowFrameSequenceExporterDialog(this)) return;
SpineObject[] spines = args.Cast<SpineObjectModel>().Select(m => m.GetSpineObject()).ToArray();
ProgressService.RunAsync((pr, ct) => ExportTask(spines, pr, ct), AppResource.Str_FrameSequenceExporterTitle);
foreach (var sp in spines) sp.Dispose();

View File

@@ -94,7 +94,7 @@ namespace SpineViewer.ViewModels.MainWindow
/// </summary>
public RelayCommand Cmd_ChangeCurrentDirectory => _cmd_ChangeCurrentDirectory ??= new(() =>
{
if (OpenFolderService.OpenFolder(out var selectedPath))
if (DialogService.ShowOpenFolderDialog(out var selectedPath))
{
_currentDirectory = selectedPath;
RefreshItems();

View File

@@ -83,13 +83,13 @@ namespace SpineViewer.ViewModels.MainWindow
/// <summary>
/// 显示诊断信息对话框
/// </summary>
public RelayCommand Cmd_ShowDiagnosticsDialog => _cmd_ShowDiagnosticsDialog ??= new(() => { DiagnosticsDialogService.ShowDiagnosticsDialog(); });
public RelayCommand Cmd_ShowDiagnosticsDialog => _cmd_ShowDiagnosticsDialog ??= new(() => { DialogService.ShowDiagnosticsDialog(); });
private RelayCommand? _cmd_ShowDiagnosticsDialog;
/// <summary>
/// 显示关于对话框
/// </summary>
public RelayCommand Cmd_ShowAboutDialog => _cmd_ShowAboutDialog ??= new(() => { AboutDialogService.ShowAboutDialog(); });
public RelayCommand Cmd_ShowAboutDialog => _cmd_ShowAboutDialog ??= new(() => { DialogService.ShowAboutDialog(); });
private RelayCommand? _cmd_ShowAboutDialog;
/// <summary>

View File

@@ -44,7 +44,7 @@ namespace SpineViewer.Views.ExporterDialogs
private void ButtonSelectOutputDir_Click(object sender, RoutedEventArgs e)
{
if (OpenFolderService.OpenFolder(out var selectedPath))
if (DialogService.ShowOpenFolderDialog(out var selectedPath))
{
var vm = (CustomFFmpegExporterViewModel)DataContext;
vm.OutputDir = selectedPath;

View File

@@ -44,7 +44,7 @@ namespace SpineViewer.Views.ExporterDialogs
private void ButtonSelectOutputDir_Click(object sender, RoutedEventArgs e)
{
if (OpenFolderService.OpenFolder(out var selectedPath))
if (DialogService.ShowOpenFolderDialog(out var selectedPath))
{
var vm = (FFmpegVideoExporterViewModel)DataContext;
vm.OutputDir = selectedPath;

View File

@@ -44,7 +44,7 @@ namespace SpineViewer.Views.ExporterDialogs
private void ButtonSelectOutputDir_Click(object sender, RoutedEventArgs e)
{
if (OpenFolderService.OpenFolder(out var selectedPath))
if (DialogService.ShowOpenFolderDialog(out var selectedPath))
{
var vm = (FrameExporterViewModel)DataContext;
vm.OutputDir = selectedPath;

View File

@@ -44,7 +44,7 @@ namespace SpineViewer.Views.ExporterDialogs
private void ButtonSelectOutputDir_Click(object sender, RoutedEventArgs e)
{
if (OpenFolderService.OpenFolder(out var selectedPath))
if (DialogService.ShowOpenFolderDialog(out var selectedPath))
{
var vm = (FrameSequenceExporterViewModel)DataContext;
vm.OutputDir = selectedPath;