From 7e85989fa8ba1a6ae4a5b9539f623a7e308d9e79 Mon Sep 17 00:00:00 2001 From: Space Time Date: Wed, 2 Oct 2024 01:04:09 +0800 Subject: [PATCH] =?UTF-8?q?1.1.1=20->=201.1.2=20=E7=AC=AC12=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Preses/MainPres.cs | 10 +++++++--- Wins/MainWin.xaml.cs | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Preses/MainPres.cs b/Preses/MainPres.cs index ee7d47b..fb37afb 100644 --- a/Preses/MainPres.cs +++ b/Preses/MainPres.cs @@ -2,6 +2,7 @@ using System.IO; using CommunityToolkit.Mvvm.ComponentModel; using MaterialDesignThemes.Wpf; +using Microsoft.Win32; using Sheas_Cealer.Consts; using Sheas_Cealer.Props; using File = System.IO.File; @@ -16,9 +17,12 @@ internal partial class MainPres : ObservableObject 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 || browserPathIndex == args.Length ? - !string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : string.Empty : - args[browserPathIndex]; + BrowserPath = browserPathIndex != 0 && browserPathIndex != args.Length ?args[browserPathIndex]: + !string.IsNullOrWhiteSpace(Settings.Default.BrowserPath) ? Settings.Default.BrowserPath : + (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\msedge.exe", string.Empty, null) ?? + Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", string.Empty, null) ?? + Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\brave.exe", string.Empty, null) ?? + string.Empty).ToString()!; UpstreamUrl = upstreamUrlIndex == 0 || upstreamUrlIndex == args.Length ? !string.IsNullOrWhiteSpace(Settings.Default.UpstreamUrl) ? Settings.Default.UpstreamUrl : MainConst.DefaultUpstreamUrl : diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index 398d921..cd95819 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -177,11 +177,12 @@ public partial class MainWin : Window private void HostWatcher_Changed(object sender, FileSystemEventArgs e) { + string hostName = e.Name!.TrimStart("Cealing-Host-".ToCharArray()).TrimEnd(".json".ToCharArray()); + try { string hostRulesFragments = string.Empty; string hostResolverRulesFragments = string.Empty; - string hostName = e.Name!.TrimStart("Cealing-Host-".ToCharArray()).TrimEnd(".json".ToCharArray()); int ruleIndex = 0; using FileStream hostStream = new(e.FullPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); @@ -202,7 +203,10 @@ public partial class MainWin : Window } CealArgsFragments[hostName] = (hostRulesFragments, hostResolverRulesFragments); - + } + catch { CealArgsFragments.Remove(hostName); } + finally + { string hostRules = string.Empty; string hostResolverRules = string.Empty; @@ -212,9 +216,8 @@ public partial class MainWin : Window hostResolverRules += CealArgsFragment.hostResolverRulesFragments; } - CealArgs = @$"--host-rules=""{hostRules.TrimEnd(',')}"" --host-resolver-rules=""{hostResolverRules.TrimEnd(',')}"" --test-type --ignore-certificate-errors"; + CealArgs = @$"/c @start .\""Uncealed-Browser.lnk"" --host-rules=""{hostRules.TrimEnd(',')}"" --host-resolver-rules=""{hostResolverRules.TrimEnd(',')}"" --test-type --ignore-certificate-errors"; } - catch { CealArgs = string.Empty; } } private void MainWin_KeyDown(object sender, KeyEventArgs e) {