diff --git a/src/platforms/egs/get_manifests.rs b/src/platforms/egs/get_manifests.rs index 9567e70..928ea7f 100644 --- a/src/platforms/egs/get_manifests.rs +++ b/src/platforms/egs/get_manifests.rs @@ -84,6 +84,7 @@ fn get_manifest_item(dir_entry: DirEntry, _path: Option) -> Option String { let drive = location.get(0..2).map(|drive| drive.to_lowercase()); let rest_path = location.get(3..).map(|rest| rest.replace('\\', "/")); diff --git a/src/platforms/egs/paths.rs b/src/platforms/egs/paths.rs index 01bd7fd..9386e21 100644 --- a/src/platforms/egs/paths.rs +++ b/src/platforms/egs/paths.rs @@ -110,52 +110,42 @@ mod windows { fn guess_default_launcher_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()) + let system_drive = env::var(key).unwrap_or_else(|_| String::from("c:")); + Path::new(format!("{}\\", system_drive).as_str()) .join("Program Files (x86)") .join("Epic Games") .join("Launcher") .join("Portal") .join("Binaries") .join("Win64") - .join("EpicGamesLauncher.exe"); - path + .join("EpicGamesLauncher.exe") } fn launcher_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\\Classes\\com.epicgames.launcher\\shell\\open\\command") - { - let launch_string: Result = launcher.get_value(""); - if let Ok(launch_string) = launch_string { - let path = Path::new(&launch_string[1..launch_string.len() - 4]); - if path.exists() { - return Some(path.to_path_buf()); - } - } - } - None + RegKey::predef(HKEY_LOCAL_MACHINE) + .open_subkey("SOFTWARE\\Classes\\com.epicgames.launcher\\shell\\open\\command") + .ok() + .and_then(|launcher| launcher.get_value("").ok()) + .and_then(|value: String| { + value + .get(1..value.len() - 4) + .map(|path| Path::new(path).to_path_buf()) + }) + .filter(|path| path.exists()) } fn guess_default_manifest_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()) + let system_drive = env::var(key).unwrap_or_else(|_| String::from("c:")); + Path::new(format!("{}\\", system_drive).as_str()) .join("ProgramData") .join("Epic") .join("EpicGamesLauncher") .join("Data") - .join("Manifests"); - path + .join("Manifests") } pub fn get_locations() -> Option { diff --git a/src/platforms/origin/origin_platform.rs b/src/platforms/origin/origin_platform.rs index 5e98729..d8410a9 100644 --- a/src/platforms/origin/origin_platform.rs +++ b/src/platforms/origin/origin_platform.rs @@ -32,7 +32,8 @@ impl NeedsPorton for OriginGame { impl OriginPlatform { fn get_shortcuts(&self) -> eyre::Result> { - let origin_folders = get_default_locations().ok_or(eyre::format_err!("Default path not found"))?; + let origin_folders = + get_default_locations().ok_or(eyre::format_err!("Default path not found"))?; let origin_folder = origin_folders.local_content_path; let origin_exe = origin_folders.exe_path; let game_folders = origin_folder.join("LocalContent").read_dir()?; @@ -164,18 +165,16 @@ fn get_exe_path() -> Option { use winreg::enums::*; use winreg::RegKey; //Computer\HKEY_CLASSES_ROOT\eadm\shell\open\command - - let hklm = RegKey::predef(HKEY_CLASSES_ROOT); - if let Ok(launcher_key) = hklm.open_subkey("eadm\\shell\\open\\command") { - let launcher_string: Result = launcher_key.get_value(""); - if let Ok(launcher_string) = launcher_string { - let path = Path::new(&launcher_string[1..launcher_string.len() - 6]); - if path.exists() { - return Some(path.to_path_buf()); - } - } - } - None + RegKey::predef(HKEY_CLASSES_ROOT) + .open_subkey("eadm\\shell\\open\\command") + .and_then(|launcher_key| launcher_key.get_value("")) + .ok() + .and_then(|value: String| { + value + .get(1..value.len() - 6) + .map(|path_str| Path::new(path_str).to_path_buf()) + }) + .filter(|path| path.exists()) } impl GamesPlatform for OriginPlatform {