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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user