refactor: replace winapi w/ windows (#6291)

This commit is contained in:
Sline 2026-02-10 14:06:27 +08:00 committed by GitHub
parent 277ded4c44
commit 4d72d2d0df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 40 deletions

2
Cargo.lock generated
View File

@ -1176,7 +1176,7 @@ dependencies = [
"tokio",
"tokio-stream",
"warp",
"winapi",
"windows 0.62.2",
"winreg 0.55.0",
"zip 7.4.0",
]

View File

@ -110,21 +110,7 @@ dark-light = { git = "https://github.com/rust-dark-light/dark-light" }
deelevate = { workspace = true }
runas = "=1.2.0"
winreg = "0.55.0"
winapi = { version = "0.3.9", features = [
"winbase",
"fileapi",
"winnt",
"handleapi",
"errhandlingapi",
"minwindef",
"winerror",
"stringapiset",
"tlhelp32",
"processthreadsapi",
"winhttp",
"winreg",
"winnls",
] }
windows = { version = "0.62.2", features = ["Win32_Globalization"] }
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-autostart = "2.5.1"

View File

@ -5,8 +5,7 @@ use std::fs;
use std::os::windows::process::CommandExt as _;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use winapi::um::stringapiset::MultiByteToWideChar;
use winapi::um::winnls::{GetACP, GetOEMCP};
use windows::Win32::Globalization::{GetACP, GetOEMCP, MULTI_BYTE_TO_WIDE_CHAR_FLAGS, MultiByteToWideChar};
const CREATE_NO_WINDOW: u32 = 0x08000000;
const TASK_NAME_USER: &str = "Clash Verge";
@ -207,34 +206,16 @@ fn decode_with_code_page(bytes: &[u8], code_page: u32) -> Option<String> {
return None;
}
let required = unsafe {
MultiByteToWideChar(
code_page,
0,
bytes.as_ptr() as *const i8,
len as i32,
std::ptr::null_mut(),
0,
)
};
let required = unsafe { MultiByteToWideChar(code_page, MULTI_BYTE_TO_WIDE_CHAR_FLAGS(0), bytes, None) };
if required == 0 {
if required <= 0 {
return None;
}
let mut wide = vec![0u16; required as usize];
let written = unsafe {
MultiByteToWideChar(
code_page,
0,
bytes.as_ptr() as *const i8,
len as i32,
wide.as_mut_ptr(),
required,
)
};
let written = unsafe { MultiByteToWideChar(code_page, MULTI_BYTE_TO_WIDE_CHAR_FLAGS(0), bytes, Some(&mut wide)) };
if written == 0 {
if written <= 0 {
return None;
}