mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-14 05:12:09 +08:00
1.1.0 -> 1.1.1 第9次更新
This commit is contained in:
parent
6204dbb7e5
commit
a123353068
@ -1,12 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MaterialDesignColors;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Sheas_Cealer.Consts;
|
||||
using Sheas_Cealer.Props;
|
||||
using Sheas_Cealer.Wins;
|
||||
using File = System.IO.File;
|
||||
|
||||
namespace Sheas_Cealer.Preses;
|
||||
@ -17,7 +15,7 @@ internal partial class MainPres : ObservableObject
|
||||
{
|
||||
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;
|
||||
extraArgsIndex = Array.FindIndex(args, arg => arg == "-e") + 1;
|
||||
|
||||
BrowserPath = browserPathIndex == 0 ?
|
||||
(!string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : string.Empty) :
|
||||
@ -30,6 +28,9 @@ 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]
|
||||
@ -69,7 +70,7 @@ internal partial class MainPres : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private string extraArgs;
|
||||
partial void OnExtraArgsChanged(string value)
|
||||
private partial void OnExtraArgsChanged(string value)
|
||||
{
|
||||
if (MainConst.ExtraArgsRegex().IsMatch(value))
|
||||
{
|
||||
|
@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using SheasCore;
|
||||
|
||||
namespace Sheas_Cealer.Utils;
|
||||
|
||||
internal class Command : Proc
|
||||
{
|
||||
internal bool EnvironmentExitAfterProcessExited = true;
|
||||
|
||||
internal Command(bool environmentExitAfterProcessExited) : base("Cmd.exe")
|
||||
{
|
||||
EnvironmentExitAfterProcessExited = environmentExitAfterProcessExited;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (EnvironmentExitAfterProcessExited)
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
18
Utils/CommandProc.cs
Normal file
18
Utils/CommandProc.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using SheasCore;
|
||||
|
||||
namespace Sheas_Cealer.Utils;
|
||||
|
||||
internal class CommandProc : Proc
|
||||
{
|
||||
internal bool ShutDownAppOnProcessExit;
|
||||
|
||||
internal CommandProc(bool shutDownAppOnProcessExit) : base("Cmd.exe") => ShutDownAppOnProcessExit = shutDownAppOnProcessExit;
|
||||
|
||||
public override void Process_Exited(object sender, EventArgs e)
|
||||
{
|
||||
if (ShutDownAppOnProcessExit)
|
||||
Application.Current.Dispatcher.InvokeShutdown();
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
<Window x:Class="Sheas_Cealer.Wins.MainWin"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:consts="clr-namespace:Sheas_Cealer.Consts"
|
||||
xmlns:convs="clr-namespace:Sheas_Cealer.Convs"
|
||||
xmlns:preses="clr-namespace:Sheas_Cealer.Preses"
|
||||
|
@ -3,13 +3,11 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using IWshRuntimeLibrary;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OnaCore;
|
||||
@ -33,14 +31,12 @@ public partial class MainWin : Window
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = MainPres = new(args);
|
||||
Task.Run(() =>
|
||||
{
|
||||
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
|
||||
CealingHostWatcher_Changed(null!, null!);
|
||||
});
|
||||
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
|
||||
CealingHostWatcher_Changed(null!, null!);
|
||||
}
|
||||
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
|
||||
private void MainWin_Loaded(object sender, RoutedEventArgs e) => SettingsBox.Focus();
|
||||
private void MainWin_Closing(object sender, CancelEventArgs e) => Environment.Exit(0);
|
||||
private void MainWin_Closing(object sender, CancelEventArgs e) => Application.Current.Shutdown();
|
||||
|
||||
private void MainWin_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
@ -97,13 +93,12 @@ public partial class MainWin : Window
|
||||
};
|
||||
}
|
||||
|
||||
private void StartCealButton_Click(object sender, RoutedEventArgs e)
|
||||
internal void StartCealButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (HoldButtonTimer.IsEnabled)
|
||||
{
|
||||
HoldButtonTimer.Stop();
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(CealArgs))
|
||||
throw new Exception("规则无法识别,请检查伪造规则是否含有语法错误");
|
||||
@ -121,7 +116,7 @@ public partial class MainWin : Window
|
||||
browserProcess.WaitForExit();
|
||||
}
|
||||
|
||||
new Command(true).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, CealArgs + (string.IsNullOrWhiteSpace(MainPres.ExtraArgs) ? "" : " " + MainPres.ExtraArgs));
|
||||
new CommandProc(true).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, (CealArgs + " " + MainPres!.ExtraArgs).Trim());
|
||||
}
|
||||
private void StartCealButton_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
@ -158,7 +153,7 @@ public partial class MainWin : Window
|
||||
if (string.IsNullOrWhiteSpace(MainPres.ExtraArgs))
|
||||
MainPres.ExtraArgs = " " + MainPres.ExtraArgs;
|
||||
|
||||
new Command(false).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, CealArgs + (string.IsNullOrWhiteSpace(MainPres.ExtraArgs) ? "" : " " + MainPres.ExtraArgs));
|
||||
new CommandProc(false).ShellRun(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, CealArgs + (string.IsNullOrWhiteSpace(MainPres.ExtraArgs) ? "" : " " + MainPres.ExtraArgs));
|
||||
}
|
||||
|
||||
private void EditHostButton_Click(object sender, RoutedEventArgs e)
|
||||
@ -170,8 +165,9 @@ public partial class MainWin : Window
|
||||
{
|
||||
string hostUrl = MainPres!.UpstreamUrl;
|
||||
string UpdateHostString = await Http.GetAsync<string>(hostUrl, MainClient);
|
||||
using StreamReader hostLocalStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"));
|
||||
string hostLocalString = hostLocalStreamReader.ReadToEnd();
|
||||
string hostLocalString;
|
||||
using (StreamReader hostLocalStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json")))
|
||||
hostLocalString = hostLocalStreamReader.ReadToEnd();
|
||||
|
||||
if (hostLocalString.Replace("\r", string.Empty) == UpdateHostString)
|
||||
MessageBox.Show("本地伪造规则和上游一模一样");
|
||||
@ -190,7 +186,7 @@ public partial class MainWin : Window
|
||||
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();
|
||||
|
||||
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||
internal void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -206,25 +202,21 @@ public partial class MainWin : Window
|
||||
hostJToken[1] = "c" + ruleIndex;
|
||||
|
||||
foreach (var hostName in hostJToken[0]!)
|
||||
{
|
||||
if (hostName != hostJToken[1])
|
||||
hostRules += "MAP " + 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;
|
||||
|
||||
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; }
|
||||
}
|
||||
private void MainWin_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.W)
|
||||
Environment.Exit(0);
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
|
||||
}
|
Loading…
Reference in New Issue
Block a user