[feat] solve common dir
todo: local cfg dir after resolving steam users
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user