diff --git a/Consts/MainConst.cs b/Consts/MainConst.cs index 0712d02..f24b2f4 100644 --- a/Consts/MainConst.cs +++ b/Consts/MainConst.cs @@ -9,7 +9,7 @@ internal enum SettingsMode internal static string DefaultUpstreamUrl => "https://gitlab.com/SpaceTimee/Cealing-Host/raw/main/Cealing-Host.json"; - [GeneratedRegex(@"^(((ht|f)tps?):\/\/)?[a-zA-Z0-9](-*[a-zA-Z0-9])*(\.[a-zA-Z0-9](-*[a-zA-Z0-9])*)*(:\d{1,5})?(\/[a-zA-Z0-9.\-_\~\!\$\&\'\(\)\*\+\,\;\=\:\@\%]*)*$")] + [GeneratedRegex(@"^(https?:\/\/)?[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])*)*)?$")] diff --git a/Preses/MainPres.cs b/Preses/MainPres.cs index 7b76e21..52f5120 100644 --- a/Preses/MainPres.cs +++ b/Preses/MainPres.cs @@ -16,15 +16,15 @@ internal MainPres(string[] args) 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 ? + BrowserPath = browserPathIndex == 0 || browserPathIndex == args.Length ? (!string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : string.Empty) : args[browserPathIndex]; - UpstreamUrl = upstreamUrlIndex == 0 ? + UpstreamUrl = upstreamUrlIndex == 0 || upstreamUrlIndex == args.Length ? (!string.IsNullOrWhiteSpace(Settings.Default.UpstreamUrl) ? Settings.Default.UpstreamUrl : MainConst.DefaultUpstreamUrl) : args[upstreamUrlIndex]; - ExtraArgs = extraArgsIndex == 0 ? + ExtraArgs = extraArgsIndex == 0 || extraArgsIndex == args.Length ? (!string.IsNullOrWhiteSpace(Settings.Default.ExtraArgs) ? Settings.Default.ExtraArgs : string.Empty) : args[extraArgsIndex]; } diff --git a/Utils/CommandProc.cs b/Utils/CommandProc.cs index e959c77..eba3bf8 100644 --- a/Utils/CommandProc.cs +++ b/Utils/CommandProc.cs @@ -6,7 +6,7 @@ namespace Sheas_Cealer.Utils; internal class CommandProc : Proc { - internal bool ShutDownAppOnProcessExit; + private static bool ShutDownAppOnProcessExit; internal CommandProc(bool shutDownAppOnProcessExit) : base("Cmd.exe") => ShutDownAppOnProcessExit = shutDownAppOnProcessExit; diff --git a/Utils/IconRemover.cs b/Utils/IconRemover.cs index 403d105..67ca68d 100644 --- a/Utils/IconRemover.cs +++ b/Utils/IconRemover.cs @@ -5,7 +5,6 @@ namespace Sheas_Cealer.Utils; -// 定义 IconRemover internal static partial class IconRemover { private const int GWL_EXSTYLE = -20; diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index ae83d02..1fc7c39 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -130,16 +130,25 @@ private void StartButtonHoldTimer_Tick(object? sender, EventArgs e) private void EditHostButton_Click(object sender, RoutedEventArgs e) { - ProcessStartInfo processStartInfo = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json")) { UseShellExecute = true }; + string cealingHostPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json"); + + if (!File.Exists(cealingHostPath)) + File.Create(cealingHostPath).Dispose(); + + ProcessStartInfo processStartInfo = new(cealingHostPath) { UseShellExecute = true }; Process.Start(processStartInfo); } private async void UpdateHostButton_Click(object sender, RoutedEventArgs e) { - string upstreamHostUrl = MainPres!.UpstreamUrl; + string upstreamHostUrl = (MainPres!.UpstreamUrl.StartsWith("http://") || MainPres!.UpstreamUrl.StartsWith("https://") ? string.Empty : "https://") + MainPres!.UpstreamUrl; string upstreamHostString = await Http.GetAsync(upstreamHostUrl, MainClient); + string localHostPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json"); string localHostString; - using (StreamReader localHostStreamReader = new(Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase!, "Cealing-Host.json"))) + if (!File.Exists(localHostPath)) + File.Create(localHostPath).Dispose(); + + using (StreamReader localHostStreamReader = new(localHostPath)) localHostString = localHostStreamReader.ReadToEnd(); if (localHostString.Replace("\r", string.Empty) == upstreamHostString)