mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-13 12:52:08 +08:00
1.1.0 -> 1.1.1 第5次更新
This commit is contained in:
parent
455ade0b2d
commit
a90798a22d
19
App.xaml.cs
19
App.xaml.cs
@ -2,16 +2,15 @@
|
||||
using System.Windows.Threading;
|
||||
using Sheas_Cealer.Wins;
|
||||
|
||||
namespace Sheas_Cealer
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show();
|
||||
namespace Sheas_Cealer;
|
||||
|
||||
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show("Error: " + e.Exception.Message);
|
||||
e.Handled = true;
|
||||
}
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e) => new MainWin(e.Args).Show();
|
||||
|
||||
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||
{
|
||||
MessageBox.Show("Error: " + e.Exception.Message);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
@ -1,16 +1,15 @@
|
||||
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 VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc";
|
||||
public static string EmailButtonUrl => "Zeus6_6@163.com";
|
||||
public static string InstructionButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Instruction";
|
||||
public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer";
|
||||
public static string PrivacyButtonUrl => "https://thoughts.teambition.com/share/6264eda98adeb10041b92fda#title=Sheas_Cealer_隐私政策";
|
||||
public static string AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#title=Sheas_Cealer_使用协议";
|
||||
}
|
||||
public static string Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2];
|
||||
public static string DeveloperButtonUrl => "https://www.spacetimee.xyz";
|
||||
public static string VersionButtonUrl => "https://spacetime.lanzouu.com/b017hp0lc";
|
||||
public static string EmailButtonUrl => "Zeus6_6@163.com";
|
||||
public static string InstructionButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer/wiki/Sheas-Cealer-Instruction";
|
||||
public static string OpenSourceButtonUrl => "https://github.com/SpaceTimee/Sheas-Cealer";
|
||||
public static string PrivacyButtonUrl => "https://thoughts.teambition.com/share/6264eda98adeb10041b92fda#title=Sheas_Cealer_隐私政策";
|
||||
public static string AgreementButtonUrl => "https://thoughts.teambition.com/share/6264edd78adeb10041b92fdb#title=Sheas_Cealer_使用协议";
|
||||
}
|
@ -1,21 +1,17 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Sheas_Cealer.Consts
|
||||
namespace Sheas_Cealer.Consts;
|
||||
|
||||
internal partial class MainConst : MainMultilangConst
|
||||
{
|
||||
internal partial class MainConst : MainMultilangConst
|
||||
{
|
||||
internal enum Mode
|
||||
{ browserPathMode, upstreamUrlMode, extraArgsMode };
|
||||
internal enum SettingsMode
|
||||
{ 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$")]
|
||||
internal static partial Regex HostRegex();
|
||||
[GeneratedRegex(@"^(((ht|f)tps?):\/\/)?[a-zA-Z0-9](-*[a-zA-Z0-9])*(\.[a-zA-Z0-9](-*[a-zA-Z0-9])*)*(:\d{1,5})?(\/[a-zA-Z0-9.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*$")]
|
||||
internal static partial Regex 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])*)*)?$")]
|
||||
internal static partial Regex ArgsRegex();
|
||||
}
|
||||
[GeneratedRegex(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")]
|
||||
internal static partial Regex ExtraArgsRegex();
|
||||
}
|
@ -2,21 +2,20 @@
|
||||
using System.Globalization;
|
||||
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)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -4,45 +4,42 @@ using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
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?;
|
||||
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)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case MainConst.Mode.browserPathMode:
|
||||
if (browserPath == MainConst.BrowserPathPlaceHolder)
|
||||
return new SolidColorBrush(Color.FromRgb(191, 205, 219));
|
||||
break;
|
||||
case MainConst.Mode.upstreamUrlMode:
|
||||
if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder)
|
||||
return new SolidColorBrush(Color.FromRgb(191, 205, 219));
|
||||
break;
|
||||
case MainConst.Mode.extraArgsMode:
|
||||
if (extraArgs == MainConst.ExtraArgsPlaceHolder)
|
||||
return new SolidColorBrush(Color.FromRgb(191, 205, 219));
|
||||
break;
|
||||
}
|
||||
case MainConst.SettingsMode.BrowserPathMode:
|
||||
if (browserPath == MainConst.BrowserPathPlaceHolder)
|
||||
return new SolidColorBrush(Color.FromRgb(191, 205, 219));
|
||||
break;
|
||||
case MainConst.SettingsMode.UpstreamUrlMode:
|
||||
if (upstreamUrl == MainConst.UpstreamUrlPlaceHolder)
|
||||
return new SolidColorBrush(Color.FromRgb(191, 205, 219));
|
||||
break;
|
||||
case MainConst.SettingsMode.ExtraArgsMode:
|
||||
if (extraArgs == MainConst.ExtraArgsPlaceHolder)
|
||||
return new SolidColorBrush(Color.FromRgb(191, 205, 219));
|
||||
break;
|
||||
}
|
||||
|
||||
return new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
return new SolidColorBrush(Color.FromRgb(0, 0, 0));
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -3,56 +3,53 @@ using System.Diagnostics;
|
||||
using System.Windows.Data;
|
||||
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?;
|
||||
bool? isFocused = values[1] as bool?;
|
||||
string? browserPath = values[2] as string;
|
||||
string? upstreamUrl = values[3] as string;
|
||||
string? extraArgs = values[4] as string;
|
||||
|
||||
if (mode == MainConst.Mode.browserPathMode)
|
||||
{
|
||||
if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath))
|
||||
return MainConst.BrowserPathPlaceHolder;
|
||||
else if ((bool)isFocused! && browserPath == MainConst.BrowserPathPlaceHolder)
|
||||
return string.Empty;
|
||||
else
|
||||
return browserPath!;
|
||||
}
|
||||
else if (mode == MainConst.Mode.upstreamUrlMode)
|
||||
{
|
||||
if ((bool)!isFocused! && string.IsNullOrEmpty(upstreamUrl))
|
||||
return MainConst.UpstreamUrlPlaceHolder;
|
||||
else if ((bool)isFocused! && upstreamUrl == MainConst.UpstreamUrlPlaceHolder)
|
||||
return string.Empty;
|
||||
else
|
||||
return upstreamUrl!;
|
||||
}
|
||||
else if (mode == MainConst.Mode.extraArgsMode)
|
||||
{
|
||||
if ((bool)!isFocused! && string.IsNullOrEmpty(extraArgs))
|
||||
return MainConst.ExtraArgsPlaceHolder;
|
||||
else if ((bool)isFocused! && extraArgs == MainConst.ExtraArgsPlaceHolder)
|
||||
return string.Empty;
|
||||
else
|
||||
return extraArgs!;
|
||||
}
|
||||
if ((bool)!isFocused! && string.IsNullOrEmpty(browserPath))
|
||||
return MainConst.BrowserPathPlaceHolder;
|
||||
else if ((bool)isFocused! && browserPath == MainConst.BrowserPathPlaceHolder)
|
||||
return string.Empty;
|
||||
else
|
||||
{
|
||||
throw new UnreachableException();
|
||||
}
|
||||
return browserPath!;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
@ -4,27 +4,26 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
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)
|
||||
return MainConst.FunctionButtonBrowserPathContent;
|
||||
else if (mode == MainConst.Mode.upstreamUrlMode)
|
||||
return MainConst.FunctionButtonUpstreamUrlContent;
|
||||
else if (mode == MainConst.Mode.extraArgsMode)
|
||||
return MainConst.FunctionButtonExtraArgsContent;
|
||||
if (mode == MainConst.SettingsMode.BrowserPathMode)
|
||||
return MainConst.FunctionButtonBrowserPathContent;
|
||||
else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
|
||||
return MainConst.FunctionButtonUpstreamUrlContent;
|
||||
else if (mode == MainConst.SettingsMode.ExtraArgsMode)
|
||||
return MainConst.FunctionButtonExtraArgsContent;
|
||||
|
||||
throw new UnreachableException();
|
||||
}
|
||||
throw new UnreachableException();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -4,24 +4,23 @@ using System.IO;
|
||||
using System.Windows.Data;
|
||||
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))
|
||||
return true;
|
||||
if (File.Exists(browserPath) && Path.GetFileName(browserPath).ToLower().EndsWith(".exe") && (MainConst.ExtraArgsRegex().IsMatch(extraArgs!) || extraArgs == MainConst.ExtraArgsPlaceHolder))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -4,27 +4,26 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
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)
|
||||
return MainConst.SwitchModeButtonBrowserPathContent;
|
||||
else if (mode == MainConst.Mode.upstreamUrlMode)
|
||||
return MainConst.SwitchModeButtonUpstreamUrlContent;
|
||||
else if (mode == MainConst.Mode.extraArgsMode)
|
||||
return MainConst.SwitchModeButtonExtraArgsContent;
|
||||
if (mode == MainConst.SettingsMode.BrowserPathMode)
|
||||
return MainConst.SwitchModeButtonBrowserPathContent;
|
||||
else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
|
||||
return MainConst.SwitchModeButtonUpstreamUrlContent;
|
||||
else if (mode == MainConst.SettingsMode.ExtraArgsMode)
|
||||
return MainConst.SwitchModeButtonExtraArgsContent;
|
||||
|
||||
throw new UnreachableException();
|
||||
}
|
||||
throw new UnreachableException();
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -3,23 +3,22 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
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!))
|
||||
return true;
|
||||
if (MainConst.UpstreamUrlRegex().IsMatch(upstreamUrl!))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -1,65 +1,65 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Sheas_Cealer.Consts;
|
||||
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)
|
||||
BrowserPath = args[0];
|
||||
else if (!string.IsNullOrWhiteSpace(Props.Settings.Default.BrowserPath))
|
||||
BrowserPath = Props.Settings.Default.BrowserPath;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Props.Settings.Default.UpstreamUrl))
|
||||
UpstreamUrl = Props.Settings.Default.UpstreamUrl;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Props.Settings.Default.ExtraArgs))
|
||||
ExtraArgs = Props.Settings.Default.ExtraArgs;
|
||||
Props.Settings.Default.BrowserPath = value;
|
||||
Props.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private MainConst.Mode mode = MainConst.Mode.browserPathMode;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isContentBoxFocused = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string browserPath = string.Empty;
|
||||
partial void OnBrowserPathChanged(string value)
|
||||
[ObservableProperty]
|
||||
private string upstreamUrl;
|
||||
private partial void OnUpstreamUrlChanged(string value)
|
||||
{
|
||||
if (MainConst.UpstreamUrlRegex().IsMatch(value))
|
||||
{
|
||||
if (File.Exists(value) && Path.GetFileName(value).ToLower().EndsWith(".exe"))
|
||||
{
|
||||
Props.Settings.Default.BrowserPath = value;
|
||||
Props.Settings.Default.Save();
|
||||
}
|
||||
Props.Settings.Default.UpstreamUrl = value;
|
||||
Props.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private string upstreamUrl = MainConst.DefaultUpstreamUrl;
|
||||
partial void OnUpstreamUrlChanged(string value)
|
||||
[ObservableProperty]
|
||||
private string extraArgs;
|
||||
private partial void OnExtraArgsChanged(string value)
|
||||
{
|
||||
if (MainConst.ExtraArgsRegex().IsMatch(value))
|
||||
{
|
||||
if (MainConst.UrlRegex().IsMatch(value))
|
||||
{
|
||||
Props.Settings.Default.UpstreamUrl = value;
|
||||
Props.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private string extraArgs = string.Empty;
|
||||
partial void OnExtraArgsChanged(string value)
|
||||
{
|
||||
if (MainConst.ArgsRegex().IsMatch(value))
|
||||
{
|
||||
Props.Settings.Default.ExtraArgs = value;
|
||||
Props.Settings.Default.Save();
|
||||
}
|
||||
Props.Settings.Default.ExtraArgs = value;
|
||||
Props.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,20 +2,19 @@
|
||||
using System.Diagnostics;
|
||||
using SheasCore;
|
||||
|
||||
namespace Sheas_Cealer.Utils
|
||||
{
|
||||
internal class Command : Proc
|
||||
{
|
||||
internal Command() : base("Cmd.exe")
|
||||
{
|
||||
}
|
||||
namespace Sheas_Cealer.Utils;
|
||||
|
||||
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);
|
||||
internal class Command : Proc
|
||||
{
|
||||
internal Command() : base("Cmd.exe")
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,58 +2,43 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
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 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;
|
||||
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;
|
||||
// 获取该窗口句柄
|
||||
IntPtr hwnd = new WindowInteropHelper(window).Handle;
|
||||
|
||||
[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);
|
||||
// 将窗口更改为不显示窗口图标
|
||||
_ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME);
|
||||
|
||||
internal static void RemoveIcon(Window window)
|
||||
{
|
||||
// 获取该窗口句柄
|
||||
IntPtr hwnd = new WindowInteropHelper(window).Handle;
|
||||
// 更新窗口的非客户区域来显示更改
|
||||
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||
|
||||
// 将窗口更改为不显示窗口图标
|
||||
_ = SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_DLGMODALFRAME);
|
||||
|
||||
// 更新窗口的非客户区域来显示更改
|
||||
SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||
|
||||
// 防止自定义图标生效
|
||||
SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
|
||||
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// 防止自定义图标生效
|
||||
SendMessage(hwnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
|
||||
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
}
|
@ -35,10 +35,9 @@
|
||||
<MultiBinding.Converter>
|
||||
<convs:AboutVersionButtonContentConv />
|
||||
</MultiBinding.Converter>
|
||||
|
||||
|
||||
<Binding Path="VersionButtonContent" Source="{StaticResource AboutConst}" />
|
||||
<Binding Path="Version" Source="{StaticResource AboutConst}" />
|
||||
|
||||
</MultiBinding>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
@ -58,6 +57,5 @@
|
||||
<Button x:Name="AgreementButton"
|
||||
Content="{Binding AgreementButtonContent, Source={StaticResource AboutConst}}" Grid.Row="1" Grid.Column="3" Margin="5" ToolTip="{Binding AgreementButtonUrl, Source={StaticResource AboutConst}}"
|
||||
Click="AboutButton_Click" />
|
||||
|
||||
</Grid>
|
||||
</Window>
|
@ -1,30 +1,30 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
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()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
if (sender as Button == VersionButton)
|
||||
MessageBox.Show("密码: 3wnj");
|
||||
|
||||
private void AboutButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
|
||||
}
|
@ -3,12 +3,11 @@
|
||||
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:preses="clr-namespace:Sheas_Cealer.Preses"
|
||||
xmlns:convs="clr-namespace:Sheas_Cealer.Convs"
|
||||
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"
|
||||
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"
|
||||
Loaded="MainWin_Loaded" Closing="MainWin_Closing" DragEnter="MainWin_DragEnter" Drop="MainWin_Drop" KeyDown="MainWin_KeyDown">
|
||||
<Window.Resources>
|
||||
@ -40,7 +39,7 @@
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<TextBox x:Name="ContentText" utils:FocusExtension.IsFocused="{Binding IsContentBoxFocused}"
|
||||
<TextBox x:Name="ContentBox"
|
||||
Grid.Column="1" Margin="5" VerticalContentAlignment="Center"
|
||||
TextChanged="ContentBox_TextChanged" PreviewDragOver="MainWin_DragEnter">
|
||||
<TextBox.Text>
|
||||
@ -54,7 +53,6 @@
|
||||
<Binding Path="BrowserPath" />
|
||||
<Binding Path="UpstreamUrl" />
|
||||
<Binding Path="ExtraArgs" />
|
||||
|
||||
</MultiBinding>
|
||||
</TextBox.Text>
|
||||
<TextBox.Foreground>
|
||||
@ -68,7 +66,6 @@
|
||||
<Binding Path="BrowserPath" />
|
||||
<Binding Path="UpstreamUrl" />
|
||||
<Binding Path="ExtraArgs" />
|
||||
|
||||
</MultiBinding>
|
||||
</TextBox.Foreground>
|
||||
</TextBox>
|
||||
@ -82,7 +79,6 @@
|
||||
</Binding>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Button IsDefault="True"
|
||||
@ -97,7 +93,6 @@
|
||||
|
||||
<Binding Path="BrowserPath" />
|
||||
<Binding Path="ExtraArgs" />
|
||||
|
||||
</MultiBinding>
|
||||
</Button.IsEnabled>
|
||||
</Button>
|
||||
@ -126,7 +121,6 @@
|
||||
<Button x:Name="AboutButton"
|
||||
Grid.Column="2" Margin="5" Content="{Binding AboutButtonContent, Source={StaticResource MainConst}}"
|
||||
Click="AboutButton_Click" />
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -16,173 +15,166 @@ using Sheas_Cealer.Preses;
|
||||
using Sheas_Cealer.Utils;
|
||||
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;
|
||||
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();
|
||||
InitializeComponent();
|
||||
|
||||
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);
|
||||
DataContext = MainPres;
|
||||
|
||||
Task.Run(() =>
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
|
||||
CealingHostWatcher_Changed(null!, null!);
|
||||
});
|
||||
}
|
||||
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 });
|
||||
ContentBox.Focus();
|
||||
MainPres!.BrowserPath = openFileDialog.FileName;
|
||||
}
|
||||
}
|
||||
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;
|
||||
int ruleIndex = 0;
|
||||
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;
|
||||
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, @"Cealing-Host.json"), UpdateHostString);
|
||||
MessageBox.Show("更新已完成");
|
||||
}
|
||||
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);
|
||||
else if (overrideResult == MessageBoxResult.No)
|
||||
Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true });
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user