mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Add option to only import installed games (#313)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use nom::{
|
use nom::{
|
||||||
bytes::{
|
bytes::{
|
||||||
complete::{take_until, take_while},
|
complete::{tag, take_until, take_while},
|
||||||
streaming::take,
|
streaming::take,
|
||||||
},
|
},
|
||||||
character::is_alphanumeric,
|
character::is_alphanumeric,
|
||||||
@@ -11,6 +11,7 @@ use nom::{
|
|||||||
pub(crate) struct NamesAndId {
|
pub(crate) struct NamesAndId {
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
pub(crate) id: String,
|
pub(crate) id: String,
|
||||||
|
pub(crate) installed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_db<'a>(content: &'a [u8]) -> nom::IResult<&'a [u8], Vec<NamesAndId>> {
|
pub(crate) fn parse_db<'a>(content: &'a [u8]) -> nom::IResult<&'a [u8], Vec<NamesAndId>> {
|
||||||
@@ -26,12 +27,24 @@ fn parse_game(i: &[u8]) -> nom::IResult<&[u8], NamesAndId> {
|
|||||||
.last()
|
.last()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let id = String::from_utf8_lossy(id_bytes).to_string();
|
let id = String::from_utf8_lossy(id_bytes).to_string();
|
||||||
|
let (i, _taken) = take_until("IsInstalled")(i)?;
|
||||||
|
let (i, _taken) = tag("IsInstalled")(i)?;
|
||||||
|
let installed = match i.get(1) {
|
||||||
|
Some(1u8) => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
let (i, _taken) = take_until("InstallSizeGroup")(i)?;
|
let (i, _taken) = take_until("InstallSizeGroup")(i)?;
|
||||||
let (i, _taken) = take_until("Name")(i)?;
|
let (i, _taken) = take_until("Name")(i)?;
|
||||||
let (i, _taken) = take(4usize)(i)?;
|
let (i, _taken) = take(4usize)(i)?;
|
||||||
let (i, _taken) = take_while(|b| !is_alphanumeric(b))(i)?;
|
let (i, _taken) = take_while(|b| !is_alphanumeric(b))(i)?;
|
||||||
let (i, name_bytes) = take_while(|b| b != 0)(i)?;
|
let (i, name_bytes) = take_while(|b| b != 0)(i)?;
|
||||||
let name = String::from_utf8_lossy(name_bytes).to_string();
|
let name = String::from_utf8_lossy(name_bytes).to_string();
|
||||||
IResult::Ok((i, NamesAndId { id, name }))
|
IResult::Ok((
|
||||||
|
i,
|
||||||
|
NamesAndId {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
installed,
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,15 @@ pub struct PlaynitePlatform {
|
|||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
pub struct PlayniteSettings {
|
pub struct PlayniteSettings {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
pub installed_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlayniteSettings {
|
impl Default for PlayniteSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { enabled: true }
|
Self {
|
||||||
|
enabled: true,
|
||||||
|
installed_only: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +61,12 @@ impl GamesPlatform for PlaynitePlatform {
|
|||||||
fn render_ui(&mut self, ui: &mut egui::Ui) {
|
fn render_ui(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.heading("Playnite");
|
ui.heading("Playnite");
|
||||||
ui.checkbox(&mut self.settings.enabled, "Import from Playnite");
|
ui.checkbox(&mut self.settings.enabled, "Import from Playnite");
|
||||||
|
if self.settings.enabled {
|
||||||
|
ui.checkbox(
|
||||||
|
&mut self.settings.installed_only,
|
||||||
|
"Only import installed games",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +88,13 @@ impl PlaynitePlatform {
|
|||||||
let games_bytes = std::fs::read(&games_file_path).unwrap();
|
let games_bytes = std::fs::read(&games_file_path).unwrap();
|
||||||
let (_, games) = parse_db(&games_bytes).map_err(|e| eyre::eyre!(e.to_string()))?;
|
let (_, games) = parse_db(&games_bytes).map_err(|e| eyre::eyre!(e.to_string()))?;
|
||||||
for game in games {
|
for game in games {
|
||||||
res.push(PlayniteGame {
|
if game.installed || !self.settings.installed_only {
|
||||||
id: game.id,
|
res.push(PlayniteGame {
|
||||||
launcher_path: launcher_path.clone().into(),
|
id: game.id,
|
||||||
name: game.name,
|
launcher_path: launcher_path.clone().into(),
|
||||||
});
|
name: game.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|||||||
Reference in New Issue
Block a user