11use enum_ordinalize:: Ordinalize ;
2- use safer_ffi:: ffi_export;
32use safer_ffi:: ඞ:: repr_c;
3+ use safer_ffi:: { derive_ReprC, ffi_export} ;
44use windows_registry:: LOCAL_MACHINE ;
5+ use log:: debug;
56
67#[ derive( Ordinalize ) ]
78enum GTAVersion {
89 Legacy ,
910 Enhanced ,
1011}
1112
13+ #[ derive_ReprC]
14+ #[ repr( C ) ]
15+ struct GtaInstallLocationResult {
16+ is_error : bool ,
17+ content : repr_c:: String ,
18+ }
19+
1220#[ ffi_export]
13- fn read_gta_location ( gta_version : i8 ) -> repr_c :: String {
21+ fn read_gta_location ( gta_version : i8 ) -> GtaInstallLocationResult {
1422 let version = GTAVersion :: from_ordinal ( gta_version) . unwrap ( ) ;
15- let location = _read_gta_location ( version) . unwrap ( ) ;
16- location. into ( )
23+
24+ match _read_gta_location ( version) {
25+ Ok ( location) => GtaInstallLocationResult {
26+ is_error : false ,
27+ content : location. into ( ) ,
28+ } ,
29+ Err ( error) => GtaInstallLocationResult {
30+ is_error : true ,
31+ content : error. to_string ( ) . into ( ) ,
32+ } ,
33+ }
1734}
1835
1936#[ ffi_export]
2037fn detect_version ( ) -> i8 {
2138 match _detect_version ( ) {
2239 None => -1 ,
23- Some ( version) => version. ordinal ( )
40+ Some ( version) => version. ordinal ( ) ,
2441 }
2542}
2643
@@ -37,17 +54,22 @@ fn _detect_version() -> Option<GTAVersion> {
3754 }
3855}
3956
40- fn _read_gta_location ( gta_version : GTAVersion ) -> windows_registry:: Result < String > {
41- let key = LOCAL_MACHINE . open ( gta_version. registry_location ( ) ) ?;
57+ fn _read_gta_location ( gta_version : GTAVersion , ) -> windows_registry:: Result < String > {
58+ let steam_key = LOCAL_MACHINE . open ( "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ Steam" ) ;
59+ let is_steam = steam_key. is_ok ( ) ;
60+ debug ! ( "Reading GTA V install location, version: {}, is_steam: {}" , gta_version, is_steam) ;
61+
62+ let key = LOCAL_MACHINE . open ( gta_version. registry_location ( is_steam) ) ?;
4263
4364 key. get_string ( "InstallFolder" )
4465}
4566
4667impl GTAVersion {
47- fn registry_location ( & self ) -> & str {
68+ fn registry_location ( & self , is_steam : bool ) -> & str {
4869 match self {
70+ GTAVersion :: Enhanced if !is_steam => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ GTAV Enhanced" ,
71+ GTAVersion :: Enhanced => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ GTA V Enhanced" ,
4972 GTAVersion :: Legacy => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ Grand Theft Auto V" ,
50- GTAVersion :: Enhanced => "SOFTWARE\\ WOW6432Node\\ Rockstar Games\\ GTAV Enhanced"
5173 }
5274 }
5375}
0 commit comments