mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-13 12:52:08 +08:00
1.1.0 -> 1.1.1 第12次更新
This commit is contained in:
parent
a40b458355
commit
3d307dd01f
@ -10,7 +10,7 @@ public partial class App : Application
|
||||
|
||||
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show("Error: " + e.Exception.Message);
|
||||
MessageBox.Show($"Error: {e.Exception.Message}");
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
22
Consts/MainMultilangConst.Designer.cs
generated
22
Consts/MainMultilangConst.Designer.cs
generated
@ -70,7 +70,7 @@ namespace Sheas_Cealer.Consts {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to open about window 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string AboutButtonToolTip {
|
||||
get {
|
||||
@ -97,7 +97,7 @@ namespace Sheas_Cealer.Consts {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to edit Cealing Host 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string EditHostButtonToolTip {
|
||||
get {
|
||||
@ -160,7 +160,7 @@ namespace Sheas_Cealer.Consts {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to process the contents of the input box 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string SettingsFunctionButtonToolTip {
|
||||
get {
|
||||
@ -178,7 +178,7 @@ namespace Sheas_Cealer.Consts {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to switch settings mode 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string SettingsModeButtonToolTip {
|
||||
get {
|
||||
@ -189,18 +189,18 @@ namespace Sheas_Cealer.Consts {
|
||||
/// <summary>
|
||||
/// 查找类似 Start Cealing 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string StartCealButtonContent {
|
||||
public static string StartButtonContent {
|
||||
get {
|
||||
return ResourceManager.GetString("StartCealButtonContent", resourceCulture);
|
||||
return ResourceManager.GetString("StartButtonContent", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to launch the injected browser 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string StartCealButtonToolTip {
|
||||
public static string StartButtonToolTip {
|
||||
get {
|
||||
return ResourceManager.GetString("StartCealButtonToolTip", resourceCulture);
|
||||
return ResourceManager.GetString("StartButtonToolTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ namespace Sheas_Cealer.Consts {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to switch themes 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string ThemesButtonToolTip {
|
||||
get {
|
||||
@ -250,7 +250,7 @@ namespace Sheas_Cealer.Consts {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 的本地化字符串。
|
||||
/// 查找类似 Click to update Cealing Host 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string UpdateHostButtonToolTip {
|
||||
get {
|
||||
|
@ -121,7 +121,7 @@
|
||||
<value>About Me</value>
|
||||
</data>
|
||||
<data name="AboutButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<value>Click to open about window</value>
|
||||
</data>
|
||||
<data name="BrowserPathModeName" xml:space="preserve">
|
||||
<value>Browser Path</value>
|
||||
@ -130,7 +130,7 @@
|
||||
<value>Edit Host</value>
|
||||
</data>
|
||||
<data name="EditHostButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<value>Click to edit Cealing Host</value>
|
||||
</data>
|
||||
<data name="ExtraArgsModeName" xml:space="preserve">
|
||||
<value>Additional Args</value>
|
||||
@ -151,19 +151,19 @@
|
||||
<value>Clear Args</value>
|
||||
</data>
|
||||
<data name="SettingsFunctionButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<value>Click to process the contents of the input box</value>
|
||||
</data>
|
||||
<data name="SettingsFunctionButtonUpstreamUrlContent" xml:space="preserve">
|
||||
<value>Reset Url</value>
|
||||
</data>
|
||||
<data name="SettingsModeButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<value>Click to switch settings mode</value>
|
||||
</data>
|
||||
<data name="StartCealButtonContent" xml:space="preserve">
|
||||
<data name="StartButtonContent" xml:space="preserve">
|
||||
<value>Start Cealing</value>
|
||||
</data>
|
||||
<data name="StartCealButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<data name="StartButtonToolTip" xml:space="preserve">
|
||||
<value>Click to launch the injected browser</value>
|
||||
</data>
|
||||
<data name="ThemesButtonDarkThemeContent" xml:space="preserve">
|
||||
<value>Light Theme</value>
|
||||
@ -175,13 +175,13 @@
|
||||
<value>Dark Theme</value>
|
||||
</data>
|
||||
<data name="ThemesButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<value>Click to switch themes</value>
|
||||
</data>
|
||||
<data name="UpdateHostButtonContent" xml:space="preserve">
|
||||
<value>Update Host</value>
|
||||
</data>
|
||||
<data name="UpdateHostButtonToolTip" xml:space="preserve">
|
||||
<value></value>
|
||||
<value>Click to update Cealing Host</value>
|
||||
</data>
|
||||
<data name="UpstreamUrlModeName" xml:space="preserve">
|
||||
<value>Upstream Url</value>
|
||||
|
@ -159,10 +159,10 @@
|
||||
<data name="SettingsModeButtonToolTip" xml:space="preserve">
|
||||
<value>点击切换输入框设置模式</value>
|
||||
</data>
|
||||
<data name="StartCealButtonContent" xml:space="preserve">
|
||||
<data name="StartButtonContent" xml:space="preserve">
|
||||
<value>启动伪造</value>
|
||||
</data>
|
||||
<data name="StartCealButtonToolTip" xml:space="preserve">
|
||||
<data name="StartButtonToolTip" xml:space="preserve">
|
||||
<value>点击启动伪造注入后的浏览器</value>
|
||||
</data>
|
||||
<data name="ThemesButtonDarkThemeContent" xml:space="preserve">
|
||||
|
@ -10,9 +10,9 @@ internal class MainSettingsBoxHintConv : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
MainConst.SettingsMode? mode = value as MainConst.SettingsMode?;
|
||||
MainConst.SettingsMode? settingsMode = value as MainConst.SettingsMode?;
|
||||
|
||||
return mode switch
|
||||
return settingsMode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => MainConst.BrowserPathModeName,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => MainConst.UpstreamUrlModeName,
|
||||
|
@ -9,12 +9,12 @@ internal class MainSettingsBoxTextConv : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
MainConst.SettingsMode? mode = values[0] as MainConst.SettingsMode?;
|
||||
MainConst.SettingsMode? settingsMode = values[0] as MainConst.SettingsMode?;
|
||||
string? browserPath = values[1] as string;
|
||||
string? upstreamUrl = values[2] as string;
|
||||
string? extraArgs = values[3] as string;
|
||||
|
||||
return mode switch
|
||||
return settingsMode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => browserPath!,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => upstreamUrl!,
|
||||
|
@ -10,9 +10,9 @@ internal class MainSettingsBoxToolTipConv : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
MainConst.SettingsMode? mode = value as MainConst.SettingsMode?;
|
||||
MainConst.SettingsMode? settingsMode = value as MainConst.SettingsMode?;
|
||||
|
||||
return mode switch
|
||||
return settingsMode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => MainConst.SettingsBoxBrowserPathPlaceHolder,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => MainConst.SettingsBoxUpstreamUrlPlaceHolder,
|
||||
|
@ -10,9 +10,9 @@ internal class MainSettingsFunctionButtonContentConv : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
MainConst.SettingsMode? mode = value as MainConst.SettingsMode?;
|
||||
MainConst.SettingsMode? settingsMode = value as MainConst.SettingsMode?;
|
||||
|
||||
return mode switch
|
||||
return settingsMode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => MainConst.SettingsFunctionButtonBrowserPathContent,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => MainConst.SettingsFunctionButtonUpstreamUrlContent,
|
||||
|
@ -9,9 +9,9 @@ internal class MainSettingsModeButtonContentConv : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
MainConst.SettingsMode? mode = value as MainConst.SettingsMode?;
|
||||
MainConst.SettingsMode? settingsMode = value as MainConst.SettingsMode?;
|
||||
|
||||
return mode switch
|
||||
return settingsMode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => MainConst.UpstreamUrlModeName,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => MainConst.ExtraArgsModeName,
|
||||
|
@ -6,14 +6,15 @@ using Sheas_Cealer.Consts;
|
||||
|
||||
namespace Sheas_Cealer.Convs;
|
||||
|
||||
internal class MainStartCealButtonIsEnabledConv : IMultiValueConverter
|
||||
internal class MainStartButtonIsEnabledConv : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
string? browserPath = values[0] as string;
|
||||
string? extraArgs = values[1] as string;
|
||||
|
||||
return File.Exists(browserPath) && Path.GetFileName(browserPath).ToLower().EndsWith(".exe") && (MainConst.ExtraArgsRegex().IsMatch(extraArgs!) || extraArgs == MainConst.SettingsBoxExtraArgsPlaceHolder);
|
||||
return (File.Exists(browserPath) && Path.GetFileName(browserPath).ToLowerInvariant().EndsWith(".exe")) &&
|
||||
(extraArgs == MainConst.SettingsBoxExtraArgsPlaceHolder || MainConst.ExtraArgsRegex().IsMatch(extraArgs!));
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
@ -11,7 +11,9 @@ internal class MainThemesButtonContentConv : IValueConverter
|
||||
{
|
||||
bool? isLightMode = value as bool?;
|
||||
|
||||
return isLightMode.HasValue ? (isLightMode.GetValueOrDefault() ? MainConst.ThemesButtonLightThemeContent : MainConst.ThemesButtonDarkThemeContent) : MainConst.ThemesButtonInheritThemeContent;
|
||||
return isLightMode.HasValue ?
|
||||
(isLightMode.GetValueOrDefault() ? MainConst.ThemesButtonLightThemeContent : MainConst.ThemesButtonDarkThemeContent) :
|
||||
MainConst.ThemesButtonInheritThemeContent;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
|
@ -4,7 +4,6 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Sheas_Cealer.Consts;
|
||||
using Sheas_Cealer.Props;
|
||||
using Sheas_Cealer.Wins;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace Sheas_Cealer.Preses;
|
||||
@ -13,9 +12,9 @@ internal partial class MainPres : ObservableObject
|
||||
{
|
||||
internal MainPres(string[] args)
|
||||
{
|
||||
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;
|
||||
int browserPathIndex = Array.FindIndex(args, arg => arg.Equals("-b", StringComparison.OrdinalIgnoreCase)) + 1;
|
||||
int upstreamUrlIndex = Array.FindIndex(args, arg => arg.Equals("-u", StringComparison.OrdinalIgnoreCase)) + 1;
|
||||
int extraArgsIndex = Array.FindIndex(args, arg => arg.Equals("-e", StringComparison.OrdinalIgnoreCase)) + 1;
|
||||
|
||||
BrowserPath = browserPathIndex == 0 ?
|
||||
(!string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : string.Empty) :
|
||||
@ -28,13 +27,10 @@ internal partial class MainPres : ObservableObject
|
||||
ExtraArgs = extraArgsIndex == 0 ?
|
||||
(!string.IsNullOrWhiteSpace(Settings.Default.ExtraArgs) ? Settings.Default.ExtraArgs : string.Empty) :
|
||||
args[extraArgsIndex];
|
||||
|
||||
if (Array.Exists(args, args => args == "-d"))
|
||||
new MainWin([]).StartCealButton_Click(null!, null!);
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private MainConst.SettingsMode mode;
|
||||
private MainConst.SettingsMode settingsMode;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool? isLightTheme = null;
|
||||
@ -42,6 +38,7 @@ internal partial class MainPres : ObservableObject
|
||||
{
|
||||
PaletteHelper paletteHelper = new();
|
||||
Theme newTheme = paletteHelper.GetTheme();
|
||||
|
||||
newTheme.SetBaseTheme(value.HasValue ? (value.GetValueOrDefault() ? BaseTheme.Light : BaseTheme.Dark) : BaseTheme.Inherit);
|
||||
paletteHelper.SetTheme(newTheme);
|
||||
}
|
||||
@ -50,7 +47,7 @@ internal partial class MainPres : ObservableObject
|
||||
private string browserPath;
|
||||
partial void OnBrowserPathChanged(string value)
|
||||
{
|
||||
if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe"))
|
||||
if (File.Exists(value) && Path.GetFileName(value).ToLowerInvariant().EndsWith(".exe"))
|
||||
{
|
||||
Settings.Default.BrowserPath = value;
|
||||
Settings.Default.Save();
|
||||
|
@ -25,17 +25,16 @@
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Column="0" Margin="5" ToolTip="{Binding Source={x:Static consts:MainConst.SettingsModeButtonToolTip}}"
|
||||
<Button Grid.Column="0" Margin="5" d:Content="# # # #" ToolTip="{Binding Source={x:Static consts:MainConst.SettingsModeButtonToolTip}}"
|
||||
Click="SettingsModeButton_Click">
|
||||
<Button.Content>
|
||||
<Binding Path="Mode">
|
||||
<Binding Path="SettingsMode">
|
||||
<Binding.Converter>
|
||||
<convs:MainSettingsModeButtonContentConv />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<TextBox x:Name="SettingsBox"
|
||||
Grid.Column="1" Margin="5" VerticalContentAlignment="Center" md:HintAssist.IsFloating="True"
|
||||
TextChanged="SettingsBox_TextChanged" PreviewDragOver="MainWin_DragEnter">
|
||||
@ -45,31 +44,31 @@
|
||||
<convs:MainSettingsBoxTextConv />
|
||||
</MultiBinding.Converter>
|
||||
|
||||
<Binding Path="Mode" />
|
||||
<Binding Path="SettingsMode" />
|
||||
<Binding Path="BrowserPath" />
|
||||
<Binding Path="UpstreamUrl" />
|
||||
<Binding Path="ExtraArgs" />
|
||||
</MultiBinding>
|
||||
</TextBox.Text>
|
||||
<TextBox.ToolTip>
|
||||
<Binding Path="Mode">
|
||||
<Binding Path="SettingsMode">
|
||||
<Binding.Converter>
|
||||
<convs:MainSettingsBoxToolTipConv />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</TextBox.ToolTip>
|
||||
<md:HintAssist.Hint>
|
||||
<Binding Path="Mode">
|
||||
<Binding Path="SettingsMode">
|
||||
<Binding.Converter>
|
||||
<convs:MainSettingsBoxHintConv />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</md:HintAssist.Hint>
|
||||
</TextBox>
|
||||
<Button Grid.Column="2" Margin="5" ToolTip="{Binding Source={x:Static consts:MainConst.SettingsFunctionButtonToolTip}}"
|
||||
<Button Grid.Column="2" Margin="5" d:Content="# #" ToolTip="{Binding Source={x:Static consts:MainConst.SettingsFunctionButtonToolTip}}"
|
||||
Click="SettingsFunctionButton_Click">
|
||||
<Button.Content>
|
||||
<Binding Path="Mode">
|
||||
<Binding Path="SettingsMode">
|
||||
<Binding.Converter>
|
||||
<convs:MainSettingsFunctionButtonContentConv />
|
||||
</Binding.Converter>
|
||||
@ -77,15 +76,13 @@
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
<Button IsDefault="True"
|
||||
Grid.Row="1" Margin="5" Content="{Binding Source={x:Static consts:MainConst.StartCealButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.StartCealButtonToolTip}}"
|
||||
Click="StartCealButton_Click" PreviewMouseDown="StartCealButton_PreviewMouseDown">
|
||||
|
||||
Grid.Row="1" Margin="5" Content="{Binding Source={x:Static consts:MainConst.StartButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.StartButtonToolTip}}"
|
||||
Click="StartButton_Click" PreviewMouseDown="StartButton_PreviewMouseDown">
|
||||
<Button.IsEnabled>
|
||||
<MultiBinding>
|
||||
<MultiBinding.Converter>
|
||||
<convs:MainStartCealButtonIsEnabledConv />
|
||||
<convs:MainStartButtonIsEnabledConv />
|
||||
</MultiBinding.Converter>
|
||||
|
||||
<Binding Path="BrowserPath" />
|
||||
@ -93,7 +90,6 @@
|
||||
</MultiBinding>
|
||||
</Button.IsEnabled>
|
||||
</Button>
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
@ -102,11 +98,9 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button x:Name="EditHostButton"
|
||||
Grid.Column="0" Margin="5" Content="{Binding Source={x:Static consts:MainConst.EditHostButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.EditHostButtonToolTip}}"
|
||||
<Button Grid.Column="0" Margin="5" Content="{Binding Source={x:Static consts:MainConst.EditHostButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.EditHostButtonToolTip}}"
|
||||
Click="EditHostButton_Click" />
|
||||
<Button x:Name="UpdateHostButton"
|
||||
Grid.Column="1" Margin="5" Content="{Binding Source={x:Static consts:MainConst.UpdateHostButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.UpdateHostButtonToolTip}}"
|
||||
<Button Grid.Column="1" Margin="5" Content="{Binding Source={x:Static consts:MainConst.UpdateHostButtonContent}}" ToolTip="{Binding Source={x:Static consts:MainConst.UpdateHostButtonToolTip}}"
|
||||
Click="UpdateHostButton_Click">
|
||||
<Button.IsEnabled>
|
||||
<Binding Path="UpstreamUrl">
|
||||
@ -116,8 +110,7 @@
|
||||
</Binding>
|
||||
</Button.IsEnabled>
|
||||
</Button>
|
||||
<Button x:Name="ThemesButton"
|
||||
Grid.Column="2" Margin="5" ToolTip="{Binding Source={x:Static consts:MainConst.ThemesButtonToolTip}}"
|
||||
<Button Grid.Column="2" Margin="5" d:Content="# # # #" ToolTip="{Binding Source={x:Static consts:MainConst.ThemesButtonToolTip}}"
|
||||
Click="ThemesButton_Click">
|
||||
<Button.Content>
|
||||
<Binding Path="IsLightTheme">
|
||||
|
@ -20,17 +20,18 @@ namespace Sheas_Cealer.Wins;
|
||||
|
||||
public partial class MainWin : Window
|
||||
{
|
||||
private static string CealArgs = string.Empty;
|
||||
private static readonly HttpClient MainClient = new();
|
||||
private static DispatcherTimer HoldButtonTimer = new() { Interval = TimeSpan.FromSeconds(1) };
|
||||
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 HttpClient MainClient = new();
|
||||
private static DispatcherTimer? HoldButtonTimer;
|
||||
private static readonly FileSystemWatcher CealingHostWatcher = new(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json") { EnableRaisingEvents = true, NotifyFilter = NotifyFilters.LastWrite };
|
||||
private static string CealArgs = string.Empty;
|
||||
|
||||
internal MainWin(string[] args)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = MainPres = new(args);
|
||||
|
||||
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
|
||||
CealingHostWatcher_Changed(null!, null!);
|
||||
}
|
||||
@ -51,7 +52,7 @@ public partial class MainWin : Window
|
||||
|
||||
private void SettingsBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
switch (MainPres!.Mode)
|
||||
switch (MainPres!.SettingsMode)
|
||||
{
|
||||
case MainConst.SettingsMode.BrowserPathMode:
|
||||
MainPres.BrowserPath = SettingsBox.Text;
|
||||
@ -64,11 +65,21 @@ public partial class MainWin : Window
|
||||
return;
|
||||
}
|
||||
}
|
||||
private void SettingsModeButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MainPres!.SettingsMode = MainPres.SettingsMode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => MainConst.SettingsMode.UpstreamUrlMode,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => MainConst.SettingsMode.ExtraArgsMode,
|
||||
MainConst.SettingsMode.ExtraArgsMode => MainConst.SettingsMode.BrowserPathMode,
|
||||
_ => throw new UnreachableException()
|
||||
};
|
||||
}
|
||||
private void SettingsFunctionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OpenFileDialog browserPathDialog = new() { Filter = "浏览器 (*.exe)|*.exe" };
|
||||
|
||||
switch (MainPres!.Mode)
|
||||
switch (MainPres!.SettingsMode)
|
||||
{
|
||||
case MainConst.SettingsMode.BrowserPathMode when browserPathDialog.ShowDialog().GetValueOrDefault():
|
||||
SettingsBox.Focus();
|
||||
@ -82,57 +93,21 @@ public partial class MainWin : Window
|
||||
return;
|
||||
}
|
||||
}
|
||||
private void SettingsModeButton_Click(object sender, RoutedEventArgs e)
|
||||
|
||||
private void StartButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MainPres!.Mode = MainPres.Mode switch
|
||||
{
|
||||
MainConst.SettingsMode.BrowserPathMode => MainConst.SettingsMode.UpstreamUrlMode,
|
||||
MainConst.SettingsMode.UpstreamUrlMode => MainConst.SettingsMode.ExtraArgsMode,
|
||||
MainConst.SettingsMode.ExtraArgsMode => MainConst.SettingsMode.BrowserPathMode,
|
||||
_ => throw new UnreachableException()
|
||||
};
|
||||
if (HoldButtonTimer!.IsEnabled)
|
||||
StartButtonHoldTimer_Tick(null, null!);
|
||||
}
|
||||
|
||||
internal void StartCealButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (HoldButtonTimer.IsEnabled)
|
||||
HoldButtonTimer.Stop();
|
||||
else
|
||||
return;
|
||||
|
||||
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 CommandProc(true).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, (CealArgs + " " + MainPres!.ExtraArgs).Trim());
|
||||
}
|
||||
private void StartCealButton_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
private void StartButton_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
HoldButtonTimer = new() { Interval = TimeSpan.FromSeconds(1) };
|
||||
HoldButtonTimer.Tick += StartCealButtonHoldButtonTimer_Tick;
|
||||
HoldButtonTimer.Tick += StartButtonHoldTimer_Tick;
|
||||
HoldButtonTimer.Start();
|
||||
}
|
||||
private void StartCealButtonHoldButtonTimer_Tick(object? sender, EventArgs e)
|
||||
private void StartButtonHoldTimer_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
HoldButtonTimer.Stop();
|
||||
|
||||
if (HoldButtonTimer.IsEnabled)
|
||||
{
|
||||
HoldButtonTimer.Stop();
|
||||
return;
|
||||
}
|
||||
HoldButtonTimer!.Stop();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(CealArgs))
|
||||
throw new Exception("规则无法识别,请检查伪造规则是否含有语法错误");
|
||||
@ -150,10 +125,7 @@ public partial class MainWin : Window
|
||||
browserProcess.WaitForExit();
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(MainPres.ExtraArgs))
|
||||
MainPres.ExtraArgs = " " + MainPres.ExtraArgs;
|
||||
|
||||
new CommandProc(false).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, CealArgs + (string.IsNullOrWhiteSpace(MainPres.ExtraArgs) ? "" : " " + MainPres.ExtraArgs));
|
||||
new CommandProc(sender == null).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, ($"{CealArgs} {MainPres!.ExtraArgs}").Trim());
|
||||
}
|
||||
|
||||
private void EditHostButton_Click(object sender, RoutedEventArgs e)
|
||||
@ -163,53 +135,54 @@ public partial class MainWin : Window
|
||||
}
|
||||
private async void UpdateHostButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string hostUrl = MainPres!.UpstreamUrl;
|
||||
string UpdateHostString = await Http.GetAsync<string>(hostUrl, MainClient);
|
||||
string hostLocalString;
|
||||
using (StreamReader hostLocalStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json")))
|
||||
hostLocalString = hostLocalStreamReader.ReadToEnd();
|
||||
string upstreamHostUrl = MainPres!.UpstreamUrl;
|
||||
string upstreamHostString = await Http.GetAsync<string>(upstreamHostUrl, MainClient);
|
||||
string localHostString;
|
||||
|
||||
if (hostLocalString.Replace("\r", string.Empty) == UpdateHostString)
|
||||
using (StreamReader localHostStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json")))
|
||||
localHostString = localHostStreamReader.ReadToEnd();
|
||||
|
||||
if (localHostString.Replace("\r", string.Empty) == upstreamHostString)
|
||||
MessageBox.Show("本地伪造规则和上游一模一样");
|
||||
else
|
||||
{
|
||||
MessageBoxResult overrideResult = MessageBox.Show("本地伪造规则和上游略有不同,需要覆盖本地吗? 否则只为你打开上游规则的网页", string.Empty, MessageBoxButton.YesNoCancel);
|
||||
if (overrideResult == MessageBoxResult.Yes)
|
||||
MessageBoxResult overrideOptionResult = MessageBox.Show("本地伪造规则和上游略有不同,需要覆盖本地吗? 否则只为你打开上游规则的网页", string.Empty, MessageBoxButton.YesNoCancel);
|
||||
if (overrideOptionResult == MessageBoxResult.Yes)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), UpdateHostString);
|
||||
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), upstreamHostString);
|
||||
MessageBox.Show("更新已完成");
|
||||
}
|
||||
else if (overrideResult == MessageBoxResult.No)
|
||||
Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true });
|
||||
else if (overrideOptionResult == MessageBoxResult.No)
|
||||
Process.Start(new ProcessStartInfo(upstreamHostUrl) { UseShellExecute = true });
|
||||
}
|
||||
}
|
||||
private void ThemesButton_Click(object sender, RoutedEventArgs e) => MainPres!.IsLightTheme = MainPres.IsLightTheme.HasValue ? (MainPres.IsLightTheme.Value ? null : true) : false;
|
||||
private void AboutButton_Click(object sender, RoutedEventArgs e) => new AboutWin().ShowDialog();
|
||||
|
||||
internal void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
string hostRules = string.Empty, hostResolverRules = string.Empty;
|
||||
string hostRules = string.Empty;
|
||||
string 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)
|
||||
foreach (JToken hostJToken in JArray.Parse(hostReader.ReadToEnd()))
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(hostJToken[1]!.ToString()))
|
||||
hostJToken[1] = "c" + ruleIndex;
|
||||
hostJToken[1] = $"c{ruleIndex}";
|
||||
|
||||
foreach (var hostName in hostJToken[0]!)
|
||||
hostRules += "MAP " + hostName + " " + hostJToken[1] + ",";
|
||||
foreach (JToken hostName in hostJToken[0]!)
|
||||
hostRules += $"MAP {hostName} {hostJToken[1]},";
|
||||
|
||||
hostResolverRules += "MAP " + hostJToken[1] + " " + hostJToken[2] + ",";
|
||||
hostResolverRules += $"MAP {hostJToken[1]} {hostJToken[2]},";
|
||||
|
||||
++ruleIndex;
|
||||
}
|
||||
|
||||
|
||||
CealArgs = @$"/c @start .\""Uncealed-Browser.lnk"" --host-rules=""{hostRules[0..^1]}"" --host-resolver-rules=""{hostResolverRules[0..^1]}"" --test-type --ignore-certificate-errors";
|
||||
}
|
||||
catch { CealArgs = string.Empty; }
|
||||
|
Loading…
Reference in New Issue
Block a user