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,16 +2,15 @@
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
{
protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show();
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) public partial class App : Application
{ {
MessageBox.Show("Error: " + e.Exception.Message); protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show();
e.Handled = true;
} private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show("Error: " + e.Exception.Message);
e.Handled = true;
} }
} }

View File

@ -1,16 +1,15 @@
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 DeveloperButtonUrl => "https://www.spacetimee.xyz";
public static string Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2]; public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc";
public static string DeveloperButtonUrl => "https://www.spacetimee.xyz"; public static string EmailButtonUrl => "Zeus6_6@163.com";
public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc"; public static string InstructionButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Instruction";
public static string EmailButtonUrl => "Zeus6_6@163.com"; public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer";
public static string InstructionButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Instruction"; public static string PrivacyButtonUrl => "https://thoughts.teambition.com/share/6264eda98adeb10041b92fda#title=Sheas_Cealer_隐私政策";
public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer"; public static string AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#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_使用协议";
}
} }

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.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*)?$")] [GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")]
internal static partial Regex UrlRegex(); internal static partial Regex ExtraArgsRegex();
[GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")]
internal static partial Regex ArgsRegex();
}
} }

View File

@ -2,21 +2,20 @@
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? 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) public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
} }
} }

View File

@ -4,45 +4,42 @@ 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
{ {
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?; switch (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.SettingsMode.BrowserPathMode:
{ if (browserPath == MainConst.BrowserPathPlaceHolder)
case MainConst.Mode.browserPathMode: return new SolidColorBrush(Color.FromRgb(191, 205, 219));
if (browserPath == MainConst.BrowserPathPlaceHolder) break;
return new SolidColorBrush(Color.FromRgb(191, 205, 219)); case MainConst.SettingsMode.UpstreamUrlMode:
break; if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder)
case MainConst.Mode.upstreamUrlMode: return new SolidColorBrush(Color.FromRgb(191, 205, 219));
if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder) break;
return new SolidColorBrush(Color.FromRgb(191, 205, 219)); case MainConst.SettingsMode.ExtraArgsMode:
break; if (extraArgs == MainConst.ExtraArgsPlaceHolder)
case MainConst.Mode.extraArgsMode: return new SolidColorBrush(Color.FromRgb(191, 205, 219));
if (extraArgs == MainConst.ExtraArgsPlaceHolder) break;
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) return new SolidColorBrush(Color.FromRgb(0, 0, 0));
{ }
throw new NotImplementedException();
} public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
} }
} }

View File

@ -3,56 +3,53 @@ 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
{ {
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?; if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath))
bool? isFocused = values[1] as bool?; return MainConst.BrowserPathPlaceHolder;
string? browserPath = values[2] as string; else if ((bool)isFocused! && browserPath == MainConst.BrowserPathPlaceHolder)
string? upstreamUrl = values[3] as string; return string.Empty;
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 else
{ return browserPath!;
throw new UnreachableException();
}
} }
else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{ {
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();
}
} }

View File

@ -4,27 +4,26 @@ 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.SettingsMode? mode = value as MainConst.SettingsMode?;
{
MainConst.Mode? mode = value as MainConst.Mode?;
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();
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
} }
} }

View File

@ -4,24 +4,23 @@ 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? 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)) 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;
} }
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
} }
} }

View File

@ -4,27 +4,26 @@ 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.SettingsMode? mode = value as MainConst.SettingsMode?;
{
MainConst.Mode? mode = value as MainConst.Mode?;
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();
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
} }
} }

View File

@ -3,23 +3,22 @@ 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;
} }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
}
} }
} }

View File

@ -1,65 +1,65 @@
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
{ {
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) Props.Settings.Default.BrowserPath = value;
BrowserPath = args[0]; Props.Settings.Default.Save();
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] [ObservableProperty]
private MainConst.Mode mode = MainConst.Mode.browserPathMode; private string upstreamUrl;
private partial void OnUpstreamUrlChanged(string value)
[ObservableProperty] {
private bool isContentBoxFocused = true; if (MainConst.UpstreamUrlRegex().IsMatch(value))
[ObservableProperty]
private string browserPath = string.Empty;
partial void OnBrowserPathChanged(string value)
{ {
if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe")) Props.Settings.Default.UpstreamUrl = value;
{ Props.Settings.Default.Save();
Props.Settings.Default.BrowserPath = value;
Props.Settings.Default.Save();
}
} }
}
[ObservableProperty] [ObservableProperty]
private string upstreamUrl = MainConst.DefaultUpstreamUrl; private string extraArgs;
partial void OnUpstreamUrlChanged(string value) private partial void OnExtraArgsChanged(string value)
{
if (MainConst.ExtraArgsRegex().IsMatch(value))
{ {
if (MainConst.UrlRegex().IsMatch(value)) Props.Settings.Default.ExtraArgs = value;
{ Props.Settings.Default.Save();
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();
}
} }
} }
} }

View File

@ -2,20 +2,19 @@
using System.Diagnostics; using System.Diagnostics;
using SheasCore; using SheasCore;
namespace Sheas_Cealer.Utils namespace Sheas_Cealer.Utils;
{
internal class Command : Proc
{
internal Command() : base("Cmd.exe")
{
}
public override void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) internal class Command : Proc
{ {
} internal Command() : base("Cmd.exe")
public override void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) {
{
}
public override void Process_Exited(object sender, EventArgs e) => Environment.Exit(0);
} }
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);
} }

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,58 +2,43 @@
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 private const int GWL_EXSTYLE = -20;
internal static partial class IconRemover 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; IntPtr hwnd = new WindowInteropHelper(window).Handle;
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); _ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME);
[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) // 更新窗口的非客户区域来显示更改
{ SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// 获取该窗口句柄
IntPtr hwnd = new WindowInteropHelper(window).Handle;
// 将窗口更改为不显示窗口图标 // 防止自定义图标生效
_ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME); SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
// 更新窗口的非客户区域来显示更改
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);
} }
} }

View File

@ -35,10 +35,9 @@
<MultiBinding.Converter> <MultiBinding.Converter>
<convs:AboutVersionButtonContentConv /> <convs:AboutVersionButtonContentConv />
</MultiBinding.Converter> </MultiBinding.Converter>
<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,30 +1,30 @@
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();
private void AboutButton_Click(object sender, RoutedEventArgs e)
{ {
internal AboutWin() if (sender as Button == VersionButton)
{ MessageBox.Show("密码: 3wnj");
InitializeComponent();
}
private void AboutButton_Click(object sender, RoutedEventArgs e) ProcessStartInfo processStartInfo = new(sender as Button == EmailButton ? "mailto:" : string.Empty + (sender as Button)!.ToolTip) { UseShellExecute = true };
{ Process.Start(processStartInfo);
if (sender as Button == VersionButton)
MessageBox.Show("密码: 3wnj");
ProcessStartInfo processStartInfo = new(sender as Button == EmailButton ? "mailto:" : string.Empty + (sender as Button)!.ToolTip) { UseShellExecute = true };
Process.Start(processStartInfo);
}
private void AboutWin_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
Close();
}
} }
private void AboutWin_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
Close();
}
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
} }

View File

@ -3,12 +3,11 @@
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"
Loaded="MainWin_Loaded" Closing="MainWin_Closing" DragEnter="MainWin_DragEnter" Drop="MainWin_Drop" KeyDown="MainWin_KeyDown"> Loaded="MainWin_Loaded" Closing="MainWin_Closing" DragEnter="MainWin_DragEnter" Drop="MainWin_Drop" KeyDown="MainWin_KeyDown">
<Window.Resources> <Window.Resources>
@ -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,173 +15,166 @@ 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 readonly HttpClient MainClient = new();
private static readonly FileSystemWatcher CealingHostWatcher = new(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json") { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
private static MainPres? MainPres;
internal MainWin(string[] args)
{ {
private static string CealArgs = string.Empty; InitializeComponent();
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 MainPres? MainPres;
private static readonly MainConst MainConst = new();
internal MainWin(string[] args) MainPres = new(args);
DataContext = MainPres;
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
}
private void MainWin_Loaded(object sender, RoutedEventArgs e) => ContentBox.Focus();
private void MainWin_Closing(object sender, CancelEventArgs e) => Environment.Exit(0);
private void MainWin_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effects = DragDropEffects.Link;
else
e.Effects = DragDropEffects.None;
e.Handled = true;
}
private void MainWin_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
MainPres!.BrowserPath = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
}
private void ContentBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox? ContentBox = sender as TextBox;
if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
MainPres.BrowserPath = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres.UpstreamUrl = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.SettingsMode.ExtraArgsMode)
MainPres.ExtraArgs = ContentBox!.Text;
else
throw new UnreachableException();
}
private void FunctionButton_Click(object sender, RoutedEventArgs e)
{
if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
{ {
InitializeComponent(); OpenFileDialog openFileDialog = new() { Filter = "浏览器 (*.exe)|*.exe" };
MainPres = new(args); if (openFileDialog.ShowDialog() == true)
DataContext = MainPres;
Task.Run(() =>
{ {
CealingHostWatcher.Changed += CealingHostWatcher_Changed; ContentBox.Focus();
CealingHostWatcher_Changed(null!, null!); MainPres!.BrowserPath = openFileDialog.FileName;
});
}
private void MainWin_Loaded(object sender, RoutedEventArgs e) => MainPres!.IsContentBoxFocused = true;
private void MainWin_Closing(object sender, CancelEventArgs e) => Environment.Exit(0);
private void MainWin_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effects = DragDropEffects.Link;
else
e.Effects = DragDropEffects.None;
e.Handled = true;
}
private void MainWin_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
MainPres!.BrowserPath = ((string[])e.Data.GetData(DataFormats.FileDrop))[0];
}
private void ContentBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox? ContentBox = sender as TextBox;
if (MainPres!.Mode == MainConst.Mode.browserPathMode)
MainPres.BrowserPath = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode)
MainPres.UpstreamUrl = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode)
MainPres.ExtraArgs = ContentBox!.Text;
else
throw new UnreachableException();
}
private void FunctionButton_Click(object sender, RoutedEventArgs e)
{
if (MainPres!.Mode == MainConst.Mode.browserPathMode)
{
OpenFileDialog openFileDialog = new() { Filter = "浏览器 (*.exe)|*.exe" };
if (openFileDialog.ShowDialog() == true)
{
MainPres!.IsContentBoxFocused = true;
MainPres!.BrowserPath = openFileDialog.FileName;
}
}
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode)
MainPres!.UpstreamUrl = MainConst.DefaultUpstreamUrl;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode)
MainPres!.ExtraArgs = string.Empty;
}
private void SwitchModeButton_Click(object sender, RoutedEventArgs e)
{
if (MainPres!.Mode == MainConst.Mode.browserPathMode)
MainPres!.Mode = MainConst.Mode.upstreamUrlMode;
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode)
MainPres!.Mode = MainConst.Mode.extraArgsMode;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode)
MainPres!.Mode = MainConst.Mode.browserPathMode;
}
private void StartCealButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(CealArgs))
throw new Exception("规则无法识别,请检查伪造规则是否含有语法错误");
if (MessageBox.Show("启动前将关闭所选浏览器的所有进程,是否继续?", string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
return;
IWshShortcut uncealedBrowserShortcut = (IWshShortcut)new WshShell().CreateShortcut(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Uncealed-Browser.lnk"));
uncealedBrowserShortcut.TargetPath = MainPres!.BrowserPath;
uncealedBrowserShortcut.Description = "Created By Sheas Cealer";
uncealedBrowserShortcut.Save();
foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres!.BrowserPath)))
{
browserProcess.Kill();
browserProcess.WaitForExit();
}
new Command().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, CealArgs + " " + MainPres!.ExtraArgs);
}
private void EditHostButton_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo processStartInfo = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json")) { UseShellExecute = true };
Process.Start(processStartInfo);
}
private async void UpdateHostButton_Click(object sender, RoutedEventArgs e)
{
string hostUrl = MainPres!.UpstreamUrl;
string UpdateHostString = await Http.GetAsync<string>(hostUrl, MainClient);
StreamReader hostLocalStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"));
string hostLocalString = hostLocalStreamReader.ReadToEnd();
hostLocalStreamReader.Close();
if (MainConst.HostRegex().Replace(hostLocalString, string.Empty) == UpdateHostString)
MessageBox.Show("本地伪造规则和上游一模一样");
else
{
MessageBoxResult overrideResult = MessageBox.Show("本地伪造规则和上游略有不同,需要覆盖本地吗? 否则只为你打开上游规则的网页", string.Empty, MessageBoxButton.YesNoCancel);
if (overrideResult == MessageBoxResult.Yes)
{
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), UpdateHostString);
MessageBox.Show("更新已完成");
}
else if (overrideResult == MessageBoxResult.No)
Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true });
} }
} }
private void AboutButton_Click(object sender, RoutedEventArgs e) else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres!.UpstreamUrl = MainConst.DefaultUpstreamUrl;
else if (MainPres!.Mode == MainConst.SettingsMode.ExtraArgsMode)
MainPres!.ExtraArgs = string.Empty;
}
private void SwitchModeButton_Click(object sender, RoutedEventArgs e)
{
if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
MainPres!.Mode = MainConst.SettingsMode.UpstreamUrlMode;
else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres!.Mode = MainConst.SettingsMode.ExtraArgsMode;
else if (MainPres!.Mode == MainConst.SettingsMode.ExtraArgsMode)
MainPres!.Mode = MainConst.SettingsMode.BrowserPathMode;
}
private void StartCealButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(CealArgs))
throw new Exception("规则无法识别,请检查伪造规则是否含有语法错误");
if (MessageBox.Show("启动前将关闭所选浏览器的所有进程,是否继续?", string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
return;
IWshShortcut uncealedBrowserShortcut = (IWshShortcut)new WshShell().CreateShortcut(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Uncealed-Browser.lnk"));
uncealedBrowserShortcut.TargetPath = MainPres!.BrowserPath;
uncealedBrowserShortcut.Description = "Created By Sheas Cealer";
uncealedBrowserShortcut.Save();
foreach (Process browserProcess in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(MainPres!.BrowserPath)))
{ {
new AboutWin().ShowDialog(); browserProcess.Kill();
browserProcess.WaitForExit();
} }
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e) new Command().ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, CealArgs + " " + MainPres!.ExtraArgs);
}
private void EditHostButton_Click(object sender, RoutedEventArgs e)
{
ProcessStartInfo processStartInfo = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json")) { UseShellExecute = true };
Process.Start(processStartInfo);
}
private async void UpdateHostButton_Click(object sender, RoutedEventArgs e)
{
string hostUrl = MainPres!.UpstreamUrl;
string UpdateHostString = await Http.GetAsync<string>(hostUrl, MainClient);
StreamReader hostLocalStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"));
string hostLocalString = hostLocalStreamReader.ReadToEnd();
hostLocalStreamReader.Close();
if (hostLocalString.Replace("\r", string.Empty) == UpdateHostString)
MessageBox.Show("本地伪造规则和上游一模一样");
else
{ {
try MessageBoxResult overrideResult = MessageBox.Show("本地伪造规则和上游略有不同,需要覆盖本地吗? 否则只为你打开上游规则的网页", string.Empty, MessageBoxButton.YesNoCancel);
if (overrideResult == MessageBoxResult.Yes)
{ {
string hostRules = string.Empty, hostResolverRules = string.Empty; File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), UpdateHostString);
int ruleIndex = 0; MessageBox.Show("更新已完成");
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());
foreach (var hostJToken in hostJArray)
{
if (string.IsNullOrWhiteSpace(hostJToken[1]!.ToString()))
hostJToken[1] = "c" + ruleIndex;
foreach (var hostName in hostJToken[0]!)
{
if (hostName != hostJToken[1])
hostRules += "MAP " + hostName + " " + hostJToken[1] + ",";
}
hostResolverRules += "MAP " + hostJToken[1] + " " + hostJToken[2] + ",";
++ruleIndex;
}
CealArgs = @"/c @start .\""Uncealed-Browser.lnk"" --host-rules=""" + hostRules[0..^1] + @""" --host-resolver-rules=""" + hostResolverRules[0..^1] + @""" --ignore-certificate-errors " + MainPres!.ExtraArgs;
} }
catch { CealArgs = string.Empty; } else if (overrideResult == MessageBoxResult.No)
} Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true });
private void MainWin_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.W)
Environment.Exit(0);
} }
} }
private void AboutButton_Click(object sender, RoutedEventArgs e) => new AboutWin().ShowDialog();
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
{
try
{
string hostRules = string.Empty, hostResolverRules = string.Empty;
int ruleIndex = 0;
using FileStream hostStream = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
using StreamReader hostReader = new(hostStream);
JArray hostJArray = JArray.Parse(hostReader.ReadToEnd());
foreach (var hostJToken in hostJArray)
{
if (string.IsNullOrWhiteSpace(hostJToken[1]!.ToString()))
hostJToken[1] = "c" + ruleIndex;
foreach (var hostName in hostJToken[0]!)
{
if (hostName != hostJToken[1])
hostRules += "MAP " + hostName + " " + hostJToken[1] + ",";
}
hostResolverRules += "MAP " + hostJToken[1] + " " + hostJToken[2] + ",";
++ruleIndex;
}
CealArgs = @"/c @start .\""Uncealed-Browser.lnk"" --host-rules=""" + hostRules[0..^1] + @""" --host-resolver-rules=""" + hostResolverRules[0..^1] + @""" --ignore-certificate-errors " + MainPres!.ExtraArgs;
}
catch { CealArgs = string.Empty; }
}
private void MainWin_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.W)
Environment.Exit(0);
}
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
} }