♻️ msix环境下将dll移动到文档目录

#206
This commit is contained in:
BTMuli
2026-01-18 17:28:44 +08:00
parent 1bd2fa34d3
commit c1ce2def26
7 changed files with 56 additions and 14 deletions

View File

@@ -48,6 +48,7 @@ features = [
"Win32_System_Memory",
"Win32_System_Pipes",
"Win32_System_Threading",
"Win32_Storage_Packaging_Appx",
"Win32_System_WindowsProgramming",
]

View File

@@ -186,3 +186,35 @@ pub fn launch_game(path: String, ticket: String) -> Result<(), String> {
Err("This command is only supported on Windows".into())
}
}
#[tauri::command]
pub fn is_msix() -> bool {
#[cfg(not(windows))]
{
false
}
#[cfg(windows)]
{
use std::ptr;
use widestring::U16CStr;
use windows_sys::Win32::Foundation::ERROR_INSUFFICIENT_BUFFER;
use windows_sys::Win32::Storage::Packaging::Appx::GetCurrentPackageFullName;
unsafe {
let mut length: u32 = 0;
let result = GetCurrentPackageFullName(&mut length, ptr::null_mut());
if result != ERROR_INSUFFICIENT_BUFFER {
println!("Not running in MSIX package. Error code: {}", result);
return false;
}
let mut buffer = vec![0u16; length as usize];
let result = GetCurrentPackageFullName(&mut length, buffer.as_mut_ptr());
if result != 0 {
println!("Failed to retrieve package full name. Error code: {}", result);
return false;
}
let pkg_name = U16CStr::from_ptr_str(buffer.as_ptr());
println!("MSIX Package Full Name: {}", pkg_name.to_string_lossy());
true
}
}
}

View File

@@ -13,8 +13,8 @@ mod yae;
use crate::client::create_mhy_client;
use crate::commands::{
create_window, execute_js, get_dir_size, hide_main_window, init_app, is_in_admin, launch_game,
quit_app, read_text_scale,
create_window, execute_js, get_dir_size, hide_main_window, init_app, is_in_admin, is_msix,
launch_game, quit_app, read_text_scale,
};
use tauri::{Emitter, Manager, Window, WindowEvent, generate_context, generate_handler};
@@ -109,6 +109,7 @@ pub fn run() {
quit_app,
read_text_scale,
launch_game,
is_msix,
#[cfg(target_os = "windows")]
yae::call_yae_dll,
#[cfg(target_os = "windows")]

View File

@@ -1,5 +1,5 @@
//! Yae 相关处理
//! @since Beta v0.9.1
//! @since Beta v0.9.2
#![cfg(target_os = "windows")]
pub mod inject;
@@ -11,7 +11,7 @@ use pt_ac::parse_achi_list;
use pt_store::parse_store_list;
use serde_json::Value;
use std::collections::HashMap;
use std::fs::{self, File};
use std::fs::File;
use std::io::{self, Read, Write};
use std::os::windows::io::{FromRawHandle, RawHandle};
use std::sync::Arc;
@@ -73,8 +73,12 @@ pub fn call_yae_dll(
game_path: String,
uid: String,
ticket: Option<String>,
is_msix: bool,
) -> Result<(), String> {
let dll_path = app_handle.path().app_config_dir().unwrap().join("YaeAchievementLib.dll");
let mut dll_path = app_handle.path().app_config_dir().unwrap().join("YaeAchievementLib.dll");
if (is_msix) {
dll_path = app_handle.path().document_dir().unwrap().join("TeyvatGuide\\YaeAchievementLib.dll");
}
dbg!(&dll_path);
// 0. 创建 YaeAchievementPipe 的 命名管道,获取句柄
dbg!("开始启动 YaeAchievementPipe 命名管道");

View File

@@ -740,13 +740,17 @@ async function tryLaunchGame(): Promise<void> {
}
return;
}
const tryCopy = await tryCopyYae();
if (!tryCopy) return;
const isMsix = await invoke<boolean>("is_msix");
if (isMsix) {
const copy = await tryCopyYae();
if (!copy) return;
}
try {
await invoke("call_yae_dll", {
gamePath: gamePath,
uid: account.value.gameUid,
ticket: resp,
is_msix: isMsix,
});
} catch (err) {
showSnackbar.error(`调用Yae DLL失败: ${err}`);

View File

@@ -19,10 +19,12 @@
</div>
</template>
<script lang="ts" setup>
import { invoke } from "@tauri-apps/api/core";
import { appConfigDir, resourceDir } from "@tauri-apps/api/path";
import { copyFile, exists } from "@tauri-apps/plugin-fs";
async function test() {
await invoke("is_msix");
const filePath = `${await resourceDir()}\\resources\\YaeAchievementLib.dll`;
console.log(filePath);
const check = await exists(filePath);

View File

@@ -6,7 +6,7 @@
import showDialog from "@comp/func/dialog.js";
import showSnackbar from "@comp/func/snackbar.js";
import { invoke } from "@tauri-apps/api/core";
import { appConfigDir, resourceDir, sep } from "@tauri-apps/api/path";
import { documentDir, 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";
@@ -67,19 +67,17 @@ export async function isRunInAdmin(): Promise<boolean> {
*/
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`;
const targetPath = `${await documentDir()}${sep()}TeyvatGuide${sep()}YaeAchievementLib.dll`;
console.log(targetPath);
await copyFile(srcDllPath, targetPath);
const check2 = await exists(targetPath);
if (!check2) {
showSnackbar.warn("移动 dll 失败,请手动移动");
// TODO: 跳转手动移动说明站点
return false;
}
return true;
@@ -131,8 +129,8 @@ export async function tryCallYae(gameDir: string, uid?: string): Promise<void> {
}
return;
}
const tryCopy = await tryCopyYae();
if (!tryCopy) return;
const isMsix = await invoke<boolean>("is_msix");
if (isMsix) await tryCopyYae();
const input = await showDialog.input("请输入存档UID", "UID:", uid);
if (!input) {
showSnackbar.cancel("已取消存档导入");
@@ -143,7 +141,7 @@ export async function tryCallYae(gameDir: string, uid?: string): Promise<void> {
return;
}
try {
await invoke("call_yae_dll", { gamePath: gamePath, uid: input });
await invoke("call_yae_dll", { gamePath: gamePath, uid: input, is_msix: isMsix });
} catch (err) {
showSnackbar.error(`调用Yae DLL失败: ${err}`);
}