mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
♻️ 获取游戏版本,完善检测
This commit is contained in:
@@ -44,6 +44,7 @@
|
|||||||
{ "identifier": "fs:allow-mkdir", "allow": [{ "path": "**" }] },
|
{ "identifier": "fs:allow-mkdir", "allow": [{ "path": "**" }] },
|
||||||
{ "identifier": "fs:allow-read-dir", "allow": [{ "path": "**" }] },
|
{ "identifier": "fs:allow-read-dir", "allow": [{ "path": "**" }] },
|
||||||
{ "identifier": "fs:allow-read-text-file", "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-remove", "allow": [{ "path": "**" }] },
|
||||||
{ "identifier": "fs:allow-write-file", "allow": [{ "path": "**" }] },
|
{ "identifier": "fs:allow-write-file", "allow": [{ "path": "**" }] },
|
||||||
{ "identifier": "fs:allow-write-text-file", "allow": [{ "path": "**" }] },
|
{ "identifier": "fs:allow-write-text-file", "allow": [{ "path": "**" }] },
|
||||||
|
|||||||
@@ -320,8 +320,8 @@ import { invoke } from "@tauri-apps/api/core";
|
|||||||
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
import type { Event, UnlistenFn } from "@tauri-apps/api/event";
|
||||||
import { exists } from "@tauri-apps/plugin-fs";
|
import { exists } from "@tauri-apps/plugin-fs";
|
||||||
import mhyClient from "@utils/TGClient.js";
|
import mhyClient from "@utils/TGClient.js";
|
||||||
|
import { isRunInAdmin, tryReadGameVer, YAE_GAME_VER } from "@utils/TGGame.js";
|
||||||
import TGLogger from "@utils/TGLogger.js";
|
import TGLogger from "@utils/TGLogger.js";
|
||||||
import { isRunInAdmin } from "@utils/toolFunc.js";
|
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { computed, onMounted, onUnmounted, ref, shallowRef } from "vue";
|
import { computed, onMounted, onUnmounted, ref, shallowRef } from "vue";
|
||||||
|
|
||||||
@@ -730,25 +730,26 @@ async function tryLaunchGame(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isInAdmin = await isRunInAdmin();
|
const isInAdmin = await isRunInAdmin();
|
||||||
if (!isInAdmin) {
|
const gameVer = await tryReadGameVer(gameDir.value);
|
||||||
|
if (!isInAdmin || !gameVer || gameVer !== YAE_GAME_VER) {
|
||||||
showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`);
|
showSnackbar.success(`成功获取ticket:${resp},正在启动应用...`);
|
||||||
try {
|
try {
|
||||||
await invoke("launch_game", { path: gamePath, ticket: resp });
|
await invoke("launch_game", { path: gamePath, ticket: resp });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showSnackbar.error(`${error}`);
|
showSnackbar.error(`${error}`);
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
try {
|
}
|
||||||
await invoke("call_yae_dll", {
|
try {
|
||||||
gamePath: gamePath,
|
await invoke("call_yae_dll", {
|
||||||
uid: account.value.gameUid,
|
gamePath: gamePath,
|
||||||
ticket: resp,
|
uid: account.value.gameUid,
|
||||||
});
|
ticket: resp,
|
||||||
} catch (err) {
|
});
|
||||||
showSnackbar.error(`调用Yae DLL失败: ${err}`);
|
} catch (err) {
|
||||||
await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`);
|
showSnackbar.error(`调用Yae DLL失败: ${err}`);
|
||||||
return;
|
await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<v-list class="config-list">
|
<v-list class="config-list">
|
||||||
<v-list-subheader :inset="true" class="config-header" title="路径" />
|
<v-list-subheader :inset="true" class="config-header" title="路径" />
|
||||||
<v-divider :inset="true" class="border-opacity-75" />
|
<v-divider :inset="true" class="border-opacity-75" />
|
||||||
<v-list-item title="用户数据目录" :subtitle="userDir">
|
<v-list-item :subtitle="userDir" title="用户数据目录">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<div class="config-icon">
|
<div class="config-icon">
|
||||||
<v-icon>mdi-folder-key</v-icon>
|
<v-icon>mdi-folder-key</v-icon>
|
||||||
@@ -10,13 +10,13 @@
|
|||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #append>
|
||||||
<div class="config-opers">
|
<div class="config-opers">
|
||||||
<v-icon @click="confirmCUD()" title="修改用户数据目录"> mdi-pencil</v-icon>
|
<v-icon title="修改用户数据目录" @click="confirmCUD()"> mdi-pencil</v-icon>
|
||||||
<v-icon @click="openDataPath('user')" title="打开用户数据目录"> mdi-folder-open</v-icon>
|
<v-icon title="打开用户数据目录" @click="openDataPath('user')"> mdi-folder-open</v-icon>
|
||||||
<v-icon @click="copyPath('user')" title="复制用户数据目录路径"> mdi-content-copy</v-icon>
|
<v-icon title="复制用户数据目录路径" @click="copyPath('user')"> mdi-content-copy</v-icon>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item title="应用数据库路径" :subtitle="dbPath">
|
<v-list-item :subtitle="dbPath" title="应用数据库路径">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<div class="config-icon">
|
<div class="config-icon">
|
||||||
<v-icon>mdi-folder-account</v-icon>
|
<v-icon>mdi-folder-account</v-icon>
|
||||||
@@ -24,12 +24,16 @@
|
|||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #append>
|
||||||
<div class="config-opers">
|
<div class="config-opers">
|
||||||
<v-icon @click="openDataPath('db')" title="打开数据库目录"> mdi-folder-open</v-icon>
|
<v-icon title="打开数据库目录" @click="openDataPath('db')"> mdi-folder-open</v-icon>
|
||||||
<v-icon @click="copyPath('db')" title="复制数据库目录路径"> mdi-content-copy</v-icon>
|
<v-icon title="复制数据库目录路径" @click="copyPath('db')"> mdi-content-copy</v-icon>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item title="游戏安装目录" :subtitle="gameDir" v-if="platform() === 'windows'">
|
<v-list-item
|
||||||
|
v-if="platform() === 'windows'"
|
||||||
|
:subtitle="gameDir"
|
||||||
|
:title="`游戏安装目录${gameVer ? `(v${gameVer})` : ''}`"
|
||||||
|
>
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<div class="config-icon">
|
<div class="config-icon">
|
||||||
<v-icon>mdi-gamepad</v-icon>
|
<v-icon>mdi-gamepad</v-icon>
|
||||||
@@ -37,13 +41,13 @@
|
|||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #append>
|
||||||
<div class="config-opers">
|
<div class="config-opers">
|
||||||
<v-icon @click="confirmCGD()" title="修改游戏安装目录"> mdi-pencil</v-icon>
|
<v-icon title="修改游戏安装目录" @click="confirmCGD()"> mdi-pencil</v-icon>
|
||||||
<v-icon @click="openDataPath('game')" title="打开游戏安装目录"> mdi-folder-open</v-icon>
|
<v-icon title="打开游戏安装目录" @click="openDataPath('game')"> mdi-folder-open</v-icon>
|
||||||
<v-icon @click="copyPath('game')" title="复制游戏安装目录"> mdi-content-copy</v-icon>
|
<v-icon title="复制游戏安装目录" @click="copyPath('game')"> mdi-content-copy</v-icon>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item title="日志目录" :subtitle="logDir">
|
<v-list-item :subtitle="logDir" title="日志目录">
|
||||||
<template #prepend>
|
<template #prepend>
|
||||||
<div class="config-icon">
|
<div class="config-icon">
|
||||||
<v-icon>mdi-folder-multiple</v-icon>
|
<v-icon>mdi-folder-multiple</v-icon>
|
||||||
@@ -51,9 +55,9 @@
|
|||||||
</template>
|
</template>
|
||||||
<template #append>
|
<template #append>
|
||||||
<div class="config-opers">
|
<div class="config-opers">
|
||||||
<v-icon @click="confirmCLD()" title="清理日志文件"> mdi-delete</v-icon>
|
<v-icon title="清理日志文件" @click="confirmCLD()"> mdi-delete</v-icon>
|
||||||
<v-icon @click="openDataPath('log')" title="打开日志目录"> mdi-folder-open</v-icon>
|
<v-icon title="打开日志目录" @click="openDataPath('log')"> mdi-folder-open</v-icon>
|
||||||
<v-icon @click="copyPath('log')" title="复制日志目录路径"> mdi-content-copy</v-icon>
|
<v-icon title="复制日志目录路径" @click="copyPath('log')"> mdi-content-copy</v-icon>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
@@ -72,10 +76,21 @@ import { exists, readDir, remove } from "@tauri-apps/plugin-fs";
|
|||||||
import { openPath } from "@tauri-apps/plugin-opener";
|
import { openPath } from "@tauri-apps/plugin-opener";
|
||||||
import { platform } from "@tauri-apps/plugin-os";
|
import { platform } from "@tauri-apps/plugin-os";
|
||||||
import { backUpUserData } from "@utils/dataBS.js";
|
import { backUpUserData } from "@utils/dataBS.js";
|
||||||
|
import { tryReadGameVer } from "@utils/TGGame.js";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { onMounted } from "vue";
|
import { onMounted, ref, watch } from "vue";
|
||||||
|
|
||||||
const { dbPath, logDir, userDir, gameDir } = storeToRefs(useAppStore());
|
const { dbPath, logDir, userDir, gameDir } = storeToRefs(useAppStore());
|
||||||
|
const gameVer = ref<string>();
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => gameDir.value,
|
||||||
|
async () => {
|
||||||
|
const gv = await tryReadGameVer(gameDir.value);
|
||||||
|
if (gv) gameVer.value = gv;
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const logDirGet = await path.appLogDir();
|
const logDirGet = await path.appLogDir();
|
||||||
|
|||||||
@@ -93,13 +93,11 @@ import TSUserAchi from "@Sqlm/userAchi.js";
|
|||||||
import useAppStore from "@store/app.js";
|
import useAppStore from "@store/app.js";
|
||||||
import useUserStore from "@store/user.js";
|
import useUserStore from "@store/user.js";
|
||||||
import { path } from "@tauri-apps/api";
|
import { path } from "@tauri-apps/api";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||||
import { open, save } from "@tauri-apps/plugin-dialog";
|
import { open, save } from "@tauri-apps/plugin-dialog";
|
||||||
import { exists, writeTextFile } from "@tauri-apps/plugin-fs";
|
import { writeTextFile } from "@tauri-apps/plugin-fs";
|
||||||
import { platform } from "@tauri-apps/plugin-os";
|
import { tryCallYae } from "@utils/TGGame.js";
|
||||||
import TGLogger from "@utils/TGLogger.js";
|
import TGLogger from "@utils/TGLogger.js";
|
||||||
import { isRunInAdmin } from "@utils/toolFunc.js";
|
|
||||||
import {
|
import {
|
||||||
getUiafHeader,
|
getUiafHeader,
|
||||||
readUiafData,
|
readUiafData,
|
||||||
@@ -315,50 +313,7 @@ async function deleteUid(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function toYae(): Promise<void> {
|
async function toYae(): Promise<void> {
|
||||||
if (platform() !== "windows") {
|
await tryCallYae(gameDir.value, uidCur.value.toString());
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
class="pbm-ne-btn"
|
class="pbm-ne-btn"
|
||||||
prepend-icon="mdi-import"
|
prepend-icon="mdi-import"
|
||||||
variant="elevated"
|
variant="elevated"
|
||||||
@click="tryCallYae()"
|
@click="tryImportMaterial()"
|
||||||
>
|
>
|
||||||
导入
|
导入
|
||||||
</v-btn>
|
</v-btn>
|
||||||
@@ -121,12 +121,7 @@ import PboMaterial from "@comp/pageBag/pbo-material.vue";
|
|||||||
import TSUserBagMaterial, { BAG_TYPE_LIST } from "@Sqlm/userBagMaterial.js";
|
import TSUserBagMaterial, { BAG_TYPE_LIST } from "@Sqlm/userBagMaterial.js";
|
||||||
import useAppStore from "@store/app.js";
|
import useAppStore from "@store/app.js";
|
||||||
import useUserStore from "@store/user.js";
|
import useUserStore from "@store/user.js";
|
||||||
import { path } from "@tauri-apps/api";
|
import { tryCallYae } from "@utils/TGGame.js";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import { exists } from "@tauri-apps/plugin-fs";
|
|
||||||
import { platform } from "@tauri-apps/plugin-os";
|
|
||||||
import TGLogger from "@utils/TGLogger.js";
|
|
||||||
import { isRunInAdmin } from "@utils/toolFunc.js";
|
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { nextTick, onMounted, ref, shallowRef, triggerRef, watch } from "vue";
|
import { nextTick, onMounted, ref, shallowRef, triggerRef, watch } from "vue";
|
||||||
|
|
||||||
@@ -342,54 +337,8 @@ function handleUpdate(info: MaterialInfo): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async function tryImportMaterial(): Promise<void> {
|
||||||
* 尝试导入材料(通过Yae)
|
await tryCallYae(gameDir.value, curUid.value.toString());
|
||||||
*/
|
|
||||||
async function tryCallYae(): Promise<void> {
|
|
||||||
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:", curUid.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.toString() });
|
|
||||||
} catch (err) {
|
|
||||||
showSnackbar.error(`调用Yae DLL失败: ${err}`);
|
|
||||||
await TGLogger.Error(`[pageAchi][toYae]调用Yae DLL失败: ${err}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,17 +16,17 @@
|
|||||||
<div class="btn-list">
|
<div class="btn-list">
|
||||||
<v-btn class="test-btn" @click="test()">测试</v-btn>
|
<v-btn class="test-btn" @click="test()">测试</v-btn>
|
||||||
</div>
|
</div>
|
||||||
<TcoHutaoVerify v-model="show" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import TcoHutaoVerify from "@comp/pageConfig/tco-hutaoVerify.vue";
|
import useAppStore from "@store/app.js";
|
||||||
import { ref } from "vue";
|
import { tryReadGameVer } from "@utils/TGGame.js";
|
||||||
|
import { storeToRefs } from "pinia";
|
||||||
|
|
||||||
const show = ref<boolean>(false);
|
const { gameDir } = storeToRefs(useAppStore());
|
||||||
|
|
||||||
async function test() {
|
async function test() {
|
||||||
show.value = true;
|
await tryReadGameVer(gameDir.value);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
|
|||||||
124
src/utils/TGGame.ts
Normal file
124
src/utils/TGGame.ts
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/**
|
||||||
|
* 游戏文件相关功能
|
||||||
|
* @since Beta v0.9.1
|
||||||
|
*/
|
||||||
|
|
||||||
|
import showDialog from "@comp/func/dialog.js";
|
||||||
|
import showSnackbar from "@comp/func/snackbar.js";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
import { sep } from "@tauri-apps/api/path";
|
||||||
|
import { exists, readTextFile, readTextFileLines } from "@tauri-apps/plugin-fs";
|
||||||
|
import { platform } from "@tauri-apps/plugin-os";
|
||||||
|
import TGLogger from "@utils/TGLogger.js";
|
||||||
|
|
||||||
|
// YAE支持的游戏版本
|
||||||
|
export const YAE_GAME_VER: Readonly<string> = "6.2.0";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 尝试获取游戏版本
|
||||||
|
* @since Beta v0.9.1
|
||||||
|
* @remarks
|
||||||
|
* 1. 读取 config.ini 下的 game_version
|
||||||
|
* 2. 没有 config.ini ,读取 YuanShen_Data\\Persistent\\ScriptVersion
|
||||||
|
* @param gameDir - 游戏目录
|
||||||
|
* @returns 版本或 false
|
||||||
|
*/
|
||||||
|
export async function tryReadGameVer(gameDir: string): Promise<false | string> {
|
||||||
|
if (platform() !== "windows") {
|
||||||
|
showSnackbar.warn("该功能仅支持Windows系统");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const iniPath = `${gameDir}${sep()}config.ini`;
|
||||||
|
if (await exists(iniPath)) {
|
||||||
|
const iniRead = await readTextFileLines(iniPath);
|
||||||
|
while (true) {
|
||||||
|
const line = await iniRead.next();
|
||||||
|
if (line.value.startsWith("game_version=")) return line.value.split("=")[1];
|
||||||
|
if (line.done) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const scriptPath = `${gameDir}${sep()}YuanShen_Data${sep()}Persistent${sep()}ScriptVersion`;
|
||||||
|
if (await exists(scriptPath)) {
|
||||||
|
return await readTextFile(scriptPath);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是管理员模式
|
||||||
|
* @since Beta v0.9.1
|
||||||
|
*/
|
||||||
|
export async function isRunInAdmin(): Promise<boolean> {
|
||||||
|
let isAdmin = false;
|
||||||
|
try {
|
||||||
|
isAdmin = await invoke<boolean>("is_in_admin");
|
||||||
|
} catch (err) {
|
||||||
|
showSnackbar.error(`检测管理员权限失败:${err}`);
|
||||||
|
await TGLogger.Error(`[TGGame][isRunInAdmin]检测管理员权限失败:${err}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 尝试调用Yae
|
||||||
|
* @since Beta v0.9.1
|
||||||
|
* @param gameDir - 游戏目录
|
||||||
|
* @param uid - 启动UID
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
|
export async function tryCallYae(gameDir: string, uid?: string): Promise<void> {
|
||||||
|
if (platform() !== "windows") {
|
||||||
|
showSnackbar.warn("该功能仅支持Windows系统");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (gameDir === "未设置") {
|
||||||
|
showSnackbar.warn("请前往设置页面设置游戏安装目录");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const gamePath = `${gameDir}${sep()}YuanShen.exe`;
|
||||||
|
if (!(await exists(gamePath))) {
|
||||||
|
showSnackbar.warn("未检测到游戏本体");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const gameVer = await tryReadGameVer(gameDir);
|
||||||
|
if (gameVer !== YAE_GAME_VER) {
|
||||||
|
const check = await showDialog.check(
|
||||||
|
"确认启动?",
|
||||||
|
`支持版本:${YAE_GAME_VER},检测版本:${gameVer === false ? "无数据" : gameVer}`,
|
||||||
|
);
|
||||||
|
showSnackbar.warn(`游戏版本不一致,支持版本为${YAE_GAME_VER}`);
|
||||||
|
if (!check) return;
|
||||||
|
}
|
||||||
|
const adminCheck = await isRunInAdmin();
|
||||||
|
if (!adminCheck) {
|
||||||
|
showSnackbar.warn("未检测到管理员权限");
|
||||||
|
const check = await showDialog.check("是否以管理员模式重启?", "该功能需要管理员权限才能使用");
|
||||||
|
if (!check) {
|
||||||
|
showSnackbar.cancel("已取消以管理员模式重启");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await invoke("run_with_admin");
|
||||||
|
} catch (err) {
|
||||||
|
showSnackbar.error(`以管理员模式重启失败:${err}`);
|
||||||
|
await TGLogger.Error(`[TGGame][tryCallYae]以管理员模式启动失败 - ${err}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const input = await showDialog.input("请输入存档UID", "UID:", uid);
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,14 +3,11 @@
|
|||||||
* @since Beta v0.9.1
|
* @since Beta v0.9.1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import showSnackbar from "@comp/func/snackbar.js";
|
|
||||||
import { tz } from "@date-fns/tz";
|
import { tz } from "@date-fns/tz";
|
||||||
import bbsEnum from "@enum/bbs.js";
|
import bbsEnum from "@enum/bbs.js";
|
||||||
import staticDataEnum from "@enum/staticData.js";
|
import staticDataEnum from "@enum/staticData.js";
|
||||||
import { path } from "@tauri-apps/api";
|
import { path } from "@tauri-apps/api";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import { type } from "@tauri-apps/plugin-os";
|
import { type } from "@tauri-apps/plugin-os";
|
||||||
import TGLogger from "@utils/TGLogger.js";
|
|
||||||
import { format, parse, parseISO } from "date-fns";
|
import { format, parse, parseISO } from "date-fns";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
|
||||||
@@ -341,22 +338,6 @@ export function getUserAvatar(
|
|||||||
return user.avatar_url;
|
return user.avatar_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否是管理员模式
|
|
||||||
* @since Beta v0.9.1
|
|
||||||
*/
|
|
||||||
export async function isRunInAdmin(): Promise<boolean> {
|
|
||||||
let isAdmin = false;
|
|
||||||
try {
|
|
||||||
isAdmin = await invoke<boolean>("is_in_admin");
|
|
||||||
} catch (err) {
|
|
||||||
showSnackbar.error(`检测管理员权限失败:${err}`);
|
|
||||||
await TGLogger.Error(`[pageAchi][toYae]检测管理员权限失败:${err}`);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return isAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 传入角色ID跟星级,返回渲染星级
|
* 传入角色ID跟星级,返回渲染星级
|
||||||
* @since Beta v0.9.1
|
* @since Beta v0.9.1
|
||||||
|
|||||||
Reference in New Issue
Block a user