diff --git a/Packager/Program.cs b/Packager/Program.cs
deleted file mode 100644
index 72c4c6340..000000000
--- a/Packager/Program.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace Packager
-{
- static class Program
- {
- ///
- /// The main entry point for the application.
- ///
- [STAThread]
- static void Main()
- {
- Application.SetHighDpiMode(HighDpiMode.SystemAware);
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- }
-}
diff --git a/README.en.md b/README.en.md
index 3e205345f..131a62647 100644
--- a/README.en.md
+++ b/README.en.md
@@ -104,8 +104,10 @@ Read what we [milestones](https://github.com/SteamTools-Team/SteamTools/mileston
* [ReactiveUI](https://github.com/reactiveui/reactiveui)
* [MessageBox.Avalonia](https://github.com/AvaloniaUtils/MessageBox.Avalonia)
* [AvaloniaUI](https://github.com/AvaloniaUI/Avalonia)
-* [EntityFrameworkCore](https://github.com/dotnet/efcore)
-* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
* [Xamarin.Essentials](https://github.com/xamarin/essentials)
+* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
+* [Entity Framework Core](https://github.com/dotnet/efcore)
+* [Windows Forms](https://github.com/dotnet/winforms)
+* [Windows Presentation Foundation (WPF)](https://github.com/dotnet/wpf)
* [.NET Extensions](https://github.com/dotnet/extensions)
* [.NET Runtime](https://github.com/dotnet/runtime)
diff --git a/README.md b/README.md
index 7e9bdfc53..ea66c78d4 100644
--- a/README.md
+++ b/README.md
@@ -114,8 +114,10 @@
* [ReactiveUI](https://github.com/reactiveui/reactiveui)
* [MessageBox.Avalonia](https://github.com/AvaloniaUtils/MessageBox.Avalonia)
* [AvaloniaUI](https://github.com/AvaloniaUI/Avalonia)
-* [EntityFrameworkCore](https://github.com/dotnet/efcore)
-* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
* [Xamarin.Essentials](https://github.com/xamarin/essentials)
+* [Entity Framework Core](https://github.com/dotnet/efcore)
+* [ASP.NET Core](https://github.com/dotnet/aspnetcore)
+* [Windows Forms](https://github.com/dotnet/winforms)
+* [Windows Presentation Foundation (WPF)](https://github.com/dotnet/wpf)
* [.NET Extensions](https://github.com/dotnet/extensions)
* [.NET Runtime](https://github.com/dotnet/runtime)
diff --git a/SteamToolsV1.2+.sln b/SteamToolsV1.2+.sln
index 736ef08a0..6a09a46dc 100644
--- a/SteamToolsV1.2+.sln
+++ b/SteamToolsV1.2+.sln
@@ -57,17 +57,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Avalonia", "System.Application.SteamTools.Client.Desktop.Avalonia\System.Application.SteamTools.Client.Desktop.Avalonia.csproj", "{4F09B6D1-3F83-45A0-AEC8-0F243E7CD263}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Platform", "System.Application.SteamTools.Client.Desktop.Platform\System.Application.SteamTools.Client.Desktop.Platform.csproj", "{DD2973AE-D1FC-4307-AFE2-EE2945183D3D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Linux", "System.Application.SteamTools.Client.Desktop.Linux\System.Application.SteamTools.Client.Desktop.Linux.csproj", "{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Platform.Linux", "System.Application.SteamTools.Client.Desktop.Platform.Linux\System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj", "{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Mac", "System.Application.SteamTools.Client.Desktop.Mac\System.Application.SteamTools.Client.Desktop.Mac.csproj", "{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Platform.Mac", "System.Application.SteamTools.Client.Desktop.Platform.Mac\System.Application.SteamTools.Client.Desktop.Platform.Mac.csproj", "{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Windows", "System.Application.SteamTools.Client.Desktop.Windows\System.Application.SteamTools.Client.Desktop.Windows.csproj", "{141532E1-540E-4E50-8723-96936C191281}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Client.Desktop.Platform.Windows", "System.Application.SteamTools.Client.Desktop.Platform.Windows\System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj", "{141532E1-540E-4E50-8723-96936C191281}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Tools.Win7Troubleshoot", "System.Application.SteamTools.Tools.Win7Troubleshoot\System.Application.SteamTools.Tools.Win7Troubleshoot.csproj", "{60530AF8-4790-4A85-BCE2-C5673E9C601B}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Win7Troubleshoot", "Win7Troubleshoot\Win7Troubleshoot.csproj", "{60530AF8-4790-4A85-BCE2-C5673E9C601B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Application.SteamTools.Tools.Packager", "System.Application.SteamTools.Tools.Packager\System.Application.SteamTools.Tools.Packager.csproj", "{5A539932-2EB9-40F6-A4C1-94E5ECAB3B34}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Packager", "Packager\Packager.csproj", "{5A539932-2EB9-40F6-A4C1-94E5ECAB3B34}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{CC6FF77A-6E6B-4D42-B12B-0177745E9D22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -137,10 +137,6 @@ Global
{4F09B6D1-3F83-45A0-AEC8-0F243E7CD263}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F09B6D1-3F83-45A0-AEC8-0F243E7CD263}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F09B6D1-3F83-45A0-AEC8-0F243E7CD263}.Release|Any CPU.Build.0 = Release|Any CPU
- {DD2973AE-D1FC-4307-AFE2-EE2945183D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {DD2973AE-D1FC-4307-AFE2-EE2945183D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {DD2973AE-D1FC-4307-AFE2-EE2945183D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {DD2973AE-D1FC-4307-AFE2-EE2945183D3D}.Release|Any CPU.Build.0 = Release|Any CPU
{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -187,12 +183,12 @@ Global
{D1F15D97-802E-4AA3-A4A5-B890ABE32897} = {B43459A1-709B-4623-9677-AAC2FEE4FBA3}
{2FFA5BCE-B3C3-46EA-8830-838C938BF814} = {1460800B-D9ED-4147-B1E7-ABF502BEF59A}
{4F09B6D1-3F83-45A0-AEC8-0F243E7CD263} = {B43459A1-709B-4623-9677-AAC2FEE4FBA3}
- {DD2973AE-D1FC-4307-AFE2-EE2945183D3D} = {B43459A1-709B-4623-9677-AAC2FEE4FBA3}
{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82} = {B43459A1-709B-4623-9677-AAC2FEE4FBA3}
{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4} = {B43459A1-709B-4623-9677-AAC2FEE4FBA3}
{141532E1-540E-4E50-8723-96936C191281} = {B43459A1-709B-4623-9677-AAC2FEE4FBA3}
- {60530AF8-4790-4A85-BCE2-C5673E9C601B} = {1460800B-D9ED-4147-B1E7-ABF502BEF59A}
- {5A539932-2EB9-40F6-A4C1-94E5ECAB3B34} = {1460800B-D9ED-4147-B1E7-ABF502BEF59A}
+ {60530AF8-4790-4A85-BCE2-C5673E9C601B} = {CC6FF77A-6E6B-4D42-B12B-0177745E9D22}
+ {5A539932-2EB9-40F6-A4C1-94E5ECAB3B34} = {CC6FF77A-6E6B-4D42-B12B-0177745E9D22}
+ {CC6FF77A-6E6B-4D42-B12B-0177745E9D22} = {1460800B-D9ED-4147-B1E7-ABF502BEF59A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3833E7C5-69BC-4CB3-92CE-A8854AA35D8A}
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs
index 32eb1c13d..2d8654c54 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Program.cs
@@ -85,6 +85,15 @@ namespace System.Application.UI
services.AddViewModelCollectionService();
services.AddViewModel();
services.AddViewModel();
+
+ // 业务用户配置文件服务
+ services.AddConfigFileService();
+
+ // hosts 文件助手服务
+ services.AddHostsFileService();
+
+ // 通用 Http 服务
+ services.AddHttpService();
}
}
}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/System.Application.SteamTools.Client.Desktop.Avalonia.App.csproj b/System.Application.SteamTools.Client.Desktop.Avalonia.App/System.Application.SteamTools.Client.Desktop.Avalonia.App.csproj
index f44323eda..410fed594 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/System.Application.SteamTools.Client.Desktop.Avalonia.App.csproj
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/System.Application.SteamTools.Client.Desktop.Avalonia.App.csproj
@@ -18,22 +18,21 @@
-
-
-
-
+
+
+
-
+
-
+
-
+
@@ -49,7 +48,7 @@
Designer
-
+
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/ServiceCollectionExtensions.cs
index 5fd2c5cda..ad9eab39c 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/ServiceCollectionExtensions.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/ServiceCollectionExtensions.cs
@@ -6,6 +6,11 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
+ ///
+ /// 添加主线程助手类(MainThreadDesktop)服务
+ ///
+ ///
+ ///
public static IServiceCollection AddMainThreadPlatformService(this IServiceCollection services)
{
services.AddSingleton();
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs
index 72e68e480..3ed732fe4 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs
@@ -8,7 +8,6 @@ using MessageBox_Avalonia::MessageBox.Avalonia.Enums;
using System.Reflection;
using System.Threading.Tasks;
-// ReSharper disable once CheckNamespace
namespace System.Windows
{
///
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs
index aadb49aec..25c79cc3c 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs
@@ -1,5 +1,4 @@
-// ReSharper disable once CheckNamespace
-namespace System.Windows
+namespace System.Windows
{
///
/// 指定显示在消息框上的按钮。 用作 .Show... 方法的参数。
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs
index be8f0b852..bfe803f8a 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs
@@ -1,5 +1,4 @@
-// ReSharper disable once CheckNamespace
-namespace System.Windows
+namespace System.Windows
{
///
/// 指定消息框所显示的图标。
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs
index 9da092dfe..86b3d1fba 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs
@@ -1,5 +1,4 @@
-// ReSharper disable once CheckNamespace
-namespace System.Windows
+namespace System.Windows
{
///
/// 指定用户单击的消息框按钮。 由 .Show... 方法返回。
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs
index b08091784..fe1c0dbe5 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs
@@ -1,6 +1,5 @@
using System.Application.Services;
-// ReSharper disable once CheckNamespace
namespace System.Windows
{
///
diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs
index b8f4c9d94..2413e17b8 100644
--- a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs
+++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs
@@ -3,7 +3,6 @@ using System.IO;
using FontFamily = Avalonia.Media.FontFamily;
using Window = Avalonia.Controls.Window;
-// ReSharper disable once CheckNamespace
namespace System.Windows
{
///
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Linux/Implementation/LinuxDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs
similarity index 66%
rename from System.Application.SteamTools.Client.Desktop.Platform.Linux/Implementation/LinuxDesktopPlatformServiceImpl.cs
rename to System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs
index e49170de0..e61cb2f7b 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform.Linux/Implementation/LinuxDesktopPlatformServiceImpl.cs
+++ b/System.Application.SteamTools.Client.Desktop.Linux/Application/Services/Implementation/LinuxDesktopPlatformServiceImpl.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using System.Application.Models;
+using System.Diagnostics;
namespace System.Application.Services.Implementation
{
@@ -12,5 +13,10 @@ namespace System.Application.Services.Implementation
{
return string.Empty;
}
+
+ public string? GetFileName(TextReaderProvider provider)
+ {
+ return null;
+ }
}
}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Linux/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Linux/ServiceCollectionExtensions.cs
similarity index 100%
rename from System.Application.SteamTools.Client.Desktop.Platform.Linux/ServiceCollectionExtensions.cs
rename to System.Application.SteamTools.Client.Desktop.Linux/ServiceCollectionExtensions.cs
diff --git a/System.Application.SteamTools.Client.Desktop.Platform/System.Application.SteamTools.Client.Desktop.Platform.csproj b/System.Application.SteamTools.Client.Desktop.Linux/System.Application.SteamTools.Client.Desktop.Linux.csproj
similarity index 76%
rename from System.Application.SteamTools.Client.Desktop.Platform/System.Application.SteamTools.Client.Desktop.Platform.csproj
rename to System.Application.SteamTools.Client.Desktop.Linux/System.Application.SteamTools.Client.Desktop.Linux.csproj
index 68edcc61b..96ead85d2 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform/System.Application.SteamTools.Client.Desktop.Platform.csproj
+++ b/System.Application.SteamTools.Client.Desktop.Linux/System.Application.SteamTools.Client.Desktop.Linux.csproj
@@ -2,7 +2,7 @@
net5.0
- System.Application.Services
+ System
@@ -12,7 +12,7 @@
-
+
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Mac/Implementation/MacDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs
similarity index 66%
rename from System.Application.SteamTools.Client.Desktop.Platform.Mac/Implementation/MacDesktopPlatformServiceImpl.cs
rename to System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs
index b7ebb71bd..7d42a52e4 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform.Mac/Implementation/MacDesktopPlatformServiceImpl.cs
+++ b/System.Application.SteamTools.Client.Desktop.Mac/Application/Services/Implementation/MacDesktopPlatformServiceImpl.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using System.Application.Models;
+using System.Diagnostics;
namespace System.Application.Services.Implementation
{
@@ -12,5 +13,10 @@ namespace System.Application.Services.Implementation
{
return string.Empty;
}
+
+ public string? GetFileName(TextReaderProvider provider)
+ {
+ return null;
+ }
}
}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Mac/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Mac/ServiceCollectionExtensions.cs
similarity index 100%
rename from System.Application.SteamTools.Client.Desktop.Platform.Mac/ServiceCollectionExtensions.cs
rename to System.Application.SteamTools.Client.Desktop.Mac/ServiceCollectionExtensions.cs
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Linux/System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj b/System.Application.SteamTools.Client.Desktop.Mac/System.Application.SteamTools.Client.Desktop.Mac.csproj
similarity index 72%
rename from System.Application.SteamTools.Client.Desktop.Platform.Linux/System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj
rename to System.Application.SteamTools.Client.Desktop.Mac/System.Application.SteamTools.Client.Desktop.Mac.csproj
index 941710b14..96ead85d2 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform.Linux/System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj
+++ b/System.Application.SteamTools.Client.Desktop.Mac/System.Application.SteamTools.Client.Desktop.Mac.csproj
@@ -2,7 +2,7 @@
net5.0
- System.Application.Services
+ System
@@ -12,7 +12,7 @@
-
+
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Mac/System.Application.SteamTools.Client.Desktop.Platform.Mac.csproj b/System.Application.SteamTools.Client.Desktop.Platform.Mac/System.Application.SteamTools.Client.Desktop.Platform.Mac.csproj
deleted file mode 100644
index 941710b14..000000000
--- a/System.Application.SteamTools.Client.Desktop.Platform.Mac/System.Application.SteamTools.Client.Desktop.Platform.Mac.csproj
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
- net5.0
- System.Application.Services
-
-
-
-
- Properties\AssemblyInfo.cs
-
-
-
-
-
-
-
-
diff --git a/System.Application.SteamTools.Client.Desktop.Platform/IDesktopPlatformService.cs b/System.Application.SteamTools.Client.Desktop.Platform/IDesktopPlatformService.cs
deleted file mode 100644
index 19cf4e631..000000000
--- a/System.Application.SteamTools.Client.Desktop.Platform/IDesktopPlatformService.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System.Diagnostics;
-using ResizeMode = System.Int32;
-
-namespace System.Application.Services
-{
- public interface IDesktopPlatformService
- {
- void SetResizeMode(IntPtr hWnd, ResizeMode value);
-
- ///
- /// 获取一个正在运行的进程的命令行参数。
- /// 与 一样,使用此方法获取的参数是包含应用程序路径的。
- /// 关于 可参见:
- /// .NET 命令行参数包含应用程序路径吗?https://blog.walterlv.com/post/when-will-the-command-line-args-contain-the-executable-path.html
- ///
- /// 一个正在运行的进程。
- /// 表示应用程序运行命令行参数的字符串。
- string GetCommandLineArgs(Process process);
-
- public const ResizeMode ResizeMode_NoResize = 0;
- public const ResizeMode ResizeMode_CanMinimize = 1;
- public const ResizeMode ResizeMode_CanResize = 2;
- public const ResizeMode ResizeMode_CanResizeWithGrip = 3;
- }
-}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Windows/Implementation/WindowsDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs
similarity index 78%
rename from System.Application.SteamTools.Client.Desktop.Platform.Windows/Implementation/WindowsDesktopPlatformServiceImpl.cs
rename to System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs
index 0e33d8fca..8a35734ad 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform.Windows/Implementation/WindowsDesktopPlatformServiceImpl.cs
+++ b/System.Application.SteamTools.Client.Desktop.Windows/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs
@@ -1,5 +1,8 @@
-using System.ComponentModel;
+using System.Application.Models;
+using System.Collections.Generic;
+using System.ComponentModel;
using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
@@ -10,6 +13,8 @@ namespace System.Application.Services.Implementation
[SupportedOSPlatform("Windows")]
internal sealed class WindowsDesktopPlatformServiceImpl : IDesktopPlatformService
{
+ const string TAG = "WindowsDesktopPlatformS";
+
#region 窗口右上角的三个按钮(最小化,最大化,关闭)
// https://stackoverflow.com/questions/339620/how-do-i-remove-minimize-and-maximize-from-a-resizable-window-in-wpf
@@ -107,5 +112,31 @@ namespace System.Application.Services.Implementation
return string.Empty;
}
}
+
+ static readonly Lazy mHostsFilePath = new Lazy(() =>
+ {
+ return Path.Combine(Environment.SystemDirectory, "drivers", "etc", "hosts");
+ });
+
+ public string HostsFilePath => mHostsFilePath.Value;
+
+ public string? GetFileName(TextReaderProvider provider)
+ {
+ switch (provider)
+ {
+ case TextReaderProvider.Notepad:
+ return "notepad";
+ case TextReaderProvider.NotepadPlusPlus:
+ return "notepad++";
+ case TextReaderProvider.VSCode:
+ var vsCodePath = Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
+ "Microsoft VS Code",
+ "Code.exe");
+ return File.Exists(vsCodePath) ? vsCodePath : null;
+ default:
+ return null;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop.Windows/Extensions/RegistryKeyExtensions.cs b/System.Application.SteamTools.Client.Desktop.Windows/Extensions/RegistryKeyExtensions.cs
new file mode 100644
index 000000000..697e001f0
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop.Windows/Extensions/RegistryKeyExtensions.cs
@@ -0,0 +1,66 @@
+using Microsoft.Win32;
+using System.Runtime.Versioning;
+
+// ReSharper disable once CheckNamespace
+namespace System
+{
+ [SupportedOSPlatform("Windows")]
+ public static class RegistryKeyExtensions
+ {
+ ///
+ /// 读取注册表值
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string Read(this RegistryKey registryKey, string path, string name)
+ {
+ var rk = registryKey.OpenSubKey(path);
+ if (rk != null)
+ {
+ var value = rk.GetValue(name)?.ToString();
+ rk.Close();
+ return value ?? string.Empty;
+ }
+ return string.Empty;
+ }
+
+ ///
+ /// 新增或修改注册表值
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void AddOrUpdate(this RegistryKey registryKey, string path, string name, string value, RegistryValueKind valueKind)
+ {
+ var rk = registryKey.OpenSubKey(path, true);
+ if (rk != null) // 该项必须已存在
+ {
+ rk.SetValue(name, value, valueKind);
+ rk.Close();
+ }
+ }
+ }
+
+#if DEBUG
+
+ [Obsolete("use RegistryKeyExtensions", true)]
+ public class RegistryKeyService
+ {
+ [Obsolete("use registryKey.Read", true)]
+ public string ReadRegistryKey(RegistryKey registryKey, string path, string key)
+ {
+ return string.Empty;
+ }
+
+ [Obsolete("use registryKey.AddOrUpdate", true)]
+ public void AddOrUpdateRegistryKey(RegistryKey registryKey, string path, string key, string value, RegistryValueKind registryValueKind)
+ {
+ }
+ }
+
+#endif
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Windows/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Windows/ServiceCollectionExtensions.cs
similarity index 81%
rename from System.Application.SteamTools.Client.Desktop.Platform.Windows/ServiceCollectionExtensions.cs
rename to System.Application.SteamTools.Client.Desktop.Windows/ServiceCollectionExtensions.cs
index 477125d6e..5a257b434 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform.Windows/ServiceCollectionExtensions.cs
+++ b/System.Application.SteamTools.Client.Desktop.Windows/ServiceCollectionExtensions.cs
@@ -7,6 +7,11 @@ namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
+ ///
+ /// 添加桌面平台服务
+ ///
+ ///
+ ///
public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services)
{
if (DI.Platform == Platform.Windows)
diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Windows/System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj b/System.Application.SteamTools.Client.Desktop.Windows/System.Application.SteamTools.Client.Desktop.Windows.csproj
similarity index 72%
rename from System.Application.SteamTools.Client.Desktop.Platform.Windows/System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj
rename to System.Application.SteamTools.Client.Desktop.Windows/System.Application.SteamTools.Client.Desktop.Windows.csproj
index fedd00562..cb8fbbd33 100644
--- a/System.Application.SteamTools.Client.Desktop.Platform.Windows/System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj
+++ b/System.Application.SteamTools.Client.Desktop.Windows/System.Application.SteamTools.Client.Desktop.Windows.csproj
@@ -2,7 +2,7 @@
net5.0
- System.Application.Services
+ System
@@ -12,11 +12,12 @@
+
-
+
diff --git a/System.Application.SteamTools.Client.Desktop/Models/AppUserSettings.cs b/System.Application.SteamTools.Client.Desktop/Models/AppUserSettings.cs
new file mode 100644
index 000000000..ef83e6c6c
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Models/AppUserSettings.cs
@@ -0,0 +1,41 @@
+using MessagePack;
+using System.Collections.Generic;
+
+namespace System.Application.Models
+{
+ ///
+ /// Steam++ 应用 用户配置项
+ ///
+ [MessagePackObject(keyAsPropertyName: true)]
+ public sealed class AppUserSettings
+ {
+ ///
+ /// 启动参数
+ ///
+ public string? StartupArgs { get; set; }
+
+ ///
+ /// 是否启用日志
+ ///
+ public bool EnableLogger { get; set; }
+
+ ///
+ /// 用户设置的文本阅读器提供商,根据平台值不同,值格式为 枚举字符串 或 程序路径
+ ///
+ public Dictionary? TextReaderProvider { get; set; }
+ }
+
+#if DEBUG
+
+ [Obsolete("use AppUserSettings", true)]
+ public class SettingsModel
+ {
+ [Obsolete("use AppUserSettings.StartupArgs", true)]
+ public string? SteamRunParam { get; set; }
+
+ [Obsolete("use AppUserSettings.EnableTextLog", true)]
+ public bool EnableTextLog { get; set; }
+ }
+
+#endif
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Models/TextReaderProvider.cs b/System.Application.SteamTools.Client.Desktop/Models/TextReaderProvider.cs
new file mode 100644
index 000000000..6f14ce81e
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Models/TextReaderProvider.cs
@@ -0,0 +1,23 @@
+namespace System.Application.Models
+{
+ ///
+ /// 文本阅读器提供商
+ ///
+ public enum TextReaderProvider
+ {
+ ///
+ /// 系统默认,例如 Win 上的记事本
+ ///
+ Notepad,
+
+ ///
+ /// Notepad++
+ ///
+ NotepadPlusPlus,
+
+ ///
+ /// Visual Studio Code
+ ///
+ VSCode,
+ }
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop/ServiceCollectionExtensions.cs
index eef5e5a2f..fe775a07c 100644
--- a/System.Application.SteamTools.Client.Desktop/ServiceCollectionExtensions.cs
+++ b/System.Application.SteamTools.Client.Desktop/ServiceCollectionExtensions.cs
@@ -53,5 +53,39 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddLogging(AppHelper.Configure);
return services;
}
+
+ ///
+ /// 添加业务用户配置文件服务
+ ///
+ ///
+ ///
+ public static IServiceCollection AddConfigFileService(this IServiceCollection services)
+ {
+ services.AddSingleton(new ConfigFileServiceImpl());
+ return services;
+ }
+
+ ///
+ /// 添加 hosts 文件助手服务
+ ///
+ ///
+ ///
+ public static IServiceCollection AddHostsFileService(this IServiceCollection services)
+ {
+ services.AddSingleton();
+ return services;
+ }
+
+ ///
+ /// 添加 通用 Http 服务
+ ///
+ ///
+ ///
+ public static IServiceCollection AddHttpService(this IServiceCollection services)
+ {
+ services.AddHttpClient();
+ services.AddSingleton();
+ return services;
+ }
}
}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/IConfigFileService.cs b/System.Application.SteamTools.Client.Desktop/Services/IConfigFileService.cs
new file mode 100644
index 000000000..212fd1c9a
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/IConfigFileService.cs
@@ -0,0 +1,43 @@
+using System.Application.Models;
+
+namespace System.Application.Services
+{
+ ///
+ /// Steam++ 应用 用户配置文件服务
+ ///
+ public interface IConfigFileService
+ {
+ const string TAG = "ConfigFileS";
+
+ const string ConfigFileName = "Config.json";
+
+ ///
+ /// 获取或设置 Steam++ 应用 用户配置项
+ ///
+ AppUserSettings UserSettings { get; set; }
+
+ ///
+ /// 将 Steam++ 应用 用户配置项 保存到本地存储中
+ ///
+ void SaveChanges();
+
+ public static IConfigFileService Instance => DI.Get();
+ }
+
+#if DEBUG
+
+ [Obsolete("use IConfigFileService.Instance", true)]
+ public class ConfigService
+ {
+ [Obsolete("use IConfigFileService.Instance.UserSettings", true)]
+ public SettingsModel? SteamToolModel { get; set; }
+
+ [Obsolete("use IConfigFileService.Instance.SaveChanges", true)]
+ public void SaveConfig() => throw new NotImplementedException();
+
+ [Obsolete("changedAutoRead", true)]
+ public SettingsModel ReadConfig() => throw new NotImplementedException();
+ }
+
+#endif
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs b/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs
new file mode 100644
index 000000000..f85526730
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/IDesktopPlatformService.cs
@@ -0,0 +1,107 @@
+using System.Application.Models;
+using System.Collections.Generic;
+using System.Diagnostics;
+using ResizeMode = System.Int32;
+
+namespace System.Application.Services
+{
+ public interface IDesktopPlatformService
+ {
+ const string TAG = "DesktopPlatformS";
+
+ void SetResizeMode(IntPtr hWnd, ResizeMode value);
+
+ ///
+ /// 获取一个正在运行的进程的命令行参数。
+ /// 与 一样,使用此方法获取的参数是包含应用程序路径的。
+ /// 关于 可参见:
+ /// .NET 命令行参数包含应用程序路径吗?https://blog.walterlv.com/post/when-will-the-command-line-args-contain-the-executable-path.html
+ ///
+ /// 一个正在运行的进程。
+ /// 表示应用程序运行命令行参数的字符串。
+ string GetCommandLineArgs(Process process);
+
+ ///
+ /// hosts 文件所在目录
+ ///
+ string HostsFilePath => "/etc/hosts";
+
+ ///
+ /// 使用文本阅读器打开文件
+ ///
+ ///
+ void OpenFileByTextReader(string filePath)
+ {
+ TextReaderProvider? userProvider = null;
+ var p = IConfigFileService.Instance.UserSettings.TextReaderProvider;
+ if (p != null)
+ {
+ var platform = DI.Platform;
+ if (p.ContainsKey(platform))
+ {
+ var value = p[platform];
+ if (!string.IsNullOrWhiteSpace(value))
+ {
+ if (Enum.TryParse(value, out var enumValue))
+ {
+ userProvider = enumValue;
+ }
+ else
+ {
+ try
+ {
+ Process.Start(value, filePath);
+ return;
+ }
+ catch (Exception e)
+ {
+ Log.Error(TAG, e, "UserSettings OpenFileByTextReader Fail.");
+ }
+ }
+ }
+ }
+ }
+
+ var providers = new List() {
+ TextReaderProvider.VSCode,
+ TextReaderProvider.NotepadPlusPlus,
+ TextReaderProvider.Notepad };
+
+ if (userProvider.HasValue)
+ {
+ providers.Remove(userProvider.Value);
+ providers.Insert(0, userProvider.Value);
+ }
+
+ foreach (var item in providers)
+ {
+ try
+ {
+ var fileName = GetFileName(item);
+ if (fileName == null) continue;
+ Process.Start(fileName, filePath);
+ return;
+ }
+ catch (Exception e)
+ {
+ if (item == TextReaderProvider.Notepad)
+ {
+ Log.Error(TAG, e, "OpenFileByTextReader Fail.");
+ }
+ }
+ }
+ }
+
+ ///
+ /// 获取文本阅读器提供商程序文件路径或文件名(如果提供程序已注册环境变量)
+ ///
+ ///
+ ///
+ string? GetFileName(TextReaderProvider provider);
+
+ public const ResizeMode ResizeMode_NoResize = 0;
+ public const ResizeMode ResizeMode_CanMinimize = 1;
+ public const ResizeMode ResizeMode_CanResize = 2;
+ public const ResizeMode ResizeMode_CanResizeWithGrip = 3;
+ }
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/IHostsFileService.cs b/System.Application.SteamTools.Client.Desktop/Services/IHostsFileService.cs
new file mode 100644
index 000000000..d74b58e3d
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/IHostsFileService.cs
@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+
+namespace System.Application.Services
+{
+ ///
+ /// hosts 文件助手服务
+ ///
+ public interface IHostsFileService
+ {
+ const string TAG = "HostsFileS";
+
+ public static IHostsFileService Instance => DI.Get();
+
+ ///
+ /// 打开 hosts 文件
+ ///
+ void OpenFile();
+
+ OperationResult> ReadHostsAllLines();
+
+ OperationResult UpdateHosts(string ip, string domain);
+
+ OperationResult UpdateHosts(IReadOnlyList<(string ip, string domain)> hosts);
+
+ OperationResult RemoveHosts(string ip, string domain);
+
+ OperationResult RemoveHostsByTag();
+ }
+
+#if DEBUG
+
+ [Obsolete("use IHostsFileService.Instance", true)]
+ public class HostsService
+ {
+ [Obsolete("use IHostsFileService.Instance.OpenFile", true)]
+ public void StartNotepadEditHosts() => throw new NotImplementedException();
+ }
+
+#endif
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/IHttpService.cs b/System.Application.SteamTools.Client.Desktop/Services/IHttpService.cs
new file mode 100644
index 000000000..7df4725db
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/IHttpService.cs
@@ -0,0 +1,21 @@
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace System.Application.Services
+{
+ public interface IHttpService
+ {
+ public static IHttpService Instance => DI.Get();
+
+ Task GetAsync(string requestUri, CancellationToken cancellationToken = default) where T : notnull;
+ }
+
+#if DEBUG
+
+ [Obsolete("use IHttpService.Instance", true)]
+ public class HttpServices
+ {
+ }
+
+#endif
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/Implementation/ConfigFileServiceImpl.cs b/System.Application.SteamTools.Client.Desktop/Services/Implementation/ConfigFileServiceImpl.cs
new file mode 100644
index 000000000..67d4700ec
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/Implementation/ConfigFileServiceImpl.cs
@@ -0,0 +1,47 @@
+using System.Application.Models;
+using System.IO;
+using System.Text;
+using static System.Application.Services.IConfigFileService;
+
+namespace System.Application.Services.Implementation
+{
+ internal sealed class ConfigFileServiceImpl : IConfigFileService
+ {
+ public string ConfigFilePath { get; }
+
+ public ConfigFileServiceImpl()
+ {
+ ConfigFilePath = Path.Combine(IOPath.AppDataDirectory, ConfigFileName);
+ UserSettings = TryReadConfig() ?? new AppUserSettings();
+ }
+
+ public AppUserSettings UserSettings { get; set; }
+
+ public void SaveChanges()
+ {
+ try
+ {
+ var jsonStr = Serializable.SJSON(UserSettings);
+ File.WriteAllText(ConfigFilePath, jsonStr, Encoding.UTF8);
+ }
+ catch (Exception e)
+ {
+ Log.Error(TAG, e, "SaveChanges Fail.");
+ }
+ }
+
+ AppUserSettings? TryReadConfig()
+ {
+ try
+ {
+ var jsonStr = File.ReadAllText(ConfigFilePath);
+ return Serializable.DJSON(jsonStr);
+ }
+ catch (Exception e)
+ {
+ Log.Error(TAG, e, "TryReadConfig Fail.");
+ }
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/Implementation/HostsFileServiceImpl.cs b/System.Application.SteamTools.Client.Desktop/Services/Implementation/HostsFileServiceImpl.cs
new file mode 100644
index 000000000..ebf2553a9
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/Implementation/HostsFileServiceImpl.cs
@@ -0,0 +1,257 @@
+using System.Application.UI.Resx;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using static System.Application.Services.IHostsFileService;
+
+namespace System.Application.Services.Implementation
+{
+ internal sealed class HostsFileServiceImpl : IHostsFileService
+ {
+ readonly IDesktopPlatformService s;
+
+ public HostsFileServiceImpl(IDesktopPlatformService s)
+ {
+ this.s = s;
+ }
+
+ public void OpenFile() => s.OpenFileByTextReader(s.HostsFilePath);
+
+ public OperationResult> ReadHostsAllLines()
+ {
+ var result = new OperationResult>(OperationResultType.Error, AppResources.Hosts_ReadError);
+ if (!File.Exists(s.HostsFilePath))
+ {
+ result.Message = "hosts file was not found";
+ return result;
+ }
+ try
+ {
+ var dataLines = File.ReadAllLines(s.HostsFilePath).ToList();
+ foreach (var line in dataLines)
+ {
+ var temp = line.Trim().Split(' ').ToList();
+ temp = temp.FindAll(s => !string.IsNullOrEmpty(s));
+ if (temp.Count >= 2)
+ {
+ if (!temp[0].StartsWith("#"))
+ {
+ result.AppendData.Add(temp?.ToString() ?? string.Empty);
+ }
+ }
+ }
+ result.ResultType = OperationResultType.Success;
+ result.Message = AppResources.Hosts_ReadSuccess;
+ }
+ catch (Exception ex)
+ {
+ Log.Error(TAG, ex, "ReadHostsAllLines catch.");
+ result.ResultType = OperationResultType.Error;
+ result.Message = ex.Message;
+ }
+ return result;
+ }
+
+ public OperationResult UpdateHosts(string ip, string domain)
+ {
+ var result = new OperationResult(OperationResultType.Error, AppResources.Hosts_WirteError);
+ if (!File.Exists(s.HostsFilePath))
+ {
+ result.Message = "hosts file was not found";
+ return result;
+ }
+ // 操作前取消只读属性
+ File.SetAttributes(s.HostsFilePath, FileAttributes.Normal);
+
+ // 避免重复写入
+ var dataLines = File.ReadAllLines(s.HostsFilePath, Encoding.Default).ToList().FindAll(s =>
+ {
+ var temp = s.Trim().Split(' ').ToList();
+ temp = temp.FindAll(s => !string.IsNullOrEmpty(s));
+ // 一行内至少要有两列数据
+ if (temp.Count >= 2)
+ {
+ if (!temp[0].StartsWith("#"))
+ {
+ if (temp.Contains(domain))
+ {
+ // 相同域名直接修改删除
+ return false;
+ }
+ }
+ }
+ return true;
+ });
+
+ try
+ {
+ dataLines.Add($"{ip} {domain} {Constants.HOST_TAG}");
+ File.WriteAllLines(s.HostsFilePath, dataLines, Encoding.UTF8);
+
+ //File.SetAttributes(HostsPath, FileAttributes.ReadOnly);
+ result.ResultType = OperationResultType.Success;
+ result.Message = AppResources.Hosts_UpdateSuccess;
+ }
+ catch (Exception ex)
+ {
+ Log.Error(TAG, ex, "UpdateHosts catch.");
+ result.ResultType = OperationResultType.Error;
+ result.AppendData = ex;
+ result.Message = ex.Message;
+ return result;
+ }
+ return result;
+ }
+
+ public OperationResult UpdateHosts(IReadOnlyList<(string ip, string domain)> hosts)
+ {
+ var result = new OperationResult(OperationResultType.Error, AppResources.Hosts_WirteError);
+ if (!File.Exists(s.HostsFilePath))
+ {
+ result.Message = "hosts file was not found";
+ return result;
+ }
+ if (hosts.Count == 0)
+ {
+ return result;
+ }
+
+ // 操作前取消只读属性
+ File.SetAttributes(s.HostsFilePath, FileAttributes.Normal);
+
+ // 避免重复写入
+ var dataLines = File.ReadAllLines(s.HostsFilePath, Encoding.Default).ToList().FindAll(s =>
+ {
+ var temp = s.Trim().Split(' ').ToList();
+ temp = temp.FindAll(s => !string.IsNullOrEmpty(s));
+ // 一行内至少要有两列数据
+ if (temp.Count >= 2)
+ {
+ if (!temp[0].StartsWith("#"))
+ {
+ foreach (var (ip, domain) in hosts)
+ {
+ if (temp.Contains(domain))
+ {
+ // 相同域名直接修改删除
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ });
+
+ foreach (var (ip, domain) in hosts)
+ {
+ dataLines.Add($"{ip} {domain} {Constants.HOST_TAG}");
+ }
+ try
+ {
+ File.WriteAllLines(s.HostsFilePath, dataLines, Encoding.UTF8);
+ //File.SetAttributes(HostsPath, FileAttributes.ReadOnly);
+ result.ResultType = OperationResultType.Success;
+ result.Message = AppResources.Hosts_UpdateSuccess;
+ }
+ catch (Exception ex)
+ {
+ Log.Error(TAG, ex, "UpdateHosts catch.");
+ result.ResultType = OperationResultType.Error;
+ result.AppendData = ex;
+ result.Message = ex.Message;
+ return result;
+ }
+ return result;
+ }
+
+ public OperationResult RemoveHosts(string ip, string domain)
+ {
+ var result = new OperationResult(OperationResultType.Error, AppResources.Hosts_WirteError);
+ if (!File.Exists(s.HostsFilePath))
+ {
+ result.Message = "hosts file was not found";
+ return result;
+ }
+ try
+ {
+ //操作前取消只读属性
+ File.SetAttributes(s.HostsFilePath, FileAttributes.Normal);
+
+ //避免重复写入
+ var dataLines = File.ReadAllLines(s.HostsFilePath, Encoding.Default).ToList().FindAll(s =>
+ {
+ var temp = s.Trim().Split(' ').ToList();
+ temp = temp.FindAll(s => !string.IsNullOrEmpty(s));
+ //一行内至少要有两列数据
+ if (temp.Count >= 2)
+ {
+ if (!temp[0].StartsWith("#"))
+ {
+ return !(temp.Contains(ip) && temp.Contains(domain));
+ }
+ }
+ return true;
+ });
+
+ File.WriteAllLines(s.HostsFilePath, dataLines, Encoding.UTF8);
+
+ //File.SetAttributes(HostsPath, FileAttributes.ReadOnly);
+ result.ResultType = OperationResultType.Success;
+ result.Message = AppResources.Hosts_UpdateSuccess;
+ }
+ catch (Exception ex)
+ {
+ Log.Error(TAG, ex, "RemoveHosts catch.");
+ result.ResultType = OperationResultType.Error;
+ result.AppendData = ex;
+ result.Message = ex.Message;
+ return result;
+ }
+ return result;
+ }
+
+ public OperationResult RemoveHostsByTag()
+ {
+ var result = new OperationResult(OperationResultType.Error, AppResources.Hosts_WirteError);
+ if (!File.Exists(s.HostsFilePath))
+ {
+ result.Message = "hosts file was not found";
+ return result;
+ }
+ try
+ {
+ //操作前取消只读属性
+ File.SetAttributes(s.HostsFilePath, FileAttributes.Normal);
+
+ var dataLines = File.ReadAllLines(s.HostsFilePath, Encoding.Default).ToList().FindAll(s =>
+ {
+ var temp = s.Trim().Split(' ').ToList().FindAll(w => !string.IsNullOrEmpty(w));
+ //有效数据一行内至少要有两列数据
+ if (temp.Count >= 2)
+ {
+ if (!temp[0].StartsWith("#"))
+ {
+ return !temp.Contains(Constants.HOST_TAG);
+ }
+ }
+ return true;
+ });
+
+ File.WriteAllLines(s.HostsFilePath, dataLines, Encoding.UTF8);
+ //File.SetAttributes(HostsPath, FileAttributes.ReadOnly);
+ result.ResultType = OperationResultType.Success;
+ result.Message = AppResources.Hosts_UpdateSuccess;
+ }
+ catch (Exception ex)
+ {
+ Log.Error(TAG, ex, "RemoveHostsByTag catch.");
+ result.ResultType = OperationResultType.Error;
+ result.AppendData = ex;
+ result.Message = ex.Message;
+ return result;
+ }
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/Implementation/HttpServiceImpl.cs b/System.Application.SteamTools.Client.Desktop/Services/Implementation/HttpServiceImpl.cs
new file mode 100644
index 000000000..e24c730b1
--- /dev/null
+++ b/System.Application.SteamTools.Client.Desktop/Services/Implementation/HttpServiceImpl.cs
@@ -0,0 +1,75 @@
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using System.IO;
+using System.Net.Http;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace System.Application.Services.Implementation
+{
+ internal sealed class HttpServiceImpl : HttpService, IHttpService
+ {
+ const string TAG = "HttpS";
+ const string Accept = MediaTypeNames.JSON;
+ readonly JsonSerializer jsonSerializer = new JsonSerializer();
+
+ public HttpServiceImpl(ILogger logger, IHttpPlatformHelper http_helper, IHttpClientFactory clientFactory) : base(logger, http_helper, clientFactory)
+ {
+ }
+
+ public async Task GetAsync(string requestUri, CancellationToken cancellationToken) where T : notnull
+ {
+ try
+ {
+ using var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
+ request.Headers.Accept.ParseAdd(Accept);
+ request.Headers.UserAgent.ParseAdd(http_helper.UserAgent);
+ var client = CreateClient();
+ using var response = await client.SendAsync(request,
+ HttpCompletionOption.ResponseHeadersRead,
+ cancellationToken)
+ .ConfigureAwait(false);
+ if (response.IsSuccessStatusCode)
+ {
+ if (response.Content != null)
+ {
+ var mime = response.Content.Headers.ContentType?.MediaType ?? Accept;
+ switch (mime)
+ {
+ case MediaTypeNames.JSON:
+ case MediaTypeNames.XML:
+ case MediaTypeNames.XML_APP:
+ {
+ using var stream = await response.Content
+ .ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
+ using var reader = new StreamReader(stream, Encoding.UTF8);
+ switch (mime)
+ {
+ case MediaTypeNames.JSON:
+ {
+ using var json = new JsonTextReader(reader);
+ return jsonSerializer.Deserialize(json);
+ }
+ case MediaTypeNames.XML:
+ case MediaTypeNames.XML_APP:
+ {
+ var xmlSerializer = new XmlSerializer(typeof(T));
+ return (T)xmlSerializer.Deserialize(reader);
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ Log.Error(TAG, e, "GetAsync Fail.");
+ }
+ return default;
+ }
+ }
+}
\ No newline at end of file
diff --git a/System.Application.SteamTools.Client.Desktop/Services/OperationResult.cs b/System.Application.SteamTools.Client.Desktop/Services/OperationResult.cs
index ab02126e8..c9d0f268a 100644
--- a/System.Application.SteamTools.Client.Desktop/Services/OperationResult.cs
+++ b/System.Application.SteamTools.Client.Desktop/Services/OperationResult.cs
@@ -1,14 +1,16 @@
-namespace System.Application.Services
+using System.Diagnostics.CodeAnalysis;
+
+namespace System.Application.Services
{
///
/// 操作结果信息类,对操作结果进行封装
///
///
- public class OperationResult
+ public abstract class OperationResultBase
{
#region 构造函数
- public OperationResult()
+ public OperationResultBase()
{
ResultType = OperationResultType.Error;
}
@@ -17,7 +19,7 @@
/// 初始化一个 操作结果信息类 的新实例
///
/// 操作结果类型
- public OperationResult(OperationResultType resultType)
+ public OperationResultBase(OperationResultType resultType)
{
ResultType = resultType;
}
@@ -27,7 +29,7 @@
///
/// 操作结果类型
/// 返回消息
- public OperationResult(OperationResultType resultType, string message)
+ public OperationResultBase(OperationResultType resultType, string message)
: this(resultType)
{
Message = message;
@@ -39,7 +41,7 @@
/// 操作结果类型
/// 返回消息
/// 返回数据
- public OperationResult(OperationResultType resultType, string message, T appendData)
+ public OperationResultBase(OperationResultType resultType, string message, T appendData)
: this(resultType, message)
{
AppendData = appendData;
@@ -51,7 +53,7 @@
/// 操作结果类型
/// 返回消息
/// 日志记录消息
- public OperationResult(OperationResultType resultType, string message, string logMessage)
+ public OperationResultBase(OperationResultType resultType, string message, string logMessage)
: this(resultType, message)
{
LogMessage = logMessage;
@@ -64,7 +66,7 @@
/// 返回消息
/// 日志记录消息
/// 返回数据
- public OperationResult(OperationResultType resultType, string message, string logMessage, T appendData)
+ public OperationResultBase(OperationResultType resultType, string message, string logMessage, T appendData)
: this(resultType, message, logMessage)
{
AppendData = appendData;
@@ -92,11 +94,80 @@
///
/// 获取或设置 操作结果附加信息
///
- public T? AppendData { get; set; }
+ public abstract T? AppendData { get; set; }
#endregion
}
- ///
- public class OperationResult : OperationResult
diff --git a/Win7Troubleshoot/App.config b/System.Application.SteamTools.Tools.Win7Troubleshoot/App.config
similarity index 100%
rename from Win7Troubleshoot/App.config
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/App.config
diff --git a/Win7Troubleshoot/NullableAttributes.cs b/System.Application.SteamTools.Tools.Win7Troubleshoot/Diagnostics.CodeAnalysis/NullableAttributes.cs
similarity index 89%
rename from Win7Troubleshoot/NullableAttributes.cs
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/Diagnostics.CodeAnalysis/NullableAttributes.cs
index af214b190..df8936757 100644
--- a/Win7Troubleshoot/NullableAttributes.cs
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/Diagnostics.CodeAnalysis/NullableAttributes.cs
@@ -1,5 +1,4 @@
-// ReSharper disable once CheckNamespace
-namespace System.Diagnostics.CodeAnalysis
+namespace System.Diagnostics.CodeAnalysis
{
/// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it.
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
diff --git a/Win7Troubleshoot/DownloadLinks.cs b/System.Application.SteamTools.Tools.Win7Troubleshoot/DownloadLinks.cs
similarity index 77%
rename from Win7Troubleshoot/DownloadLinks.cs
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/DownloadLinks.cs
index f7b92c755..f7e42decb 100644
--- a/Win7Troubleshoot/DownloadLinks.cs
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/DownloadLinks.cs
@@ -1,6 +1,6 @@
-namespace Win7Troubleshoot
+namespace System
{
- public static class DownloadLinks
+ internal static class DownloadLinks
{
public const string KB3063858_x64 = "https://www.microsoft.com/{0}/download/details.aspx?id=47442";
public const string KB3063858_x86 = "https://www.microsoft.com/{0}/download/details.aspx?id=47409";
diff --git a/Win7Troubleshoot/EnvironmentEx.cs b/System.Application.SteamTools.Tools.Win7Troubleshoot/EnvironmentEx.cs
similarity index 98%
rename from Win7Troubleshoot/EnvironmentEx.cs
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/EnvironmentEx.cs
index e136044d5..33c736eb4 100644
--- a/Win7Troubleshoot/EnvironmentEx.cs
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/EnvironmentEx.cs
@@ -1,9 +1,8 @@
// https://www.codeproject.com/questions/641314/check-64-or-32-bit-in-net-3-5
-using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
-namespace Win7Troubleshoot
+namespace System
{
public static class EnvironmentEx
{
diff --git a/Win7Troubleshoot/Program.cs b/System.Application.SteamTools.Tools.Win7Troubleshoot/Program.cs
similarity index 96%
rename from Win7Troubleshoot/Program.cs
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/Program.cs
index d7119718f..6a13c0a07 100644
--- a/Win7Troubleshoot/Program.cs
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/Program.cs
@@ -9,25 +9,22 @@
* 在配置文件 exe.config supportedRuntime 项中可添加net4x的支持
*/
-using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
+using System.Properties;
using System.Threading;
using System.Windows.Forms;
-using Win7Troubleshoot.Properties;
-namespace Win7Troubleshoot
+namespace System
{
static class Program
{
internal static Mutex? mutex;
[STAThread]
-#pragma warning disable IDE0060 // 删除未使用的参数
static void Main(string[] args)
-#pragma warning restore IDE0060 // 删除未使用的参数
{
mutex = new Mutex(true, Process.GetCurrentProcess().ProcessName, out var isNotRunning);
if (isNotRunning)
@@ -145,7 +142,6 @@ namespace Win7Troubleshoot
}
else if (Environment.OSVersion.Version.Minor == 3) // NT 6.3 / Win8.1 / WinServer 2012 R2
{
-
}
else
{
diff --git a/Win7Troubleshoot/Properties/SR.Designer.cs b/System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.Designer.cs
similarity index 96%
rename from Win7Troubleshoot/Properties/SR.Designer.cs
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.Designer.cs
index 3b95bafff..29ae259fc 100644
--- a/Win7Troubleshoot/Properties/SR.Designer.cs
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.Designer.cs
@@ -8,7 +8,7 @@
//
//------------------------------------------------------------------------------
-namespace Win7Troubleshoot.Properties {
+namespace System.Properties {
using System;
@@ -39,7 +39,7 @@ namespace Win7Troubleshoot.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Win7Troubleshoot.Properties.SR", typeof(SR).Assembly);
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Properties.SR", typeof(SR).Assembly);
resourceMan = temp;
}
return resourceMan;
diff --git a/Win7Troubleshoot/Properties/SR.en.resx b/System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.en.resx
similarity index 100%
rename from Win7Troubleshoot/Properties/SR.en.resx
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.en.resx
diff --git a/Win7Troubleshoot/Properties/SR.resx b/System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.resx
similarity index 100%
rename from Win7Troubleshoot/Properties/SR.resx
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.resx
diff --git a/Win7Troubleshoot/Properties/SR.zh-Hant.resx b/System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.zh-Hant.resx
similarity index 100%
rename from Win7Troubleshoot/Properties/SR.zh-Hant.resx
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/Properties/SR.zh-Hant.resx
diff --git a/Win7Troubleshoot/StringExtensions.cs b/System.Application.SteamTools.Tools.Win7Troubleshoot/StringExtensions.cs
similarity index 99%
rename from Win7Troubleshoot/StringExtensions.cs
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/StringExtensions.cs
index b8a8a1ede..f0bbd8690 100644
--- a/Win7Troubleshoot/StringExtensions.cs
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/StringExtensions.cs
@@ -1,7 +1,6 @@
using System.Diagnostics;
using System.Text;
-// ReSharper disable once CheckNamespace
namespace System
{
public static partial class StringExtensions
diff --git a/Win7Troubleshoot/Win7Troubleshoot.csproj b/System.Application.SteamTools.Tools.Win7Troubleshoot/System.Application.SteamTools.Tools.Win7Troubleshoot.csproj
similarity index 96%
rename from Win7Troubleshoot/Win7Troubleshoot.csproj
rename to System.Application.SteamTools.Tools.Win7Troubleshoot/System.Application.SteamTools.Tools.Win7Troubleshoot.csproj
index fc8a992f3..c8ea7d260 100644
--- a/Win7Troubleshoot/Win7Troubleshoot.csproj
+++ b/System.Application.SteamTools.Tools.Win7Troubleshoot/System.Application.SteamTools.Tools.Win7Troubleshoot.csproj
@@ -6,6 +6,7 @@
net35
..\System.Application.SteamTools.Client.Desktop.Avalonia.App\Assets\Icon.ico
Steam++.Win7
+ System
..\System.Application.SteamTools.Client.Desktop.Avalonia.App\Properties\app.manifest
diff --git a/System.Common.CoreLib/MediaTypeNames.cs b/System.Common.CoreLib/MediaTypeNames.cs
index bcc50c2f4..29a821d58 100644
--- a/System.Common.CoreLib/MediaTypeNames.cs
+++ b/System.Common.CoreLib/MediaTypeNames.cs
@@ -50,5 +50,9 @@
public const string IMAGE = "image/*";
public const string APK = "application/vnd.android.package-archive";
+
+ public const string XML = "text/xml";
+
+ public const string XML_APP = "application/xml";
}
}
\ No newline at end of file
diff --git a/System.Common.CoreLib/Net/Http/HttpService.cs b/System.Common.CoreLib/Net/Http/HttpService.cs
index bb5c16efb..40bfd6a73 100644
--- a/System.Common.CoreLib/Net/Http/HttpService.cs
+++ b/System.Common.CoreLib/Net/Http/HttpService.cs
@@ -5,13 +5,16 @@ namespace System.Net.Http
public abstract class HttpService
{
protected readonly ILogger logger;
+ protected readonly IHttpPlatformHelper http_helper;
readonly IHttpClientFactory _clientFactory;
public HttpService(
ILogger logger,
+ IHttpPlatformHelper http_helper,
IHttpClientFactory clientFactory)
{
this.logger = logger;
+ this.http_helper = http_helper;
_clientFactory = clientFactory;
}
diff --git a/System.Common.CoreLib/Serializable.cs b/System.Common.CoreLib/Serializable.cs
index bd7389940..c2c978c57 100644
--- a/System.Common.CoreLib/Serializable.cs
+++ b/System.Common.CoreLib/Serializable.cs
@@ -12,10 +12,10 @@ using SJsonSerializerOptions = System.Text.Json.JsonSerializerOptions;
namespace System
{
///
- /// 序列化、反序列化,模型类可继承此类
+ /// 序列化、反序列化 助手类
///
[Serializable]
- public abstract partial class Serializable
+ public static class Serializable
{
///
/// 序列化程式实现种类
@@ -220,10 +220,14 @@ namespace System
}
}
+ public interface ICloneableSerializable
+ {
+ }
+
public static class SerializableExtensions
{
///
- public static T Clone(this T obj) where T : Serializable => Serializable.Clone(obj);
+ public static T Clone(this T obj) where T : ICloneableSerializable => Serializable.Clone(obj);
///
/// 将 [序列化程式实现种类] 转换为 [JSON 序列化程式实现种类]
diff --git a/System.Common.DesktopLib/Application/Services/IDesktopPlatformService.cs b/System.Common.DesktopLib/Application/Services/IDesktopPlatformService.cs
deleted file mode 100644
index a16187fda..000000000
--- a/System.Common.DesktopLib/Application/Services/IDesktopPlatformService.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System.Diagnostics;
-using System.Windows;
-
-namespace System.Application.Services
-{
- public interface IDesktopPlatformService
- {
- ///
- void SetResizeMode(IntPtr hWnd, ResizeMode value);
-
- ///
- /// 获取CPU名称
- ///
- ///
- string[] GetCPUName();
-
- ///
- /// 获取GPU名称
- ///
- ///
- string[] GetGPUName();
-
- ///
- /// 当前操作系统是否为 Windows Server 版本
- ///
- ///
- bool IsWindowsServer();
-
- string GetOSVersion();
-
- bool Is64Bit(Process process);
-
- ///
- /// 是否是管理员权限
- ///
- ///
- bool IsAdministrator();
-
- ///
- /// 启用 Fluent Design System 模糊窗口样式
- ///
- ///
- void Enable_Fluent_Design_System_Style_Blur(IntPtr hWnd);
-
- string NETFrameworkDescription { get; }
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Application/Services/Implementation/DesktopPlatformServiceImpl.cs b/System.Common.DesktopLib/Application/Services/Implementation/DesktopPlatformServiceImpl.cs
deleted file mode 100644
index 40648c86b..000000000
--- a/System.Common.DesktopLib/Application/Services/Implementation/DesktopPlatformServiceImpl.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System.Diagnostics;
-using System.Windows;
-
-namespace System.Application.Services.Implementation
-{
- public class DesktopPlatformServiceImpl : IDesktopPlatformService
- {
- public virtual void SetResizeMode(IntPtr hWnd, ResizeMode value)
- {
- }
-
- public virtual string[] GetCPUName()
- {
- return new[] { string.Empty };
- }
-
- public virtual string[] GetGPUName()
- {
- return new[] { string.Empty };
- }
-
- public virtual bool IsWindowsServer()
- {
- return false;
- }
-
- public virtual string GetOSVersion()
- {
- return Environment.OSVersion.VersionString;
- }
-
- protected virtual bool Is64Bit_(Process process)
- {
- return false;
- }
-
- public bool Is64Bit(Process process)
- {
- if (!Environment.Is64BitOperatingSystem)
- return false;
- return Is64Bit_(process);
- }
-
- public virtual bool IsAdministrator()
- {
- return false;
- }
-
- public virtual void Enable_Fluent_Design_System_Style_Blur(IntPtr hWnd)
- {
- }
-
- public virtual string NETFrameworkDescription => "";
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs b/System.Common.DesktopLib/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs
deleted file mode 100644
index 777330f65..000000000
--- a/System.Common.DesktopLib/Application/Services/Implementation/WindowsDesktopPlatformServiceImpl.cs
+++ /dev/null
@@ -1,363 +0,0 @@
-#pragma warning disable CA1416 // 验证平台兼容性
-#pragma warning disable CA1806 // 不要忽略方法结果
-using Microsoft.Win32;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Management;
-using System.Runtime.InteropServices;
-using System.Security.Principal;
-using System.Windows;
-
-namespace System.Application.Services.Implementation
-{
- internal sealed class WindowsDesktopPlatformServiceImpl : DesktopPlatformServiceImpl
- {
- #region 窗口右上角的三个按钮(最小化,最大化,关闭)
-
- // https://stackoverflow.com/questions/339620/how-do-i-remove-minimize-and-maximize-from-a-resizable-window-in-wpf
- // https://blog.magnusmontin.net/2014/11/30/disabling-or-hiding-the-minimize-maximize-or-close-button-of-a-wpf-window/
-
- public const int MF_BYCOMMAND = 0x00000000;
- public const int SC_CLOSE = 0xF060;
- public const int SC_MINIMIZE = 0xF020;
- public const int SC_MAXIMIZE = 0xF030;
-
- [DllImport("user32.dll")]
- public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);
-
- [DllImport("user32.dll")]
- public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
-
- public const int GWL_STYLE = -16,
- WS_MAXIMIZEBOX = 0x10000,
- WS_MINIMIZEBOX = 0x20000;
-
- [DllImport("user32.dll")]
- public extern static int GetWindowLong(IntPtr hwnd, int index);
-
- [DllImport("user32.dll")]
- public extern static int SetWindowLong(IntPtr hwnd, int index, int value);
-
- public const int WS_SYSMENU = 0x80000;
-
- public static void EnableMinimizeButton(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) | WS_MINIMIZEBOX);
- }
-
- public static void EnableMaximizeButton(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) | WS_MAXIMIZEBOX);
- }
-
- public static void ShowMinimizeAndMaximizeButtons(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) | WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
- }
-
- public static void ShowAllButtons(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) | WS_SYSMENU);
- }
-
- public static void HideMinimizeAndMaximizeButtons(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX);
- }
-
- public static void DisableMinimizeButton(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~WS_MINIMIZEBOX);
- }
-
- public static void DisableMaximizeButton(IntPtr hWnd)
- {
- SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX);
- }
-
- public override void SetResizeMode(IntPtr hWnd, ResizeMode value)
- {
- switch (value)
- {
- case ResizeMode.NoResize:
- DeleteMenu(GetSystemMenu(hWnd, false), SC_MAXIMIZE, MF_BYCOMMAND);
- DeleteMenu(GetSystemMenu(hWnd, false), SC_MINIMIZE, MF_BYCOMMAND);
- HideMinimizeAndMaximizeButtons(hWnd);
- break;
- case ResizeMode.CanMinimize:
- DeleteMenu(GetSystemMenu(hWnd, false), SC_MAXIMIZE, MF_BYCOMMAND);
- DisableMaximizeButton(hWnd);
- break;
- }
- }
-
- #endregion
-
- #region 硬件信息
-
- static IEnumerable GetValueByManagementClass_(string managementClassPath, string propertiesName)
- {
- using var managementClass = new ManagementClass(managementClassPath);
- using var instances = managementClass.GetInstances();
- foreach (var instance in instances)
- {
- var value = instance.Properties[propertiesName].Value?.ToString()?.Trim();
- if (string.IsNullOrWhiteSpace(value)) continue;
- yield return value;
- }
- }
-
- public static string[] GetValueByManagementClass(string managementClassPath, string propertiesName)
- => new HashSet(GetValueByManagementClass_(managementClassPath, propertiesName)).ToArray();
-
- public override string[] GetCPUName() => GetValueByManagementClass("Win32_Processor", "Name");
-
- public override string[] GetGPUName() => GetValueByManagementClass("Win32_VideoController", "Name");
-
- #endregion
-
- #region OS
-
- const int OS_ANYSERVER = 29;
-
- ///
- /// https://msdn.microsoft.com/en-us/library/bb773795%28v=VS.85%29.aspx?f=255&MSPPError=-2147217396
- ///
- ///
- ///
- [DllImport("shlwapi.dll", SetLastError = true, EntryPoint = "#437")]
- static extern bool IsOS(int os);
-
- static bool IsWindowsServer_() => IsOS(OS_ANYSERVER);
-
- static readonly Lazy mIsWindowsServer = new Lazy(IsWindowsServer_);
-
- public override bool IsWindowsServer() => mIsWindowsServer.Value;
-
- static string GetOSVersion_()
- {
- try
- {
- const string subkey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
- using var ndpKey = Registry.LocalMachine.OpenSubKey(subkey);
- var productName = ndpKey?.GetValue("ProductName")?.ToString();
- var major = Environment.OSVersion.Version.Major.ToString();
- var minor = Environment.OSVersion.Version.Minor.ToString();
- var build = Environment.OSVersion.Version.Build.ToString();
- var revision = ndpKey?.GetValue("UBR")?.ToString();
- if (string.IsNullOrEmpty(revision))
- {
- var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86),
- "kernel32.dll");
- revision = File.Exists(path)
- ? FileVersionInfo.GetVersionInfo(path).ProductPrivatePart.ToString()
- : null;
- }
- var releaseId = ndpKey?.GetValue("ReleaseId")?.ToString();
- if (int.TryParse(releaseId, out var releaseIdInt32) && releaseIdInt32 >= 2009)
- {
- var displayVersion = ndpKey?.GetValue("DisplayVersion")?.ToString();
- if (!string.IsNullOrWhiteSpace(displayVersion))
- releaseId = displayVersion;
- }
- var servicePack = Environment.OSVersion.ServicePack;
- var additional = string.IsNullOrEmpty(servicePack) ? null : " " + servicePack;
- if (releaseId != null)
- additional += " (" + releaseId + ")";
- return $"{productName} {major}.{minor}.{build}{(string.IsNullOrEmpty(revision) ? null : "." + revision)}{additional}";
- }
- catch (Exception)
- {
- return Environment.OSVersion.VersionString;
- }
- }
-
- static readonly Lazy mGetOSVersion = new Lazy(GetOSVersion_);
-
- public override string GetOSVersion() => mGetOSVersion.Value;
-
- #endregion
-
- #region Process
-
- [DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
-
- protected override bool Is64Bit_(Process process)
- {
- // if this method is not available in your version of .NET, use GetNativeSystemInfo via P/Invoke instead
- if (!IsWow64Process(process.Handle, out var isWow64))
- throw new Win32Exception("function fails, the return value is zero. To get extended error information, call GetLastError.");
- return !isWow64;
- }
-
- #endregion
-
- #region Administrator
-
- static readonly Lazy mIsAdministrator = new Lazy(IsAdministrator_);
-
- static bool IsAdministrator_()
- => new WindowsPrincipal(WindowsIdentity.GetCurrent())
- .IsInRole(WindowsBuiltInRole.Administrator);
-
- ///
- /// 是否是管理员权限
- ///
- ///
- public override bool IsAdministrator() => mIsAdministrator.Value;
-
- #endregion
-
- #region Fluent Design System
-
- public override void Enable_Fluent_Design_System_Style_Blur(IntPtr hWnd)
- {
- WindowComposition.Set(hWnd, AccentState.ACCENT_ENABLE_BLURBEHIND, AccentFlags.DrawAllBorders);
- }
-
- internal static class WindowComposition
- {
- [DllImport("user32.dll")]
- internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
-
- internal static void Set(IntPtr hWnd, AccentState accentState, AccentFlags accentFlags)
- {
- var accent = new AccentPolicy
- {
- AccentState = accentState,
- AccentFlags = accentFlags,
- };
- var accentStructSize = Marshal.SizeOf(accent);
- var accentPtr = Marshal.AllocHGlobal(accentStructSize);
- Marshal.StructureToPtr(accent, accentPtr, false);
-
- var data = new WindowCompositionAttributeData
- {
- Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
- SizeOfData = accentStructSize,
- Data = accentPtr,
- };
- SetWindowCompositionAttribute(hWnd, ref data);
-
- Marshal.FreeHGlobal(accentPtr);
- }
- }
-
- internal enum AccentState
- {
- ACCENT_DISABLED = 1,
- ACCENT_ENABLE_GRADIENT = 0,
- ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
- ACCENT_ENABLE_BLURBEHIND = 3,
- ACCENT_INVALID_STATE = 4
- }
-
- [Flags]
- internal enum AccentFlags
- {
- DrawLeftBorder = 0x20,
- DrawTopBorder = 0x40,
- DrawRightBorder = 0x80,
- DrawBottomBorder = 0x100,
- DrawTopLeftBorder = (DrawLeftBorder | DrawTopBorder),
- DrawTopRightBorder = (DrawTopBorder | DrawRightBorder),
- DrawBottomLeftBorder = (DrawLeftBorder | DrawBottomBorder),
- DrawBottomRightBorder = (DrawRightBorder | DrawBottomBorder),
- DrawAllBorders = (DrawLeftBorder | DrawTopBorder | DrawRightBorder | DrawBottomBorder)
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct AccentPolicy
- {
- public AccentState AccentState;
- public AccentFlags AccentFlags;
- public int GradientColor;
- public int AnimationId;
- }
-
- internal enum WindowCompositionAttribute
- {
- WCA_UNDEFINED = 0,
- WCA_NCRENDERING_ENABLED = 1,
- WCA_NCRENDERING_POLICY = 2,
- WCA_TRANSITIONS_FORCEDISABLED = 3,
- WCA_ALLOW_NCPAINT = 4,
- WCA_CAPTION_BUTTON_BOUNDS = 5,
- WCA_NONCLIENT_RTL_LAYOUT = 6,
- WCA_FORCE_ICONIC_REPRESENTATION = 7,
- WCA_EXTENDED_FRAME_BOUNDS = 8,
- WCA_HAS_ICONIC_BITMAP = 9,
- WCA_THEME_ATTRIBUTES = 10,
- WCA_NCRENDERING_EXILED = 11,
- WCA_NCADORNMENTINFO = 12,
- WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
- WCA_VIDEO_OVERLAY_ACTIVE = 14,
- WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
- WCA_DISALLOW_PEEK = 16,
- WCA_CLOAK = 17,
- WCA_CLOAKED = 18,
- WCA_ACCENT_POLICY = 19,
- WCA_FREEZE_REPRESENTATION = 20,
- WCA_EVER_UNCLOAKED = 21,
- WCA_VISUAL_OWNER = 22,
- WCA_LAST = 23
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct WindowCompositionAttributeData
- {
- public WindowCompositionAttribute Attribute;
- public IntPtr Data;
- public int SizeOfData;
- }
-
- #endregion
-
- #region NETFramework Win32 Registry
-
- static string GetDescription(int releaseKey) => releaseKey switch
- {
- // https://docs.microsoft.com/zh-cn/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
- 378389 => ".NET Framework 4.5",
- 378675 => "使用 Windows 8.1 或 Windows Server 2012 R2 安装的 .NET Framework 4.5.1",
- 378758 => "安装在 Windows 8、Windows 7 SP1 或 Windows Vista SP2 上的 .NET Framework 4.5.1",
- 379893 => ".NET Framework 4.5.2",
- 393295 => "随 Windows 10 一起安装的 .NET Framework 4.6",
- 393297 => "在所有其他 Windows 操作系统版本上安装的 .NET Framework 4.6",
- 394254 => "Windows 10 上安装的 .NET Framework 4.6.1",
- 394271 => "在所有其他 Windows 操作系统版本上安装的 .NET Framework 4.6.1",
- 394802 => "在 Windows 10 周年更新上安装的 .NET Framework 4.6.2",
- 394806 => "在所有其他 Windows 操作系统版本上安装的 .NET Framework 4.6.2",
- 460798 => "在 Windows 10 创意者更新上安装的 .NET Framework 4.7",
- 460805 => "在所有其他 Windows 操作系统版本上安装的 .NET Framework 4.7",
- 461308 => ".NET framework 4.7.1 Windows 10 秋季创意者 Update 上安装",
- 461310 => ".NET framework 4.7.1 所有其他 Windows 操作系统版本上安装",
- 461808 => "在 Windows 10 2018 年 4 月更新和 Windows Server 版本 1803 上安装的 .NET Framework 4.7.2 ",
- 461814 => "在除 Windows 10 2018 年 4 月更新和 Windows Server 版本 1803 之外的所有 Windows 操作系统上安装的 .NET Framework 4.7.2",
- 528040 => "在 Windows 10 2019 年 5 月更新和 Windows 10 2019 年 11 月更新上安装的 .NET Framework 4.8",
- 528372 => "在 Windows 10 2020 年 5 月更新上安装的 .NET Framework 4.8",
- 528049 => "在所有其他 Windows 操作系统(包括早期版本的 Windows 10 操作系统)上安装的 .NET Framework 4.8",
- _ => "未知版本" + (releaseKey > 528049 ? "(高于 .NET Framework 4.8)" : ""),
- };
-
- static readonly Lazy mNETFrameworkDescription = new Lazy(() =>
- {
- const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full";
- using var ndpKey = Registry.LocalMachine.OpenSubKey(subkey);
- var value = ndpKey?.GetValue("Release")?.ToString();
- if (!int.TryParse(value, out var valueInt32)) return string.Empty;
- return GetDescription(valueInt32);
- });
-
- public override string NETFrameworkDescription => mNETFrameworkDescription.Value;
-
- #endregion
- }
-}
-#pragma warning restore CA1416 // 验证平台兼容性
-#pragma warning restore CA1806 // 不要忽略方法结果
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Application/UI/DragDropUtil.cs b/System.Common.DesktopLib/Application/UI/DragDropUtil.cs
deleted file mode 100644
index 660b4e757..000000000
--- a/System.Common.DesktopLib/Application/UI/DragDropUtil.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using Avalonia.Input;
-using System.Collections.Generic;
-
-namespace System.Application.UI
-{
- ///
- /// 拖拽功能工具类
- /// https://github.com/AvaloniaUI/Avalonia/blob/0.10.0-preview6/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
- ///
- public static class DragDropUtil
- {
- public static void InitDragDrop(this IOnDragDropListener listener,
- InputElement element)
- {
- element.PointerPressed += async (_, e)
- => await DragDrop.DoDragDrop(e, new DataObject(), DragDropEffects.Copy);
- element.AddHandler(DragDrop.DropEvent, Drop);
- element.AddHandler(DragDrop.DragOverEvent, DragOver);
-
- void DragOver(object? s, DragEventArgs? e)
- {
- if (e?.Data == null) return;
- listener.DragOver(s is InputElement el ? el : element, e);
- }
-
- void Drop(object? s, DragEventArgs? e)
- {
- if (e?.Data == null) return;
- listener.Drop(s is InputElement el ? el : element, e);
- }
- }
-
- public static void InitDragDrop(this IOnDragDropListener listener,
- IEnumerable elements)
- {
- foreach (var element in elements)
- {
- listener.InitDragDrop(element);
- }
- }
-
- public static void InitDragDrop(this IOnDragDropListener listener,
- params InputElement[] elements)
- {
- IEnumerable elements_ = elements;
- listener.InitDragDrop(elements_);
- }
-
- public interface IOnDragDropListener
- {
- void DragOver(InputElement sender, DragEventArgs e)
- {
- // Only allow Copy or Link as Drop Operations.
- e.DragEffects &= (DragDropEffects.Copy | DragDropEffects.Link);
-
- // Only allow if the dragged data contains text or filenames.
- if (!e.Data.Contains(DataFormats.Text)
- && !e.Data.Contains(DataFormats.FileNames))
- e.DragEffects = DragDropEffects.None;
- }
-
- void Drop(InputElement sender, DragEventArgs e)
- {
- if (e.Data.Contains(DataFormats.Text))
- {
- var text = e.Data.GetText();
- if (text != null)
- {
- DropText(sender, text);
- }
- }
- else if (e.Data.Contains(DataFormats.FileNames))
- {
- var fileNames = e.Data.GetFileNames();
- if (fileNames != null)
- {
- DropFileNames(sender, fileNames);
- }
- }
- }
-
- ///
- /// 拖拽文本
- ///
- ///
- ///
- void DropText(InputElement sender, string text);
-
- ///
- /// 拖拽路径,路径可能是文件也可能是文件夹
- ///
- ///
- ///
- void DropFileNames(InputElement sender, IEnumerable fileNames);
- }
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Application/UI/TextBoxUtil.cs b/System.Common.DesktopLib/Application/UI/TextBoxUtil.cs
deleted file mode 100644
index 4fb56d5fa..000000000
--- a/System.Common.DesktopLib/Application/UI/TextBoxUtil.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-//using Avalonia;
-//using Avalonia.Controls;
-//using AvaloniaEdit;
-//using System.Reflection;
-
-//namespace System.Application.UI
-//{
-// ///
-// /// 文本框工具类
-// ///
-// public static class TextBoxUtil
-// {
-// #region TextBox Console
-
-// public interface IConsoleView
-// {
-// TextEditor TbConsole { get; }
-// }
-
-// public static void WriteLine(this IConsoleView view, string s, bool scrollToEnd = true)
-// {
-// view.TbConsole.AppendText(s);
-// view.TbConsole.AppendText(Environment.NewLine);
-// if (scrollToEnd) view.TbConsole.ScrollToEnd();
-// }
-
-// public static void Log(this IConsoleView view, string tag, string s, bool scrollToEnd = true)
-// {
-// view.TbConsole.AppendText(DateTime.Now.ToString(DateTimeFormat.Debug2));
-// view.TbConsole.AppendText(" ");
-// view.TbConsole.AppendText(tag);
-// view.TbConsole.AppendText(": ");
-// view.TbConsole.AppendText(s);
-// view.TbConsole.AppendText(Environment.NewLine);
-// if (scrollToEnd) view.TbConsole.ScrollToEnd();
-// }
-
-// public static void InitConsole(this IConsoleView view, string projectName)
-// {
-// void WriteLine(string s) => view.WriteLine(s, false);
-// var version = Assembly.GetCallingAssembly().GetName().Version?.ToString();
-// UnityConsoleOutputHead.Write(WriteLine, projectName, version);
-// view.TbConsole.ScrollToEnd();
-// }
-
-// #endregion
-
-// ///
-// /// https://github.com/AvaloniaUI/Avalonia/issues/418#issuecomment-201916167
-// ///
-// ///
-// ///
-// public static void AddTextChangedListener(this TextBox textBox, Action listener)
-// => textBox.GetObservable(TextBox.TextProperty).Subscribe(listener);
-
-// public static void AddTextChangedListener(this TextEditor textEditor, Action listener)
-// => textEditor.TextChanged += (_, _) => listener(textEditor.Text);
-// }
-//}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/ServiceCollectionExtensions.cs b/System.Common.DesktopLib/ServiceCollectionExtensions.cs
deleted file mode 100644
index 041f0a1ed..000000000
--- a/System.Common.DesktopLib/ServiceCollectionExtensions.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Application.Services;
-using System.Application.Services.Implementation;
-
-// ReSharper disable once CheckNamespace
-namespace Microsoft.Extensions.DependencyInjection
-{
- public static class ServiceCollectionExtensions
- {
- public static IServiceCollection AddDesktopPlatformService(this IServiceCollection services)
- {
- if (DI.Platform == Platform.Windows)
- {
- services.AddSingleton();
- }
- else
- {
- services.AddSingleton();
- }
- return services;
- }
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/System.Common.DesktopLib.csproj b/System.Common.DesktopLib/System.Common.DesktopLib.csproj
deleted file mode 100644
index 6713333e6..000000000
--- a/System.Common.DesktopLib/System.Common.DesktopLib.csproj
+++ /dev/null
@@ -1,38 +0,0 @@
-
-
-
- net5.0
- System
-
-
-
-
- Properties\AssemblyInfo.cs
-
-
- Properties\InternalsVisibleTo.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MessageBox_Avalonia
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Windows/MessageBox.cs b/System.Common.DesktopLib/Windows/MessageBox.cs
deleted file mode 100644
index fbf575a0d..000000000
--- a/System.Common.DesktopLib/Windows/MessageBox.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-extern alias MessageBox_Avalonia;
-
-using Avalonia.Controls;
-using MessageBox_Avalonia::MessageBox.Avalonia;
-using MessageBox_Avalonia::MessageBox.Avalonia.BaseWindows.Base;
-using MessageBox_Avalonia::MessageBox.Avalonia.DTO;
-using MessageBox_Avalonia::MessageBox.Avalonia.Enums;
-using System.Reflection;
-using System.Threading.Tasks;
-
-namespace System.Windows
-{
- ///
- /// 显示消息框。
- ///
- public static class MessageBox
- {
- static ButtonEnum GetButtonEnum(this MessageBoxButton button) => button switch
- {
- MessageBoxButton.OK => ButtonEnum.Ok,
- MessageBoxButton.OKCancel => ButtonEnum.OkCancel,
- MessageBoxButton.YesNo => ButtonEnum.YesNo,
- MessageBoxButton.YesNoCancel => ButtonEnum.YesNoCancel,
-#pragma warning disable CS0618 // 类型或成员已过时
- MessageBoxButton.OkAbort => ButtonEnum.OkAbort,
- MessageBoxButton.YesNoAbort => ButtonEnum.YesNoAbort,
-#pragma warning restore CS0618 // 类型或成员已过时
- _ => throw new ArgumentOutOfRangeException(nameof(button), $"value: {button}"),
- };
-
- static Icon GetIcon(this MessageBoxImage icon) => icon switch
- {
- MessageBoxImage.Asterisk => Icon.Info,
- MessageBoxImage.Error => Icon.Error,
- MessageBoxImage.Exclamation => Icon.Warning,
- MessageBoxImage.None => Icon.None,
-#pragma warning disable CS0618 // 类型或成员已过时
- MessageBoxImage.Question => Icon.Info,
- MessageBoxImage.Battery => Icon.Battery,
- MessageBoxImage.Database => Icon.Database,
- MessageBoxImage.Folder => Icon.Folder,
- MessageBoxImage.Forbidden => Icon.Forbidden,
- MessageBoxImage.Plus => Icon.Plus,
- MessageBoxImage.Setting => Icon.Setting,
- MessageBoxImage.SpeakerLess => Icon.SpeakerLess,
- MessageBoxImage.SpeakerMore => Icon.SpeakerMore,
- MessageBoxImage.Stop2 => Icon.Stop,
- MessageBoxImage.Stopwatch => Icon.Stopwatch,
- MessageBoxImage.Wifi => Icon.Wifi,
-#pragma warning restore CS0618 // 类型或成员已过时
- _ => throw new ArgumentOutOfRangeException(nameof(icon), $"value: {icon}"),
- };
-
- static MessageBoxResult GetResult(this ButtonResult result) => result switch
- {
- ButtonResult.Ok => MessageBoxResult.OK,
- ButtonResult.Yes => MessageBoxResult.Yes,
- ButtonResult.No => MessageBoxResult.No,
-#pragma warning disable CS0618 // 类型或成员已过时
- ButtonResult.Abort => MessageBoxResult.Abort,
-#pragma warning restore CS0618 // 类型或成员已过时
- ButtonResult.Cancel => MessageBoxResult.Cancel,
- ButtonResult.None => MessageBoxResult.None,
- _ => throw new ArgumentOutOfRangeException(nameof(result), $"value: {result}"),
- };
-
- ///
- /// 显示一个消息框,该消息框包含消息、标题栏标题、按钮和图标,并且返回结果。
- ///
- /// 一个 ,用于指定要显示的文本。
- /// 一个 ,用于指定要显示的标题栏标题。
- /// 一个 值,用于指定要显示哪个按钮或哪些按钮。
- /// 一个 值,用于指定要显示的图标。
- /// 一个 值,用于指定用户单击了哪个消息框按钮。
- public static async Task ShowAsync(
- string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon)
- {
- var parms = new MessageBoxStandardParams
- {
- ButtonDefinitions = button.GetButtonEnum(),
- ContentTitle = caption,
- ContentMessage = messageBoxText,
- Icon = icon.GetIcon(),
- Style = Style.None,
- WindowStartupLocation = WindowStartupLocation.CenterScreen,
- };
- var msBoxStandardWindow = MessageBoxManager.GetMessageBoxStandardWindow(parms);
- var window = GetWindow(msBoxStandardWindow);
- if (window != null)
- {
- window.Topmost = true;
- window.SetResizeMode(ResizeMode.NoResize);
- window.SetDefaultFontFamily();
- }
- var result = await msBoxStandardWindow.Show();
- return GetResult(result);
- }
-
- static Window? GetWindow(IMsBoxWindow window)
- {
- var _window = window.GetType().GetField("_window", BindingFlags.NonPublic | BindingFlags.Instance);
- if (_window != null && _window.FieldType.IsSubclassOf(typeof(Window)))
- {
- if (_window.GetValue(window) is Window w)
- {
- return w;
- }
- }
- return null;
- }
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Windows/MessageBoxButton.cs b/System.Common.DesktopLib/Windows/MessageBoxButton.cs
deleted file mode 100644
index 2fe259fbf..000000000
--- a/System.Common.DesktopLib/Windows/MessageBoxButton.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace System.Windows
-{
- ///
- /// 指定显示在消息框上的按钮。 用作 .Show... 方法的参数。
- ///
- public enum MessageBoxButton
- {
- OK = 0,
- OKCancel = 1,
- YesNo = 4,
- YesNoCancel = 3,
-
- [Obsolete("non-standard api")]
- OkAbort = 1000,
- [Obsolete("non-standard api")]
- YesNoAbort = 1001,
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Windows/MessageBoxImage.cs b/System.Common.DesktopLib/Windows/MessageBoxImage.cs
deleted file mode 100644
index bfe803f8a..000000000
--- a/System.Common.DesktopLib/Windows/MessageBoxImage.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-namespace System.Windows
-{
- ///
- /// 指定消息框所显示的图标。
- ///
- public enum MessageBoxImage
- {
-#pragma warning disable CA1069 // 不应复制枚举值
- Asterisk = 64,
- Error = 16,
- Exclamation = 48,
- Hand = 16,
- Information = 64,
- None = 0,
- [Obsolete("The question mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the question mark symbol with a help information symbol. Therefore, do not use this question mark symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.")]
- Question = 32,
- Stop = 16,
- Warning = 48,
-
- [Obsolete("non-standard api")]
- Battery = 1000,
- [Obsolete("non-standard api")]
- Database,
- [Obsolete("non-standard api")]
- Folder,
- [Obsolete("non-standard api")]
- Forbidden,
- [Obsolete("non-standard api")]
- Plus,
- [Obsolete("non-standard api")]
- Setting,
- [Obsolete("non-standard api")]
- SpeakerLess,
- [Obsolete("non-standard api")]
- SpeakerMore,
- [Obsolete("non-standard api")]
- Stop2,
- [Obsolete("non-standard api")]
- Stopwatch,
- [Obsolete("non-standard api")]
- Wifi,
-#pragma warning restore CA1069 // 不应复制枚举值
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Windows/MessageBoxResult.cs b/System.Common.DesktopLib/Windows/MessageBoxResult.cs
deleted file mode 100644
index 04347710e..000000000
--- a/System.Common.DesktopLib/Windows/MessageBoxResult.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace System.Windows
-{
- ///
- /// 指定用户单击的消息框按钮。 由 .Show... 方法返回。
- ///
- public enum MessageBoxResult
- {
- Cancel = 2,
- No = 7,
- None = 0,
- OK = 1,
- Yes = 6,
-
- [Obsolete("non-standard api")]
- Abort = 1000,
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Windows/ResizeMode.cs b/System.Common.DesktopLib/Windows/ResizeMode.cs
deleted file mode 100644
index 5046ba008..000000000
--- a/System.Common.DesktopLib/Windows/ResizeMode.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-namespace System.Windows
-{
- ///
- /// 指定是否可以调整窗口大小,并在可调整大小的情况下指定如何调整窗口大小。由 SetResizeMode 使用。
- ///
- public enum ResizeMode
- {
- ///
- /// 用户无法调整窗口的大小。 不显示 "最大化" 和 "最小化" 框。
- ///
- NoResize,
-
- ///
- /// 用户只能最小化窗口并从任务栏还原。 同时显示 "最小化" 和 "最大化" 框,但只启用 "最小化" 框。
- ///
- CanMinimize,
-
- ///
- /// 用户可以通过使用 "最小化" 和 "最大化" 框以及围绕窗口的可拖动轮廓来完全调整窗口的大小。 显示和启用 "最小化" 和 "最大化" 框。 (默认) 。
- ///
- CanResize,
-
- ///
- /// 此选项具有与相同的功能 ,但会将 "调整手柄" 添加到窗口的右下角。
- ///
- [Obsolete("not implemented")]
- CanResizeWithGrip,
- }
-}
\ No newline at end of file
diff --git a/System.Common.DesktopLib/Windows/WpfCompatExtensions.cs b/System.Common.DesktopLib/Windows/WpfCompatExtensions.cs
deleted file mode 100644
index 559dbab5d..000000000
--- a/System.Common.DesktopLib/Windows/WpfCompatExtensions.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using System.Application.Services;
-using System.IO;
-using FontFamily = Avalonia.Media.FontFamily;
-using Window = Avalonia.Controls.Window;
-
-namespace System.Windows
-{
- ///
- /// 通过扩展兼容WPF部分API的内容
- ///
- public static partial class WpfCompatExtensions
- {
- static readonly Lazy lazy_has_msyh = new Lazy(() =>
- {
- if (DI.Platform == Platform.Windows)
- {
- var fontsPath = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
- var msyhFilePath = Path.Combine(fontsPath, "msyh.ttc");
- return File.Exists(msyhFilePath);
- }
- else
- {
- return false;
- }
- });
-
- public static bool HAS_FONT_MSYH => lazy_has_msyh.Value;
-
- public static void SetDefaultFontFamily(this Window window)
- {
- if (DI.Platform == Platform.Windows)
- {
- if (HAS_FONT_MSYH) // (版权、许可)不能在非WinOS上使用 微软雅黑字体,不可将字体嵌入程序
- {
- string name;
- var major = Environment.OSVersion.Version.Major;
- if (major > 6 || (major == 6 && Environment.OSVersion.Version.Minor >= 2))
- {
- name = "Microsoft YaHei UI";
- }
- else
- {
- name = "Microsoft YaHei";
- }
- window.FontFamily = new FontFamily(name);
- }
- }
- }
-
- ///
- /// 设置调整大小模式。
- ///
- ///
- ///
- public static void SetResizeMode(this Window window, ResizeMode value)
- {
- var p = DI.Get();
- switch (value)
- {
- case ResizeMode.NoResize:
- case ResizeMode.CanMinimize:
- window.CanResize = false;
- break;
- case ResizeMode.CanResize:
-#pragma warning disable CS0618 // 类型或成员已过时
- case ResizeMode.CanResizeWithGrip:
-#pragma warning restore CS0618 // 类型或成员已过时
- window.CanResize = true;
- break;
- }
- p.SetResizeMode(window.PlatformImpl.Handle.Handle, value);
- }
- }
-}
\ No newline at end of file