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;
+91
View File
@@ -0,0 +1,91 @@
use std::{
env::{self},
fmt,
path::Path,
};
mod egs;
use egs::get_egs_manifests;
use std::error::Error;
use steam_shortcuts_util::parse_shortcuts;
fn main() -> Result<(), Box<dyn Error>> {
let egs_manifests = get_egs_manifests()?;
println!("Found {} installed EGS Games", egs_manifests.len());
let shortcut_content = get_shortcuts_content()?;
let shortcuts = parse_shortcuts(shortcut_content.as_slice())?;
println!("Shortcuts found {}", shortcuts.len());
Ok(())
}
#[derive(Debug)]
struct SteamFolderNotFound {
location_tried: String,
}
impl fmt::Display for SteamFolderNotFound {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Could not find steam user data at location: {} Please specify it in the configuration",
self.location_tried
)
}
}
impl Error for SteamFolderNotFound {
fn description(&self) -> &str {
self.location_tried.as_str()
}
}
#[derive(Debug)]
struct SteamUsersDataEmpty {
location_tried: String,
}
impl fmt::Display for SteamUsersDataEmpty {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Steam users data folder is empty: {} Please specify it in the configuration",
self.location_tried
)
}
}
impl Error for SteamUsersDataEmpty {
fn description(&self) -> &str {
self.location_tried.as_str()
}
}
fn get_shortcuts_content() -> Result<Vec<u8>, Box<dyn Error>> {
let key = "PROGRAMFILES(X86)";
let program_files = env::var(key)?;
let path_string = format!(
"{program_files}//Steam//userdata//",
program_files = program_files
);
let user_data_path = Path::new(path_string.as_str());
if !user_data_path.exists() {
return Result::Err(Box::new(SteamFolderNotFound {
location_tried: path_string,
}));
}
let mut user_folders = std::fs::read_dir(&user_data_path)?;
if let Some(Ok(folder)) = user_folders.next() {
let path = folder.path();
let shortcuts_folder = format!(
"{}//config//shortcuts.vdf",
path.to_str().expect("We just checked that this was there")
);
let content = std::fs::read(shortcuts_folder)?;
Ok(content)
} else {
Err(Box::new(SteamUsersDataEmpty {
location_tried: path_string,
}))
}
}
+56
View File
@@ -0,0 +1,56 @@
{
"FormatVersion": 0,
"bIsIncompleteInstall": false,
"LaunchCommand": "",
"LaunchExecutable": "Void Bastards.exe",
"ManifestLocation": "E:\\SlowEpic\\VoidBastards/.egstore",
"bIsApplication": true,
"bIsExecutable": true,
"bIsManaged": false,
"bNeedsValidation": false,
"bRequiresAuth": true,
"bAllowMultipleInstances": false,
"bCanRunOffline": true,
"bAllowUriCmdArgs": false,
"BaseURLs": [
"http://download.epicgames.com/Builds/Org/o-pldxyabsslnt6jth2z634mmr2pw8lu/9206c13a6dd948f7a0ed1ae95bfa6dfd/default",
"http://download2.epicgames.com/Builds/Org/o-pldxyabsslnt6jth2z634mmr2pw8lu/9206c13a6dd948f7a0ed1ae95bfa6dfd/default",
"http://download3.epicgames.com/Builds/Org/o-pldxyabsslnt6jth2z634mmr2pw8lu/9206c13a6dd948f7a0ed1ae95bfa6dfd/default",
"http://download4.epicgames.com/Builds/Org/o-pldxyabsslnt6jth2z634mmr2pw8lu/9206c13a6dd948f7a0ed1ae95bfa6dfd/default",
"http://epicgames-download1.akamaized.net/Builds/Org/o-pldxyabsslnt6jth2z634mmr2pw8lu/9206c13a6dd948f7a0ed1ae95bfa6dfd/default",
"http://fastly-download.epicgames.com/Builds/Org/o-pldxyabsslnt6jth2z634mmr2pw8lu/9206c13a6dd948f7a0ed1ae95bfa6dfd/default"
],
"BuildLabel": "Live",
"AppCategories": [
"public",
"games",
"applications"
],
"ChunkDbs": [],
"CompatibleApps": [],
"DisplayName": "Void Bastards",
"InstallationGuid": "2D5C19734137C4172B48478C09F908BD",
"InstallLocation": "E:\\SlowEpic\\VoidBastards",
"InstallSessionId": "978E0F85440F5F6EFCDDA7AE5677B1B8",
"InstallTags": [],
"InstallComponents": [],
"HostInstallationGuid": "00000000000000000000000000000000",
"PrereqIds": [],
"StagingLocation": "E:\\SlowEpic\\VoidBastards/.egstore/bps",
"TechnicalType": "public,games,applications",
"VaultThumbnailUrl": "",
"VaultTitleText": "",
"InstallSize": 6180063330,
"MainWindowProcessName": "",
"ProcessNames": [],
"MandatoryAppFolderName": "VoidBastards",
"OwnershipToken": "false",
"CatalogNamespace": "6b753bd045604be89d9779e741c604b1",
"CatalogItemId": "486ccd7673284a02bd62dd6d5fa289e0",
"AppName": "595e35287b824902a2f7107139603732",
"AppVersionString": "2.0.33",
"MainGameCatalogNamespace": "6b753bd045604be89d9779e741c604b1",
"MainGameCatalogItemId": "486ccd7673284a02bd62dd6d5fa289e0",
"MainGameAppName": "595e35287b824902a2f7107139603732",
"AllowedUriEnvVars": []
}
+55
View File
@@ -0,0 +1,55 @@
{
"FormatVersion": 0,
"bIsIncompleteInstall": false,
"LaunchCommand": "",
"LaunchExecutable": "Spectrum.exe",
"ManifestLocation": "E:\\SlowEpic\\TheSpectrumRetreat/.egstore",
"bIsApplication": true,
"bIsExecutable": true,
"bIsManaged": false,
"bNeedsValidation": false,
"bRequiresAuth": true,
"bAllowMultipleInstances": false,
"bCanRunOffline": true,
"bAllowUriCmdArgs": false,
"BaseURLs": [
"http://download.epicgames.com/Builds/Org/o-fbx9l7z95axq9s73trhbttadbareuq/b9018aa99bd1475687cf964588f588e2/default",
"http://download2.epicgames.com/Builds/Org/o-fbx9l7z95axq9s73trhbttadbareuq/b9018aa99bd1475687cf964588f588e2/default",
"http://download3.epicgames.com/Builds/Org/o-fbx9l7z95axq9s73trhbttadbareuq/b9018aa99bd1475687cf964588f588e2/default",
"http://download4.epicgames.com/Builds/Org/o-fbx9l7z95axq9s73trhbttadbareuq/b9018aa99bd1475687cf964588f588e2/default",
"http://epicgames-download1.akamaized.net/Builds/Org/o-fbx9l7z95axq9s73trhbttadbareuq/b9018aa99bd1475687cf964588f588e2/default",
"http://fastly-download.epicgames.com/Builds/Org/o-fbx9l7z95axq9s73trhbttadbareuq/b9018aa99bd1475687cf964588f588e2/default"
],
"BuildLabel": "Live",
"AppCategories": [
"games",
"applications"
],
"ChunkDbs": [],
"CompatibleApps": [],
"DisplayName": "The Spectrum Retreat",
"InstallationGuid": "60D16FC34A870439914B5282434CD35A",
"InstallLocation": "E:\\SlowEpic\\TheSpectrumRetreat",
"InstallSessionId": "CF352F6B4AD87AB135486E9E76BB5915",
"InstallTags": [],
"InstallComponents": [],
"HostInstallationGuid": "00000000000000000000000000000000",
"PrereqIds": [],
"StagingLocation": "E:\\SlowEpic\\TheSpectrumRetreat/.egstore/bps",
"TechnicalType": "games,applications",
"VaultThumbnailUrl": "",
"VaultTitleText": "",
"InstallSize": 6608600518,
"MainWindowProcessName": "",
"ProcessNames": [],
"MandatoryAppFolderName": "TheSpectrumRetreat",
"OwnershipToken": "false",
"CatalogNamespace": "32ef234417314b65a4f76041b684f4d0",
"CatalogItemId": "7f65d209277f4c10ac7c5eb4f1ed3ae9",
"AppName": "7b8fb449c8d3404ba7eda9cd4da1401b",
"AppVersionString": "1.0rc",
"MainGameCatalogNamespace": "32ef234417314b65a4f76041b684f4d0",
"MainGameCatalogItemId": "7f65d209277f4c10ac7c5eb4f1ed3ae9",
"MainGameAppName": "7b8fb449c8d3404ba7eda9cd4da1401b",
"AllowedUriEnvVars": []
}