[feat] solve common dir

todo: local cfg dir after resolving steam users
This commit is contained in:
Purp1e
2025-03-21 18:00:16 +08:00
parent 2e18fbdffd
commit e7a416dfec
10 changed files with 1170 additions and 754 deletions

View File

@@ -1,4 +1,8 @@
use std::process::Command;
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
// const DETACHED_PROCESS: u32 = 0x00000008;
pub fn kill(name: &str) -> String {
Command::new("taskkill")
@@ -36,10 +40,30 @@ pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
}
pub fn open_path(path: &str) -> Result<(), std::io::Error> {
let p = format!("file:///{}", path);
Command::new("explorer")
.args([p])
// path中所有/ 转换为 \
let path = path.replace("/", "\\");
Command::new("cmd.exe")
.args(["/c", "start", "", &path])
.creation_flags(CREATE_NO_WINDOW)
.spawn()
.expect("Failed to open path");
.unwrap();
Ok(())
}
mod tests {
use super::*;
#[test]
fn test_open_path() {
let path = "D:\\Programs\\Steam";
println!("test open path: {}", path);
open_path(path).unwrap();
let path = "D:\\Programs\\Steam\\steamapps\\common\\Counter-Strike Global Offensive\\game\\bin\\win64";
println!("test open path: {}", path);
open_path(path).unwrap();
let path = "%appdata%/Wmpvp/demo";
println!("test open path: {}", path);
open_path(path).unwrap()
}
}