From a0649d05db4deb0f24139d6070d624b453bf61a9 Mon Sep 17 00:00:00 2001 From: zdAnQi <131591012+zaodonganqi@users.noreply.github.com> Date: Sun, 20 Jul 2025 23:10:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BB=93=E5=BA=93=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=AE=A2=E9=98=85=E5=90=8E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20(#1896)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 辉鸭蛋 --- .../Core/Script/ScriptRepoUpdater.cs | 48 ++++++++++++++++++- .../Core/Script/WebView/RepoWebBridge.cs | 22 ++++++++- .../View/Windows/ScriptRepoWindow.xaml.cs | 5 +- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs b/BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs index 5fb9747b..d8437e75 100644 --- a/BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs +++ b/BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs @@ -1,4 +1,4 @@ -using BetterGenshinImpact.Core.Config; +using BetterGenshinImpact.Core.Config; using BetterGenshinImpact.Core.Script.WebView; using BetterGenshinImpact.GameTask; using BetterGenshinImpact.Helpers; @@ -407,7 +407,7 @@ public class ScriptRepoUpdater : Singleton ZipFile.ExtractToDirectory(zipPath, ReposPath, true); } - public async Task ImportScriptFromClipboard( string clipboardText ) + public async Task ImportScriptFromClipboard(string clipboardText) { // 获取剪切板内容 try @@ -604,6 +604,7 @@ public class ScriptRepoUpdater : Singleton File.Copy(scriptPath, destPath, true); } + UpdateSubscribedScriptPaths(); Toast.Success("脚本订阅链接导入完成"); } else @@ -613,6 +614,34 @@ public class ScriptRepoUpdater : Singleton } } + // 更新订阅脚本路径列表,移除无效路径 + public void UpdateSubscribedScriptPaths() + { + var scriptConfig = TaskContext.Instance().Config.ScriptConfig; + var validRoots = PathMapper.Keys.ToHashSet(); + + // 过滤并保留有效路径 + scriptConfig.SubscribedScriptPaths = scriptConfig.SubscribedScriptPaths + .Distinct() + .Where(path => + { + if (string.IsNullOrEmpty(path) || !path.Contains('/')) + return false; + + var root = path.Split('/')[0]; + + if (!validRoots.Contains(root)) + return false; + + var (_, remainingPath) = GetFirstFolderAndRemainingPath(path); + var userPath = Path.Combine(PathMapper[root], remainingPath); + + return Directory.Exists(userPath) || File.Exists(userPath); + }) + .OrderBy(path => path) + .ToList(); + } + private void CopyDirectory(string sourceDir, string destDir) { // 创建目标目录 @@ -667,7 +696,22 @@ public class ScriptRepoUpdater : Singleton _webWindow.Panel!.DownloadFolderPath = MapPathingViewModel.PathJsonPath; _webWindow.NavigateToFile(Global.Absolute(@"Assets\Web\ScriptRepo\index.html")); _webWindow.Panel!.OnWebViewInitializedAction = () => + { _webWindow.Panel!.WebView.CoreWebView2.AddHostObjectToScript("repoWebBridge", new RepoWebBridge()); + + // 允许内部外链使用默认浏览器打开 + _webWindow.Panel!.WebView.CoreWebView2.NewWindowRequested += (sender, e) => + { + var psi = new ProcessStartInfo + { + UseShellExecute = true, + FileName = e.Uri + }; + Process.Start(psi); + + e.Handled = true; + }; + }; _webWindow.Show(); } else diff --git a/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs b/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs index 2023a7ae..63f7371c 100644 --- a/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs +++ b/BetterGenshinImpact/Core/Script/WebView/RepoWebBridge.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -55,4 +55,22 @@ public class RepoWebBridge await MessageBox.ShowAsync(e.Message, "订阅脚本链接失败!"); } } -} \ No newline at end of file + + public async Task GetUserConfigJson() + { + try + { + string userConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "User", "config.json"); + if (!File.Exists(userConfigPath)) + { + throw new Exception("用户配置文件不存在: " + userConfigPath); + } + return await File.ReadAllTextAsync(userConfigPath); + } + catch (Exception e) + { + await MessageBox.ShowAsync(e.Message, "获取用户配置失败"); + return ""; + } + } +} diff --git a/BetterGenshinImpact/View/Windows/ScriptRepoWindow.xaml.cs b/BetterGenshinImpact/View/Windows/ScriptRepoWindow.xaml.cs index 9ea9b7b2..d599755a 100644 --- a/BetterGenshinImpact/View/Windows/ScriptRepoWindow.xaml.cs +++ b/BetterGenshinImpact/View/Windows/ScriptRepoWindow.xaml.cs @@ -85,7 +85,8 @@ public partial class ScriptRepoWindow { new("CNB", "https://cnb.cool/bettergi/bettergi-scripts-list"), new("GitCode", "https://gitcode.com/huiyadanli/bettergi-scripts-list"), - new("Gitee", "https://gitee.com/babalae/bettergi-scripts-list"), + // 暂时无法使用 + // new("Gitee", "https://gitee.com/babalae/bettergi-scripts-list"), new("GitHub", "https://github.com/babalae/bettergi-scripts-list"), new("自定义", "https://example.com/custom-repo") }; @@ -228,4 +229,4 @@ public partial class ScriptRepoWindow } } } -} \ No newline at end of file +}