Skip to content

Commit

Permalink
Windows clippy (#322)
Browse files Browse the repository at this point in the history
* Remove indexing

* Remove more indexing and expects on windows
  • Loading branch information
PhilipK authored Jan 8, 2023
1 parent fb68a32 commit 8dc87f9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/platforms/egs/get_manifests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fn get_manifest_item(dir_entry: DirEntry, _path: Option<PathBuf>) -> Option<Mani
None
}

#[cfg(target_family = "unix")]
fn replace_with_dosdevices(compat_folder: &Path, location: &str) -> String {
let drive = location.get(0..2).map(|drive| drive.to_lowercase());
let rest_path = location.get(3..).map(|rest| rest.replace('\\', "/"));
Expand Down
42 changes: 16 additions & 26 deletions src/platforms/egs/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
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<String, _> = 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<EpicPaths> {
Expand Down
25 changes: 12 additions & 13 deletions src/platforms/origin/origin_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl NeedsPorton<OriginPlatform> for OriginGame {

impl OriginPlatform {
fn get_shortcuts(&self) -> eyre::Result<Vec<OriginGame>> {
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()?;
Expand Down Expand Up @@ -164,18 +165,16 @@ fn get_exe_path() -> Option<PathBuf> {
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<String, _> = 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 {
Expand Down

0 comments on commit 8dc87f9

Please sign in to comment.