a few clippy fixes
This commit is contained in:
+14
-13
@@ -40,7 +40,7 @@ impl Process {
|
||||
pub fn kill(&self) -> bool {
|
||||
let mut taskkill = Command::new("taskkill.exe");
|
||||
taskkill.creation_flags(CREATE_NO_WINDOW.0);
|
||||
taskkill.arg("/F").arg("/PID").arg(&self.pid.to_string());
|
||||
taskkill.arg("/F").arg("/PID").arg(self.pid.to_string());
|
||||
match taskkill.output() {
|
||||
Ok(output) => output.status.success(),
|
||||
Err(_) => false,
|
||||
@@ -57,17 +57,19 @@ impl SystemInfo {
|
||||
pub fn refresh(&mut self) {
|
||||
let mut processes = Vec::new();
|
||||
let snapshot_handle = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0).unwrap() };
|
||||
let mut process_entry = PROCESSENTRY32::default();
|
||||
process_entry.dwSize = size_of::<PROCESSENTRY32>() as u32;
|
||||
unsafe { Process32First(snapshot_handle, &mut process_entry).unwrap() };
|
||||
let exe_full_path = get_exe_full_path(process_entry);
|
||||
let mut process_entry = PROCESSENTRY32 {
|
||||
dwSize: size_of::<PROCESSENTRY32>() as u32,
|
||||
..Default::default()
|
||||
};
|
||||
unsafe { Process32First(snapshot_handle, &raw mut process_entry).unwrap() };
|
||||
let exe_full_path = get_exe_full_path(&process_entry);
|
||||
processes.push(Process {
|
||||
pid: process_entry.th32ProcessID,
|
||||
name: c_char_arr_to_string(&process_entry.szExeFile),
|
||||
exe: exe_full_path,
|
||||
});
|
||||
while unsafe { Process32Next(snapshot_handle, &mut process_entry) }.is_ok() {
|
||||
let exe_full_path = get_exe_full_path(process_entry);
|
||||
while unsafe { Process32Next(snapshot_handle, &raw mut process_entry) }.is_ok() {
|
||||
let exe_full_path = get_exe_full_path(&process_entry);
|
||||
processes.push(Process {
|
||||
pid: process_entry.th32ProcessID,
|
||||
name: c_char_arr_to_string(&process_entry.szExeFile),
|
||||
@@ -82,7 +84,7 @@ impl SystemInfo {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_exe_full_path(process_entry: PROCESSENTRY32) -> Option<PathBuf> {
|
||||
fn get_exe_full_path(process_entry: &PROCESSENTRY32) -> Option<PathBuf> {
|
||||
let process_handle_result = unsafe {
|
||||
OpenProcess(
|
||||
PROCESS_QUERY_LIMITED_INFORMATION,
|
||||
@@ -92,23 +94,22 @@ fn get_exe_full_path(process_entry: PROCESSENTRY32) -> Option<PathBuf> {
|
||||
};
|
||||
let mut exename = [0u16; 260];
|
||||
let mut dwsize = exename.len() as u32;
|
||||
let exe_full_path = process_handle_result.map_or(None, |process_handle| {
|
||||
process_handle_result.map_or(None, |process_handle| {
|
||||
let image_name_result = unsafe {
|
||||
QueryFullProcessImageNameW(
|
||||
process_handle,
|
||||
PROCESS_NAME_WIN32,
|
||||
PWSTR(exename.as_mut_ptr()),
|
||||
&mut dwsize,
|
||||
&raw mut dwsize,
|
||||
)
|
||||
};
|
||||
match image_name_result {
|
||||
Ok(_) => Some(PathBuf::from(
|
||||
Ok(()) => Some(PathBuf::from(
|
||||
unsafe { PWSTR(exename.as_mut_ptr()).to_string() }.unwrap(),
|
||||
)),
|
||||
Err(_) => None,
|
||||
}
|
||||
});
|
||||
exe_full_path
|
||||
})
|
||||
}
|
||||
|
||||
fn c_char_arr_to_string(arr: &[i8]) -> String {
|
||||
|
||||
Reference in New Issue
Block a user