mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-15 03:53:16 +08:00
✨ 完成成就导入
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
//! @file src/commands.rs
|
||||
//! @desc 命令模块,负责处理命令
|
||||
//! @since Beta v0.7.4
|
||||
//! 命令模块,负责处理命令
|
||||
//! @since Beta v0.7.8
|
||||
|
||||
use tauri::{AppHandle, Emitter, Manager, WebviewWindowBuilder};
|
||||
use tauri_utils::config::{WebviewUrl, WindowConfig};
|
||||
@@ -72,9 +71,13 @@ pub async fn get_dir_size(path: String) -> u64 {
|
||||
}
|
||||
|
||||
// 判断是否是管理员权限
|
||||
#[cfg(target_os = "windows")]
|
||||
#[tauri::command]
|
||||
pub fn is_in_admin() -> bool {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
Err("This function is only supported on Windows.".into())
|
||||
}
|
||||
|
||||
use windows_sys::Win32::Foundation::HANDLE;
|
||||
use windows_sys::Win32::Security::{
|
||||
AllocateAndInitializeSid, CheckTokenMembership, FreeSid, SID_IDENTIFIER_AUTHORITY, TOKEN_QUERY,
|
||||
@@ -113,10 +116,14 @@ pub fn is_in_admin() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
// 在 Windows 上以管理员权限重启应用
|
||||
#[cfg(target_os = "windows")]
|
||||
// 以管理员权限重启应用
|
||||
#[tauri::command]
|
||||
pub fn run_with_admin() -> Result<(), String> {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
Err("This function is only supported on Windows.".into())
|
||||
}
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::iter::once;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
|
||||
@@ -104,6 +104,10 @@ fn read_exact_vec<R: Read>(r: &mut R, len: usize) -> io::Result<Vec<u8>> {
|
||||
/// 调用 dll
|
||||
#[tauri::command]
|
||||
pub fn call_yae_dll(app_handle: AppHandle, game_path: String) -> () {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
Err("This function is only supported on Windows.".into())
|
||||
}
|
||||
let dll_path = app_handle.path().resource_dir().unwrap().join("resources/YaeAchievementLib.dll");
|
||||
dbg!(&dll_path);
|
||||
// 0. 创建 YaeAchievementPipe 的 命名管道,获取句柄
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
//! Yae 成就信息的 Protobuf 定义
|
||||
//! @since Beta v0.9.0
|
||||
//! @since Beta v0.8.7
|
||||
|
||||
use prost::encoding::{decode_key, WireType};
|
||||
use prost::DecodeError;
|
||||
use prost::Message;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Cursor;
|
||||
use std::io::Read;
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
#[derive(Clone, PartialEq, Message, Serialize)]
|
||||
pub struct AchievementProtoFieldInfo {
|
||||
@@ -106,15 +105,14 @@ pub struct AchievementInfo {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Serialize)]
|
||||
pub struct AchiItemRes {
|
||||
pub struct UiafAchiItem {
|
||||
pub id: u32,
|
||||
pub total: u32,
|
||||
pub cur: u32,
|
||||
pub ts: u32,
|
||||
pub stat: u32,
|
||||
pub current: u32,
|
||||
pub timestamp: u32,
|
||||
pub status: u32,
|
||||
}
|
||||
|
||||
pub fn parse_achi_list(bytes: &[u8]) -> Result<Vec<AchiItemRes>, DecodeError> {
|
||||
pub fn parse_achi_list(bytes: &[u8]) -> Result<Vec<UiafAchiItem>, DecodeError> {
|
||||
let mut cursor = Cursor::new(bytes);
|
||||
let mut dicts: Vec<HashMap<u32, u32>> = Vec::new();
|
||||
|
||||
@@ -146,13 +144,13 @@ pub fn parse_achi_list(bytes: &[u8]) -> Result<Vec<AchiItemRes>, DecodeError> {
|
||||
|
||||
let achievements = dicts
|
||||
.into_iter()
|
||||
.map(|d| AchiItemRes {
|
||||
.map(|d| UiafAchiItem {
|
||||
id: d.get(&15).copied().unwrap_or(0),
|
||||
stat: d.get(&11).copied().unwrap_or(0),
|
||||
total: d.get(&8).copied().unwrap_or(0),
|
||||
cur: d.get(&13).copied().unwrap_or(0),
|
||||
ts: d.get(&7).copied().unwrap_or(0),
|
||||
status: d.get(&11).copied().unwrap_or(0),
|
||||
current: d.get(&13).copied().unwrap_or(0),
|
||||
timestamp: d.get(&7).copied().unwrap_or(0),
|
||||
})
|
||||
.filter(|a| a.timestamp != 0)
|
||||
.collect();
|
||||
|
||||
Ok(achievements)
|
||||
|
||||
Reference in New Issue
Block a user