Merge branch 'develop' of https://github.com/rmbadmin/SteamTools into develop

This commit is contained in:
rmbgame
2021-02-22 03:02:15 +08:00
29 changed files with 743 additions and 21 deletions
+4
View File
@@ -1,4 +1,8 @@
<Project>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
+28 -7
View File
@@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Common.ClientLib", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Common.CoreLib", "System.Common.CoreLib\System.Common.CoreLib.csproj", "{E7468FDD-75F7-4B08-BA47-B715BBCFCC11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Common.DesktopLib", "System.Common.DesktopLib\System.Common.DesktopLib.csproj", "{F37D23AA-4EA9-4E07-9B3D-F966ABED046F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Common.ClientLib.Droid", "System.Common.ClientLib.Droid\System.Common.ClientLib.Droid.csproj", "{7C8D906E-426B-49AB-9072-178555370F62}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Common.ClientLib.iOS", "System.Common.ClientLib.iOS\System.Common.ClientLib.iOS.csproj", "{F8F6973C-5831-43D1-89C2-1AD543CE7408}"
@@ -59,6 +57,14 @@ 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}"
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}"
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}"
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -77,10 +83,6 @@ Global
{E7468FDD-75F7-4B08-BA47-B715BBCFCC11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7468FDD-75F7-4B08-BA47-B715BBCFCC11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7468FDD-75F7-4B08-BA47-B715BBCFCC11}.Release|Any CPU.Build.0 = Release|Any CPU
{F37D23AA-4EA9-4E07-9B3D-F966ABED046F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F37D23AA-4EA9-4E07-9B3D-F966ABED046F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F37D23AA-4EA9-4E07-9B3D-F966ABED046F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F37D23AA-4EA9-4E07-9B3D-F966ABED046F}.Release|Any CPU.Build.0 = Release|Any CPU
{7C8D906E-426B-49AB-9072-178555370F62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C8D906E-426B-49AB-9072-178555370F62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C8D906E-426B-49AB-9072-178555370F62}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -131,6 +133,22 @@ 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
{D4CF08F5-8EAB-48FB-AAA3-1A221F7B2A82}.Release|Any CPU.Build.0 = Release|Any CPU
{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{948C1EA8-12DB-4F8A-A190-8615DFBD9FE4}.Release|Any CPU.Build.0 = Release|Any CPU
{141532E1-540E-4E50-8723-96936C191281}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{141532E1-540E-4E50-8723-96936C191281}.Debug|Any CPU.Build.0 = Debug|Any CPU
{141532E1-540E-4E50-8723-96936C191281}.Release|Any CPU.ActiveCfg = Release|Any CPU
{141532E1-540E-4E50-8723-96936C191281}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -139,7 +157,6 @@ Global
{512B0511-41AB-444D-BAD8-E19B7D3B52CB} = {DA8EFCA8-5396-48C7-8DC0-CB28A09488D9}
{8B9F2E93-B31B-4BA7-920D-732695A473E6} = {9AF522B5-8923-41E6-8A0A-FAE8E8F83439}
{E7468FDD-75F7-4B08-BA47-B715BBCFCC11} = {D40853F1-B3C5-418A-B1D3-E0FB70B2F394}
{F37D23AA-4EA9-4E07-9B3D-F966ABED046F} = {9AF522B5-8923-41E6-8A0A-FAE8E8F83439}
{7C8D906E-426B-49AB-9072-178555370F62} = {9AF522B5-8923-41E6-8A0A-FAE8E8F83439}
{F8F6973C-5831-43D1-89C2-1AD543CE7408} = {9AF522B5-8923-41E6-8A0A-FAE8E8F83439}
{D40853F1-B3C5-418A-B1D3-E0FB70B2F394} = {2D44BDCF-B70C-4C02-BDC8-4F1DD5066A75}
@@ -158,6 +175,10 @@ 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}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3833E7C5-69BC-4CB3-92CE-A8854AA35D8A}
@@ -4,13 +4,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefineConstants>PUBLISH;$(DefineConstants)</DefineConstants>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\Publish</PublishDir>
<PublishDir>bin\Release\Publish\linux-x64</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>link</TrimMode>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
@@ -4,13 +4,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefineConstants>PUBLISH;$(DefineConstants)</DefineConstants>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\Publish</PublishDir>
<PublishDir>bin\Release\Publish\osx-x64</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>link</TrimMode>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
@@ -4,13 +4,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefineConstants>PUBLISH;$(DefineConstants)</DefineConstants>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\Publish</PublishDir>
<PublishDir>bin\Release\Publish\win-x64</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishSingleFile>false</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<TrimMode>link</TrimMode>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
@@ -19,13 +19,24 @@
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Avalonia\System.Application.SteamTools.Client.Desktop.Avalonia.csproj" />
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform\System.Application.SteamTools.Client.Desktop.Platform.csproj" />
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop\System.Application.SteamTools.Client.Desktop.csproj" />
<ProjectReference Include="..\System.Common.CoreLib\System.Common.CoreLib.csproj" />
<ProjectReference Include="..\System.Common.DesktopLib\System.Common.DesktopLib.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`win`)) Or ('$(OS)' == 'Windows_NT' And !$(DefineConstants.Contains(`PUBLISH`))) ">
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform.Windows\System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`osx`)) Or ('$(OS)' == 'OSX' And !$(DefineConstants.Contains(`PUBLISH`))) ">
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform.Mac\System.Application.SteamTools.Client.Desktop.Platform.Mac.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(RuntimeIdentifier.Contains(`linux`)) Or ('$(OS)' == 'Unix' And !$(DefineConstants.Contains(`PUBLISH`))) ">
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform.Linux\System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0" />
<PackageReference Include="MessageBox.Avalonia" Version="1.0.5">
<Aliases>MessageBox_Avalonia</Aliases>
</PackageReference>
@@ -0,0 +1,97 @@
using Avalonia.Input;
using System.Collections.Generic;
namespace System.Application.UI
{
/// <summary>
/// 拖拽功能工具类
/// https://github.com/AvaloniaUI/Avalonia/blob/0.10.0-preview6/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
/// </summary>
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<InputElement> elements)
{
foreach (var element in elements)
{
listener.InitDragDrop(element);
}
}
public static void InitDragDrop(this IOnDragDropListener listener,
params InputElement[] elements)
{
IEnumerable<InputElement> 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);
}
}
}
/// <summary>
/// 拖拽文本
/// </summary>
/// <param name="sender"></param>
/// <param name="text"></param>
void DropText(InputElement sender, string text);
/// <summary>
/// 拖拽路径,路径可能是文件也可能是文件夹
/// </summary>
/// <param name="sender"></param>
/// <param name="fileNames"></param>
void DropFileNames(InputElement sender, IEnumerable<string> fileNames);
}
}
}
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>System.Application</RootNamespace>
<RootNamespace>System</RootNamespace>
</PropertyGroup>
<ItemGroup>
@@ -12,14 +12,20 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop\System.Application.SteamTools.Client.Desktop.csproj"/>
<ProjectReference Include="..\System.Common.CoreLib\System.Common.CoreLib.csproj"/>
<ProjectReference Include="..\System.Common.DesktopLib\System.Common.DesktopLib.csproj"/>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop\System.Application.SteamTools.Client.Desktop.csproj" />
<ProjectReference Include="..\System.Common.CoreLib\System.Common.CoreLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.0" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0" />
<PackageReference Include="MessageBox.Avalonia" Version="1.0.5">
<Aliases>MessageBox_Avalonia</Aliases>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0" />
</ItemGroup>
</Project>
@@ -0,0 +1,113 @@
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;
// ReSharper disable once CheckNamespace
namespace System.Windows
{
/// <summary>
/// 显示消息框。
/// </summary>
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}"),
};
/// <summary>
/// 显示一个消息框,该消息框包含消息、标题栏标题、按钮和图标,并且返回结果。
/// </summary>
/// <param name="messageBoxText">一个 <see cref="string"/>,用于指定要显示的文本。</param>
/// <param name="caption">一个 <see cref="string"/>,用于指定要显示的标题栏标题。</param>
/// <param name="button">一个 <see cref="MessageBoxButton"/> 值,用于指定要显示哪个按钮或哪些按钮。</param>
/// <param name="icon">一个 <see cref="MessageBoxImage"/> 值,用于指定要显示的图标。</param>
/// <returns>一个 <see cref="MessageBoxResult"/> 值,用于指定用户单击了哪个消息框按钮。</returns>
public static async Task<MessageBoxResult> 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<ButtonResult> 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;
}
}
}
@@ -0,0 +1,19 @@
// ReSharper disable once CheckNamespace
namespace System.Windows
{
/// <summary>
/// 指定显示在消息框上的按钮。 用作 <see cref="MessageBox"/>.Show... 方法的参数。
/// </summary>
public enum MessageBoxButton
{
OK = 0,
OKCancel = 1,
YesNo = 4,
YesNoCancel = 3,
[Obsolete("non-standard api")]
OkAbort = 1000,
[Obsolete("non-standard api")]
YesNoAbort = 1001,
}
}
@@ -0,0 +1,45 @@
// ReSharper disable once CheckNamespace
namespace System.Windows
{
/// <summary>
/// 指定消息框所显示的图标。
/// </summary>
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 // 不应复制枚举值
}
}
@@ -0,0 +1,18 @@
// ReSharper disable once CheckNamespace
namespace System.Windows
{
/// <summary>
/// 指定用户单击的消息框按钮。 由 <see cref="MessageBox"/>.Show... 方法返回。
/// </summary>
public enum MessageBoxResult
{
Cancel = 2,
No = 7,
None = 0,
OK = 1,
Yes = 6,
[Obsolete("non-standard api")]
Abort = 1000,
}
}
@@ -0,0 +1,32 @@
using System.Application.Services;
// ReSharper disable once CheckNamespace
namespace System.Windows
{
/// <summary>
/// 指定是否可以调整窗口大小,并在可调整大小的情况下指定如何调整窗口大小。由 SetResizeMode 使用。
/// </summary>
public enum ResizeMode
{
/// <summary>
/// 用户无法调整窗口的大小。 不显示 "最大化" 和 "最小化" 框。
/// </summary>
NoResize = IDesktopPlatformService.ResizeMode_NoResize,
/// <summary>
/// 用户只能最小化窗口并从任务栏还原。 同时显示 "最小化" 和 "最大化" 框,但只启用 "最小化" 框。
/// </summary>
CanMinimize = IDesktopPlatformService.ResizeMode_CanMinimize,
/// <summary>
/// 用户可以通过使用 "最小化" 和 "最大化" 框以及围绕窗口的可拖动轮廓来完全调整窗口的大小。 显示和启用 "最小化" 和 "最大化" 框。 (默认) 。
/// </summary>
CanResize = IDesktopPlatformService.ResizeMode_CanResize,
/// <summary>
/// 此选项具有与相同的功能 <see cref="CanResize"/> ,但会将 "调整手柄" 添加到窗口的右下角。
/// </summary>
[Obsolete("not implemented")]
CanResizeWithGrip = IDesktopPlatformService.ResizeMode_CanResizeWithGrip,
}
}
@@ -0,0 +1,75 @@
using System.Application.Services;
using System.IO;
using FontFamily = Avalonia.Media.FontFamily;
using Window = Avalonia.Controls.Window;
// ReSharper disable once CheckNamespace
namespace System.Windows
{
/// <summary>
/// 通过扩展兼容WPF部分API的内容
/// </summary>
public static partial class WpfCompatExtensions
{
static readonly Lazy<bool> lazy_has_msyh = new Lazy<bool>(() =>
{
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);
}
}
}
/// <summary>
/// 设置调整大小模式。
/// </summary>
/// <param name="window"></param>
/// <param name="value"></param>
public static void SetResizeMode(this Window window, ResizeMode value)
{
var p = DI.Get<IDesktopPlatformService>();
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, (int)value);
}
}
}
@@ -0,0 +1,10 @@
namespace System.Application.Services.Implementation
{
internal sealed class LinuxDesktopPlatformServiceImpl : IDesktopPlatformService
{
public void SetResizeMode(IntPtr hWnd, int value)
{
}
}
}
@@ -0,0 +1,23 @@
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.Linux)
{
services.AddSingleton<IDesktopPlatformService, LinuxDesktopPlatformServiceImpl>();
}
else
{
throw new PlatformNotSupportedException();
}
return services;
}
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>System.Application.Services</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\System.Common.CoreLib\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform\System.Application.SteamTools.Client.Desktop.Platform.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,9 @@
namespace System.Application.Services.Implementation
{
internal sealed class MacDesktopPlatformServiceImpl : IDesktopPlatformService
{
public void SetResizeMode(IntPtr hWnd, int value)
{
}
}
}
@@ -0,0 +1,23 @@
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.Apple)
{
services.AddSingleton<IDesktopPlatformService, MacDesktopPlatformServiceImpl>();
}
else
{
throw new PlatformNotSupportedException();
}
return services;
}
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>System.Application.Services</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\System.Common.CoreLib\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform\System.Application.SteamTools.Client.Desktop.Platform.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,90 @@
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace System.Application.Services.Implementation
{
[SupportedOSPlatform("Windows")]
internal sealed class WindowsDesktopPlatformServiceImpl : IDesktopPlatformService
{
#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 void SetResizeMode(IntPtr hWnd, int value)
{
switch (value)
{
case IDesktopPlatformService.ResizeMode_NoResize:
_ = DeleteMenu(GetSystemMenu(hWnd, false), SC_MAXIMIZE, MF_BYCOMMAND);
_ = DeleteMenu(GetSystemMenu(hWnd, false), SC_MINIMIZE, MF_BYCOMMAND);
HideMinimizeAndMaximizeButtons(hWnd);
break;
case IDesktopPlatformService.ResizeMode_CanMinimize:
_ = DeleteMenu(GetSystemMenu(hWnd, false), SC_MAXIMIZE, MF_BYCOMMAND);
DisableMaximizeButton(hWnd);
break;
}
}
#endregion
}
}
@@ -0,0 +1,23 @@
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<IDesktopPlatformService, WindowsDesktopPlatformServiceImpl>();
}
else
{
throw new PlatformNotSupportedException();
}
return services;
}
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>System.Application.Services</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\System.Common.CoreLib\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform\System.Application.SteamTools.Client.Desktop.Platform.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,14 @@
using ResizeMode = System.Int32;
namespace System.Application.Services
{
public interface IDesktopPlatformService
{
void SetResizeMode(IntPtr hWnd, ResizeMode value);
public const ResizeMode ResizeMode_NoResize = 0;
public const ResizeMode ResizeMode_CanMinimize = 1;
public const ResizeMode ResizeMode_CanResize = 2;
public const ResizeMode ResizeMode_CanResizeWithGrip = 3;
}
}
@@ -0,0 +1,9 @@
namespace System.Application.Services.Implementation
{
public class DesktopPlatformServiceImpl : IDesktopPlatformService
{
public void SetResizeMode(IntPtr hWnd, int value)
{
}
}
}
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>System.Application.Services</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\System.Common.CoreLib\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client\System.Application.SteamTools.Client.csproj" />
</ItemGroup>
</Project>
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>System.Application</RootNamespace>
</PropertyGroup>
@@ -16,6 +16,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Application.SteamTools.Client.Desktop.Platform\System.Application.SteamTools.Client.Desktop.Platform.csproj" />
<ProjectReference Include="..\System.Application.SteamTools.Client\System.Application.SteamTools.Client.csproj" />
</ItemGroup>
@@ -23,13 +23,17 @@
</Compile>
<Compile Include="..\System.Common.UnitTest\Logging\*.cs">
<Link />
<LinkBase>Logging</LinkBase>
</Compile>
<Compile Include="..\System.Common.UnitTest\Utils\*.cs">
<Link />
<LinkBase>Utils</LinkBase>
</Compile>
<Compile Include="..\System.Common.UnitTest\Droid\*.cs">
<Link />
<LinkBase>Droid</LinkBase>
</Compile>
<!--https://docs.microsoft.com/zh-cn/visualstudio/msbuild/common-msbuild-item-metadata?view=vs-2019-->
</ItemGroup>
<ItemGroup>