♻️ 调整dll移动方式

#206
This commit is contained in:
BTMuli
2026-01-18 00:00:18 +08:00
parent 6db1ab0a45
commit b136a93464
5 changed files with 41 additions and 15 deletions

View File

@@ -46,6 +46,7 @@
{ "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-copy-file", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-write-file", "allow": [{ "path": "**" }] },
{ "identifier": "fs:allow-write-text-file", "allow": [{ "path": "**" }] },
{ "identifier": "opener:allow-open-path", "allow": [{ "path": "**" }] },

View File

@@ -74,14 +74,7 @@ pub fn call_yae_dll(
uid: String,
ticket: Option<String>,
) -> Result<(), String> {
let dll_local_path =
app_handle.path().resource_dir().unwrap().join("resources/YaeAchievementLib.dll");
let dll_path = app_handle.path().app_config_dir().unwrap().join("YaeAchievementLib.dll");
// -1. 移动 dll 到应用目录以解决权限问题
match fs::copy(&dll_local_path, &dll_path) {
Ok(_) => println!("✅ DLL 已成功复制到 {:?}", dll_path),
Err(e) => eprintln!("❌ 复制 DLL 失败: {:?}", e),
}
dbg!(&dll_path);
// 0. 创建 YaeAchievementPipe 的 命名管道,获取句柄
dbg!("开始启动 YaeAchievementPipe 命名管道");

View File

@@ -320,7 +320,7 @@ 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 { isRunInAdmin, tryCopyYae, tryReadGameVer, YAE_GAME_VER } from "@utils/TGGame.js";
import TGLogger from "@utils/TGLogger.js";
import { storeToRefs } from "pinia";
import { computed, onMounted, onUnmounted, ref, shallowRef } from "vue";
@@ -740,6 +740,8 @@ async function tryLaunchGame(): Promise<void> {
}
return;
}
const tryCopy = await tryCopyYae();
if (!tryCopy) return;
try {
await invoke("call_yae_dll", {
gamePath: gamePath,

View File

@@ -19,12 +19,16 @@
</div>
</template>
<script lang="ts" setup>
import showLoading from "@comp/func/loading.js";
import { appConfigDir, resourceDir } from "@tauri-apps/api/path";
import { copyFile, exists } from "@tauri-apps/plugin-fs";
async function test() {
await showLoading.start("测试");
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
await showLoading.end();
const filePath = `${await resourceDir()}\\resources\\YaeAchievementLib.dll`;
console.log(filePath);
const check = await exists(filePath);
console.log(check);
const targetPath = `${await appConfigDir()}\\YaeAchievementLib.dll`;
await copyFile(filePath, targetPath);
}
</script>
<style lang="css" scoped>

View File

@@ -1,13 +1,13 @@
/**
* 游戏文件相关功能
* @since Beta v0.9.1
* @since Beta v0.9.2
*/
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 { appConfigDir, resourceDir, sep } from "@tauri-apps/api/path";
import { copyFile, exists, readTextFile, readTextFileLines } from "@tauri-apps/plugin-fs";
import { platform } from "@tauri-apps/plugin-os";
import TGLogger from "@utils/TGLogger.js";
@@ -60,6 +60,30 @@ export async function isRunInAdmin(): Promise<boolean> {
return isAdmin;
}
/**
* 尝试移动dll
* @since Beta v0.9.2
* @returns 无返回值
*/
export async function tryCopyYae(): Promise<boolean> {
const srcDllPath = `${await resourceDir()}${sep()}resources${sep()}YaeAchievementLib.dll`;
console.log(srcDllPath);
const srcCheck = await exists(srcDllPath);
if (!srcCheck) {
showSnackbar.warn("未检测到本地 dll");
return false;
}
const targetPath = `${await appConfigDir()}${sep()}YaeAchievementLib.dll`;
console.log(targetPath);
await copyFile(srcDllPath, targetPath);
const check2 = await exists(targetPath);
if (!check2) {
showSnackbar.warn("移动 dll 失败");
return false;
}
return true;
}
/**
* 尝试调用Yae
* @since Beta v0.9.2
@@ -106,6 +130,8 @@ export async function tryCallYae(gameDir: string, uid?: string): Promise<void> {
}
return;
}
const tryCopy = await tryCopyYae();
if (!tryCopy) return;
const input = await showDialog.input("请输入存档UID", "UID:", uid);
if (!input) {
showSnackbar.cancel("已取消存档导入");