Initial commit

This commit is contained in:
Philip
2021-09-05 12:46:34 +02:00
commit f99b6cd9aa
9 changed files with 1358 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
use std::env::{self, VarError};
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()?;
let manifest_dir_result = std::fs::read_dir(&manifest_dir_path);
if let Err(err) = manifest_dir_result {
//TODO make a new error type here instead
println!("Could not find manifest directory: {}", manifest_dir_path);
return Result::Err(Box::new(err));
}
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 is_game_installed(manifest:&ManifestItem) -> bool{
Path::new(manifest.manifest_location.as_str()).exists()
}
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()) {
let reader = BufReader::new(file);
return serde_json::from_reader(reader).ok();
}
}
}
None
}
+20
View File
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ManifestItem {
#[serde(alias = "LaunchExecutable")]
pub launch_executable: String,
#[serde(alias = "ManifestLocation")]
pub manifest_location: String,
#[serde(alias = "DisplayName")]
pub display_name: String,
#[serde(alias = "InstallLocation")]
pub install_location: String,
#[serde(alias = "AppName")]
pub app_name: String,
}
+4
View File
@@ -0,0 +1,4 @@
mod get_manifests;
mod manifest_item;
pub use manifest_item::*;
pub use get_manifests::get_egs_manifests;