mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 14:03:42 +02:00
Launch games through heroic launcher (#151)
* Add option to launch heroic games through launcher * Add ui * Let users choose which game to launch through Heroic
This commit is contained in:
+58
-31
@@ -1,9 +1,10 @@
|
||||
use std::path::Path;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::heroic_platform::InstallationMode;
|
||||
use serde::Deserialize;
|
||||
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct HeroicGame {
|
||||
pub app_name: String,
|
||||
pub title: String,
|
||||
@@ -11,6 +12,10 @@ pub struct HeroicGame {
|
||||
pub install_path: String,
|
||||
pub executable: String,
|
||||
pub launch_parameters: String,
|
||||
#[serde(skip_deserializing)]
|
||||
pub install_mode: Option<InstallationMode>,
|
||||
#[serde(skip_deserializing)]
|
||||
pub launch_through_heroic: bool,
|
||||
}
|
||||
|
||||
impl HeroicGame {
|
||||
@@ -23,41 +28,63 @@ impl HeroicGame {
|
||||
|
||||
impl From<HeroicGame> for ShortcutOwned {
|
||||
fn from(game: HeroicGame) -> Self {
|
||||
let target_path = Path::new(&game.install_path).join(game.executable);
|
||||
let mut owned_shortcut = if game.launch_through_heroic && game.install_mode.is_some() {
|
||||
let launch_parameter = format!("heroic://launch/{}", game.app_name);
|
||||
let (exe, parameter) = match game.install_mode.unwrap() {
|
||||
InstallationMode::FlatPak => (
|
||||
"flatpak",
|
||||
format!("run com.heroicgameslauncher.hgl {}", launch_parameter),
|
||||
),
|
||||
InstallationMode::UserBin => ("heroic", launch_parameter),
|
||||
};
|
||||
Shortcut::new(
|
||||
"0",
|
||||
game.title.as_str(),
|
||||
exe,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
parameter.as_str(),
|
||||
)
|
||||
.to_owned()
|
||||
} else {
|
||||
let target_path = Path::new(&game.install_path).join(game.executable);
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
let mut target = target_path.to_string_lossy().to_string();
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
if !target.starts_with('\"') && !target.ends_with('\"') {
|
||||
target = format!("\"{}\"", target);
|
||||
#[cfg(target_family = "unix")]
|
||||
let mut target = target_path.to_string_lossy().to_string();
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
if !target.starts_with('\"') && !target.ends_with('\"') {
|
||||
target = format!("\"{}\"", target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_family = "unix")]
|
||||
let mut install_path = game.install_path.to_string();
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
if !install_path.starts_with('\"') && !install_path.ends_with('\"') {
|
||||
install_path = format!("\"{}\"", install_path);
|
||||
#[cfg(target_family = "unix")]
|
||||
let mut install_path = game.install_path.to_string();
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
if !install_path.starts_with('\"') && !install_path.ends_with('\"') {
|
||||
install_path = format!("\"{}\"", install_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
let install_path = game.install_path.to_string();
|
||||
#[cfg(target_os = "windows")]
|
||||
let install_path = game.install_path.to_string();
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let target = target_path.to_string_lossy().to_string();
|
||||
#[cfg(target_os = "windows")]
|
||||
let target = target_path.to_string_lossy().to_string();
|
||||
|
||||
let shortcut = Shortcut::new(
|
||||
"0",
|
||||
game.title.as_str(),
|
||||
&target,
|
||||
&install_path,
|
||||
&target,
|
||||
"",
|
||||
game.launch_parameters.as_str(),
|
||||
);
|
||||
let mut owned_shortcut = shortcut.to_owned();
|
||||
let shortcut = Shortcut::new(
|
||||
"0",
|
||||
game.title.as_str(),
|
||||
&target,
|
||||
&install_path,
|
||||
&target,
|
||||
"",
|
||||
game.launch_parameters.as_str(),
|
||||
);
|
||||
|
||||
shortcut.to_owned()
|
||||
};
|
||||
owned_shortcut.tags.push("Heroic".to_owned());
|
||||
owned_shortcut.tags.push("Ready TO Play".to_owned());
|
||||
owned_shortcut.tags.push("Installed".to_owned());
|
||||
|
||||
Reference in New Issue
Block a user