diff --git a/Cargo.lock b/Cargo.lock index 7e5fc20..18778b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,6 +103,7 @@ dependencies = [ "steamgriddb_api", "tokio", "toml", + "winreg 0.10.1", ] [[package]] @@ -1037,7 +1038,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "winreg 0.7.0", ] [[package]] @@ -1549,6 +1550,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "wyz" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index af01070..7a1f210 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ flate2 = "^1.0.22" toml = { version = "^0.5.8", optional = true } futures = { version = "^0.3.17" } dashmap = { version = "^4.0.2", features = ["serde"] } +winreg = "0.10.1" [build-dependencies] fl2rust = { version = "0.4", optional = true } diff --git a/src/egs/get_manifests.rs b/src/egs/get_manifests.rs index 4ea2ac7..893a2c1 100644 --- a/src/egs/get_manifests.rs +++ b/src/egs/get_manifests.rs @@ -81,16 +81,10 @@ pub fn get_default_location() -> Option { #[cfg(target_os = "windows")] { - let key = "SYSTEMDRIVE"; - let system_drive = - env::var(key).expect("We are on windows, we must know what the SYSTEMDRIVE is"); - - let path = Path::new(format!("{}\\", system_drive).as_str()) - .join("ProgramData") - .join("Epic") - .join("EpicGamesLauncher") - .join("Data") - .join("Manifests"); + let path = match location_from_registry(){ + Some(path) => path, + None => guess_default_location() + }; if path.exists() { Some(path) } else { @@ -98,6 +92,38 @@ pub fn get_default_location() -> Option { } } } +#[cfg(target_os = "windows")] +fn location_from_registry() -> Option { + use winreg::enums::*; + use winreg::RegKey; + + let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); + if let Ok(launcher) = hklm.open_subkey("SOFTWARE\\WOW6432Node\\Epic Games\\EpicGamesLauncher") { + let path_string: Result = launcher.get_value("AppDataPath"); + if let Ok(path_string) = path_string { + let path = Path::new(&path_string).join("Manifests"); + if path.exists() { + return Some(path.to_path_buf()); + } + } + } + None +} + +#[cfg(target_os = "windows")] +fn guess_default_location() -> PathBuf { + let key = "SYSTEMDRIVE"; + let system_drive = + env::var(key).expect("We are on windows, we must know what the SYSTEMDRIVE is"); + + let path = Path::new(format!("{}\\", system_drive).as_str()) + .join("ProgramData") + .join("Epic") + .join("EpicGamesLauncher") + .join("Data") + .join("Manifests"); + path.to_path_buf() +} fn is_game_installed(manifest: &ManifestItem) -> bool { Path::new(manifest.manifest_location.as_str()).exists()