From a834b7589e1c7ca3830942f8678f7ac8fa3453aa Mon Sep 17 00:00:00 2001 From: Space Time Date: Sat, 11 May 2024 22:32:05 +0800 Subject: [PATCH] =?UTF-8?q?1.1.0=20->=201.1.1=20=E7=AC=AC2=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 | 3 +- Consts/AboutConst.cs | 16 ++ Consts/AboutMultilangConst.Designer.cs | 126 +++++++++++++++ Consts/AboutMultilangConst.resx | 141 +++++++++++++++++ Consts/AboutMultilangConst.zh.resx | 121 ++++++++++++++ Consts/MainConst.cs | 21 +++ Consts/MainMultilangConst.Designer.cs | 144 +++++++++++++++++ Consts/MainMultilangConst.resx | 127 +++++++++++++++ Consts/MainMultilangConst.zh.resx | 147 ++++++++++++++++++ Convs/AboutVersionButtonContentConv.cs | 22 +++ Convs/MainContentBoxForegroundConv.cs | 48 ++++++ Convs/MainContentBoxTextConv.cs | 57 +++++++ Preses/MainPres.cs | 65 ++++++++ {Properties => Props}/AssemblyInfo.cs | 0 {Properties => Props}/Settings.Designer.cs | 28 +++- {Properties => Props}/Settings.settings | 8 +- Sheas-Cealer.csproj | 29 +++- Sheas-Cealer.sln | 6 + {Utilities => Utils}/Command.cs | 2 +- Utils/FocusExtension.cs | 66 ++++++++ {Utilities => Utils}/IconRemover.cs | 22 +-- Windows/AboutWindow.xaml | 31 ---- Windows/MainWindow.xaml | 38 ----- Wins/AboutWin.xaml | 63 ++++++++ .../AboutWin.xaml.cs | 12 +- Wins/MainWin.xaml | 94 +++++++++++ .../MainWin.xaml.cs | 147 +++++++++--------- 27 files changed, 1416 insertions(+), 168 deletions(-) create mode 100644 Consts/AboutConst.cs create mode 100644 Consts/AboutMultilangConst.Designer.cs create mode 100644 Consts/AboutMultilangConst.resx create mode 100644 Consts/AboutMultilangConst.zh.resx create mode 100644 Consts/MainConst.cs create mode 100644 Consts/MainMultilangConst.Designer.cs create mode 100644 Consts/MainMultilangConst.resx create mode 100644 Consts/MainMultilangConst.zh.resx create mode 100644 Convs/AboutVersionButtonContentConv.cs create mode 100644 Convs/MainContentBoxForegroundConv.cs create mode 100644 Convs/MainContentBoxTextConv.cs create mode 100644 Preses/MainPres.cs rename {Properties => Props}/AssemblyInfo.cs (100%) rename {Properties => Props}/Settings.Designer.cs (61%) rename {Properties => Props}/Settings.settings (54%) rename {Utilities => Utils}/Command.cs (94%) create mode 100644 Utils/FocusExtension.cs rename {Utilities => Utils}/IconRemover.cs (82%) delete mode 100644 Windows/AboutWindow.xaml delete mode 100644 Windows/MainWindow.xaml create mode 100644 Wins/AboutWin.xaml rename Windows/AboutWindow.xaml.cs => Wins/AboutWin.xaml.cs (57%) create mode 100644 Wins/MainWin.xaml rename Windows/MainWindow.xaml.cs => Wins/MainWin.xaml.cs (54%) diff --git a/App.xaml.cs b/App.xaml.cs index 43005ae..84bb9d6 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,11 +1,12 @@ using System.Windows; using System.Windows.Threading; +using Sheas_Cealer.Wins; namespace Sheas_Cealer { public partial class App : Application { - protected override void OnStartup(StartupEventArgs e) => new MainWindow(e.Args).Show(); + protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show(); private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { diff --git a/Consts/AboutConst.cs b/Consts/AboutConst.cs new file mode 100644 index 0000000..d8e3b54 --- /dev/null +++ b/Consts/AboutConst.cs @@ -0,0 +1,16 @@ +using System.Reflection; + +namespace Sheas_Cealer.Consts +{ + 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_使用协议"; + } +} \ No newline at end of file diff --git a/Consts/AboutMultilangConst.Designer.cs b/Consts/AboutMultilangConst.Designer.cs new file mode 100644 index 0000000..5ecb36a --- /dev/null +++ b/Consts/AboutMultilangConst.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace Sheas_Cealer.Consts { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class AboutMultilangConst { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal AboutMultilangConst() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sheas_Cealer.Consts.AboutMultilangConst", typeof(AboutMultilangConst).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找类似 ToS. 的本地化字符串。 + /// + public static string AgreementButtonContent { + get { + return ResourceManager.GetString("AgreementButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Dev. Space Time 的本地化字符串。 + /// + public static string DeveloperButtonContent { + get { + return ResourceManager.GetString("DeveloperButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Email 的本地化字符串。 + /// + public static string EmailButtonContent { + get { + return ResourceManager.GetString("EmailButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Docs 的本地化字符串。 + /// + public static string InstructionButtonContent { + get { + return ResourceManager.GetString("InstructionButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Repo 的本地化字符串。 + /// + public static string OpenSourceButtonContent { + get { + return ResourceManager.GetString("OpenSourceButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 PP. 的本地化字符串。 + /// + public static string PrivacyButtonContent { + get { + return ResourceManager.GetString("PrivacyButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Ver. 的本地化字符串。 + /// + public static string VersionButtonContent { + get { + return ResourceManager.GetString("VersionButtonContent", resourceCulture); + } + } + } +} diff --git a/Consts/AboutMultilangConst.resx b/Consts/AboutMultilangConst.resx new file mode 100644 index 0000000..fac6fad --- /dev/null +++ b/Consts/AboutMultilangConst.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ToS. + + + Dev. Space Time + + + Email + + + Docs + + + Repo + + + PP. + + + Ver. + + \ No newline at end of file diff --git a/Consts/AboutMultilangConst.zh.resx b/Consts/AboutMultilangConst.zh.resx new file mode 100644 index 0000000..41d71d9 --- /dev/null +++ b/Consts/AboutMultilangConst.zh.resx @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 使用协议 + + + 开发者: Space Time + + + 联系邮箱 + + + 使用文档 + + + 开源地址 + + + 隐私政策 + + + 版本号: + + \ No newline at end of file diff --git a/Consts/MainConst.cs b/Consts/MainConst.cs new file mode 100644 index 0000000..83549a5 --- /dev/null +++ b/Consts/MainConst.cs @@ -0,0 +1,21 @@ +using System.Text.RegularExpressions; + +namespace Sheas_Cealer.Consts +{ + internal partial class MainConst : MainMultilangConst + { + internal enum Mode + { browserPathMode, upstreamUrlMode, extraArgsMode }; + + 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 UrlRegex(); + + [GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")] + internal static partial Regex ArgsRegex(); + } +} \ No newline at end of file diff --git a/Consts/MainMultilangConst.Designer.cs b/Consts/MainMultilangConst.Designer.cs new file mode 100644 index 0000000..b16c670 --- /dev/null +++ b/Consts/MainMultilangConst.Designer.cs @@ -0,0 +1,144 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace Sheas_Cealer.Consts { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class MainMultilangConst { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal MainMultilangConst() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sheas_Cealer.Consts.MainMultilangConst", typeof(MainMultilangConst).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找类似 About Me 的本地化字符串。 + /// + public static string AboutButtonContent { + get { + return ResourceManager.GetString("AboutButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Browse 的本地化字符串。 + /// + public static string BrowseButtonContent { + get { + return ResourceManager.GetString("BrowseButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 (Fill in the path of a Chromium-based browser) 的本地化字符串。 + /// + public static string BrowserPathPlaceHolder { + get { + return ResourceManager.GetString("BrowserPathPlaceHolder", resourceCulture); + } + } + + /// + /// 查找类似 Edit Host 的本地化字符串。 + /// + public static string EditHostButtonContent { + get { + return ResourceManager.GetString("EditHostButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 (fill in extra Chromium startup arguments) 的本地化字符串。 + /// + public static string ExtraArgsPlaceHolder { + get { + return ResourceManager.GetString("ExtraArgsPlaceHolder", resourceCulture); + } + } + + /// + /// 查找类似 Start Cealing 的本地化字符串。 + /// + public static string StartCealButtonContent { + get { + return ResourceManager.GetString("StartCealButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Switch 的本地化字符串。 + /// + public static string SwitchModeButtonContent { + get { + return ResourceManager.GetString("SwitchModeButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Update Host 的本地化字符串。 + /// + public static string UpdateHostButtonContent { + get { + return ResourceManager.GetString("UpdateHostButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 (Fill in the link to an upstream Cealing Host) 的本地化字符串。 + /// + public static string UpstreamUrlPlaceHolder { + get { + return ResourceManager.GetString("UpstreamUrlPlaceHolder", resourceCulture); + } + } + } +} diff --git a/Consts/MainMultilangConst.resx b/Consts/MainMultilangConst.resx new file mode 100644 index 0000000..2a35480 --- /dev/null +++ b/Consts/MainMultilangConst.resx @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + About Me + + + Browse + + + (Fill in the path of a Chromium-based browser) + + + Edit Host + + + (fill in extra Chromium startup arguments) + + + Switch + + + Start Cealing + + + Update Host + + + (Fill in the link to an upstream Cealing Host) + + \ No newline at end of file diff --git a/Consts/MainMultilangConst.zh.resx b/Consts/MainMultilangConst.zh.resx new file mode 100644 index 0000000..6757cf8 --- /dev/null +++ b/Consts/MainMultilangConst.zh.resx @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 关于项目 + + + 浏览 + + + (填入任意以 Chromium 为内核的浏览器的路径) + + + 编辑规则 + + + (填入任意额外的 Chromium 启动参数) + + + 切换 + + + 启动伪造 + + + 更新规则 + + + (填入任意上游伪造规则的链接) + + \ No newline at end of file diff --git a/Convs/AboutVersionButtonContentConv.cs b/Convs/AboutVersionButtonContentConv.cs new file mode 100644 index 0000000..01e9a4e --- /dev/null +++ b/Convs/AboutVersionButtonContentConv.cs @@ -0,0 +1,22 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace Sheas_Cealer.Convs +{ + internal class AboutVersionButtonContentConv : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + string? VersionButtonContent = values[0] as string; + string? version = values[1] as string; + + return VersionButtonContent + version; + } + + 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 new file mode 100644 index 0000000..ea6aa5b --- /dev/null +++ b/Convs/MainContentBoxForegroundConv.cs @@ -0,0 +1,48 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; +using Sheas_Cealer.Consts; + +namespace Sheas_Cealer.Convs +{ + internal class MainContentBoxForegroundConv : IMultiValueConverter + { + private static readonly MainConst MainConst = new(); + + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + 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) + { + 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; + } + } + + 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 new file mode 100644 index 0000000..d21d6ca --- /dev/null +++ b/Convs/MainContentBoxTextConv.cs @@ -0,0 +1,57 @@ +using System; +using System.Windows.Data; +using Sheas_Cealer.Consts; + +namespace Sheas_Cealer.Convs +{ + internal class MainContentBoxTextConv : IMultiValueConverter + { + private static readonly MainConst MainConst = new(); + + public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + 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!; + } + else + { + throw new Exception("Invalid mode"); + } + } + + 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/Preses/MainPres.cs b/Preses/MainPres.cs new file mode 100644 index 0000000..10f0689 --- /dev/null +++ b/Preses/MainPres.cs @@ -0,0 +1,65 @@ +using System.IO; +using CommunityToolkit.Mvvm.ComponentModel; +using Sheas_Cealer.Consts; +using File = System.IO.File; + +namespace Sheas_Cealer.Preses +{ + internal partial class MainPres : ObservableObject + { + private static readonly MainConst MainConst = new(); + + internal MainPres(string[] args) + { + 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; + } + + [ObservableProperty] + private MainConst.Mode mode = MainConst.Mode.browserPathMode; + + [ObservableProperty] + private bool isContentBoxFocused = true; + + [ObservableProperty] + private string browserPath = string.Empty; + partial void OnBrowserPathChanged(string value) + { + if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe")) + { + Props.Settings.Default.BrowserPath = value; + Props.Settings.Default.Save(); + } + } + + [ObservableProperty] + private string upstreamUrl = MainConst.DefaultUpstreamUrl; + partial void OnUpstreamUrlChanged(string 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(); + } + } + } +} \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Props/AssemblyInfo.cs similarity index 100% rename from Properties/AssemblyInfo.cs rename to Props/AssemblyInfo.cs diff --git a/Properties/Settings.Designer.cs b/Props/Settings.Designer.cs similarity index 61% rename from Properties/Settings.Designer.cs rename to Props/Settings.Designer.cs index 19cb3d4..4166d68 100644 --- a/Properties/Settings.Designer.cs +++ b/Props/Settings.Designer.cs @@ -8,11 +8,11 @@ // //------------------------------------------------------------------------------ -namespace Sheas_Cealer.Properties { +namespace Sheas_Cealer.Props { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -34,5 +34,29 @@ namespace Sheas_Cealer.Properties { this["BrowserPath"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string UpstreamUrl { + get { + return ((string)(this["UpstreamUrl"])); + } + set { + this["UpstreamUrl"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string ExtraArgs { + get { + return ((string)(this["ExtraArgs"])); + } + set { + this["ExtraArgs"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Props/Settings.settings similarity index 54% rename from Properties/Settings.settings rename to Props/Settings.settings index 30558fa..ae75391 100644 --- a/Properties/Settings.settings +++ b/Props/Settings.settings @@ -1,9 +1,15 @@  - + + + + + + + \ No newline at end of file diff --git a/Sheas-Cealer.csproj b/Sheas-Cealer.csproj index db004ea..11e2211 100644 --- a/Sheas-Cealer.csproj +++ b/Sheas-Cealer.csproj @@ -21,7 +21,7 @@ git Copyright © 2077 WinExe - net8.0-windows10.0.22000.0 + net8.0-windows10.0.22621.0 10.0.17763.0 Sheas_Cealer enable @@ -31,6 +31,7 @@ True none true + Props @@ -72,6 +73,7 @@ + @@ -86,15 +88,36 @@ - + + True + True + AboutMultilangConst.resx + + True True Settings.settings + + True + True + MainMultilangConst.resx + - + + PublicResXFileCodeGenerator + AboutMultilangConst.Designer.cs + + + PublicResXFileCodeGenerator + MainMultilangConst.Designer.cs + + + + + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/Sheas-Cealer.sln b/Sheas-Cealer.sln index 8158f2f..cc9fcad 100644 --- a/Sheas-Cealer.sln +++ b/Sheas-Cealer.sln @@ -32,6 +32,12 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution + RESX_DuplicateKeyHandling = Fail + RESX_AutoCreateNewLanguageFiles = True + RESX_ConfirmAddLanguageFile = True + RESX_NeutralResourcesLanguage = en-US SolutionGuid = {33005A8D-2D3D-4101-AFF0-F68B29FE9B28} + RESX_SortFileContentOnSave = True + RESX_Rules = {"EnabledRules":["StringFormat","WhiteSpaceLead","WhiteSpaceTail","PunctuationLead"]} EndGlobalSection EndGlobal diff --git a/Utilities/Command.cs b/Utils/Command.cs similarity index 94% rename from Utilities/Command.cs rename to Utils/Command.cs index 31a998f..8d6ba35 100644 --- a/Utilities/Command.cs +++ b/Utils/Command.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using SheasCore; -namespace Sheas_Cealer +namespace Sheas_Cealer.Utils { internal class Command : Proc { diff --git a/Utils/FocusExtension.cs b/Utils/FocusExtension.cs new file mode 100644 index 0000000..d1ba1ae --- /dev/null +++ b/Utils/FocusExtension.cs @@ -0,0 +1,66 @@ +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/Utilities/IconRemover.cs b/Utils/IconRemover.cs similarity index 82% rename from Utilities/IconRemover.cs rename to Utils/IconRemover.cs index a141cf3..be4cbe6 100644 --- a/Utilities/IconRemover.cs +++ b/Utils/IconRemover.cs @@ -2,10 +2,11 @@ using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; +using Sheas_Cealer.Utils; -namespace Sheas_Cealer +namespace Sheas_Cealer.Utils { - //定义IconRemover + // 定义IconRemover internal static partial class IconRemover { private const int GWL_EXSTYLE = -20; @@ -28,27 +29,30 @@ namespace Sheas_Cealer internal static void RemoveIcon(Window window) { - //获取该窗口句柄 + // 获取该窗口句柄 IntPtr hwnd = new WindowInteropHelper(window).Handle; - //将窗口更改为不显示窗口图标 + // 将窗口更改为不显示窗口图标 _ = 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); } } +} - //使用IconRemover - public partial class MainWindow +namespace Sheas_Cealer.Wins +{ + // 使用IconRemover + public partial class MainWin { protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this); } - public partial class AboutWindow + public partial class AboutWin { protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this); } diff --git a/Windows/AboutWindow.xaml b/Windows/AboutWindow.xaml deleted file mode 100644 index 7a604a5..0000000 --- a/Windows/AboutWindow.xaml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - +