Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ethangreen-dev committed Mar 20, 2024
1 parent ab2402c commit 15b8079
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 101 deletions.
10 changes: 7 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ pub enum Error {
)]
InstallerNotExecutable,

#[error("
#[error(
"
The installer '{package_id}' does not support the current tcli installer protocol.
Expected: {our_version:#?}
Recieved: {given_version:#?}
")]
"
)]
InstallerBadVersion {
package_id: String,
given_version: Version,
Expand All @@ -94,7 +96,9 @@ pub enum Error {
#[error("The installer returned an error:\n\t{message}")]
InstallerError { message: String },

#[error("The provided game id '{0}' does not exist or has not been imported into this profile.")]
#[error(
"The provided game id '{0}' does not exist or has not been imported into this profile."
)]
BadGameId(String),

#[error("The Steam app with id '{0}' could not be found.")]
Expand Down
21 changes: 11 additions & 10 deletions src/game/import/ea.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::path::PathBuf;

use super::{Error, GameImporter};
use crate::game::import::ImportBase;
use crate::game::registry::{ActiveDistribution, GameData};
use crate::ts::v1::models::ecosystem::GameDefPlatform;
use crate::util::reg::{self, HKey};

use super::{Error, GameImporter};

pub struct EaImporter {
pub struct EaImporter {
ident: String,
}

Expand All @@ -25,20 +24,22 @@ impl GameImporter for EaImporter {
let value = reg::get_value_at(HKey::LocalMachine, &subkey, "Install Dir")?;

let game_dir = PathBuf::from(value);
let r2mm = base
.game_def
.r2modman
.as_ref()
.expect("Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.");
let r2mm = base.game_def.r2modman.as_ref().expect(
"Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.",
);

let exe_path = base
.overrides
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &game_dir))
.ok_or_else(|| super::Error::ExeNotFound(base.game_def.label.clone(), game_dir.clone()))?;
.ok_or_else(|| {
super::Error::ExeNotFound(base.game_def.label.clone(), game_dir.clone())
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::Origin { identifier: self.ident.to_string() },
dist: GameDefPlatform::Origin {
identifier: self.ident.to_string(),
},
game_dir: game_dir.to_path_buf(),
data_dir: game_dir.join(&r2mm.data_folder_name),
exe_path,
Expand Down
40 changes: 22 additions & 18 deletions src/game/import/egs.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::fs;
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use super::{Error, GameImporter, ImportBase};
use crate::game::registry::{ActiveDistribution, GameData};
use crate::ts::v1::models::ecosystem::GameDefPlatform;
use crate::util::reg::{self, HKey};

use super::{Error, GameImporter, ImportBase};

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct PartialInstallManifest {
install_location: PathBuf,
app_name: String,
}

pub struct EgsImporter {
pub struct EgsImporter {
ident: String,
}

Expand Down Expand Up @@ -55,29 +55,33 @@ impl GameImporter for EgsImporter {
.collect::<Vec<_>>();

// Search for the manifest which contains the correct game AppName.
let game_dir = manifest_files.into_iter().find_map(|x| {
let file_contents = fs::read_to_string(x).unwrap();
let manifest: PartialInstallManifest = serde_json::from_str(&file_contents).unwrap();
let game_dir = manifest_files
.into_iter()
.find_map(|x| {
let file_contents = fs::read_to_string(x).unwrap();
let manifest: PartialInstallManifest =
serde_json::from_str(&file_contents).unwrap();

if manifest.app_name == self.ident {
Some(manifest.install_location)
} else {
None
}
}).ok_or_else(|| super::Error::NotFound(game_label.clone(), "EGS".to_string()))?;
if manifest.app_name == self.ident {
Some(manifest.install_location)
} else {
None
}
})
.ok_or_else(|| super::Error::NotFound(game_label.clone(), "EGS".to_string()))?;

let r2mm = base
.game_def
.r2modman
.as_ref()
.expect("Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.");
let r2mm = base.game_def.r2modman.as_ref().expect(
"Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.",
);

let exe_path = base
.overrides
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &game_dir))
.ok_or_else(|| super::Error::ExeNotFound(base.game_def.label.clone(), game_dir.clone()))?;
.ok_or_else(|| {
super::Error::ExeNotFound(base.game_def.label.clone(), game_dir.clone())
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::Other,
game_dir: game_dir.to_path_buf(),
Expand Down
33 changes: 19 additions & 14 deletions src/game/import/gamepass.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::path::PathBuf;

use super::Error;
use super::{GameImporter, ImportBase};
use crate::game::registry::{ActiveDistribution, GameData};
use crate::ts::v1::models::ecosystem::GameDefPlatform;
use crate::util::reg::{self, HKey};
use crate::game::registry::{ActiveDistribution, GameData};

use super::{GameImporter, ImportBase};
use super::Error;

pub struct GamepassImporter {
ident: String,
Expand All @@ -26,35 +25,41 @@ impl GameImporter for GamepassImporter {
let uuid = reg::get_values_at(HKey::LocalMachine, &format!("{root}\\Package\\"))?
.into_iter()
.find(|x| x.key.starts_with(&self.ident))
.ok_or_else(|| super::Error::NotFound(base.game_def.label.clone(), "Gamepass".to_string()))?
.ok_or_else(|| {
super::Error::NotFound(base.game_def.label.clone(), "Gamepass".to_string())
})?
.val
.replace('\"', "");

let game_root = reg::get_keys_at(HKey::LocalMachine, &format!("Root\\{}\\", uuid))?
.into_iter()
.next()
.ok_or_else(|| super::Error::NotFound(base.game_def.label.clone(), "Gamepass".to_string()))?;
.ok_or_else(|| {
super::Error::NotFound(base.game_def.label.clone(), "Gamepass".to_string())
})?;
let game_dir = PathBuf::from(reg::get_value_at(HKey::LocalMachine, &game_root, "Root")?);

let r2mm = base
.game_def
.r2modman
.as_ref()
.expect("Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.");
let r2mm = base.game_def.r2modman.as_ref().expect(
"Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.",
);

let exe_path = base
.overrides
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &game_dir))
.ok_or_else(|| super::Error::ExeNotFound(base.game_def.label.clone(), game_dir.clone()))?;
.ok_or_else(|| {
super::Error::ExeNotFound(base.game_def.label.clone(), game_dir.clone())
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::GamePass { identifier: self.ident.to_string() },
dist: GameDefPlatform::GamePass {
identifier: self.ident.to_string(),
},
game_dir: game_dir.to_path_buf(),
data_dir: game_dir.join(&r2mm.data_folder_name),
exe_path,
};

Ok(super::construct_data(base, dist))
}
}
}
43 changes: 27 additions & 16 deletions src/game/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ pub mod steam;

use std::path::{Path, PathBuf};

use super::registry::{ActiveDistribution, GameData};
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::{ecosystem, models::ecosystem::GameDefPlatform};
use crate::ts::v1::models::ecosystem::GameDef;
use crate::ts::v1::{ecosystem, models::ecosystem::GameDefPlatform};
use crate::util::reg;

use super::registry::{ActiveDistribution, GameData};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("The game '{0}' is not supported by platform '{1}'.")]
Expand Down Expand Up @@ -87,10 +86,7 @@ impl ImportBase {
}

pub fn with_overrides(self, overrides: ImportOverrides) -> Self {
ImportBase {
overrides,
..self
}
ImportBase { overrides, ..self }
}

pub fn with_wine_prefix(self, wine_prefix: Option<String>) -> Self {
Expand All @@ -102,16 +98,25 @@ impl ImportBase {
}

pub fn select_importer(base: &ImportBase) -> Result<Box<dyn GameImporter>, Error> {
base
.game_def
base.game_def
.distributions
.iter()
.find_map(|dist| match dist {
GameDefPlatform::Origin { identifier } => Some(Box::new(EaImporter::new(identifier)) as _),
GameDefPlatform::EpicGames { identifier } => Some(Box::new(EgsImporter::new(identifier)) as _),
GameDefPlatform::GamePass { identifier } => Some(Box::new(GamepassImporter::new(identifier)) as _),
GameDefPlatform::Steam { identifier } => Some(Box::new(SteamImporter::new(identifier)) as _),
GameDefPlatform::SteamDirect { identifier } => Some(Box::new(SteamImporter::new(identifier)) as _),
GameDefPlatform::Origin { identifier } => {
Some(Box::new(EaImporter::new(identifier)) as _)
}
GameDefPlatform::EpicGames { identifier } => {
Some(Box::new(EgsImporter::new(identifier)) as _)
}
GameDefPlatform::GamePass { identifier } => {
Some(Box::new(GamepassImporter::new(identifier)) as _)
}
GameDefPlatform::Steam { identifier } => {
Some(Box::new(SteamImporter::new(identifier)) as _)
}
GameDefPlatform::SteamDirect { identifier } => {
Some(Box::new(SteamImporter::new(identifier)) as _)
}
_ => None,
})
.ok_or_else(|| Error::NotSupported(base.game_id.clone(), "".into()))
Expand All @@ -126,9 +131,15 @@ pub fn find_game_exe(possible: &[String], base_path: &Path) -> Option<PathBuf> {

pub fn construct_data(base: ImportBase, dist: ActiveDistribution) -> GameData {
GameData {
identifier: base.overrides.custom_id.unwrap_or(base.game_def.label.clone()),
identifier: base
.overrides
.custom_id
.unwrap_or(base.game_def.label.clone()),
ecosystem_label: base.game_def.label,
display_name: base.overrides.custom_name.unwrap_or(base.game_def.meta.display_name),
display_name: base
.overrides
.custom_name
.unwrap_or(base.game_def.meta.display_name),
active_distribution: dist,
possible_distributions: base.game_def.distributions,
}
Expand Down
17 changes: 8 additions & 9 deletions src/game/import/nodrm.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::path::{Path, PathBuf};

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

use super::{Error, GameImporter, ImportBase};

pub struct NoDrmImporter {
pub struct NoDrmImporter {
game_dir: PathBuf,
}

Expand All @@ -23,18 +22,18 @@ impl GameImporter for NoDrmImporter {
Err(Error::DirNotFound(self.game_dir.to_path_buf()))?;
}

let r2mm = base
.game_def
.r2modman
.as_ref()
.expect("Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.");
let r2mm = base.game_def.r2modman.as_ref().expect(
"Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.",
);

let exe_path = base
.overrides
.custom_exe
.clone()
.or_else(|| super::find_game_exe(&r2mm.exe_names, &self.game_dir))
.ok_or_else(|| super::Error::ExeNotFound(base.game_def.label.clone(), self.game_dir.clone()))?;
.ok_or_else(|| {
super::Error::ExeNotFound(base.game_def.label.clone(), self.game_dir.clone())
})?;
let dist = ActiveDistribution {
dist: GameDefPlatform::Other,
game_dir: self.game_dir.to_path_buf(),
Expand Down
Loading

0 comments on commit 15b8079

Please sign in to comment.