diff --git a/Directory.Build.props b/Directory.Build.props index 7f04f1d15..932b68ade 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,4 +1,8 @@ + + none + false + 9.0 enable diff --git a/SteamToolsV1.2+.sln b/SteamToolsV1.2+.sln index f5b92addb..c75298a57 100644 --- a/SteamToolsV1.2+.sln +++ b/SteamToolsV1.2+.sln @@ -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} diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/linux-x64.pubxml b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/linux-x64.pubxml index 6cf50537c..7a12665dc 100644 --- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/linux-x64.pubxml +++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/linux-x64.pubxml @@ -4,13 +4,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> + PUBLISH;$(DefineConstants) Release Any CPU - bin\Release\Publish + bin\Release\Publish\linux-x64 FileSystem linux-x64 true - True + false True link false diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/osx-x64.pubxml b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/osx-x64.pubxml index ac366a88b..b928399b5 100644 --- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/osx-x64.pubxml +++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/osx-x64.pubxml @@ -4,13 +4,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> + PUBLISH;$(DefineConstants) Release Any CPU - bin\Release\Publish + bin\Release\Publish\osx-x64 FileSystem osx-x64 true - True + false True link false diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/win-x64.pubxml b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/win-x64.pubxml index ee34f554d..ff61d88a3 100644 --- a/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/win-x64.pubxml +++ b/System.Application.SteamTools.Client.Desktop.Avalonia.App/Properties/PublishProfiles/win-x64.pubxml @@ -4,13 +4,14 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> + PUBLISH;$(DefineConstants) Release Any CPU - bin\Release\Publish + bin\Release\Publish\win-x64 FileSystem win-x64 true - True + false True link false 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 dfb6cba3f..c99babe5b 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 @@ -2,7 +2,7 @@ WinExe - net5.0 + net5.0优化 MSBuild 在 Release 时 不生成PDB false System.Application.UI @@ -19,13 +19,24 @@ + - + + + + + + + + + + + + - MessageBox_Avalonia diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Services/Implementation/MainThreadPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Application/Services/Implementation/MainThreadPlatformServiceImpl.cs similarity index 100% rename from System.Application.SteamTools.Client.Desktop.Avalonia/Services/Implementation/MainThreadPlatformServiceImpl.cs rename to System.Application.SteamTools.Client.Desktop.Avalonia/Application/Services/Implementation/MainThreadPlatformServiceImpl.cs diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/DragDropUtil.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/DragDropUtil.cs new file mode 100644 index 000000000..660b4e757 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/DragDropUtil.cs @@ -0,0 +1,97 @@ +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.Application.SteamTools.Client.Desktop.Avalonia/System.Application.SteamTools.Client.Desktop.Avalonia.csproj b/System.Application.SteamTools.Client.Desktop.Avalonia/System.Application.SteamTools.Client.Desktop.Avalonia.csproj index 7a38c06f2..c5df7c780 100644 --- a/System.Application.SteamTools.Client.Desktop.Avalonia/System.Application.SteamTools.Client.Desktop.Avalonia.csproj +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/System.Application.SteamTools.Client.Desktop.Avalonia.csproj @@ -1,8 +1,8 @@ - + net5.0 - System.Application + System @@ -12,14 +12,20 @@ - - - + + + + + MessageBox_Avalonia + + + + \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs new file mode 100644 index 000000000..6c2119c55 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBox.cs @@ -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 +{ + /// + /// 显示消息框。 + /// + 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.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs new file mode 100644 index 000000000..aadb49aec --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxButton.cs @@ -0,0 +1,19 @@ +// ReSharper disable once CheckNamespace +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.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs new file mode 100644 index 000000000..be8f0b852 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxImage.cs @@ -0,0 +1,45 @@ +// ReSharper disable once CheckNamespace +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.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs new file mode 100644 index 000000000..9da092dfe --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/MessageBoxResult.cs @@ -0,0 +1,18 @@ +// ReSharper disable once CheckNamespace +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.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs new file mode 100644 index 000000000..b08091784 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/ResizeMode.cs @@ -0,0 +1,32 @@ +using System.Application.Services; + +// ReSharper disable once CheckNamespace +namespace System.Windows +{ + /// + /// 指定是否可以调整窗口大小,并在可调整大小的情况下指定如何调整窗口大小。由 SetResizeMode 使用。 + /// + public enum ResizeMode + { + /// + /// 用户无法调整窗口的大小。 不显示 "最大化" 和 "最小化" 框。 + /// + NoResize = IDesktopPlatformService.ResizeMode_NoResize, + + /// + /// 用户只能最小化窗口并从任务栏还原。 同时显示 "最小化" 和 "最大化" 框,但只启用 "最小化" 框。 + /// + CanMinimize = IDesktopPlatformService.ResizeMode_CanMinimize, + + /// + /// 用户可以通过使用 "最小化" 和 "最大化" 框以及围绕窗口的可拖动轮廓来完全调整窗口的大小。 显示和启用 "最小化" 和 "最大化" 框。 (默认) 。 + /// + CanResize = IDesktopPlatformService.ResizeMode_CanResize, + + /// + /// 此选项具有与相同的功能 ,但会将 "调整手柄" 添加到窗口的右下角。 + /// + [Obsolete("not implemented")] + CanResizeWithGrip = IDesktopPlatformService.ResizeMode_CanResizeWithGrip, + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs new file mode 100644 index 000000000..b8f4c9d94 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Avalonia/Windows/WpfCompatExtensions.cs @@ -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 +{ + /// + /// 通过扩展兼容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, (int)value); + } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Linux/Implementation/LinuxDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Platform.Linux/Implementation/LinuxDesktopPlatformServiceImpl.cs new file mode 100644 index 000000000..157df67d0 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Linux/Implementation/LinuxDesktopPlatformServiceImpl.cs @@ -0,0 +1,10 @@ +namespace System.Application.Services.Implementation +{ + internal sealed class LinuxDesktopPlatformServiceImpl : IDesktopPlatformService + { + public void SetResizeMode(IntPtr hWnd, int value) + { + + } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Linux/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Platform.Linux/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..18a7a3ebc --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Linux/ServiceCollectionExtensions.cs @@ -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(); + } + else + { + throw new PlatformNotSupportedException(); + } + return services; + } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Linux/System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj b/System.Application.SteamTools.Client.Desktop.Platform.Linux/System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj new file mode 100644 index 000000000..941710b14 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Linux/System.Application.SteamTools.Client.Desktop.Platform.Linux.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + System.Application.Services + + + + + Properties\AssemblyInfo.cs + + + + + + + + diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Mac/Implementation/MacDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Platform.Mac/Implementation/MacDesktopPlatformServiceImpl.cs new file mode 100644 index 000000000..3a3fb55f5 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Mac/Implementation/MacDesktopPlatformServiceImpl.cs @@ -0,0 +1,9 @@ +namespace System.Application.Services.Implementation +{ + internal sealed class MacDesktopPlatformServiceImpl : IDesktopPlatformService + { + public void SetResizeMode(IntPtr hWnd, int value) + { + } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Mac/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Platform.Mac/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..087a9c028 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Mac/ServiceCollectionExtensions.cs @@ -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(); + } + else + { + throw new PlatformNotSupportedException(); + } + return services; + } + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..941710b14 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Mac/System.Application.SteamTools.Client.Desktop.Platform.Mac.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + System.Application.Services + + + + + Properties\AssemblyInfo.cs + + + + + + + + diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Windows/Implementation/WindowsDesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Platform.Windows/Implementation/WindowsDesktopPlatformServiceImpl.cs new file mode 100644 index 000000000..88201cc01 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Windows/Implementation/WindowsDesktopPlatformServiceImpl.cs @@ -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 + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Windows/ServiceCollectionExtensions.cs b/System.Application.SteamTools.Client.Desktop.Platform.Windows/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..477125d6e --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Windows/ServiceCollectionExtensions.cs @@ -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(); + } + else + { + throw new PlatformNotSupportedException(); + } + return services; + } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform.Windows/System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj b/System.Application.SteamTools.Client.Desktop.Platform.Windows/System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj new file mode 100644 index 000000000..941710b14 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform.Windows/System.Application.SteamTools.Client.Desktop.Platform.Windows.csproj @@ -0,0 +1,18 @@ + + + + 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 new file mode 100644 index 000000000..f8ebaef50 --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform/IDesktopPlatformService.cs @@ -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; + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform/Implementation/DesktopPlatformServiceImpl.cs b/System.Application.SteamTools.Client.Desktop.Platform/Implementation/DesktopPlatformServiceImpl.cs new file mode 100644 index 000000000..c6512b0ff --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform/Implementation/DesktopPlatformServiceImpl.cs @@ -0,0 +1,9 @@ +namespace System.Application.Services.Implementation +{ + public class DesktopPlatformServiceImpl : IDesktopPlatformService + { + public void SetResizeMode(IntPtr hWnd, int value) + { + } + } +} \ No newline at end of file diff --git a/System.Application.SteamTools.Client.Desktop.Platform/System.Application.SteamTools.Client.Desktop.Platform.csproj b/System.Application.SteamTools.Client.Desktop.Platform/System.Application.SteamTools.Client.Desktop.Platform.csproj new file mode 100644 index 000000000..68edcc61b --- /dev/null +++ b/System.Application.SteamTools.Client.Desktop.Platform/System.Application.SteamTools.Client.Desktop.Platform.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + System.Application.Services + + + + + Properties\AssemblyInfo.cs + + + + + + + + diff --git a/System.Application.SteamTools.Client.Desktop/System.Application.SteamTools.Client.Desktop.csproj b/System.Application.SteamTools.Client.Desktop/System.Application.SteamTools.Client.Desktop.csproj index 368091b12..5420ff62c 100644 --- a/System.Application.SteamTools.Client.Desktop/System.Application.SteamTools.Client.Desktop.csproj +++ b/System.Application.SteamTools.Client.Desktop/System.Application.SteamTools.Client.Desktop.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + net5.0 System.Application @@ -16,6 +16,7 @@ + diff --git a/System.Common.UnitTest.Droid/System.Common.UnitTest.Droid.csproj b/System.Common.UnitTest.Droid/System.Common.UnitTest.Droid.csproj index c96f8412b..8c78ff20c 100644 --- a/System.Common.UnitTest.Droid/System.Common.UnitTest.Droid.csproj +++ b/System.Common.UnitTest.Droid/System.Common.UnitTest.Droid.csproj @@ -23,13 +23,17 @@ + Logging + Utils + Droid +