diff --git a/src-tauri/capabilities/TeyvatGuide.json b/src-tauri/capabilities/TeyvatGuide.json index dd8073da..72a8a3ed 100644 --- a/src-tauri/capabilities/TeyvatGuide.json +++ b/src-tauri/capabilities/TeyvatGuide.json @@ -44,6 +44,7 @@ { "identifier": "fs:allow-mkdir", "allow": [{ "path": "**" }] }, { "identifier": "fs:allow-read-dir", "allow": [{ "path": "**" }] }, { "identifier": "fs:allow-read-text-file", "allow": [{ "path": "**" }] }, + { "identifier": "fs:allow-read-text-file-lines", "allow": [{ "path": "**" }] }, { "identifier": "fs:allow-remove", "allow": [{ "path": "**" }] }, { "identifier": "fs:allow-write-file", "allow": [{ "path": "**" }] }, { "identifier": "fs:allow-write-text-file", "allow": [{ "path": "**" }] }, diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index 2674464a..77bed49d 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -320,8 +320,8 @@ import { invoke } from "@tauri-apps/api/core"; import type { Event, UnlistenFn } from "@tauri-apps/api/event"; import { exists } from "@tauri-apps/plugin-fs"; import mhyClient from "@utils/TGClient.js"; +import { isRunInAdmin, tryReadGameVer, YAE_GAME_VER } from "@utils/TGGame.js"; import TGLogger from "@utils/TGLogger.js"; -import { isRunInAdmin } from "@utils/toolFunc.js"; import { storeToRefs } from "pinia"; import { computed, onMounted, onUnmounted, ref, shallowRef } from "vue"; @@ -730,25 +730,26 @@ async function tryLaunchGame(): Promise { return; } const isInAdmin = await isRunInAdmin(); - if (!isInAdmin) { + const gameVer = await tryReadGameVer(gameDir.value); + if (!isInAdmin || !gameVer || gameVer !== YAE_GAME_VER) { showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`); try { await invoke("launch_game", { path: gamePath, ticket: resp }); } catch (error) { showSnackbar.error(`${error}`); } - } else { - try { - await invoke("call_yae_dll", { - gamePath: gamePath, - uid: account.value.gameUid, - ticket: resp, - }); - } catch (err) { - showSnackbar.error(`调用Yae DLL失败: ${err}`); - await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`); - return; - } + return; + } + try { + await invoke("call_yae_dll", { + gamePath: gamePath, + uid: account.value.gameUid, + ticket: resp, + }); + } catch (err) { + showSnackbar.error(`调用Yae DLL失败: ${err}`); + await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`); + return; } } diff --git a/src/components/pageConfig/tc-dataDir.vue b/src/components/pageConfig/tc-dataDir.vue index 30406fc3..3037cf72 100644 --- a/src/components/pageConfig/tc-dataDir.vue +++ b/src/components/pageConfig/tc-dataDir.vue @@ -2,7 +2,7 @@ - + - + - + - + @@ -72,10 +76,21 @@ import { exists, readDir, remove } from "@tauri-apps/plugin-fs"; import { openPath } from "@tauri-apps/plugin-opener"; import { platform } from "@tauri-apps/plugin-os"; import { backUpUserData } from "@utils/dataBS.js"; +import { tryReadGameVer } from "@utils/TGGame.js"; import { storeToRefs } from "pinia"; -import { onMounted } from "vue"; +import { onMounted, ref, watch } from "vue"; const { dbPath, logDir, userDir, gameDir } = storeToRefs(useAppStore()); +const gameVer = ref(); + +watch( + () => gameDir.value, + async () => { + const gv = await tryReadGameVer(gameDir.value); + if (gv) gameVer.value = gv; + }, + { immediate: true }, +); onMounted(async () => { const logDirGet = await path.appLogDir(); diff --git a/src/pages/common/PageAchi.vue b/src/pages/common/PageAchi.vue index b72afe64..0baaad7d 100644 --- a/src/pages/common/PageAchi.vue +++ b/src/pages/common/PageAchi.vue @@ -93,13 +93,11 @@ import TSUserAchi from "@Sqlm/userAchi.js"; 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 { listen, type UnlistenFn } from "@tauri-apps/api/event"; import { open, save } from "@tauri-apps/plugin-dialog"; -import { exists, writeTextFile } from "@tauri-apps/plugin-fs"; -import { platform } from "@tauri-apps/plugin-os"; +import { writeTextFile } from "@tauri-apps/plugin-fs"; +import { tryCallYae } from "@utils/TGGame.js"; import TGLogger from "@utils/TGLogger.js"; -import { isRunInAdmin } from "@utils/toolFunc.js"; import { getUiafHeader, readUiafData, @@ -315,50 +313,7 @@ async function deleteUid(): Promise { } async function toYae(): Promise { - if (platform() !== "windows") { - showSnackbar.warn("该功能仅支持Windows系统"); - return; - } - if (gameDir.value === "未设置") { - showSnackbar.warn("请前往设置页面设置游戏安装目录"); - return; - } - const gamePath = `${gameDir.value}${path.sep()}YuanShen.exe`; - if (!(await exists(gamePath))) { - showSnackbar.warn("未检测到原神本体应用!"); - return; - } - const isInAdmin = await isRunInAdmin(); - if (!isInAdmin) { - const check = await showDialog.check("是否以管理员模式重启?", "该功能需要管理员权限才能使用"); - if (!check) { - showSnackbar.cancel("已取消以管理员模式重启"); - return; - } - try { - await invoke("run_with_admin"); - } catch (err) { - showSnackbar.error(`以管理员模式重启失败:${err}`); - await TGLogger.Error(`[pageAchi][toYae]以管理员模式启动失败 - ${err}`); - return; - } - } - const input = await showDialog.input("请输入存档UID", "UID:", uidCur.value.toString()); - if (!input) { - showSnackbar.cancel("已取消存档导入"); - return; - } - if (input === "" || isNaN(Number(input))) { - showSnackbar.warn("请输入合法数字"); - return; - } - try { - await invoke("call_yae_dll", { gamePath: gamePath, uid: input }); - } catch (err) { - showSnackbar.error(`调用Yae DLL失败: ${err}`); - await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`); - return; - } + await tryCallYae(gameDir.value, uidCur.value.toString()); }