-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from PhilipK/lutris-support
Lutris support
- Loading branch information
Showing
11 changed files
with
213 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ create_symlinks = true | |
[steamgrid_db] | ||
enabled = true | ||
prefer_animated = false | ||
|
||
[lutris] | ||
enabled = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use super::lutris_game::LutrisGame; | ||
|
||
pub fn parse_lutris_games<'a>(input: &'a str) -> Vec<LutrisGame> { | ||
input | ||
.split("\n") | ||
.into_iter() | ||
.filter(|s| !s.is_empty()) | ||
.filter_map(parse_line) | ||
.collect() | ||
} | ||
|
||
fn parse_line<'a>(input: &'a str) -> Option<LutrisGame> { | ||
let mut sections = input.split("|"); | ||
if sections.clone().count() < 4 { | ||
return None; | ||
} | ||
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(), | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn can_parse_output() { | ||
let content = include_str!("test_output.txt"); | ||
|
||
let games = parse_lutris_games(content); | ||
|
||
assert_eq!(19, games.len()); | ||
} | ||
|
||
#[test] | ||
fn reads_index() { | ||
let content = include_str!("test_output.txt"); | ||
|
||
let games = parse_lutris_games(content); | ||
|
||
assert_eq!(games[0].index, "7"); | ||
} | ||
|
||
#[test] | ||
fn reads_name() { | ||
let content = include_str!("test_output.txt"); | ||
|
||
let games = parse_lutris_games(content); | ||
|
||
assert_eq!(games[1].name, "Cave Story+"); | ||
} | ||
|
||
#[test] | ||
fn reads_id() { | ||
let content = include_str!("test_output.txt"); | ||
|
||
let games = parse_lutris_games(content); | ||
|
||
assert_eq!(games[3].id, "dicey-dungeons"); | ||
} | ||
|
||
#[test] | ||
fn reads_platform() { | ||
let content = include_str!("test_output.txt"); | ||
|
||
let games = parse_lutris_games(content); | ||
|
||
assert_eq!(games[18].platform, "steam"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut}; | ||
|
||
#[derive(Clone)] | ||
pub struct LutrisGame { | ||
pub index: String, | ||
pub name: String, | ||
pub id: String, | ||
pub platform: String, | ||
} | ||
|
||
impl From<LutrisGame> for ShortcutOwned { | ||
fn from(game: LutrisGame) -> Self { | ||
let options = format!("lutris:rungame/{}", game.id); | ||
Shortcut::new( | ||
0, | ||
game.name.as_str(), | ||
"lutris", | ||
"", | ||
"", | ||
"", | ||
&options.as_str(), | ||
) | ||
.to_owned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::game_list_parser::parse_lutris_games; | ||
use super::lutris_game::LutrisGame; | ||
use super::settings::LutrisSettings; | ||
use crate::platform::{Platform, SettingsValidity}; | ||
use std::error::Error; | ||
use std::process::Command; | ||
|
||
pub struct LutrisPlatform { | ||
pub settings: LutrisSettings, | ||
} | ||
|
||
|
||
impl Platform<LutrisGame, Box<dyn Error>> for LutrisPlatform { | ||
fn enabled(&self) -> bool { | ||
self.settings.enabled | ||
} | ||
|
||
fn name(&self) -> &str { | ||
"Lutris" | ||
} | ||
|
||
fn get_shortcuts(&self) -> Result<Vec<LutrisGame>, Box<dyn Error>> { | ||
let default_lutris_exe = "lutris".to_string(); | ||
let lutris_executable = self.settings.executable.as_ref().unwrap_or(&default_lutris_exe); | ||
let lutris_command = Command::new(lutris_executable).arg("-lo").output()?; | ||
let output = String::from_utf8_lossy(&lutris_command.stdout).to_string(); | ||
let games = parse_lutris_games(output.as_str()); | ||
let mut res = vec![]; | ||
for game in games { | ||
if game.platform != "steam" { | ||
res.push(game); | ||
} | ||
} | ||
Ok(res) | ||
} | ||
|
||
#[cfg(target_family = "unix")] | ||
fn create_symlinks(&self) -> bool { | ||
false | ||
} | ||
|
||
fn settings_valid(&self) -> crate::platform::SettingsValidity { | ||
let shortcuts_res = self.get_shortcuts(); | ||
match shortcuts_res { | ||
Ok(_) => SettingsValidity::Valid, | ||
Err(err) => SettingsValidity::Invalid { | ||
reason: format!("{}", err), | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod game_list_parser; | ||
pub mod lutris_game; | ||
pub mod lutris_platform; | ||
pub mod settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use serde::{Serialize,Deserialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize,Clone)] | ||
pub struct LutrisSettings { | ||
pub enabled: bool, | ||
pub executable: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 | - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod egs; | ||
mod gog; | ||
mod itch; | ||
mod lutris; | ||
mod legendary; | ||
mod origin; | ||
mod platform; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters