Open urls with exe (#146)

* Launch Epic Games in safe mode through the exe

* Launch through exe for amazon games

* Remove unused comment

* Launch Uplay games through exe

* Fix epic tests

* Always launch origin games through the exe

* Fix that compat_folder is an option on unix
This commit is contained in:
Philip Kristoffersen
2022-05-22 14:53:23 +02:00
committed by GitHub
parent f2c83cb107
commit d1389fd757
12 changed files with 233 additions and 56 deletions
+12 -16
View File
@@ -6,7 +6,7 @@ use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
pub struct OriginGame {
pub id: String,
pub title: String,
pub origin_location: Option<PathBuf>,
pub origin_location: PathBuf,
pub origin_compat_folder: Option<PathBuf>,
}
@@ -20,21 +20,17 @@ impl From<OriginGame> for ShortcutOwned {
"\"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"",
game.id)
};
let mut owned_shortcut = if let Some(origin_location) = game.origin_location {
let origin_location = format!("\"{}\"", origin_location.to_string_lossy());
Shortcut::new(
"0",
game.title.as_str(),
&origin_location,
"",
"",
"",
launch.as_str(),
)
.to_owned()
} else {
Shortcut::new("0", game.title.as_str(), launch.as_str(), "", "", "", "").to_owned()
};
let origin_location = format!("\"{}\"",game.origin_location.to_string_lossy());
let mut owned_shortcut = Shortcut::new(
"0",
game.title.as_str(),
&origin_location,
"",
"",
"",
launch.as_str(),
)
.to_owned();
owned_shortcut.tags.push("Origin".to_owned());
owned_shortcut.tags.push("Ready TO Play".to_owned());
owned_shortcut.tags.push("Installed".to_owned());
+41 -13
View File
@@ -28,13 +28,13 @@ impl Platform<OriginGame, OriginErrors> for OriginPlatform {
fn get_shortcuts(&self) -> Result<Vec<OriginGame>, OriginErrors> {
let origin_folders = get_default_locations();
if origin_folders.local_content_path.is_none() {
if origin_folders.is_none() {
return Err(OriginErrors::PathNotFound {
path: "Default path".to_string(),
});
}
let origin_folder = origin_folders.local_content_path.unwrap();
let origin_folders = origin_folders.unwrap();
let origin_folder = origin_folders.local_content_path;
let origin_exe = origin_folders.exe_path;
let game_folders = origin_folder.join("LocalContent").read_dir().map_err(|e| {
OriginErrors::CouldNotReadGameDir {
@@ -115,15 +115,15 @@ fn parse_id_from_file(i: &str) -> nom::IResult<&str, &str> {
#[derive(Default)]
struct OriginPathData {
//~/.steam/steam/steamapps/compatdata/X/pfx/drive_c/Program Files (x86)/Origin/Origin.exe
exe_path: Option<PathBuf>,
exe_path: PathBuf,
//~/.steam/steam/steamapps/compatdata/X/pfx/drive_c/ProgramData/Origin/LocalContent
local_content_path: Option<PathBuf>,
local_content_path: PathBuf,
//~/.steam/steam/steamapps/compatdata/X
compat_folder: Option<PathBuf>,
}
#[cfg(target_family = "unix")]
fn get_default_locations() -> OriginPathData {
fn get_default_locations() -> Option<OriginPathData> {
let mut res = OriginPathData::default();
if let Ok(home) = std::env::var("HOME") {
let compat_folder_path = Path::new(&home)
@@ -150,29 +150,57 @@ fn get_default_locations() -> OriginPathData {
.join("Origin");
if origin_exe_path.exists() && origin_local_content.exists() {
res.exe_path = Some(origin_exe_path);
res.local_content_path = Some(origin_local_content);
res.exe_path = origin_exe_path;
res.local_content_path = origin_local_content;
res.compat_folder = Some(dir.path().to_path_buf());
return Some(res);
}
}
}
}
res
None
}
#[cfg(target_os = "windows")]
fn get_default_locations() -> OriginPathData {
fn get_default_locations() -> Option<OriginPathData> {
let mut res = OriginPathData::default();
let key = "PROGRAMDATA";
let program_data = std::env::var(key);
if let Ok(program_data) = program_data {
let origin_folder = Path::new(&program_data).join("Origin");
if origin_folder.exists() {
res.local_content_path = Some(origin_folder);
res.local_content_path = origin_folder;
} else {
return None;
}
let exe_path = get_exe_path();
if exe_path.is_none() {
return None;
} else {
res.exe_path = exe_path.unwrap();
}
}
res
Some(res)
}
#[cfg(target_os = "windows")]
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]);
println!("{:?}",path);
if path.exists() {
return Some(path.to_path_buf());
}
}
}
None
}
#[derive(Debug, Fail)]