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,8 +2,8 @@
using System.Windows.Threading;
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();
@ -14,4 +14,3 @@ namespace Sheas_Cealer
e.Handled = true;
}
}
}

View File

@ -1,7 +1,7 @@
using System.Reflection;
namespace Sheas_Cealer.Consts
{
namespace Sheas_Cealer.Consts;
internal class AboutConst : AboutMultilangConst
{
public static string Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2];
@ -13,4 +13,3 @@ namespace Sheas_Cealer.Consts
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;
namespace Sheas_Cealer.Consts
{
namespace Sheas_Cealer.Consts;
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";
[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 UrlRegex();
[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(@"^(--[a-z](-?[a-z])*( --[a-z](-?[a-z])*)*)?$")]
internal static partial Regex ArgsRegex();
}
internal static partial Regex ExtraArgsRegex();
}

View File

@ -2,8 +2,8 @@
using System.Globalization;
using System.Windows.Data;
namespace Sheas_Cealer.Convs
{
namespace Sheas_Cealer.Convs;
internal class AboutVersionButtonContentConv : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
@ -19,4 +19,3 @@ namespace Sheas_Cealer.Convs
throw new NotImplementedException();
}
}
}

View File

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

View File

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

View File

@ -4,19 +4,19 @@ using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs
{
namespace Sheas_Cealer.Convs;
internal class MainFunctionButtonContentConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
MainConst.Mode? mode = value as MainConst.Mode?;
MainConst.SettingsMode? mode = value as MainConst.SettingsMode?;
if (mode == MainConst.Mode.browserPathMode)
if (mode == MainConst.SettingsMode.BrowserPathMode)
return MainConst.FunctionButtonBrowserPathContent;
else if (mode == MainConst.Mode.upstreamUrlMode)
else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
return MainConst.FunctionButtonUpstreamUrlContent;
else if (mode == MainConst.Mode.extraArgsMode)
else if (mode == MainConst.SettingsMode.ExtraArgsMode)
return MainConst.FunctionButtonExtraArgsContent;
throw new UnreachableException();
@ -27,4 +27,3 @@ namespace Sheas_Cealer.Convs
throw new NotImplementedException();
}
}
}

View File

@ -4,8 +4,8 @@ using System.IO;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs
{
namespace Sheas_Cealer.Convs;
internal class MainStartCealButtonIsEnabledConv : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
@ -13,7 +13,7 @@ namespace Sheas_Cealer.Convs
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 false;
@ -24,4 +24,3 @@ namespace Sheas_Cealer.Convs
throw new NotImplementedException();
}
}
}

View File

@ -4,19 +4,19 @@ using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs
{
namespace Sheas_Cealer.Convs;
internal class MainSwitchModeButtonContentConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
MainConst.Mode? mode = value as MainConst.Mode?;
MainConst.SettingsMode? mode = value as MainConst.SettingsMode?;
if (mode == MainConst.Mode.browserPathMode)
if (mode == MainConst.SettingsMode.BrowserPathMode)
return MainConst.SwitchModeButtonBrowserPathContent;
else if (mode == MainConst.Mode.upstreamUrlMode)
else if (mode == MainConst.SettingsMode.UpstreamUrlMode)
return MainConst.SwitchModeButtonUpstreamUrlContent;
else if (mode == MainConst.Mode.extraArgsMode)
else if (mode == MainConst.SettingsMode.ExtraArgsMode)
return MainConst.SwitchModeButtonExtraArgsContent;
throw new UnreachableException();
@ -27,4 +27,3 @@ namespace Sheas_Cealer.Convs
throw new NotImplementedException();
}
}
}

View File

@ -3,15 +3,15 @@ using System.Globalization;
using System.Windows.Data;
using Sheas_Cealer.Consts;
namespace Sheas_Cealer.Convs
{
namespace Sheas_Cealer.Convs;
internal class MainUpdateHostButtonIsEnabledConv : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string? upstreamUrl = value as string;
if (MainConst.UrlRegex().IsMatch(upstreamUrl!))
if (MainConst.UpstreamUrlRegex().IsMatch(upstreamUrl!))
return true;
return false;
@ -22,4 +22,3 @@ namespace Sheas_Cealer.Convs
throw new NotImplementedException();
}
}
}

View File

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

View File

@ -2,8 +2,8 @@
using System.Diagnostics;
using SheasCore;
namespace Sheas_Cealer.Utils
{
namespace Sheas_Cealer.Utils;
internal class Command : Proc
{
internal Command() : base("Cmd.exe")
@ -18,4 +18,3 @@ namespace Sheas_Cealer.Utils
}
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,10 +2,9 @@
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
{
@ -43,17 +42,3 @@ namespace Sheas_Cealer.Utils
SendMessage(hwnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
}
}
}
namespace Sheas_Cealer.Wins
{
// 使用IconRemover
public partial class MainWin
{
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
}
public partial class AboutWin
{
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
}
}

View File

@ -38,7 +38,6 @@
<Binding Path="VersionButtonContent" Source="{StaticResource AboutConst}" />
<Binding Path="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>

View File

@ -1,16 +1,15 @@
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
{
internal AboutWin()
{
InitializeComponent();
}
internal AboutWin() => InitializeComponent();
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
@ -26,5 +25,6 @@ namespace Sheas_Cealer.Wins
if (e.Key == Key.Escape)
Close();
}
}
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
}

View File

@ -3,10 +3,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns: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"
Style="{DynamicResource CommonWindow}" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" SizeToContent="Height" Width="500" MinWidth="500"
@ -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>

View File

@ -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,15 +15,14 @@ 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
{
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();
internal MainWin(string[] args)
{
@ -32,14 +30,9 @@ namespace Sheas_Cealer.Wins
MainPres = new(args);
DataContext = MainPres;
Task.Run(() =>
{
CealingHostWatcher.Changed += CealingHostWatcher_Changed;
CealingHostWatcher_Changed(null!, null!);
});
}
private void MainWin_Loaded(object sender, RoutedEventArgs e) => MainPres!.IsContentBoxFocused = true;
private void MainWin_Loaded(object sender, RoutedEventArgs e) => ContentBox.Focus();
private void MainWin_Closing(object sender, CancelEventArgs e) => Environment.Exit(0);
private void MainWin_DragEnter(object sender, DragEventArgs e)
@ -61,40 +54,40 @@ namespace Sheas_Cealer.Wins
{
TextBox? ContentBox = sender as TextBox;
if (MainPres!.Mode == MainConst.Mode.browserPathMode)
if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
MainPres.BrowserPath = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode)
else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres.UpstreamUrl = ContentBox!.Text;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode)
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.Mode.browserPathMode)
if (MainPres!.Mode == MainConst.SettingsMode.BrowserPathMode)
{
OpenFileDialog openFileDialog = new() { Filter = "浏览器 (*.exe)|*.exe" };
if (openFileDialog.ShowDialog() == true)
{
MainPres!.IsContentBoxFocused = true;
ContentBox.Focus();
MainPres!.BrowserPath = openFileDialog.FileName;
}
}
else if (MainPres!.Mode == MainConst.Mode.upstreamUrlMode)
else if (MainPres!.Mode == MainConst.SettingsMode.UpstreamUrlMode)
MainPres!.UpstreamUrl = MainConst.DefaultUpstreamUrl;
else if (MainPres!.Mode == MainConst.Mode.extraArgsMode)
else if (MainPres!.Mode == MainConst.SettingsMode.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;
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)
@ -131,7 +124,7 @@ namespace Sheas_Cealer.Wins
string hostLocalString = hostLocalStreamReader.ReadToEnd();
hostLocalStreamReader.Close();
if (MainConst.HostRegex().Replace(hostLocalString, string.Empty) == UpdateHostString)
if (hostLocalString.Replace("\r", string.Empty) == UpdateHostString)
MessageBox.Show("本地伪造规则和上游一模一样");
else
{
@ -145,10 +138,7 @@ namespace Sheas_Cealer.Wins
Process.Start(new ProcessStartInfo(hostUrl) { UseShellExecute = true });
}
}
private void AboutButton_Click(object sender, RoutedEventArgs e)
{
new AboutWin().ShowDialog();
}
private void AboutButton_Click(object sender, RoutedEventArgs e) => new AboutWin().ShowDialog();
private void CealingHostWatcher_Changed(object sender, FileSystemEventArgs e)
{
@ -156,8 +146,9 @@ namespace Sheas_Cealer.Wins
{
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());
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)
{
@ -184,5 +175,6 @@ namespace Sheas_Cealer.Wins
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.W)
Environment.Exit(0);
}
}
protected override void OnSourceInitialized(EventArgs e) => IconRemover.RemoveIcon(this);
}