diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index e4ce4793..469a1b78 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -48,6 +48,7 @@ features = [ "Win32_System_Memory", "Win32_System_Pipes", "Win32_System_Threading", + "Win32_Storage_Packaging_Appx", "Win32_System_WindowsProgramming", ] diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 3352ff71..64ad9398 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -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 + } + } +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 50fe7b23..a4c76f5b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -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")] diff --git a/src-tauri/src/yae/mod.rs b/src-tauri/src/yae/mod.rs index c4156a2c..2c1b4122 100644 --- a/src-tauri/src/yae/mod.rs +++ b/src-tauri/src/yae/mod.rs @@ -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, + 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 命名管道"); diff --git a/src/components/app/t-sidebar.vue b/src/components/app/t-sidebar.vue index db548af8..44a7da50 100644 --- a/src/components/app/t-sidebar.vue +++ b/src/components/app/t-sidebar.vue @@ -740,13 +740,17 @@ async function tryLaunchGame(): Promise { } return; } - const tryCopy = await tryCopyYae(); - if (!tryCopy) return; + const isMsix = await invoke("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}`); diff --git a/src/pages/common/PageTest.vue b/src/pages/common/PageTest.vue index 9adbdb8c..d65f9d2b 100644 --- a/src/pages/common/PageTest.vue +++ b/src/pages/common/PageTest.vue @@ -19,10 +19,12 @@