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> {
|
fn get_gta_pid(system_info: &mut SystemInfo) -> Option<u32> {
|
||||||
system_info.refresh();
|
system_info.refresh();
|
||||||
if let Some(p) = system_info
|
system_info
|
||||||
.processes()
|
.processes()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
{
|
.map(|p| p.pid())
|
||||||
return Some(p.pid());
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate(game_handle: &mut HANDLE, system_info: &mut SystemInfo) -> Result<(), ()> {
|
pub fn activate(game_handle: &mut HANDLE, system_info: &mut SystemInfo) -> Result<(), ()> {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ fn activate(system_info: &mut SystemInfo) {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
.filter(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
.for_each(|p| {
|
.for_each(|p| {
|
||||||
if p.kill() == false {
|
if !p.kill() {
|
||||||
log::log(
|
log::log(
|
||||||
log::LogLevel::Error,
|
log::LogLevel::Error,
|
||||||
"failed to force close game, probably due to access denied",
|
"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> {
|
fn get_game_exe_path(system_info: &mut SystemInfo) -> Option<&Path> {
|
||||||
system_info.refresh();
|
system_info.refresh();
|
||||||
if let Some(process) = system_info
|
system_info
|
||||||
.processes()
|
.processes()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
{
|
.and_then(|p| p.exe())
|
||||||
process.exe()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-6
@@ -117,16 +117,15 @@ impl App {
|
|||||||
ui.header("Session");
|
ui.header("Session");
|
||||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui.button("Empty current session").clicked() {
|
if ui.button("Empty current session").clicked()
|
||||||
if features::empty_session::activate(
|
&& features::empty_session::activate(
|
||||||
&mut self.game_handle,
|
&mut self.game_handle,
|
||||||
&mut self.system_info,
|
&mut self.system_info,
|
||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
self.empty_session.interval = Instant::now();
|
self.empty_session.interval = Instant::now();
|
||||||
self.empty_session.disabled = true;
|
self.empty_session.disabled = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ui.label(&self.empty_session.countdown.i_string);
|
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 std::{fs::File, io::Write};
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
|
|
||||||
#[derive(Display)]
|
#[derive(Clone, Copy, Display)]
|
||||||
pub enum LogLevel {
|
pub enum LogLevel {
|
||||||
Error,
|
Error,
|
||||||
Panic,
|
Panic,
|
||||||
|
|||||||
+14
-13
@@ -40,7 +40,7 @@ impl Process {
|
|||||||
pub fn kill(&self) -> bool {
|
pub fn kill(&self) -> bool {
|
||||||
let mut taskkill = Command::new("taskkill.exe");
|
let mut taskkill = Command::new("taskkill.exe");
|
||||||
taskkill.creation_flags(CREATE_NO_WINDOW.0);
|
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() {
|
match taskkill.output() {
|
||||||
Ok(output) => output.status.success(),
|
Ok(output) => output.status.success(),
|
||||||
Err(_) => false,
|
Err(_) => false,
|
||||||
@@ -57,17 +57,19 @@ impl SystemInfo {
|
|||||||
pub fn refresh(&mut self) {
|
pub fn refresh(&mut self) {
|
||||||
let mut processes = Vec::new();
|
let mut processes = Vec::new();
|
||||||
let snapshot_handle = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0).unwrap() };
|
let snapshot_handle = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0).unwrap() };
|
||||||
let mut process_entry = PROCESSENTRY32::default();
|
let mut process_entry = PROCESSENTRY32 {
|
||||||
process_entry.dwSize = size_of::<PROCESSENTRY32>() as u32;
|
dwSize: size_of::<PROCESSENTRY32>() as u32,
|
||||||
unsafe { Process32First(snapshot_handle, &mut process_entry).unwrap() };
|
..Default::default()
|
||||||
let exe_full_path = get_exe_full_path(process_entry);
|
};
|
||||||
|
unsafe { Process32First(snapshot_handle, &raw mut process_entry).unwrap() };
|
||||||
|
let exe_full_path = get_exe_full_path(&process_entry);
|
||||||
processes.push(Process {
|
processes.push(Process {
|
||||||
pid: process_entry.th32ProcessID,
|
pid: process_entry.th32ProcessID,
|
||||||
name: c_char_arr_to_string(&process_entry.szExeFile),
|
name: c_char_arr_to_string(&process_entry.szExeFile),
|
||||||
exe: exe_full_path,
|
exe: exe_full_path,
|
||||||
});
|
});
|
||||||
while unsafe { Process32Next(snapshot_handle, &mut process_entry) }.is_ok() {
|
while unsafe { Process32Next(snapshot_handle, &raw mut process_entry) }.is_ok() {
|
||||||
let exe_full_path = get_exe_full_path(process_entry);
|
let exe_full_path = get_exe_full_path(&process_entry);
|
||||||
processes.push(Process {
|
processes.push(Process {
|
||||||
pid: process_entry.th32ProcessID,
|
pid: process_entry.th32ProcessID,
|
||||||
name: c_char_arr_to_string(&process_entry.szExeFile),
|
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 {
|
let process_handle_result = unsafe {
|
||||||
OpenProcess(
|
OpenProcess(
|
||||||
PROCESS_QUERY_LIMITED_INFORMATION,
|
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 exename = [0u16; 260];
|
||||||
let mut dwsize = exename.len() as u32;
|
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 {
|
let image_name_result = unsafe {
|
||||||
QueryFullProcessImageNameW(
|
QueryFullProcessImageNameW(
|
||||||
process_handle,
|
process_handle,
|
||||||
PROCESS_NAME_WIN32,
|
PROCESS_NAME_WIN32,
|
||||||
PWSTR(exename.as_mut_ptr()),
|
PWSTR(exename.as_mut_ptr()),
|
||||||
&mut dwsize,
|
&raw mut dwsize,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
match image_name_result {
|
match image_name_result {
|
||||||
Ok(_) => Some(PathBuf::from(
|
Ok(()) => Some(PathBuf::from(
|
||||||
unsafe { PWSTR(exename.as_mut_ptr()).to_string() }.unwrap(),
|
unsafe { PWSTR(exename.as_mut_ptr()).to_string() }.unwrap(),
|
||||||
)),
|
)),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
exe_full_path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn c_char_arr_to_string(arr: &[i8]) -> String {
|
fn c_char_arr_to_string(arr: &[i8]) -> String {
|
||||||
|
|||||||
+3
-3
@@ -26,7 +26,7 @@ pub fn is_cursor_visible() -> bool {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
GetCursorInfo(&mut ci).unwrap();
|
GetCursorInfo(&raw mut ci).unwrap();
|
||||||
}
|
}
|
||||||
ci.flags == CURSOR_SHOWING
|
ci.flags == CURSOR_SHOWING
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ pub fn elevate(closing: ElevationExitMethod) {
|
|||||||
pub fn is_elevated() -> bool {
|
pub fn is_elevated() -> bool {
|
||||||
let mut token: HANDLE = HANDLE::default();
|
let mut token: HANDLE = HANDLE::default();
|
||||||
unsafe {
|
unsafe {
|
||||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_err() {
|
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &raw mut token).is_err() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let mut elevation = TOKEN_ELEVATION::default();
|
let mut elevation = TOKEN_ELEVATION::default();
|
||||||
@@ -77,7 +77,7 @@ pub fn is_elevated() -> bool {
|
|||||||
TokenElevation,
|
TokenElevation,
|
||||||
Some((&raw mut elevation).cast()),
|
Some((&raw mut elevation).cast()),
|
||||||
size,
|
size,
|
||||||
&mut size,
|
&raw mut size,
|
||||||
);
|
);
|
||||||
CloseHandle(token).unwrap();
|
CloseHandle(token).unwrap();
|
||||||
result.is_ok() && elevation.TokenIsElevated != 0
|
result.is_ok() && elevation.TokenIsElevated != 0
|
||||||
|
|||||||
Reference in New Issue
Block a user