1.1.0 -> 1.1.1 第5次更新

This commit is contained in:
Space Time 2024-05-18 18:16:48 +08:00
parent 455ade0b2d
commit a90798a22d
18 changed files with 432 additions and 547 deletions

View File

@ -2,10 +2,10 @@
using System.Windows.Threading; using System.Windows.Threading;
using Sheas_Cealer.Wins; using Sheas_Cealer.Wins;
namespace Sheas_Cealer namespace Sheas_Cealer;
public partial class App : Application
{ {
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show(); protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show();
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
@ -13,5 +13,4 @@ namespace Sheas_Cealer
MessageBox.Show("Error: " + e.Exception.Message); MessageBox.Show("Error: " + e.Exception.Message);
e.Handled = true; e.Handled = true;
} }
}
} }

View File

@ -1,9 +1,9 @@
using System.Reflection; 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 Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2];
public static string DeveloperButtonUrl => "https://www.spacetimee.xyz"; public static string DeveloperButtonUrl => "https://www.spacetimee.xyz";
public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc"; public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc";
@ -12,5 +12,4 @@ namespace Sheas_Cealer.Consts
public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer"; 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 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 AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#title=Sheas_Cealer_使用协议";
}
} }

View File

@ -1,21 +1,17 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Sheas_Cealer.Consts namespace Sheas_Cealer.Consts;
internal partial class MainConst : MainMultilangConst
{ {
internal partial class MainConst : MainMultilangConst internal enum SettingsMode
{ { BrowserPathMode, UpstreamUrlMode, ExtraArgsMode };
internal enum Mode
{ 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$")] [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 HostRegex(); 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])*)*)?$")] [GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")]
internal static partial Regex ArgsRegex(); internal static partial Regex ExtraArgsRegex();
}
} }

View File

@ -2,10 +2,10 @@
using System.Globalization; using System.Globalization;
using System.Windows.Data; 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? VersionButtonContent = values[0] as string;
@ -18,5 +18,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -4,15 +4,13 @@ using System.Windows.Data;
using System.Windows.Media; using System.Windows.Media;
using Sheas_Cealer.Consts; using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs namespace Sheas_Cealer.Convs;
{
internal class MainContentBoxForegroundConv : IMultiValueConverter
{
private static readonly MainConst MainConst = new();
internal class MainContentBoxForegroundConv : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{ {
MainConst.Mode? mode = values[0] as MainConst.Mode?; MainConst.SettingsMode? mode = values[0] as MainConst.SettingsMode?;
bool? isFocused = values[1] as bool?; bool? isFocused = values[1] as bool?;
string? browserPath = values[2] as string; string? browserPath = values[2] as string;
string? upstreamUrl = values[3] as string; string? upstreamUrl = values[3] as string;
@ -22,15 +20,15 @@ namespace Sheas_Cealer.Convs
{ {
switch (mode) switch (mode)
{ {
case MainConst.Mode.browserPathMode: case MainConst.SettingsMode.BrowserPathMode:
if (browserPath == MainConst.BrowserPathPlaceHolder) if (browserPath == MainConst.BrowserPathPlaceHolder)
return new SolidColorBrush(Color.FromRgb(191, 205, 219)); return new SolidColorBrush(Color.FromRgb(191, 205, 219));
break; break;
case MainConst.Mode.upstreamUrlMode: case MainConst.SettingsMode.UpstreamUrlMode:
if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder) if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder)
return new SolidColorBrush(Color.FromRgb(191, 205, 219)); return new SolidColorBrush(Color.FromRgb(191, 205, 219));
break; break;
case MainConst.Mode.extraArgsMode: case MainConst.SettingsMode.ExtraArgsMode:
if (extraArgs == MainConst.ExtraArgsPlaceHolder) if (extraArgs == MainConst.ExtraArgsPlaceHolder)
return new SolidColorBrush(Color.FromRgb(191, 205, 219)); return new SolidColorBrush(Color.FromRgb(191, 205, 219));
break; break;
@ -44,5 +42,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -3,21 +3,19 @@ using System.Diagnostics;
using System.Windows.Data; using System.Windows.Data;
using Sheas_Cealer.Consts; using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs namespace Sheas_Cealer.Convs;
{
internal class MainContentBoxTextConv : IMultiValueConverter
{
private static readonly MainConst MainConst = new();
internal class MainContentBoxTextConv : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{ {
MainConst.Mode? mode = values[0] as MainConst.Mode?; MainConst.SettingsMode? mode = values[0] as MainConst.SettingsMode?;
bool? isFocused = values[1] as bool?; bool? isFocused = values[1] as bool?;
string? browserPath = values[2] as string; string? browserPath = values[2] as string;
string? upstreamUrl = values[3] as string; string? upstreamUrl = values[3] as string;
string? extraArgs = values[4] as string; string? extraArgs = values[4] as string;
if (mode == MainConst.Mode.browserPathMode) if (mode == MainConst.SettingsMode.BrowserPathMode)
{ {
if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath)) if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath))
return MainConst.BrowserPathPlaceHolder; return MainConst.BrowserPathPlaceHolder;
@ -26,7 +24,7 @@ namespace Sheas_Cealer.Convs
else else
return browserPath!; return browserPath!;
} }
else if (mode == MainConst.Mode.upstreamUrlMode) else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
{ {
if ((bool)!isFocused! && string.IsNullOrEmpty(upstreamUrl)) if ((bool)!isFocused! && string.IsNullOrEmpty(upstreamUrl))
return MainConst.UpstreamUrlPlaceHolder; return MainConst.UpstreamUrlPlaceHolder;
@ -35,7 +33,7 @@ namespace Sheas_Cealer.Convs
else else
return upstreamUrl!; return upstreamUrl!;
} }
else if (mode == MainConst.Mode.extraArgsMode) else if (mode == MainConst.SettingsMode.ExtraArgsMode)
{ {
if ((bool)!isFocused! && string.IsNullOrEmpty(extraArgs)) if ((bool)!isFocused! && string.IsNullOrEmpty(extraArgs))
return MainConst.ExtraArgsPlaceHolder; return MainConst.ExtraArgsPlaceHolder;
@ -54,5 +52,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -4,19 +4,19 @@ using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
using Sheas_Cealer.Consts; 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) if (mode == MainConst.SettingsMode.BrowserPathMode)
return MainConst.FunctionButtonBrowserPathContent; return MainConst.FunctionButtonBrowserPathContent;
else if (mode == MainConst.Mode.upstreamUrlMode) else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
return MainConst.FunctionButtonUpstreamUrlContent; return MainConst.FunctionButtonUpstreamUrlContent;
else if (mode == MainConst.Mode.extraArgsMode) else if (mode == MainConst.SettingsMode.ExtraArgsMode)
return MainConst.FunctionButtonExtraArgsContent; return MainConst.FunctionButtonExtraArgsContent;
throw new UnreachableException(); throw new UnreachableException();
@ -26,5 +26,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -4,16 +4,16 @@ using System.IO;
using System.Windows.Data; using System.Windows.Data;
using Sheas_Cealer.Consts; 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? browserPath = values[0] as string;
string? extraArgs = values[1] 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)) if (File.Exists(browserPath) && Path.GetFileName(browserPath).ToLower().EndsWith(".exe") && (MainConst.ExtraArgsRegex().IsMatch(extraArgs!) || extraArgs == MainConst.ExtraArgsPlaceHolder))
return true; return true;
return false; return false;
@ -23,5 +23,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -4,19 +4,19 @@ using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
using Sheas_Cealer.Consts; 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) if (mode == MainConst.SettingsMode.BrowserPathMode)
return MainConst.SwitchModeButtonBrowserPathContent; return MainConst.SwitchModeButtonBrowserPathContent;
else if (mode == MainConst.Mode.upstreamUrlMode) else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
return MainConst.SwitchModeButtonUpstreamUrlContent; return MainConst.SwitchModeButtonUpstreamUrlContent;
else if (mode == MainConst.Mode.extraArgsMode) else if (mode == MainConst.SettingsMode.ExtraArgsMode)
return MainConst.SwitchModeButtonExtraArgsContent; return MainConst.SwitchModeButtonExtraArgsContent;
throw new UnreachableException(); throw new UnreachableException();
@ -26,5 +26,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -3,15 +3,15 @@ using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
using Sheas_Cealer.Consts; 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!)) if (MainConst.UpstreamUrlRegex().IsMatch(upstreamUrl!))
return true; return true;
return false; return false;
@ -21,5 +21,4 @@ namespace Sheas_Cealer.Convs
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
}
} }

View File

@ -1,37 +1,38 @@
using System.IO; using System;
using System.IO;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using Sheas_Cealer.Consts; using Sheas_Cealer.Consts;
using File = System.IO.File; using File = System.IO.File;
namespace Sheas_Cealer.Preses namespace Sheas_Cealer.Preses;
{
internal partial class MainPres : ObservableObject
{
private static readonly MainConst MainConst = new();
internal partial class MainPres : ObservableObject
{
internal MainPres(string[] args) internal MainPres(string[] args)
{ {
if (args.Length > 0) int browserPathIndex = Array.FindIndex(args, arg => arg == "-b") + 1,
BrowserPath = args[0]; upstreamUrlIndex = Array.FindIndex(args, arg => arg == "-u") + 1,
else if (!string.IsNullOrWhiteSpace(Props.Settings.Default.BrowserPath)) extraArgsIndex = Array.FindIndex(args, arg => arg == "e") + 1;
BrowserPath = Props.Settings.Default.BrowserPath;
if (!string.IsNullOrWhiteSpace(Props.Settings.Default.UpstreamUrl)) BrowserPath = browserPathIndex == 0 ?
UpstreamUrl = Props.Settings.Default.UpstreamUrl; (!string.IsNullOrWhiteSpace(Props.Settings.Default.BrowserPath) ? Props.Settings.Default.BrowserPath : string.Empty) :
args[browserPathIndex];
if (!string.IsNullOrWhiteSpace(Props.Settings.Default.ExtraArgs)) UpstreamUrl = upstreamUrlIndex == 0 ?
ExtraArgs = Props.Settings.Default.ExtraArgs; (!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] [ObservableProperty]
private MainConst.Mode mode = MainConst.Mode.browserPathMode; private MainConst.SettingsMode mode = MainConst.SettingsMode.BrowserPathMode;
[ObservableProperty] [ObservableProperty]
private bool isContentBoxFocused = true; private string browserPath;
private partial void OnBrowserPathChanged(string value)
[ObservableProperty]
private string browserPath = string.Empty;
partial void OnBrowserPathChanged(string value)
{ {
if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe")) if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe"))
{ {
@ -41,10 +42,10 @@ namespace Sheas_Cealer.Preses
} }
[ObservableProperty] [ObservableProperty]
private string upstreamUrl = MainConst.DefaultUpstreamUrl; private string upstreamUrl;
partial void OnUpstreamUrlChanged(string value) private partial void OnUpstreamUrlChanged(string value)
{ {
if (MainConst.UrlRegex().IsMatch(value)) if (MainConst.UpstreamUrlRegex().IsMatch(value))
{ {
Props.Settings.Default.UpstreamUrl = value; Props.Settings.Default.UpstreamUrl = value;
Props.Settings.Default.Save(); Props.Settings.Default.Save();
@ -52,14 +53,13 @@ namespace Sheas_Cealer.Preses
} }
[ObservableProperty] [ObservableProperty]
private string extraArgs = string.Empty; private string extraArgs;
partial void OnExtraArgsChanged(string value) private partial void OnExtraArgsChanged(string value)
{ {
if (MainConst.ArgsRegex().IsMatch(value)) if (MainConst.ExtraArgsRegex().IsMatch(value))
{ {
Props.Settings.Default.ExtraArgs = value; Props.Settings.Default.ExtraArgs = value;
Props.Settings.Default.Save(); Props.Settings.Default.Save();
} }
} }
}
} }

View File

@ -2,10 +2,10 @@
using System.Diagnostics; using System.Diagnostics;
using SheasCore; using SheasCore;
namespace Sheas_Cealer.Utils namespace Sheas_Cealer.Utils;
internal class Command : Proc
{ {
internal class Command : Proc
{
internal Command() : base("Cmd.exe") internal Command() : base("Cmd.exe")
{ {
} }
@ -17,5 +17,4 @@ namespace Sheas_Cealer.Utils
{ {
} }
public override void Process_Exited(object sender, EventArgs e) => Environment.Exit(0); public override void Process_Exited(object sender, EventArgs e) => Environment.Exit(0);
}
} }

View File

@ -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);
}
}
}

View File

@ -2,13 +2,12 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
using System.Windows.Interop; 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 GWL_EXSTYLE = -20;
private const int WS_EX_DLGMODALFRAME = 0x0001; private const int WS_EX_DLGMODALFRAME = 0x0001;
private const int SWP_NOSIZE = 0x0001; private const int SWP_NOSIZE = 0x0001;
@ -42,18 +41,4 @@ namespace Sheas_Cealer.Utils
SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero); SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, 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);
}
} }

View File

@ -38,7 +38,6 @@
<Binding Path="VersionButtonContent" Source="{StaticResource AboutConst}" /> <Binding Path="VersionButtonContent" Source="{StaticResource AboutConst}" />
<Binding Path="Version" Source="{StaticResource AboutConst}" /> <Binding Path="Version" Source="{StaticResource AboutConst}" />
</MultiBinding> </MultiBinding>
</Button.Content> </Button.Content>
</Button> </Button>
@ -58,6 +57,5 @@
<Button x:Name="AgreementButton" <Button x:Name="AgreementButton"
Content="{Binding AgreementButtonContent, Source={StaticResource AboutConst}}" Grid.Row="1" Grid.Column="3" Margin="5" ToolTip="{Binding AgreementButtonUrl, Source={StaticResource AboutConst}}" Content="{Binding AgreementButtonContent, Source={StaticResource AboutConst}}" Grid.Row="1" Grid.Column="3" Margin="5" ToolTip="{Binding AgreementButtonUrl, Source={StaticResource AboutConst}}"
Click="AboutButton_Click" /> Click="AboutButton_Click" />
</Grid> </Grid>
</Window> </Window>

View File

@ -1,16 +1,15 @@
using System.Diagnostics; using System;
using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using Sheas_Cealer.Utils;
namespace Sheas_Cealer.Wins namespace Sheas_Cealer.Wins;
public partial class AboutWin : Window
{ {
public partial class AboutWin : Window internal AboutWin() => InitializeComponent();
{
internal AboutWin()
{
InitializeComponent();
}
private void AboutButton_Click(object sender, RoutedEventArgs e) private void AboutButton_Click(object sender, RoutedEventArgs e)
{ {
@ -26,5 +25,6 @@ namespace Sheas_Cealer.Wins
if (e.Key == Key.Escape) if (e.Key == Key.Escape)
Close(); Close();
} }
}
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
} }

View File

@ -3,10 +3,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:preses="clr-namespace:Sheas_Cealer.Preses"
xmlns:convs="clr-namespace:Sheas_Cealer.Convs"
xmlns:consts="clr-namespace:Sheas_Cealer.Consts" xmlns:consts="clr-namespace:Sheas_Cealer.Consts"
xmlns:utils="clr-namespace:Sheas_Cealer.Utils" xmlns:convs="clr-namespace:Sheas_Cealer.Convs"
xmlns:preses="clr-namespace:Sheas_Cealer.Preses"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance preses:MainPres}" AllowDrop="True" d:DataContext="{d:DesignInstance preses:MainPres}" AllowDrop="True"
Style="{DynamicResource CommonWindow}" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" SizeToContent="Height" Width="500" MinWidth="500" Style="{DynamicResource CommonWindow}" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" SizeToContent="Height" Width="500" MinWidth="500"
@ -40,7 +39,7 @@
</Button.Content> </Button.Content>
</Button> </Button>
<TextBox x:Name="ContentText" utils:FocusExtension.IsFocused="{Binding IsContentBoxFocused}" <TextBox x:Name="ContentBox"
Grid.Column="1" Margin="5" VerticalContentAlignment="Center" Grid.Column="1" Margin="5" VerticalContentAlignment="Center"
TextChanged="ContentBox_TextChanged" PreviewDragOver="MainWin_DragEnter"> TextChanged="ContentBox_TextChanged" PreviewDragOver="MainWin_DragEnter">
<TextBox.Text> <TextBox.Text>
@ -54,7 +53,6 @@
<Binding Path="BrowserPath" /> <Binding Path="BrowserPath" />
<Binding Path="UpstreamUrl" /> <Binding Path="UpstreamUrl" />
<Binding Path="ExtraArgs" /> <Binding Path="ExtraArgs" />
</MultiBinding> </MultiBinding>
</TextBox.Text> </TextBox.Text>
<TextBox.Foreground> <TextBox.Foreground>
@ -68,7 +66,6 @@
<Binding Path="BrowserPath" /> <Binding Path="BrowserPath" />
<Binding Path="UpstreamUrl" /> <Binding Path="UpstreamUrl" />
<Binding Path="ExtraArgs" /> <Binding Path="ExtraArgs" />
</MultiBinding> </MultiBinding>
</TextBox.Foreground> </TextBox.Foreground>
</TextBox> </TextBox>
@ -82,7 +79,6 @@
</Binding> </Binding>
</Button.Content> </Button.Content>
</Button> </Button>
</Grid> </Grid>
<Button IsDefault="True" <Button IsDefault="True"
@ -97,7 +93,6 @@
<Binding Path="BrowserPath" /> <Binding Path="BrowserPath" />
<Binding Path="ExtraArgs" /> <Binding Path="ExtraArgs" />
</MultiBinding> </MultiBinding>
</Button.IsEnabled> </Button.IsEnabled>
</Button> </Button>
@ -126,7 +121,6 @@
<Button x:Name="AboutButton" <Button x:Name="AboutButton"
Grid.Column="2" Margin="5" Content="{Binding AboutButtonContent, Source={StaticResource MainConst}}" Grid.Column="2" Margin="5" Content="{Binding AboutButtonContent, Source={StaticResource MainConst}}"
Click="AboutButton_Click" /> Click="AboutButton_Click" />
</Grid> </Grid>
</Grid> </Grid>
</Window> </Window>

View File

@ -3,7 +3,6 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -16,15 +15,14 @@ using Sheas_Cealer.Preses;
using Sheas_Cealer.Utils; using Sheas_Cealer.Utils;
using File = System.IO.File; using File = System.IO.File;
namespace Sheas_Cealer.Wins namespace Sheas_Cealer.Wins;
public partial class MainWin : Window
{ {
public partial class MainWin : Window
{
private static string CealArgs = string.Empty; private static string CealArgs = string.Empty;
private static readonly HttpClient MainClient = new(); private static readonly HttpClient MainClient = new();
private static readonly FileSystemWatcher CealingHostWatcher = new(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json") { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite }; private static readonly FileSystemWatcher CealingHostWatcher = new(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json") { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
private static MainPres? MainPres; private static MainPres? MainPres;
private static readonly MainConst MainConst = new();
internal MainWin(string[] args) internal MainWin(string[] args)
{ {
@ -32,14 +30,9 @@ namespace Sheas_Cealer.Wins
MainPres = new(args); MainPres = new(args);
DataContext = MainPres; DataContext = MainPres;
Task.Run(() =>
{
CealingHostWatcher.Changed += CealingHostWatcher_Changed; CealingHostWatcher.Changed += CealingHostWatcher_Changed;
CealingHostWatcher_Changed(null!, null!);
});
} }
private void MainWin_Loaded(object sender, RoutedEventArgs e) => MainPres!.IsContentBoxFocused = true; private void MainWin_Loaded(object sender, RoutedEventArgs e) => ContentBox.Focus();
private void MainWin_Closing(object sender, CancelEventArgs e) => Environment.Exit(0); private void MainWin_Closing(object sender, CancelEventArgs e) => Environment.Exit(0);
private void MainWin_DragEnter(object sender, DragEventArgs e) private void MainWin_DragEnter(object sender, DragEventArgs e)
@ -61,40 +54,40 @@ namespace Sheas_Cealer.Wins
{ {
TextBox? ContentBox = sender as TextBox; TextBox? ContentBox = sender as TextBox;
if (MainPres!.Mode == MainConst.Mode.browserPathMode) if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
MainPres.BrowserPath = ContentBox!.Text; MainPres.BrowserPath = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode) else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres.UpstreamUrl = ContentBox!.Text; MainPres.UpstreamUrl = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode) else if (MainPres!.Mode == MainConst.SettingsMode.ExtraArgsMode)
MainPres.ExtraArgs = ContentBox!.Text; MainPres.ExtraArgs = ContentBox!.Text;
else else
throw new UnreachableException(); throw new UnreachableException();
} }
private void FunctionButton_Click(object sender, RoutedEventArgs e) private void FunctionButton_Click(object sender, RoutedEventArgs e)
{ {
if (MainPres!.Mode == MainConst.Mode.browserPathMode) if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
{ {
OpenFileDialog openFileDialog = new() { Filter = "浏览器 (*.exe)|*.exe" }; OpenFileDialog openFileDialog = new() { Filter = "浏览器 (*.exe)|*.exe" };
if (openFileDialog.ShowDialog() == true) if (openFileDialog.ShowDialog() == true)
{ {
MainPres!.IsContentBoxFocused = true; ContentBox.Focus();
MainPres!.BrowserPath = openFileDialog.FileName; MainPres!.BrowserPath = openFileDialog.FileName;
} }
} }
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode) else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres!.UpstreamUrl = MainConst.DefaultUpstreamUrl; MainPres!.UpstreamUrl = MainConst.DefaultUpstreamUrl;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode) else if (MainPres!.Mode == MainConst.SettingsMode.ExtraArgsMode)
MainPres!.ExtraArgs = string.Empty; MainPres!.ExtraArgs = string.Empty;
} }
private void SwitchModeButton_Click(object sender, RoutedEventArgs e) private void SwitchModeButton_Click(object sender, RoutedEventArgs e)
{ {
if (MainPres!.Mode == MainConst.Mode.browserPathMode) if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
MainPres!.Mode = MainConst.Mode.upstreamUrlMode; MainPres!.Mode = MainConst.SettingsMode.UpstreamUrlMode;
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode) else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres!.Mode = MainConst.Mode.extraArgsMode; MainPres!.Mode = MainConst.SettingsMode.ExtraArgsMode;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode) else if (MainPres!.Mode == MainConst.SettingsMode.ExtraArgsMode)
MainPres!.Mode = MainConst.Mode.browserPathMode; MainPres!.Mode = MainConst.SettingsMode.BrowserPathMode;
} }
private void StartCealButton_Click(object sender, RoutedEventArgs e) private void StartCealButton_Click(object sender, RoutedEventArgs e)
@ -131,7 +124,7 @@ namespace Sheas_Cealer.Wins
string hostLocalString = hostLocalStreamReader.ReadToEnd(); string hostLocalString = hostLocalStreamReader.ReadToEnd();
hostLocalStreamReader.Close(); hostLocalStreamReader.Close();
if (MainConst.HostRegex().Replace(hostLocalString, string.Empty) == UpdateHostString) if (hostLocalString.Replace("\r", string.Empty) == UpdateHostString)
MessageBox.Show("本地伪造规则和上游一模一样"); MessageBox.Show("本地伪造规则和上游一模一样");
else else
{ {
@ -145,10 +138,7 @@ namespace Sheas_Cealer.Wins
Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true }); Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true });
} }
} }
private void AboutButton_Click(object sender, RoutedEventArgs e) private void AboutButton_Click(object sender, RoutedEventArgs e) => new AboutWin().ShowDialog();
{
new AboutWin().ShowDialog();
}
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e) private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
{ {
@ -156,8 +146,9 @@ namespace Sheas_Cealer.Wins
{ {
string hostRules = string.Empty, hostResolverRules = string.Empty; string hostRules = string.Empty, hostResolverRules = string.Empty;
int ruleIndex = 0; int ruleIndex = 0;
FileStream hostStream = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); using FileStream hostStream = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
JArray hostJArray = JArray.Parse(new StreamReader(hostStream).ReadToEnd()); using StreamReader hostReader = new(hostStream);
JArray hostJArray = JArray.Parse(hostReader.ReadToEnd());
foreach (var hostJToken in hostJArray) foreach (var hostJToken in hostJArray)
{ {
@ -184,5 +175,6 @@ namespace Sheas_Cealer.Wins
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.W) if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.W)
Environment.Exit(0); Environment.Exit(0);
} }
}
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
} }