mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Add settings for EGS and SteamgridDB
This commit is contained in:
+85
-23
@@ -1,39 +1,101 @@
|
||||
use super::{EpicGamesLauncherSettings, ManifestItem};
|
||||
use std::env::{self, VarError};
|
||||
use std::error::Error;
|
||||
use std::fs::{DirEntry, File};
|
||||
use std::io::BufReader;
|
||||
use std::path::Path;
|
||||
use std::error::Error;
|
||||
use super::ManifestItem;
|
||||
|
||||
pub fn get_egs_manifests() -> Result<Vec<ManifestItem>, Box<dyn Error>> {
|
||||
let manifest_dir_path = get_manifest_dir_path()?;
|
||||
use failure::*;
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum EpicGamesManifestsError {
|
||||
#[fail(display = "Path to EpicGamesLauncher not defined, it must be defined on linux")]
|
||||
PathNotDefined,
|
||||
|
||||
#[fail(
|
||||
display = "EpicGamesLauncher path: {} could not be found. Try to specify a different path for the EpicGamesLauncher.",
|
||||
path
|
||||
)]
|
||||
PathNotFound { path: String },
|
||||
|
||||
#[fail(
|
||||
display = "Could not read EpicGamesLauncher manifest directory at {} error: {}",
|
||||
path, error
|
||||
)]
|
||||
ReadDirError { path: String, error: std::io::Error },
|
||||
}
|
||||
|
||||
pub fn get_egs_manifests(
|
||||
settings: &EpicGamesLauncherSettings,
|
||||
) -> Result<Vec<ManifestItem>, EpicGamesManifestsError> {
|
||||
use EpicGamesManifestsError::*;
|
||||
|
||||
let manifest_dir_path = get_manifest_dir_path(settings)?;
|
||||
let manifest_dir_result = std::fs::read_dir(&manifest_dir_path);
|
||||
if let Err(err) = manifest_dir_result {
|
||||
println!("Could not find manifest directory: {}", manifest_dir_path);
|
||||
return Result::Err(Box::new(err));
|
||||
|
||||
match manifest_dir_result {
|
||||
Ok(manifest_dir) => {
|
||||
let manifests = manifest_dir
|
||||
.filter_map(|dir| dir.ok())
|
||||
.filter_map(get_manifest_item)
|
||||
.filter(is_game_installed);
|
||||
Ok(manifests.collect())
|
||||
}
|
||||
Err(err) => Err(ReadDirError {
|
||||
error: err,
|
||||
path: manifest_dir_path,
|
||||
}),
|
||||
}
|
||||
let manifest_dir = manifest_dir_result?;
|
||||
let manifests = manifest_dir
|
||||
.filter_map(|dir| dir.ok())
|
||||
.filter_map(get_manifest_item)
|
||||
.filter(is_game_installed);
|
||||
Ok(manifests.collect())
|
||||
}
|
||||
|
||||
fn get_manifest_dir_path() -> Result<String, VarError> {
|
||||
let key = "SYSTEMDRIVE";
|
||||
let system_drive = env::var(key)?;
|
||||
Ok(format!(
|
||||
"{system_drive}//ProgramData//Epic//EpicGamesLauncher//Data//Manifests",
|
||||
system_drive = system_drive
|
||||
))
|
||||
fn get_manifest_dir_path(
|
||||
settings: &EpicGamesLauncherSettings,
|
||||
) -> Result<String, EpicGamesManifestsError> {
|
||||
use EpicGamesManifestsError::*;
|
||||
if let Some(location) = &settings.location {
|
||||
let path = Path::new(location).join("Data").join("Manifests");
|
||||
if path.exists() {
|
||||
return Ok(path.to_str().unwrap().to_string());
|
||||
} else {
|
||||
return Err(PathNotFound {
|
||||
path: path.to_str().unwrap().to_string(),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
//No path defined for epic gamestore, and we cannot guess on linux
|
||||
return Err(PathNotDefined);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let key = "SYSTEMDRIVE";
|
||||
let system_drive =
|
||||
env::var(key).expect("We are on windows, we must know what the SYSTEMDRIVE is");
|
||||
|
||||
let path = Path::new(system_drive.as_str())
|
||||
.join("ProgramData")
|
||||
.join("Epic")
|
||||
.join("EpicGamesLauncher")
|
||||
.join("Data")
|
||||
.join("Manifests");
|
||||
if path.exists() {
|
||||
return Ok(path.to_str().unwrap().to_string());
|
||||
} else {
|
||||
return Err(PathNotFound {
|
||||
path: path.to_str().unwrap().to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_game_installed(manifest:&ManifestItem) -> bool{
|
||||
Path::new(manifest.manifest_location.as_str()).exists()
|
||||
fn is_game_installed(manifest: &ManifestItem) -> bool {
|
||||
Path::new(manifest.manifest_location.as_str()).exists()
|
||||
}
|
||||
|
||||
fn get_manifest_item(dir_entry: DirEntry) -> Option<ManifestItem> {
|
||||
fn get_manifest_item(dir_entry: DirEntry) -> Option<ManifestItem> {
|
||||
if let Some(extension) = dir_entry.path().extension() {
|
||||
if extension.eq("item") {
|
||||
if let Ok(file) = File::open(dir_entry.path()) {
|
||||
|
||||
+2
-1
@@ -2,4 +2,5 @@ mod get_manifests;
|
||||
mod manifest_item;
|
||||
mod settings;
|
||||
pub use manifest_item::*;
|
||||
pub use get_manifests::get_egs_manifests;
|
||||
pub use get_manifests::get_egs_manifests;
|
||||
pub use settings::EpicGamesLauncherSettings;
|
||||
+6
-6
@@ -1,12 +1,12 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct EpicGamesLauncher {
|
||||
enabled: bool,
|
||||
location: Option<String>,
|
||||
pub struct EpicGamesLauncherSettings {
|
||||
pub enabled: bool,
|
||||
pub location: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for EpicGamesLauncher {
|
||||
impl Default for EpicGamesLauncherSettings {
|
||||
fn default() -> Self {
|
||||
|
||||
// On windows
|
||||
@@ -16,11 +16,11 @@ impl Default for EpicGamesLauncher {
|
||||
|
||||
|
||||
// On linux
|
||||
// We can notguess, so lets not enable by default
|
||||
// We can not guess, so lets not enable by default
|
||||
#[cfg(target_os = "linux")]
|
||||
let enabled = false;
|
||||
|
||||
EpicGamesLauncher {
|
||||
EpicGamesLauncherSettings {
|
||||
enabled,
|
||||
location: None,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
mod legendary_game;
|
||||
mod get_legendary_games;
|
||||
mod settings;
|
||||
|
||||
pub use get_legendary_games::*;
|
||||
pub use legendary_game::*;
|
||||
pub use legendary_game::*;
|
||||
pub use settings::*;
|
||||
@@ -0,0 +1,16 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct LegendarySettings {
|
||||
pub enabled: bool,
|
||||
pub executable: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for LegendarySettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
executable: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
-23
@@ -9,9 +9,11 @@ use std::{
|
||||
mod cached_search;
|
||||
mod egs;
|
||||
mod legendary;
|
||||
mod settings;
|
||||
mod steamgriddb;
|
||||
mod platform;
|
||||
|
||||
use crate::legendary::get_legendary_games;
|
||||
use crate::{legendary::get_legendary_games, settings::Settings};
|
||||
use egs::{get_egs_manifests, ManifestItem};
|
||||
use std::error::Error;
|
||||
use steam_shortcuts_util::{
|
||||
@@ -60,35 +62,35 @@ fn get_shortcuts_for_user(user: &SteamUsersInfo) -> ShortcutInfo {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
if !Path::new("auth_key.txt").exists() {
|
||||
println!("File auth_key.txt not found, the file has been created, please get a key from https://www.steamgriddb.com/ and copy it into auth_key.txt");
|
||||
File::create(Path::new("auth_key.txt"))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let auth_key = std::fs::read_to_string("auth_key.txt")?;
|
||||
|
||||
if auth_key.trim().is_empty() {
|
||||
println!("File auth_key.txt is empty please get an API key from https://www.steamgriddb.com/ and paste it into auth_key.txt");
|
||||
let settings = Settings::new()?;
|
||||
|
||||
|
||||
let auth_key = settings.steamgrid_db.auth_key;
|
||||
if settings.steamgrid_db.enabled && auth_key.is_none() {
|
||||
println!("auth_key not found, please add it to the steamgrid_db settings ");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let auth_key = auth_key.unwrap();
|
||||
|
||||
let client = steamgriddb_api::Client::new(auth_key);
|
||||
let mut search = CachedSearch::new(&client);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let egs_shortcuts = {
|
||||
let egs_manifests = match get_egs_manifests() {
|
||||
Ok(manifests) => manifests,
|
||||
Err(e) => {
|
||||
println!("Error getting manifests: {}", e);
|
||||
vec![]
|
||||
}
|
||||
if settings.epic_games.enabled {
|
||||
let egs_shortcuts = {
|
||||
let egs_manifests = match get_egs_manifests(&settings.epic_games) {
|
||||
Ok(manifests) => manifests,
|
||||
Err(e) => {
|
||||
println!("Error getting manifests for Epic Games Store: {}", e);
|
||||
vec![]
|
||||
}
|
||||
};
|
||||
let egs_shortcuts: Vec<ShortcutOwned> =
|
||||
egs_manifests.iter().map(|f| f.into()).collect();
|
||||
println!("Found {} installed EGS Games", egs_manifests.len());
|
||||
egs_shortcuts
|
||||
};
|
||||
let egs_shortcuts: Vec<ShortcutOwned> = egs_manifests.iter().map(|f| f.into()).collect();
|
||||
println!("Found {} installed EGS Games", egs_manifests.len());
|
||||
egs_shortcuts
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
let legendary_shortcuts = {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
use crate::{egs::EpicGamesLauncherSettings, legendary::LegendarySettings};
|
||||
|
||||
pub enum Platform{
|
||||
EpicGames{
|
||||
settings: EpicGamesLauncherSettings,
|
||||
},
|
||||
Legendary{
|
||||
settings: LegendarySettings
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+57
-7
@@ -1,18 +1,68 @@
|
||||
use std::env;
|
||||
use config::{ConfigError, Config, File, Environment};
|
||||
use crate::{
|
||||
egs::EpicGamesLauncherSettings, legendary::LegendarySettings, steamgriddb::SteamGridDbSettings,
|
||||
};
|
||||
|
||||
use config::{Config, ConfigError, Environment, File};
|
||||
use serde::Deserialize;
|
||||
use std::{env, path::Path};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
pub struct Settings {
|
||||
debug: bool,
|
||||
database: EpicGamesLauncher,
|
||||
pub debug: bool,
|
||||
pub epic_games: EpicGamesLauncherSettings,
|
||||
pub legendary: LegendarySettings,
|
||||
pub steamgrid_db: SteamGridDbSettings,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default)]
|
||||
struct SettingsOptional {
|
||||
pub debug: Option<bool>,
|
||||
pub epic_games: Option<EpicGamesLauncherSettings>,
|
||||
pub legendary: Option<LegendarySettings>,
|
||||
pub steamgrid_db: Option<SteamGridDbSettings>,
|
||||
}
|
||||
|
||||
impl From<SettingsOptional> for Settings {
|
||||
fn from(optional: SettingsOptional) -> Self {
|
||||
Self {
|
||||
debug: optional.debug.unwrap_or(false),
|
||||
epic_games: optional.epic_games.unwrap_or(Default::default()),
|
||||
legendary: optional.legendary.unwrap_or(Default::default()),
|
||||
steamgrid_db: optional.steamgrid_db.unwrap_or(Default::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//https://github.com/JosefNemec/Playnite/tree/master/source/Plugins/OriginLibrary
|
||||
//https://github.com/JosefNemec/Playnite/blob/master/source/Plugins/OriginLibrary/Origin.cs#L109
|
||||
impl Settings {
|
||||
|
||||
pub fn new() -> Result<Self, ConfigError> {
|
||||
let default = Self::default();
|
||||
if !Path::new("config.toml").exists() {
|
||||
return Ok(default);
|
||||
}
|
||||
let mut s = Config::new();
|
||||
|
||||
// Start off by merging in the "default" configuration file
|
||||
s.merge(File::with_name("config.toml").required(false))?;
|
||||
|
||||
// Add in the current environment file
|
||||
// Default to 'development' env
|
||||
// Note that this file is _optional_
|
||||
let env = env::var("RUN_MODE").unwrap_or_else(|_| "development".into());
|
||||
s.merge(File::with_name(&format!("config/{}", env)).required(false))?;
|
||||
|
||||
// Add in a local configuration file
|
||||
// This file shouldn't be checked in to git
|
||||
s.merge(File::with_name("local.toml").required(false))?;
|
||||
|
||||
// Add in settings from the environment (with a prefix of STEAM_SYNC)
|
||||
// Eg.. `STEAM_SYNC_DEBUG=1 ./target/app` would set the `debug` key
|
||||
s.merge(Environment::with_prefix("steam_sync"))?;
|
||||
|
||||
// You can deserialize (and thus freeze) the entire configuration as
|
||||
let optionals: SettingsOptional = s.try_into()?;
|
||||
|
||||
Ok(optionals.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
mod settings;
|
||||
pub use settings::*;
|
||||
pub use settings::SteamGridDbSettings;
|
||||
@@ -1,12 +1,12 @@
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SteamGridDb {
|
||||
pub struct SteamGridDbSettings {
|
||||
pub enabled: bool,
|
||||
pub auth_key: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for SteamGridDb {
|
||||
impl Default for SteamGridDbSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
|
||||
Reference in New Issue
Block a user