feat: Add itch.io as possible platform

This commit is contained in:
Philip Kristoffersen
2021-09-29 22:08:15 +02:00
parent 750379202e
commit 05dbaa95e4
8 changed files with 60 additions and 11 deletions
Generated
+13
View File
@@ -200,6 +200,18 @@ version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82cf52a69f51e16cffda2993f68b33a0fafd0d664163f87fa80e5e4fec2fc232" checksum = "82cf52a69f51e16cffda2993f68b33a0fafd0d664163f87fa80e5e4fec2fc232"
[[package]]
name = "flate2"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f"
dependencies = [
"cfg-if",
"crc32fast",
"libc",
"miniz_oxide",
]
[[package]] [[package]]
name = "fltk" name = "fltk"
version = "1.2.3" version = "1.2.3"
@@ -1091,6 +1103,7 @@ dependencies = [
"config", "config",
"failure", "failure",
"fl2rust", "fl2rust",
"flate2",
"fltk", "fltk",
"nom 7.0.0", "nom 7.0.0",
"nom_locate", "nom_locate",
+1
View File
@@ -17,6 +17,7 @@ failure = "^0.1.8"
fltk = { version = "^1.2", features = ["fltk-bundled"], optional = true } fltk = { version = "^1.2", features = ["fltk-bundled"], optional = true }
nom = "^7.0.*" nom = "^7.0.*"
nom_locate = "^3.0.*" nom_locate = "^3.0.*"
flate2 = "^1.0.22"
[build-dependencies] [build-dependencies]
fl2rust = { version = "0.4", optional = true } fl2rust = { version = "0.4", optional = true }
+1 -1
View File
@@ -27,7 +27,7 @@ pub enum EpicGamesManifestsError {
ReadDirError { path: String, error: std::io::Error }, ReadDirError { path: String, error: std::io::Error },
} }
pub fn get_egs_manifests( pub(crate) fn get_egs_manifests(
settings: &EpicGamesLauncherSettings, settings: &EpicGamesLauncherSettings,
) -> Result<Vec<ManifestItem>, EpicGamesManifestsError> { ) -> Result<Vec<ManifestItem>, EpicGamesManifestsError> {
use EpicGamesManifestsError::*; use EpicGamesManifestsError::*;
+1 -1
View File
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
use steam_shortcuts_util::{Shortcut, shortcut::ShortcutOwned}; use steam_shortcuts_util::{Shortcut, shortcut::ShortcutOwned};
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ManifestItem { pub(crate) struct ManifestItem {
#[serde(alias = "LaunchExecutable")] #[serde(alias = "LaunchExecutable")]
pub launch_executable: String, pub launch_executable: String,
+1
View File
@@ -4,6 +4,7 @@ use nom::{
IResult, IResult,
}; };
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct DbPaths<'a> { pub(crate) struct DbPaths<'a> {
pub(crate) base_path: &'a str, pub(crate) base_path: &'a str,
pub(crate) path: &'a str, pub(crate) path: &'a str,
+31 -9
View File
@@ -1,7 +1,12 @@
use super::butler_db_parser::*; use super::butler_db_parser::*;
use super::receipt::Receipt;
use super::{ItchGame, ItchSettings}; use super::{ItchGame, ItchSettings};
use crate::platform::Platform; use crate::platform::Platform;
use _core::iter::FromIterator;
use failure::*; use failure::*;
use flate2::read::GzDecoder;
use std::collections::HashSet;
use std::io::prelude::*;
use std::path::Path; use std::path::Path;
pub struct ItchPlatform { pub struct ItchPlatform {
@@ -36,7 +41,7 @@ impl Platform<ItchGame, ItchErrors> for ItchPlatform {
let shortcut_bytes = std::fs::read(&itch_db_location).unwrap(); let shortcut_bytes = std::fs::read(&itch_db_location).unwrap();
let res = match parse_butler_db(&shortcut_bytes) { let paths = match parse_butler_db(&shortcut_bytes) {
Ok((_, shortcuts)) => Ok(shortcuts), Ok((_, shortcuts)) => Ok(shortcuts),
Err(e) => Err(ItchErrors::ParseError { Err(e) => Err(ItchErrors::ParseError {
error: e.to_string(), error: e.to_string(),
@@ -44,18 +49,35 @@ impl Platform<ItchGame, ItchErrors> for ItchPlatform {
}), }),
}?; }?;
let res = res //This is done to remove douplicates
.iter() let paths: HashSet<&DbPaths> = HashSet::from_iter(paths.iter());
.map(|paths| ItchGame {
install_path: paths.base_path.to_owned(), let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect();
executable: paths.path.to_owned(),
title: paths.path.to_owned(),
})
.collect();
Ok(res) Ok(res)
} }
} }
fn dbpath_to_game(paths: &DbPaths<'_>) -> Option<ItchGame> {
let recipt = Path::new(paths.base_path)
.join(".itch")
.join("receipt.json.gz");
if !&recipt.exists() {
return None;
}
let gz_bytes = std::fs::read(&recipt).unwrap();
let mut d = GzDecoder::new(gz_bytes.as_slice());
let mut s = String::new();
d.read_to_string(&mut s).unwrap();
let receipt_op: Option<Receipt> = serde_json::from_str(&s).ok();
receipt_op.map(|re| ItchGame {
install_path: paths.base_path.to_owned(),
executable: paths.path.to_owned(),
title: re.game.title,
})
}
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn get_default_location() -> String { fn get_default_location() -> String {
//If we don't have a home drive we have to just die //If we don't have a home drive we have to just die
+1
View File
@@ -2,6 +2,7 @@ mod settings;
mod itch_game; mod itch_game;
mod itch_platform; mod itch_platform;
mod butler_db_parser; mod butler_db_parser;
mod receipt;
pub use settings::*; pub use settings::*;
pub use itch_game::*; pub use itch_game::*;
+11
View File
@@ -0,0 +1,11 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub(crate) struct Receipt{
pub game:Game,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub(crate) struct Game{
pub title:String
}