🚸 添加游戏目录存在性检查,优化用户提示信息

This commit is contained in:
BTMuli
2026-05-19 19:08:57 +08:00
parent eff562494a
commit 73752ea28b
3 changed files with 23 additions and 4 deletions

View File

@@ -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 { readDir } from "@tauri-apps/plugin-fs";
import { exists, readDir } from "@tauri-apps/plugin-fs";
import mhyClient from "@utils/TGClient.js";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
@@ -849,6 +849,11 @@ async function tryLaunchGame(): Promise<void> {
showSnackbar.warn("请前往设置页面设置游戏安装目录");
return;
}
if (!(await exists(gameDir.value))) {
showSnackbar.warn("游戏目录不存在请检查设置");
await TGLogger.Warn(`[sidebar][tryLaunchGame] 游戏目录不存在: ${gameDir.value}`);
return;
}
const dirRead = await readDir(gameDir.value);
const find = dirRead.find((i) => i.isFile && i.name.toLowerCase() === "yuanshen.exe");
if (!find) {

View File

@@ -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 { readDir } from "@tauri-apps/plugin-fs";
import { exists, readDir } from "@tauri-apps/plugin-fs";
import TGHttps from "@utils/TGHttps.js";
import TGLogger from "@utils/TGLogger.js";
import { storeToRefs } from "pinia";
@@ -43,6 +43,11 @@ async function tryPlayGame(): Promise<void> {
showSnackbar.warn("未设置游戏安装目录!");
return;
}
if (!(await exists(gameDir.value))) {
showSnackbar.warn("游戏目录不存在,请检查设置");
await TGLogger.Warn(`[config][gameBadge] 游戏目录不存在: ${gameDir.value}`);
return;
}
const dirRead = await readDir(gameDir.value);
const find = dirRead.find((i) => i.isFile && i.name.toLowerCase() === "yuanshen.exe");
if (!find) {

View File

@@ -1,6 +1,6 @@
/**
* 游戏文件相关功能
* @since Beta v0.9.9
* @since Beta v0.10.2
*/
import showDialog from "@comp/func/dialog.js";
@@ -32,7 +32,7 @@ function verifyConfigIni(data: object): data is TGApp.Game.Config.GameConf {
/**
* 尝试获取游戏版本
* @since Beta v0.9.9
* @since Beta v0.10.2
* @remarks
* 1. 读取 config.ini 下的 game_version
* 2. 没有 config.ini ,读取 YuanShen_Data\\Persistent\\ScriptVersion
@@ -44,6 +44,10 @@ export async function tryReadGameVer(gameDir: string): Promise<false | string> {
showSnackbar.warn("该功能仅支持Windows系统");
return false;
}
if (!(await exists(gameDir))) {
await TGLogger.Warn(`[TGGame][tryReadGameVer] 游戏目录不存在: ${gameDir}`);
return false;
}
const iniPath = `${gameDir}${sep()}config.ini`;
if (await exists(iniPath)) {
const iniRead = await readTextFile(iniPath);
@@ -113,6 +117,11 @@ export async function tryCallYae(gameDir: string, uid?: string): Promise<void> {
showSnackbar.warn("请前往设置页面设置游戏安装目录");
return;
}
if (!(await exists(gameDir))) {
showSnackbar.warn("游戏目录不存在,请检查设置");
await TGLogger.Warn(`[TGGame][tryCallYae] 游戏目录不存在: ${gameDir}`);
return;
}
const dirRead = await readDir(gameDir);
const find = dirRead.find((i) => i.isFile && i.name.toLowerCase() === "yuanshen.exe");
if (!find) {