From b965cccbf169a042629285e84f07db2d4b11f55a Mon Sep 17 00:00:00 2001 From: BTMuli Date: Thu, 26 Feb 2026 17:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20=E5=A4=84=E7=90=86=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #219 --- src/components/app/t-sidebar.vue | 12 +++++++++--- src/components/pageConfig/tc-dataDir.vue | 9 ++++++--- src/components/pageConfig/tc-gameBadge.vue | 10 ++++++---- src/utils/TGGame.ts | 15 ++++++++++++--- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index 929d3886..9e2c6883 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -330,7 +330,7 @@ import useUserStore from "@store/user.js"; import { event, path, webviewWindow } from "@tauri-apps/api"; import { invoke } from "@tauri-apps/api/core"; import type { Event, UnlistenFn } from "@tauri-apps/api/event"; -import { exists } from "@tauri-apps/plugin-fs"; +import { readDir } from "@tauri-apps/plugin-fs"; import mhyClient from "@utils/TGClient.js"; import { isRunInAdmin, tryCopyYae, tryReadGameVer, YAE_GAME_VER } from "@utils/TGGame.js"; import TGLogger from "@utils/TGLogger.js"; @@ -729,11 +729,17 @@ async function tryLaunchGame(): Promise { showSnackbar.warn("请先登录!"); return; } - const gamePath = `${gameDir.value}${path.sep()}YuanShen.exe`; - if (!(await exists(gamePath))) { + if (gameDir.value === "未设置") { + showSnackbar.warn("请前往设置页面设置游戏安装目录"); + return; + } + const dirRead = await readDir(gameDir.value); + const find = dirRead.find((i) => i.isFile && i.name.toLowerCase() === "yuanshen.exe"); + if (!find) { showSnackbar.warn("未检测到原神本体应用!"); return; } + const gamePath = `${gameDir.value}${path.sep()}${find.name}`; const resp = await passportReq.authTicket(account.value, cookie.value); if (typeof resp !== "string") { showSnackbar.error(`[${resp.retcode}] ${resp.message}`); diff --git a/src/components/pageConfig/tc-dataDir.vue b/src/components/pageConfig/tc-dataDir.vue index 80f61098..9ceaa6a8 100644 --- a/src/components/pageConfig/tc-dataDir.vue +++ b/src/components/pageConfig/tc-dataDir.vue @@ -145,7 +145,7 @@ async function confirmCGD(): Promise { const oriEmpty = gameDir.value === "未设置"; const editCheck = await showDialog.check( oriEmpty ? "确认设置游戏目录?" : "确认修改游戏目录?", - oriEmpty ? "请选择 Yuanshen.exe 所在目录" : `当前:${gameDir.value}`, + oriEmpty ? "请选择 YuanShen.exe 所在目录" : `当前:${gameDir.value}`, ); if (!editCheck) { showSnackbar.cancel(oriEmpty ? "已取消设置" : "已取消修改"); @@ -159,11 +159,14 @@ async function confirmCGD(): Promise { showSnackbar.warn("路径不能为空!"); return; } - if (!file.endsWith("YuanShen.exe")) { + if (!file.toLowerCase().endsWith("yuanshen.exe")) { showSnackbar.warn("请选中游戏本体(YuanShen.exe)"); return; } - if (!oriEmpty && `${gameDir.value}${path.sep()}YuanShen.exe` === file) { + if ( + !oriEmpty && + `${gameDir.value}${path.sep()}YuanShen.exe`.toLowerCase() === file.toLowerCase() + ) { showSnackbar.warn("路径未修改!"); return; } diff --git a/src/components/pageConfig/tc-gameBadge.vue b/src/components/pageConfig/tc-gameBadge.vue index 5b40308f..c4c9f045 100644 --- a/src/components/pageConfig/tc-gameBadge.vue +++ b/src/components/pageConfig/tc-gameBadge.vue @@ -2,7 +2,7 @@
✨原神,启动!
- +
@@ -22,7 +22,7 @@ import useAppStore from "@store/app.js"; import useUserStore from "@store/user.js"; import { path } from "@tauri-apps/api"; import { invoke } from "@tauri-apps/api/core"; -import { exists } from "@tauri-apps/plugin-fs"; +import { readDir } from "@tauri-apps/plugin-fs"; import TGLogger from "@utils/TGLogger.js"; import { storeToRefs } from "pinia"; @@ -42,11 +42,13 @@ async function tryPlayGame(): Promise { showSnackbar.warn("未设置游戏安装目录!"); return; } - const gamePath = `${gameDir.value}${path.sep()}YuanShen.exe`; - if (!(await exists(gamePath))) { + const dirRead = await readDir(gameDir.value); + const find = dirRead.find((i) => i.isFile && i.name.toLowerCase() === "yuanshen.exe"); + if (!find) { showSnackbar.warn("未检测到原神本体应用!"); return; } + const gamePath = `${gameDir.value}${path.sep()}${find.name}`; const resp = await passportReq.authTicket(account.value, cookie.value); if (typeof resp !== "string") { showSnackbar.error(`[${resp.retcode}] ${resp.message}`); diff --git a/src/utils/TGGame.ts b/src/utils/TGGame.ts index c4b052e9..a9f8e49e 100644 --- a/src/utils/TGGame.ts +++ b/src/utils/TGGame.ts @@ -7,7 +7,14 @@ import showDialog from "@comp/func/dialog.js"; import showSnackbar from "@comp/func/snackbar.js"; import { invoke } from "@tauri-apps/api/core"; import { documentDir, resourceDir, sep } from "@tauri-apps/api/path"; -import { copyFile, exists, mkdir, readTextFile, readTextFileLines } from "@tauri-apps/plugin-fs"; +import { + copyFile, + exists, + mkdir, + readDir, + readTextFile, + readTextFileLines, +} from "@tauri-apps/plugin-fs"; import { platform } from "@tauri-apps/plugin-os"; import TGLogger from "@utils/TGLogger.js"; @@ -97,11 +104,13 @@ export async function tryCallYae(gameDir: string, uid?: string): Promise { showSnackbar.warn("请前往设置页面设置游戏安装目录"); return; } - const gamePath = `${gameDir}${sep()}YuanShen.exe`; - if (!(await exists(gamePath))) { + const dirRead = await readDir(gameDir); + const find = dirRead.find((i) => i.isFile && i.name.toLowerCase() === "yuanshen.exe"); + if (!find) { showSnackbar.warn("未检测到游戏本体"); return; } + const gamePath = `${gameDir}${sep()}${find.name}`; const isRun = await invoke("is_process_running", { processName: "Yuanshen.exe" }); if (isRun) { showSnackbar.warn("检测到已启动的原神进程,请关闭进程(Yuanshen.exe)后重试");