mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
✨ 检测本体是否启动
This commit is contained in:
@@ -218,3 +218,52 @@ pub fn is_msix() -> bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn is_process_running(process_name: String) -> bool {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
false
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use windows_sys::Win32::Foundation::{CloseHandle, HANDLE, INVALID_HANDLE_VALUE};
|
||||
use windows_sys::Win32::System::Diagnostics::ToolHelp::{
|
||||
CreateToolhelp32Snapshot, PROCESSENTRY32W, Process32FirstW, Process32NextW,
|
||||
TH32CS_SNAPPROCESS,
|
||||
};
|
||||
unsafe {
|
||||
// 创建进程快照
|
||||
let snapshot: HANDLE = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if snapshot == INVALID_HANDLE_VALUE {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut entry: PROCESSENTRY32W = std::mem::zeroed();
|
||||
entry.dwSize = std::mem::size_of::<PROCESSENTRY32W>() as u32;
|
||||
|
||||
// 遍历进程列表
|
||||
if Process32FirstW(snapshot, &mut entry) != 0 {
|
||||
loop {
|
||||
// 将 exe 文件名转为 Rust String
|
||||
let exe_name = {
|
||||
let len = entry.szExeFile.iter().position(|&c| c == 0).unwrap_or(entry.szExeFile.len());
|
||||
String::from_utf16_lossy(&entry.szExeFile[..len])
|
||||
};
|
||||
|
||||
if exe_name.eq_ignore_ascii_case(&process_name) {
|
||||
CloseHandle(snapshot);
|
||||
return true;
|
||||
}
|
||||
|
||||
if Process32NextW(snapshot, &mut entry) == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(snapshot);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ 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, is_msix,
|
||||
launch_game, quit_app, read_text_scale,
|
||||
is_process_running, launch_game, quit_app, read_text_scale,
|
||||
};
|
||||
use tauri::{Emitter, Manager, Window, WindowEvent, generate_context, generate_handler};
|
||||
|
||||
@@ -110,6 +110,7 @@ pub fn run() {
|
||||
read_text_scale,
|
||||
launch_game,
|
||||
is_msix,
|
||||
is_process_running,
|
||||
#[cfg(target_os = "windows")]
|
||||
yae::call_yae_dll,
|
||||
#[cfg(target_os = "windows")]
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
<script lang="ts" setup>
|
||||
import VpReplyDebug from "@comp/viewPost/vp-reply-debug.vue";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { appConfigDir, resourceDir } from "@tauri-apps/api/path";
|
||||
import { copyFile, exists } from "@tauri-apps/plugin-fs";
|
||||
import { ref } from "vue";
|
||||
|
||||
const showReply = ref<boolean>(false);
|
||||
@@ -34,13 +32,8 @@ function testReply(): void {
|
||||
}
|
||||
|
||||
async function test() {
|
||||
await invoke("is_msix");
|
||||
const filePath = `${await resourceDir()}\\resources\\YaeAchievementLib.dll`;
|
||||
console.log(filePath);
|
||||
const check = await exists(filePath);
|
||||
const check = await invoke("is_process_running", { processName: "Yuanshen.exe" });
|
||||
console.log(check);
|
||||
const targetPath = `${await appConfigDir()}\\YaeAchievementLib.dll`;
|
||||
await copyFile(filePath, targetPath);
|
||||
}
|
||||
</script>
|
||||
<style lang="css" scoped>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 游戏文件相关功能
|
||||
* @since Beta v0.9.4
|
||||
* @since Beta v0.9.6
|
||||
*/
|
||||
|
||||
import showDialog from "@comp/func/dialog.js";
|
||||
@@ -83,7 +83,7 @@ export async function tryCopyYae(): Promise<boolean> {
|
||||
|
||||
/**
|
||||
* 尝试调用Yae
|
||||
* @since Beta v0.9.2
|
||||
* @since Beta v0.9.6
|
||||
* @param gameDir - 游戏目录
|
||||
* @param uid - 启动UID
|
||||
* @returns void
|
||||
@@ -102,6 +102,11 @@ export async function tryCallYae(gameDir: string, uid?: string): Promise<void> {
|
||||
showSnackbar.warn("未检测到游戏本体");
|
||||
return;
|
||||
}
|
||||
const isRun = await invoke<boolean>("is_process_running", { processName: "Yuanshen.exe" });
|
||||
if (isRun) {
|
||||
showSnackbar.warn("检测到已启动的原神进程,请关闭进程(Yuanshen.exe)后重试");
|
||||
return;
|
||||
}
|
||||
const gameVer = await tryReadGameVer(gameDir);
|
||||
if (gameVer !== YAE_GAME_VER) {
|
||||
const check = await showDialog.check(
|
||||
|
||||
Reference in New Issue
Block a user