mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
fix: get games list as json from lutris (#191)
This commit is contained in:
@@ -1,32 +1,15 @@
|
||||
use super::lutris_game::LutrisGame;
|
||||
|
||||
pub fn parse_lutris_games(input: &str) -> Vec<LutrisGame> {
|
||||
input
|
||||
.split('\n')
|
||||
.into_iter()
|
||||
.filter(|s| !s.is_empty())
|
||||
.filter_map(parse_line)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn parse_line(input: &str) -> Option<LutrisGame> {
|
||||
let mut sections = input.split('|');
|
||||
if sections.clone().count() < 4 {
|
||||
return None;
|
||||
let games = serde_json::from_str::<Vec<LutrisGame>>(&input);
|
||||
match games {
|
||||
Ok(games) => {
|
||||
return games
|
||||
}
|
||||
Err(_err) => {
|
||||
return Vec::new()
|
||||
}
|
||||
}
|
||||
let index = sections.next().unwrap().trim();
|
||||
let name = sections.next().unwrap().trim();
|
||||
let id = sections.next().unwrap().trim();
|
||||
let platform = sections.next().unwrap().trim();
|
||||
|
||||
Some(LutrisGame {
|
||||
id: id.to_string(),
|
||||
index: index.to_string(),
|
||||
name: name.to_string(),
|
||||
platform: platform.to_string(),
|
||||
//theese will be added by the platform class
|
||||
settings: None,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -39,7 +22,7 @@ mod tests {
|
||||
|
||||
let games = parse_lutris_games(content);
|
||||
|
||||
assert_eq!(19, games.len());
|
||||
assert_eq!(6, games.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -48,7 +31,7 @@ mod tests {
|
||||
|
||||
let games = parse_lutris_games(content);
|
||||
|
||||
assert_eq!(games[0].index, "7");
|
||||
assert_eq!(games[0].id, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -57,7 +40,7 @@ mod tests {
|
||||
|
||||
let games = parse_lutris_games(content);
|
||||
|
||||
assert_eq!(games[1].name, "Cave Story+");
|
||||
assert_eq!(games[5].name, "The Witcher 3: Wild Hunt - Game of the Year Edition");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -66,7 +49,7 @@ mod tests {
|
||||
|
||||
let games = parse_lutris_games(content);
|
||||
|
||||
assert_eq!(games[3].id, "dicey-dungeons");
|
||||
assert_eq!(games[5].slug, "the-witcher-3-wild-hunt-game-of-the-year-edition");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,6 +58,6 @@ mod tests {
|
||||
|
||||
let games = parse_lutris_games(content);
|
||||
|
||||
assert_eq!(games[18].platform, "steam");
|
||||
assert_eq!(games[1].runner, "steam");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
use crate::lutris::settings::LutrisSettings;
|
||||
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
|
||||
|
||||
#[derive(Clone)]
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct LutrisGame {
|
||||
pub index: String,
|
||||
pub id: i64,
|
||||
pub slug: String,
|
||||
pub name: String,
|
||||
pub id: String,
|
||||
pub runner: String,
|
||||
pub platform: String,
|
||||
pub settings: Option<LutrisSettings>,
|
||||
}
|
||||
@@ -36,15 +39,15 @@ impl LutrisGame {
|
||||
.unwrap_or_default();
|
||||
if is_flatpak {
|
||||
format!(
|
||||
"run {} lutris:rungameid/{}",
|
||||
"run {} lutris:rungame/{}",
|
||||
self.settings
|
||||
.as_ref()
|
||||
.map(|s| s.flatpak_image.clone())
|
||||
.unwrap_or_default(),
|
||||
self.index
|
||||
self.slug
|
||||
)
|
||||
} else {
|
||||
format!("lutris:rungame/{}", self.id)
|
||||
format!("lutris:rungame/{}", self.slug)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ impl Platform<LutrisGame, Box<dyn Error>> for LutrisPlatform {
|
||||
let games = parse_lutris_games(output.as_str());
|
||||
let mut res = vec![];
|
||||
for mut game in games {
|
||||
if game.platform != "steam" {
|
||||
if game.runner != "steam" {
|
||||
game.settings = Some(self.settings.clone());
|
||||
res.push(game);
|
||||
}
|
||||
@@ -55,10 +55,10 @@ fn get_lutris_command_output(settings: &LutrisSettings) -> Result<String, Box<dy
|
||||
let output = if settings.flatpak {
|
||||
let flatpak_image = &settings.flatpak_image;
|
||||
let mut command = Command::new("flatpak");
|
||||
command.arg("run").arg(flatpak_image).arg("-lo").output()?
|
||||
command.arg("run").arg(flatpak_image).arg("-lo").arg("--json").output()?
|
||||
} else {
|
||||
let mut command = Command::new(&settings.executable);
|
||||
command.arg("-lo").output()?
|
||||
command.arg("-lo").arg("--json").output()?
|
||||
};
|
||||
|
||||
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
||||
|
||||
+74
-19
@@ -1,19 +1,74 @@
|
||||
7 | 7 Billion Humans | 7-billion-humans | steam | -
|
||||
1 | Cave Story+ | cave-story | steam | -
|
||||
15 | Dead Cells | dead-cells | steam | -
|
||||
6 | Dicey Dungeons | dicey-dungeons | steam | -
|
||||
12 | Finding Paradise | finding-paradise | steam | -
|
||||
17 | Griftlands | griftlands | steam | -
|
||||
4 | Gunpoint | gunpoint | steam | -
|
||||
5 | Impostor Factory | impostor-factory | steam | -
|
||||
3 | Kentucky Route Zero | kentucky-route-zero | steam | -
|
||||
13 | Monster Train | monster-train | steam | -
|
||||
19 | My Test Game | my-test-game | linux | -
|
||||
8 | Owlboy | owlboy | steam | -
|
||||
16 | Papers, Please | papers-please | steam | -
|
||||
11 | Reventure | reventure | steam | -
|
||||
2 | Slay the Spire | slay-the-spire | steam | -
|
||||
9 | Space Pirates and Zombies | space-pirates-and-zombies | steam | -
|
||||
10 | The Detail | the-detail | steam | -
|
||||
14 | The Henry Stickmin Collection | the-henry-stickmin-collection | steam | -
|
||||
18 | Vampire Survivors | vampire-survivors | steam | -
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"slug": "aperture-desk-job",
|
||||
"name": "Aperture Desk Job",
|
||||
"runner": "steam",
|
||||
"platform": "Linux",
|
||||
"year": null,
|
||||
"directory": null,
|
||||
"hidden": false,
|
||||
"playtime": null,
|
||||
"lastplayed": null
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"slug": "dark-souls-iii",
|
||||
"name": "DARK SOULS\u2122 III",
|
||||
"runner": "steam",
|
||||
"platform": "Linux",
|
||||
"year": null,
|
||||
"directory": null,
|
||||
"hidden": false,
|
||||
"playtime": null,
|
||||
"lastplayed": null
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"slug": "disco-elysium",
|
||||
"name": "Disco Elysium",
|
||||
"runner": "wine",
|
||||
"platform": "Windows",
|
||||
"year": 2019,
|
||||
"directory": "/home/deck/Games/gog/disco-elysium",
|
||||
"hidden": false,
|
||||
"playtime": "0:01:16",
|
||||
"lastplayed": "2022-07-25 23:21:56"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"slug": "hollow-knight",
|
||||
"name": "Hollow Knight",
|
||||
"runner": "steam",
|
||||
"platform": "Linux",
|
||||
"year": null,
|
||||
"directory": null,
|
||||
"hidden": false,
|
||||
"playtime": null,
|
||||
"lastplayed": null
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"slug": "lumino-city",
|
||||
"name": "Lumino City",
|
||||
"runner": "wine",
|
||||
"platform": "Windows",
|
||||
"year": null,
|
||||
"directory": "/home/deck/Games/gog/lumino-city",
|
||||
"hidden": false,
|
||||
"playtime": null,
|
||||
"lastplayed": null
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"slug": "the-witcher-3-wild-hunt-game-of-the-year-edition",
|
||||
"name": "The Witcher 3: Wild Hunt - Game of the Year Edition",
|
||||
"runner": "wine",
|
||||
"platform": "Windows",
|
||||
"year": 2015,
|
||||
"directory": "/home/deck/Games/gog/the-witcher-3-wild-hunt-game-of-the-year-edition",
|
||||
"hidden": false,
|
||||
"playtime": "0:00:54",
|
||||
"lastplayed": "2022-07-25 23:20:40"
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user