Add support for legendary games

This commit is contained in:
Philip Kristoffersen
2021-09-18 09:27:26 +02:00
parent aa4c6304f3
commit de4d6d0973
8 changed files with 164 additions and 51 deletions
+14
View File
@@ -0,0 +1,14 @@
use super::legendary_game::LegendaryGame;
use serde_json::from_str;
use std::process::Command;
use std::{error::Error};
pub fn get_legendary_games() -> Result<Vec<LegendaryGame>, Box<dyn Error>> {
let legendary_command = Command::new("legendary")
.arg("list-installed")
.arg("--json")
.output()?;
let json = String::from_utf8_lossy(&legendary_command.stdout);
let legendary_ouput = from_str(&json)?;
Ok(legendary_ouput)
}
+38
View File
@@ -0,0 +1,38 @@
use serde::{Deserialize, Serialize};
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LegendaryGame {
pub app_name: String,
pub can_run_offline: bool,
pub title: String,
pub is_dlc: bool,
pub install_path: String,
pub executable: String,
}
impl From<&LegendaryGame> for ShortcutOwned {
fn from(game: &LegendaryGame) -> Self {
let exe = format!("\"{}\\{}\"", game.install_path, game.executable);
let launch = format!("legendary launch {}", game.app_name);
let mut start_dir = game.install_path.clone();
if !game.install_path.starts_with("\"") {
start_dir = format!("\"{}\"", game.install_path);
}
let shortcut = Shortcut::new(
0,
game.title.as_str(),
launch.as_str(),
start_dir.as_str(),
exe.as_str(),
"",
"",
);
let mut owned_shortcut = shortcut.to_owned();
owned_shortcut.tags.push("Legendary".to_owned());
owned_shortcut.tags.push("Ready TO Play".to_owned());
owned_shortcut.tags.push("Installed".to_owned());
owned_shortcut
}
}
+5
View File
@@ -0,0 +1,5 @@
mod legendary_game;
mod get_legendary_games;
pub use get_legendary_games::*;
pub use legendary_game::*;