mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
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:
@@ -34,6 +34,8 @@ pub(crate) fn get_egs_manifests(
|
||||
let manifest_dir_path = get_manifest_dir_path(settings)?;
|
||||
let manifest_dir_result = std::fs::read_dir(&manifest_dir_path);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let launcher_path = launcher_location_from_registry().unwrap_or_else(guess_default_launcher_location);
|
||||
match manifest_dir_result {
|
||||
Ok(manifest_dir) => {
|
||||
let manifests = manifest_dir
|
||||
@@ -59,6 +61,10 @@ pub(crate) fn get_egs_manifests(
|
||||
|| settings.safe_launch.contains(&manifest.get_key())
|
||||
{
|
||||
manifest.safe_launch = true;
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
manifest.launcher_path = Some(launcher_path.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(manifests)
|
||||
@@ -84,7 +90,7 @@ fn get_manifest_dir_path(
|
||||
});
|
||||
}
|
||||
} else {
|
||||
let path = get_default_location();
|
||||
let path = get_default_manifests_location();
|
||||
|
||||
match path {
|
||||
Some(path) => Ok(path.to_str().unwrap().to_string()),
|
||||
@@ -93,7 +99,7 @@ fn get_manifest_dir_path(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_default_location() -> Option<PathBuf> {
|
||||
pub fn get_default_manifests_location() -> Option<PathBuf> {
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
//No path defined for epic gamestore, and we cannot guess on linux
|
||||
@@ -102,9 +108,9 @@ pub fn get_default_location() -> Option<PathBuf> {
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let path = match location_from_registry() {
|
||||
let path = match manifest_location_from_registry() {
|
||||
Some(path) => path,
|
||||
None => guess_default_location(),
|
||||
None => guess_default_manifest_location(),
|
||||
};
|
||||
if path.exists() {
|
||||
Some(path)
|
||||
@@ -113,8 +119,9 @@ pub fn get_default_location() -> Option<PathBuf> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn location_from_registry() -> Option<PathBuf> {
|
||||
fn manifest_location_from_registry() -> Option<PathBuf> {
|
||||
use winreg::enums::*;
|
||||
use winreg::RegKey;
|
||||
|
||||
@@ -132,7 +139,7 @@ fn location_from_registry() -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn guess_default_location() -> PathBuf {
|
||||
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");
|
||||
@@ -146,6 +153,42 @@ fn guess_default_location() -> PathBuf {
|
||||
path
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
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
|
||||
}
|
||||
|
||||
#[cfg(target_os = "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())
|
||||
.join("Program Files (x86)")
|
||||
.join("Epic Games")
|
||||
.join("Launcher")
|
||||
.join("Portal")
|
||||
.join("Binaries")
|
||||
.join("Win64")
|
||||
.join("EpicGamesLauncher.exe");
|
||||
path
|
||||
}
|
||||
|
||||
fn is_game_installed(manifest: &ManifestItem) -> bool {
|
||||
Path::new(manifest.manifest_location.as_str()).exists()
|
||||
}
|
||||
@@ -165,3 +208,23 @@ fn get_manifest_item(dir_entry: DirEntry) -> Option<ManifestItem> {
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
//Commented out because it will change from machine to machine
|
||||
// #[cfg(test)]
|
||||
// pub mod test{
|
||||
// use super::guess_default_launcher_location;
|
||||
// use super::launcher_location_from_registry;
|
||||
|
||||
// #[test]
|
||||
// pub fn test_launcher_registry(){
|
||||
// let launcher = launcher_location_from_registry();
|
||||
// assert_eq!(Some(std::path::Path::new("C:\\Program Files (x86)\\Epic Games\\Launcher\\Portal\\Binaries\\Win64\\EpicGamesLauncher.exe").to_path_buf()),launcher);
|
||||
// }
|
||||
|
||||
|
||||
// #[test]
|
||||
// pub fn test_launcher_guess(){
|
||||
// let launcher = guess_default_launcher_location();
|
||||
// assert_eq!(std::path::Path::new("C:\\Program Files (x86)\\Epic Games\\Launcher\\Portal\\Binaries\\Win64\\EpicGamesLauncher.exe").to_path_buf(),launcher);
|
||||
// }
|
||||
// }
|
||||
+12
-10
@@ -1,9 +1,9 @@
|
||||
use std::{collections::HashMap, path::Path};
|
||||
use std::{collections::HashMap, path::{Path, PathBuf}};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{Deserialize};
|
||||
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub(crate) struct ManifestItem {
|
||||
#[serde(alias = "LaunchExecutable")]
|
||||
pub launch_executable: String,
|
||||
@@ -34,6 +34,9 @@ pub(crate) struct ManifestItem {
|
||||
|
||||
#[serde(default)]
|
||||
pub safe_launch: bool,
|
||||
|
||||
//This is not acutally in the manifest, but it will get added by get_manifests.rs
|
||||
pub launcher_path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn exe_shortcut(manifest: ManifestItem) -> ShortcutOwned {
|
||||
@@ -59,11 +62,11 @@ fn launcher_shortcut(manifest: ManifestItem) -> ShortcutOwned {
|
||||
Shortcut::new(
|
||||
"0",
|
||||
manifest.display_name.as_str(),
|
||||
url.as_str(),
|
||||
"",
|
||||
manifest.launcher_path.as_ref().map(|p| p.to_string_lossy().to_string()).unwrap_or_default().as_str(),
|
||||
manifest.launcher_path.map(|p| p.parent().unwrap_or(Path::new("")).to_string_lossy().to_string()).unwrap_or_default().as_str(),
|
||||
icon.as_str(),
|
||||
"",
|
||||
"",
|
||||
url.as_str(),
|
||||
)
|
||||
.to_owned()
|
||||
}
|
||||
@@ -147,9 +150,8 @@ mod tests {
|
||||
let mut manifest: ManifestItem = serde_json::from_str(json).unwrap();
|
||||
manifest.is_managed = true;
|
||||
let shortcut: ShortcutOwned = manifest.clone().into();
|
||||
|
||||
assert_eq!(shortcut.exe, manifest.get_launch_url());
|
||||
assert_eq!(shortcut.launch_options, "");
|
||||
|
||||
assert_eq!(shortcut.launch_options, manifest.get_launch_url());
|
||||
}
|
||||
#[test]
|
||||
fn generates_shortcut_not_managed() {
|
||||
@@ -175,7 +177,7 @@ mod tests {
|
||||
let shortcut: ShortcutOwned = manifest.into();
|
||||
|
||||
let expected ="com.epicgames.launcher://apps/2a09fb19b47f46dfb11ebd382f132a8f%3A88f4bb0bb06e4962a2042d5e20fb6ace%3A63a665088eb1480298f1e57943b225d8?action=launch&silent=true";
|
||||
let actual = shortcut.exe;
|
||||
let actual = shortcut.launch_options;
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ mod manifest_item;
|
||||
mod settings;
|
||||
|
||||
pub use epic_platform::*;
|
||||
pub use get_manifests::get_default_location;
|
||||
pub use get_manifests::get_default_manifests_location;
|
||||
use get_manifests::get_egs_manifests;
|
||||
pub(crate) use manifest_item::*;
|
||||
pub use settings::EpicGamesLauncherSettings;
|
||||
|
||||
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct EpicGamesLauncherSettings {
|
||||
pub enabled: bool,
|
||||
pub location: Option<String>,
|
||||
pub launcher_exe : Option<String>,
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
pub create_symlinks: bool,
|
||||
|
||||
Reference in New Issue
Block a user