Clippy approved

This commit is contained in:
IQuant 2024-08-10 15:18:52 +03:00
parent 1d1cf35e93
commit c193482098
4 changed files with 62 additions and 57 deletions

View file

@ -1,3 +1,4 @@
use crate::steam_helper::SteamState;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::{
@ -7,7 +8,6 @@ use std::{
};
use steamworks::AppId;
use tracing::{info, warn};
use crate::steam_helper::SteamState;
struct NoitaStartCmd {
executable: OsString,
args: Vec<OsString>,
@ -44,7 +44,11 @@ pub struct NoitaLauncher {
}
impl NoitaLauncher {
pub fn new(game_exe_path: &Path, start_args: Option<&str>, steam_state: Option<&mut SteamState>) -> Self {
pub fn new(
game_exe_path: &Path,
start_args: Option<&str>,
steam_state: Option<&mut SteamState>,
) -> Self {
let game_dir_path = game_exe_path
.parent()
.expect("game directory to exist")
@ -60,7 +64,7 @@ impl NoitaLauncher {
noita_install: None,
})
} else {
linux_try_get_noita_start_cmd(game_exe_path,steam_state)
linux_try_get_noita_start_cmd(game_exe_path, steam_state)
};
let start_args = start_args
@ -98,7 +102,10 @@ impl NoitaLauncher {
}
}
fn linux_try_get_noita_start_cmd(game_exe_path: &Path, steam_state: Option<&mut SteamState>) -> Option<NoitaStartCmd> {
fn linux_try_get_noita_start_cmd(
game_exe_path: &Path,
steam_state: Option<&mut SteamState>,
) -> Option<NoitaStartCmd> {
let executable = game_exe_path.as_os_str().to_owned();
// ~/.local/share/Steam/steamapps/common/Noita/noita.exe
let game_path = game_exe_path.parent()?;
@ -111,38 +118,45 @@ fn linux_try_get_noita_start_cmd(game_exe_path: &Path, steam_state: Option<&mut
.ok()?;
let file = BufReader::new(config_info_file)
.lines()
.skip(1)
.next()?
.nth(1)?
.inspect_err(|err| warn!("Couldn't find proton fonts paths: {}", err))
.ok()?;
let proton_path_fonts = Path::new(&file);
let proton_path=proton_path_from_fonts(proton_path_fonts)?;
let tool_manifest=File::open(proton_path.join("toolmanifest.vdf"))
let proton_path = proton_path_from_fonts(proton_path_fonts)?;
let tool_manifest = File::open(proton_path.join("toolmanifest.vdf"))
.inspect_err(|err| warn!("Couldn't open toolmanifest.vdf file: {}", err))
.ok()?;
let runtime_appid=BufReader::new(tool_manifest).lines().skip(4).next().map(|a| a.unwrap().split('"').skip(3).next().map(|b|b.parse::<u32>()));
match (steam_state,runtime_appid)
{
(Some(state),Some(Some(Ok(appid)))) =>
{
let runtime_appid = BufReader::new(tool_manifest)
.lines()
.nth(4)
.map(|a| a.unwrap().split('"').nth(3).map(|b| b.parse::<u32>()));
match (steam_state, runtime_appid) {
(Some(state), Some(Some(Ok(appid)))) => {
let apps = state.client.apps();
let app_id = AppId::from(appid);
let app_install_dir = apps.app_install_dir(app_id);
Some(NoitaStartCmd {
executable: PathBuf::from(app_install_dir).join("_v2-entry-point").into(),
args: vec!["--verb=run".into(), proton_path.join("proton").into_os_string(), "run".into(), executable.into()],
steam_install: steam_intall_path(steamapps_path),
noita_compat_data: Some(noita_compatdata_path),
noita_install: Some(game_path.to_path_buf()),
})
executable: PathBuf::from(app_install_dir)
.join("_v2-entry-point")
.into(),
args: vec![
"--verb=run".into(),
proton_path.join("proton").into_os_string(),
"run".into(),
executable,
],
steam_install: steam_intall_path(steamapps_path),
noita_compat_data: Some(noita_compatdata_path),
noita_install: Some(game_path.to_path_buf()),
})
}
_=> Some(NoitaStartCmd {
executable: proton_path.join("proton").into_os_string(),
args: vec!["run".into(), executable.into()],
steam_install: steam_intall_path(steamapps_path),
noita_compat_data: Some(noita_compatdata_path),
noita_install: Some(game_path.to_path_buf()),
})
_ => Some(NoitaStartCmd {
executable: proton_path.join("proton").into_os_string(),
args: vec!["run".into(), executable],
steam_install: steam_intall_path(steamapps_path),
noita_compat_data: Some(noita_compatdata_path),
noita_install: Some(game_path.to_path_buf()),
}),
}
} else {
None
@ -150,12 +164,7 @@ fn linux_try_get_noita_start_cmd(game_exe_path: &Path, steam_state: Option<&mut
}
fn proton_path_from_fonts(proton_path_fonts: &Path) -> Option<PathBuf> {
Some(
proton_path_fonts
.parent()?
.parent()?
.parent()?.into()
)
Some(proton_path_fonts.parent()?.parent()?.parent()?.into())
}
fn steam_intall_path(steamapps_path: &Path) -> Option<PathBuf> {

View file

@ -261,30 +261,26 @@ impl NetManager {
}
// Handle all available messages from Noita.
loop {
if let Some(ws) = &mut state.ws {
let msg = ws.read();
{
match msg {
Ok(msg) => {
if let tungstenite::Message::Binary(msg) = msg {
self.handle_mod_message_2(msg, &mut state);
}
}
Err(tungstenite::Error::Io(io_err))
if io_err.kind() == io::ErrorKind::WouldBlock
|| io_err.kind() == io::ErrorKind::TimedOut =>
{
break
}
Err(err) => {
error!("Error occured while reading from websocket: {}", err);
state.ws = None;
}
while let Some(ws) = &mut state.ws {
let msg = ws.read();
match msg {
Ok(msg) => {
if let tungstenite::Message::Binary(msg) = msg {
self.handle_mod_message_2(msg, &mut state);
}
};
} else {
break;
}
Err(tungstenite::Error::Io(io_err))
if io_err.kind() == io::ErrorKind::WouldBlock
|| io_err.kind() == io::ErrorKind::TimedOut =>
{
break
}
Err(err) => {
error!("Error occured while reading from websocket: {}", err);
state.ws = None;
}
}
}

View file

@ -104,7 +104,7 @@ impl WorldModel {
runner.put_pixel(self.get_pixel(x + i, y + j).to_raw())
}
}
runner.to_noita(x, y, (w - 1) as u8, (h - 1) as u8)
runner.into_noita_update(x, y, (w - 1) as u8, (h - 1) as u8)
}
pub fn get_all_noita_updates(&self) -> Vec<Vec<u8>> {

View file

@ -88,7 +88,7 @@ impl<Pixel: Eq + Copy> PixelRunner<Pixel> {
impl PixelRunner<RawPixel> {
/// Note: w/h are actualy width/height -1
pub fn to_noita(self, x: i32, y: i32, w: u8, h: u8) -> NoitaWorldUpdate {
pub fn into_noita_update(self, x: i32, y: i32, w: u8, h: u8) -> NoitaWorldUpdate {
let runs = self.build();
NoitaWorldUpdate {
header: Header {