From a90798a22d488e5846e3dd8643f0d56284c06b3a Mon Sep 17 00:00:00 2001 From: Space Time Date: Sat, 18 May 2024 18:16:48 +0800 Subject: [PATCH] =?UTF-8?q?1.1.0=20->=201.1.1=20=E7=AC=AC5=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 19 +- Consts/AboutConst.cs | 23 +- Consts/MainConst.cs | 24 +- Convs/AboutVersionButtonContentConv.cs | 23 +- Convs/MainContentBoxForegroundConv.cs | 61 ++--- Convs/MainContentBoxTextConv.cs | 83 +++--- Convs/MainFunctionButtonContentConv.cs | 33 ++- Convs/MainStartCealButtonIsEnabledConv.cs | 27 +- Convs/MainSwitchModeButtonContentConv.cs | 33 ++- Convs/MainUpdateHostButtonIsEnabledConv.cs | 25 +- Preses/MainPres.cs | 96 +++---- Utils/Command.cs | 27 +- Utils/FocusExtension.cs | 66 ----- Utils/IconRemover.cs | 79 +++--- Wins/AboutWin.xaml | 4 +- Wins/AboutWin.xaml.cs | 42 +-- Wins/MainWin.xaml | 14 +- Wins/MainWin.xaml.cs | 300 ++++++++++----------- 18 files changed, 432 insertions(+), 547 deletions(-) delete mode 100644 Utils/FocusExtension.cs diff --git a/App.xaml.cs b/App.xaml.cs index 84bb9d6..68d7c2b 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -2,16 +2,15 @@ using System.Windows.Threading; using Sheas_Cealer.Wins; -namespace Sheas_Cealer -{ - public partial class App : Application - { - protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show(); +namespace Sheas_Cealer; - private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) - { - MessageBox.Show("Error: " + e.Exception.Message); - e.Handled = true; - } +public partial class App : Application +{ + protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show(); + + private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) + { + MessageBox.Show("Error: " + e.Exception.Message); + e.Handled = true; } } \ No newline at end of file diff --git a/Consts/AboutConst.cs b/Consts/AboutConst.cs index d8e3b54..58b0826 100644 --- a/Consts/AboutConst.cs +++ b/Consts/AboutConst.cs @@ -1,16 +1,15 @@ using System.Reflection; -namespace Sheas_Cealer.Consts +namespace Sheas_Cealer.Consts; + +internal class AboutConst : AboutMultilangConst { - internal class AboutConst : AboutMultilangConst - { - public static string Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2]; - public static string DeveloperButtonUrl => "https://www.spacetimee.xyz"; - public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc"; - public static string EmailButtonUrl => "Zeus6_6@163.com"; - public static string InstructionButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Instruction"; - public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer"; - public static string PrivacyButtonUrl => "https://thoughts.teambition.com/share/6264eda98adeb10041b92fda#title=Sheas_Cealer_隐私政策"; - public static string AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#title=Sheas_Cealer_使用协议"; - } + public static string Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2]; + public static string DeveloperButtonUrl => "https://www.spacetimee.xyz"; + public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc"; + public static string EmailButtonUrl => "Zeus6_6@163.com"; + public static string InstructionButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Instruction"; + public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer"; + public static string PrivacyButtonUrl => "https://thoughts.teambition.com/share/6264eda98adeb10041b92fda#title=Sheas_Cealer_隐私政策"; + public static string AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#title=Sheas_Cealer_使用协议"; } \ No newline at end of file diff --git a/Consts/MainConst.cs b/Consts/MainConst.cs index 34c67d6..0712d02 100644 --- a/Consts/MainConst.cs +++ b/Consts/MainConst.cs @@ -1,21 +1,17 @@ using System.Text.RegularExpressions; -namespace Sheas_Cealer.Consts +namespace Sheas_Cealer.Consts; + +internal partial class MainConst : MainMultilangConst { - internal partial class MainConst : MainMultilangConst - { - internal enum Mode - { browserPathMode, upstreamUrlMode, extraArgsMode }; + internal enum SettingsMode + { BrowserPathMode, UpstreamUrlMode, ExtraArgsMode }; - internal static string DefaultUpstreamUrl => "https://gitlab.com/SpaceTimee/Cealing-Host/raw/main/Cealing-Host.json"; + internal static string DefaultUpstreamUrl => "https://gitlab.com/SpaceTimee/Cealing-Host/raw/main/Cealing-Host.json"; - [GeneratedRegex(@"^\r$")] - internal static partial Regex HostRegex(); + [GeneratedRegex(@"^(((ht|f)tps?):\/\/)?[a-zA-Z0-9](-*[a-zA-Z0-9])*(\.[a-zA-Z0-9](-*[a-zA-Z0-9])*)*(:\d{1,5})?(\/[a-zA-Z0-9.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*$")] + internal static partial Regex UpstreamUrlRegex(); - [GeneratedRegex(@"^((((ht|f)tps?):\/\/)?[a-zA-Z0-9](-*[a-zA-Z0-9])*(\.[a-zA-Z0-9](-*[a-zA-Z0-9])*)*(:\d{1,5})?(\/[a-zA-Z0-9.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*)?$")] - internal static partial Regex UrlRegex(); - - [GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")] - internal static partial Regex ArgsRegex(); - } + [GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")] + internal static partial Regex ExtraArgsRegex(); } \ No newline at end of file diff --git a/Convs/AboutVersionButtonContentConv.cs b/Convs/AboutVersionButtonContentConv.cs index 01e9a4e..bc1a279 100644 --- a/Convs/AboutVersionButtonContentConv.cs +++ b/Convs/AboutVersionButtonContentConv.cs @@ -2,21 +2,20 @@ using System.Globalization; using System.Windows.Data; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class AboutVersionButtonContentConv : IMultiValueConverter { - internal class AboutVersionButtonContentConv : IMultiValueConverter + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - string? VersionButtonContent = values[0] as string; - string? version = values[1] as string; + string? VersionButtonContent = values[0] as string; + string? version = values[1] as string; - return VersionButtonContent + version; - } + return VersionButtonContent + version; + } - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Convs/MainContentBoxForegroundConv.cs b/Convs/MainContentBoxForegroundConv.cs index ea6aa5b..87ea598 100644 --- a/Convs/MainContentBoxForegroundConv.cs +++ b/Convs/MainContentBoxForegroundConv.cs @@ -4,45 +4,42 @@ using System.Windows.Data; using System.Windows.Media; using Sheas_Cealer.Consts; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class MainContentBoxForegroundConv : IMultiValueConverter { - internal class MainContentBoxForegroundConv : IMultiValueConverter + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - private static readonly MainConst MainConst = new(); + MainConst.SettingsMode? mode = values[0] as MainConst.SettingsMode?; + bool? isFocused = values[1] as bool?; + string? browserPath = values[2] as string; + string? upstreamUrl = values[3] as string; + string? extraArgs = values[4] as string; - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + if (!(bool)isFocused!) { - MainConst.Mode? mode = values[0] as MainConst.Mode?; - bool? isFocused = values[1] as bool?; - string? browserPath = values[2] as string; - string? upstreamUrl = values[3] as string; - string? extraArgs = values[4] as string; - - if (!(bool)isFocused!) + switch (mode) { - switch (mode) - { - case MainConst.Mode.browserPathMode: - if (browserPath == MainConst.BrowserPathPlaceHolder) - return new SolidColorBrush(Color.FromRgb(191, 205, 219)); - break; - case MainConst.Mode.upstreamUrlMode: - if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder) - return new SolidColorBrush(Color.FromRgb(191, 205, 219)); - break; - case MainConst.Mode.extraArgsMode: - if (extraArgs == MainConst.ExtraArgsPlaceHolder) - return new SolidColorBrush(Color.FromRgb(191, 205, 219)); - break; - } + case MainConst.SettingsMode.BrowserPathMode: + if (browserPath == MainConst.BrowserPathPlaceHolder) + return new SolidColorBrush(Color.FromRgb(191, 205, 219)); + break; + case MainConst.SettingsMode.UpstreamUrlMode: + if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder) + return new SolidColorBrush(Color.FromRgb(191, 205, 219)); + break; + case MainConst.SettingsMode.ExtraArgsMode: + if (extraArgs == MainConst.ExtraArgsPlaceHolder) + return new SolidColorBrush(Color.FromRgb(191, 205, 219)); + break; } - - return new SolidColorBrush(Color.FromRgb(0, 0, 0)); } - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } + return new SolidColorBrush(Color.FromRgb(0, 0, 0)); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Convs/MainContentBoxTextConv.cs b/Convs/MainContentBoxTextConv.cs index c8839eb..f3c3e48 100644 --- a/Convs/MainContentBoxTextConv.cs +++ b/Convs/MainContentBoxTextConv.cs @@ -3,56 +3,53 @@ using System.Diagnostics; using System.Windows.Data; using Sheas_Cealer.Consts; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class MainContentBoxTextConv : IMultiValueConverter { - internal class MainContentBoxTextConv : IMultiValueConverter + public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { - private static readonly MainConst MainConst = new(); + MainConst.SettingsMode? mode = values[0] as MainConst.SettingsMode?; + bool? isFocused = values[1] as bool?; + string? browserPath = values[2] as string; + string? upstreamUrl = values[3] as string; + string? extraArgs = values[4] as string; - public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) + if (mode == MainConst.SettingsMode.BrowserPathMode) { - MainConst.Mode? mode = values[0] as MainConst.Mode?; - bool? isFocused = values[1] as bool?; - string? browserPath = values[2] as string; - string? upstreamUrl = values[3] as string; - string? extraArgs = values[4] as string; - - if (mode == MainConst.Mode.browserPathMode) - { - if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath)) - return MainConst.BrowserPathPlaceHolder; - else if ((bool)isFocused! && browserPath == MainConst.BrowserPathPlaceHolder) - return string.Empty; - else - return browserPath!; - } - else if (mode == MainConst.Mode.upstreamUrlMode) - { - if ((bool)!isFocused! && string.IsNullOrEmpty(upstreamUrl)) - return MainConst.UpstreamUrlPlaceHolder; - else if ((bool)isFocused! && upstreamUrl == MainConst.UpstreamUrlPlaceHolder) - return string.Empty; - else - return upstreamUrl!; - } - else if (mode == MainConst.Mode.extraArgsMode) - { - if ((bool)!isFocused! && string.IsNullOrEmpty(extraArgs)) - return MainConst.ExtraArgsPlaceHolder; - else if ((bool)isFocused! && extraArgs == MainConst.ExtraArgsPlaceHolder) - return string.Empty; - else - return extraArgs!; - } + if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath)) + return MainConst.BrowserPathPlaceHolder; + else if ((bool)isFocused! && browserPath == MainConst.BrowserPathPlaceHolder) + return string.Empty; else - { - throw new UnreachableException(); - } + return browserPath!; } - - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) + else if (mode == MainConst.SettingsMode.UpstreamUrlMode) { - throw new NotImplementedException(); + if ((bool)!isFocused! && string.IsNullOrEmpty(upstreamUrl)) + return MainConst.UpstreamUrlPlaceHolder; + else if ((bool)isFocused! && upstreamUrl == MainConst.UpstreamUrlPlaceHolder) + return string.Empty; + else + return upstreamUrl!; + } + else if (mode == MainConst.SettingsMode.ExtraArgsMode) + { + if ((bool)!isFocused! && string.IsNullOrEmpty(extraArgs)) + return MainConst.ExtraArgsPlaceHolder; + else if ((bool)isFocused! && extraArgs == MainConst.ExtraArgsPlaceHolder) + return string.Empty; + else + return extraArgs!; + } + else + { + throw new UnreachableException(); } } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/Convs/MainFunctionButtonContentConv.cs b/Convs/MainFunctionButtonContentConv.cs index 792ed9c..4ec2881 100644 --- a/Convs/MainFunctionButtonContentConv.cs +++ b/Convs/MainFunctionButtonContentConv.cs @@ -4,27 +4,26 @@ using System.Globalization; using System.Windows.Data; using Sheas_Cealer.Consts; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class MainFunctionButtonContentConv : IValueConverter { - internal class MainFunctionButtonContentConv : IValueConverter + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - MainConst.Mode? mode = value as MainConst.Mode?; + MainConst.SettingsMode? mode = value as MainConst.SettingsMode?; - if (mode == MainConst.Mode.browserPathMode) - return MainConst.FunctionButtonBrowserPathContent; - else if (mode == MainConst.Mode.upstreamUrlMode) - return MainConst.FunctionButtonUpstreamUrlContent; - else if (mode == MainConst.Mode.extraArgsMode) - return MainConst.FunctionButtonExtraArgsContent; + if (mode == MainConst.SettingsMode.BrowserPathMode) + return MainConst.FunctionButtonBrowserPathContent; + else if (mode == MainConst.SettingsMode.UpstreamUrlMode) + return MainConst.FunctionButtonUpstreamUrlContent; + else if (mode == MainConst.SettingsMode.ExtraArgsMode) + return MainConst.FunctionButtonExtraArgsContent; - throw new UnreachableException(); - } + throw new UnreachableException(); + } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Convs/MainStartCealButtonIsEnabledConv.cs b/Convs/MainStartCealButtonIsEnabledConv.cs index 87c9fa3..81052d2 100644 --- a/Convs/MainStartCealButtonIsEnabledConv.cs +++ b/Convs/MainStartCealButtonIsEnabledConv.cs @@ -4,24 +4,23 @@ using System.IO; using System.Windows.Data; using Sheas_Cealer.Consts; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class MainStartCealButtonIsEnabledConv : IMultiValueConverter { - internal class MainStartCealButtonIsEnabledConv : IMultiValueConverter + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - string? browserPath = values[0] as string; - string? extraArgs = values[1] as string; + string? browserPath = values[0] as string; + string? extraArgs = values[1] as string; - if (File.Exists(browserPath) && Path.GetFileName(browserPath).ToLower().EndsWith(".exe") && (MainConst.ArgsRegex().IsMatch(extraArgs!) || extraArgs == MainConst.ExtraArgsPlaceHolder)) - return true; + if (File.Exists(browserPath) && Path.GetFileName(browserPath).ToLower().EndsWith(".exe") && (MainConst.ExtraArgsRegex().IsMatch(extraArgs!) || extraArgs == MainConst.ExtraArgsPlaceHolder)) + return true; - return false; - } + return false; + } - public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Convs/MainSwitchModeButtonContentConv.cs b/Convs/MainSwitchModeButtonContentConv.cs index c0f4b0d..be8e201 100644 --- a/Convs/MainSwitchModeButtonContentConv.cs +++ b/Convs/MainSwitchModeButtonContentConv.cs @@ -4,27 +4,26 @@ using System.Globalization; using System.Windows.Data; using Sheas_Cealer.Consts; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class MainSwitchModeButtonContentConv : IValueConverter { - internal class MainSwitchModeButtonContentConv : IValueConverter + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - MainConst.Mode? mode = value as MainConst.Mode?; + MainConst.SettingsMode? mode = value as MainConst.SettingsMode?; - if (mode == MainConst.Mode.browserPathMode) - return MainConst.SwitchModeButtonBrowserPathContent; - else if (mode == MainConst.Mode.upstreamUrlMode) - return MainConst.SwitchModeButtonUpstreamUrlContent; - else if (mode == MainConst.Mode.extraArgsMode) - return MainConst.SwitchModeButtonExtraArgsContent; + if (mode == MainConst.SettingsMode.BrowserPathMode) + return MainConst.SwitchModeButtonBrowserPathContent; + else if (mode == MainConst.SettingsMode.UpstreamUrlMode) + return MainConst.SwitchModeButtonUpstreamUrlContent; + else if (mode == MainConst.SettingsMode.ExtraArgsMode) + return MainConst.SwitchModeButtonExtraArgsContent; - throw new UnreachableException(); - } + throw new UnreachableException(); + } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Convs/MainUpdateHostButtonIsEnabledConv.cs b/Convs/MainUpdateHostButtonIsEnabledConv.cs index fab5534..21a820d 100644 --- a/Convs/MainUpdateHostButtonIsEnabledConv.cs +++ b/Convs/MainUpdateHostButtonIsEnabledConv.cs @@ -3,23 +3,22 @@ using System.Globalization; using System.Windows.Data; using Sheas_Cealer.Consts; -namespace Sheas_Cealer.Convs +namespace Sheas_Cealer.Convs; + +internal class MainUpdateHostButtonIsEnabledConv : IValueConverter { - internal class MainUpdateHostButtonIsEnabledConv : IValueConverter + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - string? upstreamUrl = value as string; + string? upstreamUrl = value as string; - if (MainConst.UrlRegex().IsMatch(upstreamUrl!)) - return true; + if (MainConst.UpstreamUrlRegex().IsMatch(upstreamUrl!)) + return true; - return false; - } + return false; + } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotImplementedException(); - } + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/Preses/MainPres.cs b/Preses/MainPres.cs index 10f0689..2c64e83 100644 --- a/Preses/MainPres.cs +++ b/Preses/MainPres.cs @@ -1,65 +1,65 @@ -using System.IO; +using System; +using System.IO; using CommunityToolkit.Mvvm.ComponentModel; using Sheas_Cealer.Consts; using File = System.IO.File; -namespace Sheas_Cealer.Preses +namespace Sheas_Cealer.Preses; + +internal partial class MainPres : ObservableObject { - internal partial class MainPres : ObservableObject + internal MainPres(string[] args) { - private static readonly MainConst MainConst = new(); + int browserPathIndex = Array.FindIndex(args, arg => arg == "-b") + 1, + upstreamUrlIndex = Array.FindIndex(args, arg => arg == "-u") + 1, + extraArgsIndex = Array.FindIndex(args, arg => arg == "e") + 1; - internal MainPres(string[] args) + BrowserPath = browserPathIndex == 0 ? + (!string.IsNullOrWhiteSpace(Props.Settings.Default.BrowserPath) ? Props.Settings.Default.BrowserPath : string.Empty) : + args[browserPathIndex]; + + UpstreamUrl = upstreamUrlIndex == 0 ? + (!string.IsNullOrWhiteSpace(Props.Settings.Default.UpstreamUrl) ? Props.Settings.Default.UpstreamUrl : MainConst.DefaultUpstreamUrl) : + args[upstreamUrlIndex]; + + ExtraArgs = extraArgsIndex == 0 ? + (!string.IsNullOrWhiteSpace(Props.Settings.Default.ExtraArgs) ? Props.Settings.Default.ExtraArgs : string.Empty) : + args[extraArgsIndex]; + } + + [ObservableProperty] + private MainConst.SettingsMode mode = MainConst.SettingsMode.BrowserPathMode; + + [ObservableProperty] + private string browserPath; + private partial void OnBrowserPathChanged(string value) + { + if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe")) { - if (args.Length > 0) - BrowserPath = args[0]; - else if (!string.IsNullOrWhiteSpace(Props.Settings.Default.BrowserPath)) - BrowserPath = Props.Settings.Default.BrowserPath; - - if (!string.IsNullOrWhiteSpace(Props.Settings.Default.UpstreamUrl)) - UpstreamUrl = Props.Settings.Default.UpstreamUrl; - - if (!string.IsNullOrWhiteSpace(Props.Settings.Default.ExtraArgs)) - ExtraArgs = Props.Settings.Default.ExtraArgs; + Props.Settings.Default.BrowserPath = value; + Props.Settings.Default.Save(); } + } - [ObservableProperty] - private MainConst.Mode mode = MainConst.Mode.browserPathMode; - - [ObservableProperty] - private bool isContentBoxFocused = true; - - [ObservableProperty] - private string browserPath = string.Empty; - partial void OnBrowserPathChanged(string value) + [ObservableProperty] + private string upstreamUrl; + private partial void OnUpstreamUrlChanged(string value) + { + if (MainConst.UpstreamUrlRegex().IsMatch(value)) { - if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe")) - { - Props.Settings.Default.BrowserPath = value; - Props.Settings.Default.Save(); - } + Props.Settings.Default.UpstreamUrl = value; + Props.Settings.Default.Save(); } + } - [ObservableProperty] - private string upstreamUrl = MainConst.DefaultUpstreamUrl; - partial void OnUpstreamUrlChanged(string value) + [ObservableProperty] + private string extraArgs; + private partial void OnExtraArgsChanged(string value) + { + if (MainConst.ExtraArgsRegex().IsMatch(value)) { - if (MainConst.UrlRegex().IsMatch(value)) - { - Props.Settings.Default.UpstreamUrl = value; - Props.Settings.Default.Save(); - } - } - - [ObservableProperty] - private string extraArgs = string.Empty; - partial void OnExtraArgsChanged(string value) - { - if (MainConst.ArgsRegex().IsMatch(value)) - { - Props.Settings.Default.ExtraArgs = value; - Props.Settings.Default.Save(); - } + Props.Settings.Default.ExtraArgs = value; + Props.Settings.Default.Save(); } } } \ No newline at end of file diff --git a/Utils/Command.cs b/Utils/Command.cs index 8d6ba35..f0f066d 100644 --- a/Utils/Command.cs +++ b/Utils/Command.cs @@ -2,20 +2,19 @@ using System.Diagnostics; using SheasCore; -namespace Sheas_Cealer.Utils -{ - internal class Command : Proc - { - internal Command() : base("Cmd.exe") - { - } +namespace Sheas_Cealer.Utils; - public override void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) - { - } - public override void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) - { - } - public override void Process_Exited(object sender, EventArgs e) => Environment.Exit(0); +internal class Command : Proc +{ + internal Command() : base("Cmd.exe") + { } + + public override void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) + { + } + public override void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) + { + } + public override void Process_Exited(object sender, EventArgs e) => Environment.Exit(0); } \ No newline at end of file diff --git a/Utils/FocusExtension.cs b/Utils/FocusExtension.cs deleted file mode 100644 index d1ba1ae..0000000 --- a/Utils/FocusExtension.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Windows; - -namespace Sheas_Cealer.Utils -{ - public static class FocusExtension - { - public static readonly DependencyProperty IsFocusedProperty = - DependencyProperty.RegisterAttached("IsFocused", typeof(bool?), typeof(FocusExtension), new FrameworkPropertyMetadata(IsFocusedChanged) { BindsTwoWayByDefault = true }); - - public static bool? GetIsFocused(DependencyObject element) - { - ArgumentNullException.ThrowIfNull(element); - - return (bool?)element.GetValue(IsFocusedProperty); - } - - public static void SetIsFocused(DependencyObject element, bool? value) - { - ArgumentNullException.ThrowIfNull(element); - - element.SetValue(IsFocusedProperty, value); - } - - private static void IsFocusedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var fe = (FrameworkElement)d; - - if (e.OldValue == null) - { - fe.GotFocus += FrameworkElement_GotFocus; - fe.LostFocus += FrameworkElement_LostFocus; - } - - if (!fe.IsVisible) - { - fe.IsVisibleChanged += new DependencyPropertyChangedEventHandler(fe_IsVisibleChanged); - } - - if (e.NewValue != null && (bool)e.NewValue) - { - fe.Focus(); - } - } - - private static void fe_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) - { - var fe = (FrameworkElement)sender; - if (fe.IsVisible && (bool)fe.GetValue(IsFocusedProperty)) - { - fe.IsVisibleChanged -= fe_IsVisibleChanged; - fe.Focus(); - } - } - - private static void FrameworkElement_GotFocus(object sender, RoutedEventArgs e) - { - ((FrameworkElement)sender).SetValue(IsFocusedProperty, true); - } - - private static void FrameworkElement_LostFocus(object sender, RoutedEventArgs e) - { - ((FrameworkElement)sender).SetValue(IsFocusedProperty, false); - } - } -} diff --git a/Utils/IconRemover.cs b/Utils/IconRemover.cs index be4cbe6..f091fd2 100644 --- a/Utils/IconRemover.cs +++ b/Utils/IconRemover.cs @@ -2,58 +2,43 @@ using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; -using Sheas_Cealer.Utils; -namespace Sheas_Cealer.Utils +namespace Sheas_Cealer.Utils; + +// 定义IconRemover +internal static partial class IconRemover { - // 定义IconRemover - internal static partial class IconRemover + private const int GWL_EXSTYLE = -20; + private const int WS_EX_DLGMODALFRAME = 0x0001; + private const int SWP_NOSIZE = 0x0001; + private const int SWP_NOMOVE = 0x0002; + private const int SWP_NOZORDER = 0x0004; + private const int SWP_FRAMECHANGED = 0x0020; + private const uint WM_SETICON = 0x0080; + + [LibraryImport("user32.dll", EntryPoint = "GetWindowLongW")] + private static partial int GetWindowLong(IntPtr hwnd, int index); + [LibraryImport("user32.dll", EntryPoint = "SetWindowLongW")] + private static partial int SetWindowLong(IntPtr hwnd, int index, int newStyle); + [LibraryImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags); + [LibraryImport("user32.dll", EntryPoint = "SendMessageW")] + private static partial IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam); + + internal static void RemoveIcon(Window window) { - private const int GWL_EXSTYLE = -20; - private const int WS_EX_DLGMODALFRAME = 0x0001; - private const int SWP_NOSIZE = 0x0001; - private const int SWP_NOMOVE = 0x0002; - private const int SWP_NOZORDER = 0x0004; - private const int SWP_FRAMECHANGED = 0x0020; - private const uint WM_SETICON = 0x0080; + // 获取该窗口句柄 + IntPtr hwnd = new WindowInteropHelper(window).Handle; - [LibraryImport("user32.dll", EntryPoint = "GetWindowLongW")] - private static partial int GetWindowLong(IntPtr hwnd, int index); - [LibraryImport("user32.dll", EntryPoint = "SetWindowLongW")] - private static partial int SetWindowLong(IntPtr hwnd, int index, int newStyle); - [LibraryImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - private static partial bool SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, uint flags); - [LibraryImport("user32.dll", EntryPoint = "SendMessageW")] - private static partial IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam); + // 将窗口更改为不显示窗口图标 + _ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME); - internal static void RemoveIcon(Window window) - { - // 获取该窗口句柄 - IntPtr hwnd = new WindowInteropHelper(window).Handle; + // 更新窗口的非客户区域来显示更改 + SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - // 将窗口更改为不显示窗口图标 - _ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME); - - // 更新窗口的非客户区域来显示更改 - SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - - // 防止自定义图标生效 - SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero); - SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero); - } - } -} - -namespace Sheas_Cealer.Wins -{ - // 使用IconRemover - public partial class MainWin - { - protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this); - } - public partial class AboutWin - { - protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this); + // 防止自定义图标生效 + SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero); + SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero); } } \ No newline at end of file diff --git a/Wins/AboutWin.xaml b/Wins/AboutWin.xaml index baf51a8..ca7a0d4 100644 --- a/Wins/AboutWin.xaml +++ b/Wins/AboutWin.xaml @@ -35,10 +35,9 @@ - + - @@ -58,6 +57,5 @@ - @@ -54,7 +53,6 @@ - @@ -68,7 +66,6 @@ - @@ -82,7 +79,6 @@ - @@ -126,7 +121,6 @@