Skip to content

Spring cleaning - format, lint, upgrade #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
961 changes: 515 additions & 446 deletions Cargo.lock

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ version = "0.3.0"
edition = "2021"

[dependencies]
once_cell = "1.17"
wildmatch = "2.1"
once_cell = "1.21"
wildmatch = "2.4"
reqwest = { version = "0.11", features = ["json", "stream"] }

petgraph = { version = "0.6", features = ["serde-1"] }

# errors, ux, other user-facing communication
thiserror = "1.0"
miette = { version = "5.10", features = ["fancy"] }
colored = "2.0"
indicatif = { version = "0.17.8", features = ["improved_unicode", "tokio"] }
colored = "2.2"
indicatif = { version = "0.17.11", features = ["improved_unicode", "tokio"] }

# async runtime and helpers
futures = "0.3"
futures-util = "0.3"
tokio = { version = "1.34", features = [
tokio = { version = "1.44", features = [
"macros",
"process",
"rt-multi-thread",
Expand All @@ -28,27 +28,27 @@ tokio-util = { version = "0.7", features = ["io"] }
async-compression = { version = "0.4", features = ["futures-io", "gzip"] }

# parsers, serializations, and other data processing
clap = { version = "4.2", features = ["derive", "color"] }
clap = { version = "4.5", features = ["derive", "color"] }
figment = { version = "0.10", features = ["env", "toml"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "2.3"
toml = "0.7.3"
toml = "0.7.8"
md-5 = "0.10"
base64 = "0.21"

# files, directories, and other fs operations
walkdir = "2.3"
zip = "2.2.3"
walkdir = "2.5"
zip = "2.6.1"
directories = "5.0"
steamlocate = "2.0.0-beta.2"
steamlocate = "2.0.1"

sysinfo = "0.29"
chrono = { version = "0.4.35", features = ["serde"] }
log = "0.4.21"
chrono = { version = "0.4.40", features = ["serde"] }
log = "0.4.27"

[target.'cfg(windows)'.dependencies]
winreg = "0.50"

[dev-dependencies]
tempfile = "3.10"
tempfile = "3.19"
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub enum ExternSubcommand {
/// Use the `list` command to query the list of imported and supported games.
#[clap(long)]
game_id: String,
}
},
}

#[derive(Subcommand, Debug)]
Expand Down
10 changes: 6 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::path::{Path, PathBuf};

use crate::server::ServerError;
use crate::ts::error::ApiError;

use crate::game::error::GameError;
use crate::package::error::PackageError;
use crate::project::error::ProjectError;
use crate::server::ServerError;
use crate::ts::error::ApiError;

#[derive(Debug, thiserror::Error)]
#[repr(u32)]
Expand Down Expand Up @@ -82,7 +81,10 @@ impl From<std::io::Error> for Error {

impl From<reqwest::Error> for Error {
fn from(value: reqwest::Error) -> Self {
Self::Api(ApiError::BadRequest { source: value, response_body: None })
Self::Api(ApiError::BadRequest {
source: value,
response_body: None,
})
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/game/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub enum GameError {
NotFound(String, String),

#[error("Could not find any of '{possible_names:?}' in base directory: '{base_path}'.")]
ExeNotFound { possible_names: Vec<String>, base_path: PathBuf},
ExeNotFound {
possible_names: Vec<String>,
base_path: PathBuf,
},

#[error("The Steam library could not be automatically found.")]
SteamDirNotFound,
Expand Down
9 changes: 4 additions & 5 deletions src/game/import/ea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ impl GameImporter for EaImporter {
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &game_dir))
.ok_or_else(|| {
GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: game_dir.clone(),
}})?;
.ok_or_else(|| GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: game_dir.clone(),
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::Origin {
identifier: self.ident.to_string(),
Expand Down
11 changes: 5 additions & 6 deletions src/game/import/egs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};

use super::{GameImporter, ImportBase};
use crate::error::{IoError, Error};
use crate::error::{Error, IoError};
use crate::game::error::GameError;
use crate::game::registry::{ActiveDistribution, GameData};
use crate::ts::v1::models::ecosystem::GameDefPlatform;
Expand Down Expand Up @@ -81,11 +81,10 @@ impl GameImporter for EgsImporter {
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &game_dir))
.ok_or_else(|| {
GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: game_dir.clone(),
}})?;
.ok_or_else(|| GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: game_dir.clone(),
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::Other,
game_dir: game_dir.to_path_buf(),
Expand Down
9 changes: 4 additions & 5 deletions src/game/import/gamepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ impl GameImporter for GamepassImporter {
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &game_dir))
.ok_or_else(|| {
GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: game_dir.clone(),
}})?;
.ok_or_else(|| GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: game_dir.clone(),
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::GamePass {
identifier: self.ident.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/game/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::game::import::ea::EaImporter;
use crate::game::import::egs::EgsImporter;
use crate::game::import::gamepass::GamepassImporter;
use crate::game::import::steam::SteamImporter;
use crate::ts::v1::models::ecosystem::{ GameDef, GameDefPlatform };
use crate::ts::v1::models::ecosystem::{GameDef, GameDefPlatform};

pub trait GameImporter {
fn construct(self: Box<Self>, base: ImportBase) -> Result<GameData, Error>;
Expand Down
7 changes: 4 additions & 3 deletions src/game/import/nodrm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::{Path, PathBuf};

use super::{GameImporter, ImportBase};
use crate::error::{Error, IoError};
use crate::game::error::GameError;
use super::{GameImporter, ImportBase};
use crate::game::registry::{ActiveDistribution, GameData};
use crate::ts::v1::models::ecosystem::GameDefPlatform;

Expand Down Expand Up @@ -33,8 +33,9 @@ impl GameImporter for NoDrmImporter {
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &self.game_dir))
.ok_or_else(|| {
GameError::ExeNotFound { possible_names: r2mm.exe_names.clone(), base_path: self.game_dir.clone() }
.ok_or_else(|| GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: self.game_dir.clone(),
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::Other,
Expand Down
15 changes: 7 additions & 8 deletions src/game/import/steam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl GameImporter for SteamImporter {
.as_ref()
.map_or_else(SteamDir::locate, |x| SteamDir::from_dir(x))
.map_err(|e: steamlocate::Error| match e {
steamlocate::Error::InvalidSteamDir(_) => {
GameError::SteamDirBadPath(self.steam_dir.as_ref().unwrap().to_path_buf())
}
steamlocate::Error::InvalidSteamDir(_) => GameError::SteamDirBadPath(
self.steam_dir.as_ref().unwrap().to_path_buf(),
),
steamlocate::Error::FailedLocate(_) => GameError::SteamDirNotFound,
_ => unreachable!(),
})?;
Expand Down Expand Up @@ -75,11 +75,10 @@ impl GameImporter for SteamImporter {
.iter()
.map(|x| app_dir.join(x))
.find(|x| x.is_file())
.ok_or_else(|| {
GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: app_dir.clone(),
}})?;
.ok_or_else(|| GameError::ExeNotFound {
possible_names: r2mm.exe_names.clone(),
base_path: app_dir.clone(),
})?;

let dist = ActiveDistribution {
dist: GameDefPlatform::Steam {
Expand Down
2 changes: 1 addition & 1 deletion src/game/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod ecosystem;
pub mod error;
pub mod import;
pub mod proc;
pub mod registry;
pub mod error;
51 changes: 26 additions & 25 deletions src/game/proc.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
use std::{ffi::OsStr, path::{Path, PathBuf}};
use sysinfo::{
Pid,
ProcessExt,
System,
SystemExt
use std::{
ffi::OsStr,
path::{Path, PathBuf},
};

use sysinfo::{Pid, ProcessExt, System, SystemExt};

use crate::error::Error;

pub fn get_pid_files(dir: &Path) -> Result<Vec<PathBuf>, Error> {
let ext = OsStr::new("pid");
let files = dir
.read_dir()?
.filter_map(|x| x.ok())
.filter(|x| x.path().extension() == Some(ext))
.map(|x| x.path())
.collect();

Ok(files)
let ext = OsStr::new("pid");
let files = dir
.read_dir()?
.filter_map(|x| x.ok())
.filter(|x| x.path().extension() == Some(ext))
.map(|x| x.path())
.collect();

Ok(files)
}

pub fn is_running(pid: usize) -> bool {
let mut system = System::new();
system.refresh_processes();
let mut system = System::new();
system.refresh_processes();

system.process(Pid::from(pid)).is_some()
system.process(Pid::from(pid)).is_some()
}

pub fn kill(pid: usize) {
let mut system = System::new();
system.refresh_processes();
let mut system = System::new();
system.refresh_processes();

let proc = system.process(Pid::from(pid)).expect("Expected a running process.");
proc.kill();
let proc = system
.process(Pid::from(pid))
.expect("Expected a running process.");
proc.kill();
}

pub fn get_name(pid: usize) -> Option<String> {
let system = System::new();
let proc = system.process(Pid::from(pid))?;
let system = System::new();
let proc = system.process(Pid::from(pid))?;

Some(proc.name().to_string())
Some(proc.name().to_string())
}
16 changes: 9 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![allow(dead_code)]

use std::io::{self, Stdin};
use std::io;
use std::path::PathBuf;

use clap::Parser;
use cli::{ExternSubcommand, InitSubcommand};
use colored::Colorize;
use directories::BaseDirs;
use error::{IoError, Error};
use game::import::{select_importer, GameImporter};
use error::{Error, IoError};
use game::import::GameImporter;
use once_cell::sync::Lazy;
use project::error::ProjectError;
use project::ProjectKind;
Expand Down Expand Up @@ -353,7 +353,7 @@ async fn main() -> Result<(), Error> {
Ok(())
}
},
Commands::Server { project_path }=> {
Commands::Server { project_path } => {
let read = io::stdin();
let write = io::stdout();
server::spawn(read, write, &project_path).await?;
Expand All @@ -365,10 +365,12 @@ async fn main() -> Result<(), Error> {
match command {
ExternSubcommand::GameData { game_id } => {
let base = ImportBase::new(&game_id).await?;
let game_data = import::select_importer(&base)?
.construct(base)?;
let game_data = import::select_importer(&base)?.construct(base)?;

println!("{}", serde_json::to_string_pretty(&game_data.active_distribution)?);
println!(
"{}",
serde_json::to_string_pretty(&game_data.active_distribution)?
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/package/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::PathBuf;

use once_cell::sync::Lazy;

use crate::error::{IoResultToTcli, Error};
use crate::error::{Error, IoResultToTcli};
use crate::ts::package_reference::PackageReference;
use crate::util::TempFile;
use crate::TCLI_HOME;
Expand Down
Loading
Loading