Use winreg to look up epic location

This commit is contained in:
Philip
2022-01-01 12:27:52 +01:00
parent 0e8509a87f
commit a3d0377878
3 changed files with 48 additions and 11 deletions
Generated
+11 -1
View File
@@ -103,6 +103,7 @@ dependencies = [
"steamgriddb_api", "steamgriddb_api",
"tokio", "tokio",
"toml", "toml",
"winreg 0.10.1",
] ]
[[package]] [[package]]
@@ -1037,7 +1038,7 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",
"winreg", "winreg 0.7.0",
] ]
[[package]] [[package]]
@@ -1549,6 +1550,15 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "winreg"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "wyz" name = "wyz"
version = "0.2.0" version = "0.2.0"
+1
View File
@@ -21,6 +21,7 @@ flate2 = "^1.0.22"
toml = { version = "^0.5.8", optional = true } toml = { version = "^0.5.8", optional = true }
futures = { version = "^0.3.17" } futures = { version = "^0.3.17" }
dashmap = { version = "^4.0.2", features = ["serde"] } dashmap = { version = "^4.0.2", features = ["serde"] }
winreg = "0.10.1"
[build-dependencies] [build-dependencies]
fl2rust = { version = "0.4", optional = true } fl2rust = { version = "0.4", optional = true }
+32 -6
View File
@@ -81,6 +81,37 @@ pub fn get_default_location() -> Option<PathBuf> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
let path = match location_from_registry(){
Some(path) => path,
None => guess_default_location()
};
if path.exists() {
Some(path)
} else {
None
}
}
}
#[cfg(target_os = "windows")]
fn location_from_registry() -> Option<PathBuf> {
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<String, _> = 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 key = "SYSTEMDRIVE";
let system_drive = let system_drive =
env::var(key).expect("We are on windows, we must know what the SYSTEMDRIVE is"); env::var(key).expect("We are on windows, we must know what the SYSTEMDRIVE is");
@@ -91,12 +122,7 @@ pub fn get_default_location() -> Option<PathBuf> {
.join("EpicGamesLauncher") .join("EpicGamesLauncher")
.join("Data") .join("Data")
.join("Manifests"); .join("Manifests");
if path.exists() { path.to_path_buf()
Some(path)
} else {
None
}
}
} }
fn is_game_installed(manifest: &ManifestItem) -> bool { fn is_game_installed(manifest: &ManifestItem) -> bool {