@@ -3,11 +3,11 @@ use std::path::PathBuf;
33
44use serde:: { Deserialize , Serialize } ;
55
6- use super :: { GameImporter , ImportBase } ;
6+ use super :: ImportOverrides ;
77use crate :: error:: { Error , IoError } ;
88use crate :: game:: error:: GameError ;
9- use crate :: game:: registry:: { ActiveDistribution , GameData } ;
10- use crate :: ts:: v1:: models:: ecosystem:: GameDefPlatform ;
9+ use crate :: game:: registry:: ActiveDistribution ;
10+ use crate :: ts:: v1:: models:: ecosystem:: { GameDef , GameDefPlatform } ;
1111use crate :: util:: reg:: { self , HKey } ;
1212
1313#[ derive( Serialize , Deserialize , Debug ) ]
@@ -17,81 +17,65 @@ struct PartialInstallManifest {
1717 app_name : String ,
1818}
1919
20- pub struct EgsImporter {
21- ident : String ,
22- }
23-
24- impl EgsImporter {
25- pub fn new ( ident : & str ) -> EgsImporter {
26- EgsImporter {
27- ident : ident. into ( ) ,
28- }
29- }
30- }
20+ pub fn get_gamedist ( ident : & str , game_def : & GameDef , overrides : & ImportOverrides ) -> Result < Option < ActiveDistribution > , Error > {
21+ let game_label = game_def. label . clone ( ) ;
3122
32- impl GameImporter for EgsImporter {
33- fn construct ( self : Box < Self > , base : ImportBase ) -> Result < GameData , Error > {
34- let game_label = base. game_def . label . clone ( ) ;
23+ // There's a couple ways that we can retrieve the path of a game installed via EGS.
24+ // 1. Parse LauncherInstalled.dat in C:/ProgramData/Epic/UnrealEngineLauncher/
25+ // 2. Parse game manifest files in C:/ProgramData/Epic/EpicGamesLauncher/Data/Manifests
26+ // I'm going to go for the second option.
3527
36- // There's a couple ways that we can retrieve the path of a game installed via EGS .
37- // 1. Parse LauncherInstalled.dat in C:/ProgramData/ Epic/UnrealEngineLauncher/
38- // 2. Parse game manifest files in C:/ProgramData/Epic/EpicGamesLauncher/Data/Manifests
39- // I'm going to go for the second option.
28+ // Attempt to get the path of the EGS /Data directory from the registry .
29+ let subkey = r#"Software\WOW64Node\ Epic Games\EpicGamesLauncher"# ;
30+ let value = reg :: get_value_at ( HKey :: LocalMachine , subkey , "AppDataPath" ) ? ;
31+ let manifests_dir = PathBuf :: from ( value ) . join ( "Manifests" ) ;
4032
41- // Attempt to get the path of the EGS /Data directory from the registry.
42- let subkey = r#"Software\WOW64Node\Epic Games\EpicGamesLauncher"# ;
43- let value = reg:: get_value_at ( HKey :: LocalMachine , subkey, "AppDataPath" ) ?;
44- let manifests_dir = PathBuf :: from ( value) . join ( "Manifests" ) ;
45-
46- if !manifests_dir. exists ( ) {
47- Err ( IoError :: DirNotFound ( manifests_dir. clone ( ) ) ) ?;
48- }
33+ if !manifests_dir. exists ( ) {
34+ Err ( IoError :: DirNotFound ( manifests_dir. clone ( ) ) ) ?;
35+ }
4936
50- // Manifest files are JSON files with .item extensions.
51- let manifest_files = fs:: read_dir ( manifests_dir)
52- . unwrap ( )
53- . filter_map ( |x| x. ok ( ) )
54- . map ( |x| x. path ( ) )
55- . filter ( |x| x. is_file ( ) && x. extension ( ) . is_some ( ) )
56- . filter ( |x| x. extension ( ) . unwrap ( ) == "item" )
57- . collect :: < Vec < _ > > ( ) ;
37+ // Manifest files are JSON files with .item extensions.
38+ let manifest_files = fs:: read_dir ( manifests_dir)
39+ . unwrap ( )
40+ . filter_map ( |x| x. ok ( ) )
41+ . map ( |x| x. path ( ) )
42+ . filter ( |x| x. is_file ( ) && x. extension ( ) . is_some ( ) )
43+ . filter ( |x| x. extension ( ) . unwrap ( ) == "item" )
44+ . collect :: < Vec < _ > > ( ) ;
5845
59- // Search for the manifest which contains the correct game AppName.
60- let game_dir = manifest_files
61- . into_iter ( )
62- . find_map ( |x| {
63- let file_contents = fs:: read_to_string ( x) . unwrap ( ) ;
64- let manifest: PartialInstallManifest =
65- serde_json:: from_str ( & file_contents) . unwrap ( ) ;
46+ // Search for the manifest which contains the correct game AppName.
47+ let game_dir = manifest_files
48+ . into_iter ( )
49+ . find_map ( |x| {
50+ let file_contents = fs:: read_to_string ( x) . unwrap ( ) ;
51+ let manifest: PartialInstallManifest =
52+ serde_json:: from_str ( & file_contents) . unwrap ( ) ;
6653
67- if manifest. app_name == self . ident {
68- Some ( manifest. install_location )
69- } else {
70- None
71- }
72- } )
73- . ok_or_else ( || GameError :: NotFound ( game_label. clone ( ) , "EGS" . to_string ( ) ) ) ?;
54+ if manifest. app_name == ident {
55+ Some ( manifest. install_location )
56+ } else {
57+ None
58+ }
59+ } )
60+ . ok_or_else ( || GameError :: NotFound ( game_label. clone ( ) , "EGS" . to_string ( ) ) ) ?;
7461
75- let r2mm = base . game_def . r2modman . as_ref ( ) . expect (
76- "Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug." ,
77- ) ;
62+ let r2mm = game_def. r2modman . as_ref ( ) . expect (
63+ "Expected a valid r2mm field in the ecosystem schema, got nothing. This is a bug." ,
64+ ) . first ( ) . unwrap ( ) ;
7865
79- let exe_path = base
80- . overrides
81- . custom_exe
82- . clone ( )
83- . or_else ( || super :: find_game_exe ( & r2mm. exe_names , & game_dir) )
84- . ok_or_else ( || GameError :: ExeNotFound {
85- possible_names : r2mm. exe_names . clone ( ) ,
86- base_path : game_dir. clone ( ) ,
87- } ) ?;
88- let dist = ActiveDistribution {
89- dist : GameDefPlatform :: Other ,
90- game_dir : game_dir. to_path_buf ( ) ,
91- data_dir : game_dir. join ( & r2mm. data_folder_name ) ,
92- exe_path,
93- } ;
66+ let exe_path = overrides
67+ . custom_exe
68+ . clone ( )
69+ . or_else ( || super :: find_game_exe ( & r2mm. exe_names , & game_dir) )
70+ . ok_or_else ( || GameError :: ExeNotFound {
71+ possible_names : r2mm. exe_names . clone ( ) ,
72+ base_path : game_dir. clone ( ) ,
73+ } ) ?;
9474
95- Ok ( super :: construct_data ( base, dist) )
96- }
75+ Ok ( Some ( ActiveDistribution {
76+ dist : GameDefPlatform :: Other ,
77+ game_dir : game_dir. to_path_buf ( ) ,
78+ data_dir : game_dir. join ( & r2mm. data_folder_name ) ,
79+ exe_path,
80+ } ) )
9781}
0 commit comments