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",
"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"
+1
View File
@@ -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 }
+36 -10
View File
@@ -81,16 +81,10 @@ pub fn get_default_location() -> Option<PathBuf> {
#[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<PathBuf> {
}
}
}
#[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 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()