-
Notifications
You must be signed in to change notification settings - Fork 0
Simplify game resolver code and add support for platform specifiers #22
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,36 @@ | ||
use std::path::PathBuf; | ||
|
||
use super::GameImporter; | ||
use super::ImportOverrides; | ||
use crate::error::Error; | ||
use crate::game::error::GameError; | ||
use crate::game::import::ImportBase; | ||
use crate::game::registry::{ActiveDistribution, GameData}; | ||
use crate::ts::v1::models::ecosystem::GameDefPlatform; | ||
use crate::game::registry::ActiveDistribution; | ||
use crate::ts::v1::models::ecosystem::{GameDef, GamePlatform}; | ||
use crate::util::reg::{self, HKey}; | ||
|
||
pub struct EaImporter { | ||
ident: String, | ||
} | ||
|
||
impl EaImporter { | ||
pub fn new(ident: &str) -> EaImporter { | ||
EaImporter { | ||
ident: ident.into(), | ||
} | ||
} | ||
} | ||
|
||
impl GameImporter for EaImporter { | ||
fn construct(self: Box<Self>, base: ImportBase) -> Result<GameData, Error> { | ||
let subkey = format!("Software\\{}\\", self.ident.replace('.', "\\")); | ||
let value = reg::get_value_at(HKey::LocalMachine, &subkey, "Install Dir")?; | ||
pub fn get_gamedist(ident: &str, game_def: &GameDef, overrides: &ImportOverrides) -> Result<Option<ActiveDistribution>, Error> { | ||
let subkey = format!("Software\\{}\\", ident.replace('.', "\\")); | ||
let value = reg::get_value_at(HKey::LocalMachine, &subkey, "Install Dir")?; | ||
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
|
||
|
||
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 game_dir = PathBuf::from(value); | ||
let r2mm = game_def.r2modman.as_ref().expect( | ||
"Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug.", | ||
).first().unwrap(); | ||
|
||
let exe_path = base | ||
.overrides | ||
.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(), | ||
})?; | ||
let dist = ActiveDistribution { | ||
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, | ||
}; | ||
let exe_path = overrides | ||
.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(super::construct_data(base, dist)) | ||
} | ||
Ok(Some(ActiveDistribution { | ||
dist: GamePlatform::Origin { | ||
identifier: ident.to_string(), | ||
}, | ||
game_dir: game_dir.to_path_buf(), | ||
data_dir: game_dir.join(&r2mm.data_folder_name), | ||
exe_path, | ||
})) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,50 @@ | ||
use std::path::PathBuf; | ||
|
||
use super::{GameImporter, ImportBase}; | ||
use super::ImportOverrides; | ||
use crate::error::Error; | ||
use crate::game::error::GameError; | ||
use crate::game::registry::{ActiveDistribution, GameData}; | ||
use crate::ts::v1::models::ecosystem::GameDefPlatform; | ||
use crate::game::registry::ActiveDistribution; | ||
use crate::ts::v1::models::ecosystem::{GameDef, GamePlatform}; | ||
use crate::util::reg::{self, HKey}; | ||
|
||
pub struct GamepassImporter { | ||
ident: String, | ||
} | ||
|
||
impl GamepassImporter { | ||
pub fn new(ident: &str) -> GamepassImporter { | ||
GamepassImporter { | ||
ident: ident.into(), | ||
} | ||
} | ||
} | ||
|
||
impl GameImporter for GamepassImporter { | ||
fn construct(self: Box<Self>, base: ImportBase) -> Result<GameData, Error> { | ||
let root = r#"Software\Microsoft\GamingServices\PackageRepository"#; | ||
|
||
let uuid = reg::get_values_at(HKey::LocalMachine, &format!("{root}\\Package\\"))? | ||
.into_iter() | ||
.find(|x| x.key.starts_with(&self.ident)) | ||
.ok_or_else(|| { | ||
GameError::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(|| { | ||
GameError::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 exe_path = base | ||
.overrides | ||
.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(), | ||
})?; | ||
let dist = ActiveDistribution { | ||
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)) | ||
} | ||
pub fn get_gamedist(ident: &str, game_def: &GameDef, overrides: &ImportOverrides) -> Result<Option<ActiveDistribution>, Error> { | ||
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
|
||
let root = r#"Software\Microsoft\GamingServices\PackageRepository"#; | ||
let r2mm = game_def.r2modman.as_ref().expect( | ||
"Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug." | ||
).first().unwrap(); | ||
|
||
let uuid = reg::get_values_at(HKey::LocalMachine, &format!("{root}\\Package\\"))? | ||
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
|
||
.into_iter() | ||
.find(|x| x.key.starts_with(ident)) | ||
.ok_or_else(|| { | ||
GameError::NotFound(ident.into(), "Gamepass".to_string()) | ||
})? | ||
.val | ||
.replace('\"', ""); | ||
|
||
let game_root = reg::get_keys_at(HKey::LocalMachine, &format!("Root\\{}\\", uuid))? | ||
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
|
||
.into_iter() | ||
.next() | ||
.ok_or_else(|| { | ||
GameError::NotFound(ident.into(), "Gamepass".to_string()) | ||
})?; | ||
let game_dir = PathBuf::from(reg::get_value_at(HKey::LocalMachine, &game_root, "Root")?); | ||
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
Check failureCode scanning / clippy ? couldn't convert the error to error::Error Error
? couldn't convert the error to error::Error
|
||
|
||
let exe_path = overrides | ||
.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(Some(ActiveDistribution { | ||
dist: GamePlatform::XboxGamePass { | ||
identifier: ident.to_string(), | ||
}, | ||
game_dir: game_dir.to_path_buf(), | ||
data_dir: game_dir.join(&r2mm.data_folder_name), | ||
exe_path, | ||
})) | ||
} |
Check failure
Code scanning / clippy
? couldn't convert the error to error::Error Error