1+ use std:: fmt:: Display ;
12use enum_ordinalize:: Ordinalize ;
2- use safer_ffi:: ffi_export;
33use safer_ffi:: ඞ:: repr_c;
4+ use safer_ffi:: { derive_ReprC, ffi_export} ;
45use windows_registry:: LOCAL_MACHINE ;
6+ use log:: debug;
57
68#[ derive( Ordinalize ) ]
79enum GTAVersion {
810 Legacy ,
911 Enhanced ,
1012}
1113
14+ impl Display for GTAVersion {
15+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
16+ let version = match self {
17+ GTAVersion :: Legacy => "Legacy" ,
18+ GTAVersion :: Enhanced => "Enhanced"
19+ } ;
20+
21+ write ! ( f, "{:?}" , version)
22+ }
23+ }
24+
25+ #[ derive_ReprC]
26+ #[ repr( C ) ]
27+ struct GtaInstallLocationResult {
28+ is_error : bool ,
29+ content : repr_c:: String ,
30+ }
31+
1232#[ ffi_export]
13- fn read_gta_location ( gta_version : i8 ) -> repr_c :: String {
33+ fn read_gta_location ( gta_version : i8 ) -> GtaInstallLocationResult {
1434 let version = GTAVersion :: from_ordinal ( gta_version) . unwrap ( ) ;
15- let location = _read_gta_location ( version) . unwrap ( ) ;
16- location. into ( )
35+
36+ match _read_gta_location ( version) {
37+ Ok ( location) => GtaInstallLocationResult {
38+ is_error : false ,
39+ content : location. into ( ) ,
40+ } ,
41+ Err ( error) => GtaInstallLocationResult {
42+ is_error : true ,
43+ content : error. to_string ( ) . into ( ) ,
44+ } ,
45+ }
1746}
1847
1948#[ ffi_export]
2049fn detect_version ( ) -> i8 {
2150 match _detect_version ( ) {
2251 None => -1 ,
23- Some ( version) => version. ordinal ( )
52+ Some ( version) => version. ordinal ( ) ,
2453 }
2554}
2655
@@ -37,17 +66,22 @@ fn _detect_version() -> Option<GTAVersion> {
3766 }
3867}
3968
40- fn _read_gta_location ( gta_version : GTAVersion ) -> windows_registry:: Result < String > {
41- let key = LOCAL_MACHINE . open ( gta_version. registry_location ( ) ) ?;
69+ fn _read_gta_location ( gta_version : GTAVersion , ) -> windows_registry:: Result < String > {
70+ let steam_key = LOCAL_MACHINE . open ( "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ Steam" ) ;
71+ let is_steam = steam_key. is_ok ( ) ;
72+ debug ! ( "Reading GTA V install location, version: {}, is_steam: {}" , gta_version, is_steam) ;
73+
74+ let key = LOCAL_MACHINE . open ( gta_version. registry_location ( is_steam) ) ?;
4275
4376 key. get_string ( "InstallFolder" )
4477}
4578
4679impl GTAVersion {
47- fn registry_location ( & self ) -> & str {
80+ fn registry_location ( & self , is_steam : bool ) -> & str {
4881 match self {
82+ GTAVersion :: Enhanced if !is_steam => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ GTAV Enhanced" ,
83+ GTAVersion :: Enhanced => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ GTA V Enhanced" ,
4984 GTAVersion :: Legacy => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ Grand Theft Auto V" ,
50- GTAVersion :: Enhanced => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ GTAV Enhanced"
5185 }
5286 }
5387}
0 commit comments