a few clippy fixes
This commit is contained in:
@@ -51,15 +51,11 @@ unsafe extern "system" {
|
||||
|
||||
fn get_gta_pid(system_info: &mut SystemInfo) -> Option<u32> {
|
||||
system_info.refresh();
|
||||
if let Some(p) = system_info
|
||||
system_info
|
||||
.processes()
|
||||
.iter()
|
||||
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||
{
|
||||
return Some(p.pid());
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
.map(|p| p.pid())
|
||||
}
|
||||
|
||||
pub fn activate(game_handle: &mut HANDLE, system_info: &mut SystemInfo) -> Result<(), ()> {
|
||||
|
||||
@@ -61,7 +61,7 @@ fn activate(system_info: &mut SystemInfo) {
|
||||
.iter()
|
||||
.filter(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||
.for_each(|p| {
|
||||
if p.kill() == false {
|
||||
if !p.kill() {
|
||||
log::log(
|
||||
log::LogLevel::Error,
|
||||
"failed to force close game, probably due to access denied",
|
||||
|
||||
@@ -137,13 +137,9 @@ impl GameNetworking {
|
||||
|
||||
fn get_game_exe_path(system_info: &mut SystemInfo) -> Option<&Path> {
|
||||
system_info.refresh();
|
||||
if let Some(process) = system_info
|
||||
system_info
|
||||
.processes()
|
||||
.iter()
|
||||
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||
{
|
||||
process.exe()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.and_then(|p| p.exe())
|
||||
}
|
||||
|
||||
+5
-6
@@ -117,16 +117,15 @@ impl App {
|
||||
ui.header("Session");
|
||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Empty current session").clicked() {
|
||||
if features::empty_session::activate(
|
||||
if ui.button("Empty current session").clicked()
|
||||
&& features::empty_session::activate(
|
||||
&mut self.game_handle,
|
||||
&mut self.system_info,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
self.empty_session.interval = Instant::now();
|
||||
self.empty_session.disabled = true;
|
||||
}
|
||||
{
|
||||
self.empty_session.interval = Instant::now();
|
||||
self.empty_session.disabled = true;
|
||||
}
|
||||
ui.label(&self.empty_session.countdown.i_string);
|
||||
});
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ use crate::util::consts::path;
|
||||
use std::{fs::File, io::Write};
|
||||
use strum::Display;
|
||||
|
||||
#[derive(Display)]
|
||||
#[derive(Clone, Copy, Display)]
|
||||
pub enum LogLevel {
|
||||
Error,
|
||||
Panic,
|
||||
|
||||
+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 {
|
||||
|
||||
+3
-3
@@ -26,7 +26,7 @@ pub fn is_cursor_visible() -> bool {
|
||||
..Default::default()
|
||||
};
|
||||
unsafe {
|
||||
GetCursorInfo(&mut ci).unwrap();
|
||||
GetCursorInfo(&raw mut ci).unwrap();
|
||||
}
|
||||
ci.flags == CURSOR_SHOWING
|
||||
}
|
||||
@@ -67,7 +67,7 @@ pub fn elevate(closing: ElevationExitMethod) {
|
||||
pub fn is_elevated() -> bool {
|
||||
let mut token: HANDLE = HANDLE::default();
|
||||
unsafe {
|
||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_err() {
|
||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &raw mut token).is_err() {
|
||||
return false;
|
||||
}
|
||||
let mut elevation = TOKEN_ELEVATION::default();
|
||||
@@ -77,7 +77,7 @@ pub fn is_elevated() -> bool {
|
||||
TokenElevation,
|
||||
Some((&raw mut elevation).cast()),
|
||||
size,
|
||||
&mut size,
|
||||
&raw mut size,
|
||||
);
|
||||
CloseHandle(token).unwrap();
|
||||
result.is_ok() && elevation.TokenIsElevated != 0
|
||||
|
||||
Reference in New Issue
Block a user