From 206d900ef12e3f40f0d5e9968c8250a0d97c7b39 Mon Sep 17 00:00:00 2001 From: Philip Kristoffersen Date: Tue, 5 Oct 2021 17:21:52 +0200 Subject: [PATCH] Find gog games on linux --- src/gog/gog_config.rs | 5 ++++- src/gog/gog_platform.rs | 46 ++++++++++++++++++++++++++++++++++++++--- src/gog/gog_settings.rs | 1 + 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/gog/gog_config.rs b/src/gog/gog_config.rs index 9879a32..df542f5 100644 --- a/src/gog/gog_config.rs +++ b/src/gog/gog_config.rs @@ -3,5 +3,8 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone)] pub(crate) struct GogConfig { #[serde(alias = "installationPaths")] - pub installation_paths: Vec, + pub installation_paths: Option>, + + #[serde(alias = "libraryPath")] + pub library_path: Option, } diff --git a/src/gog/gog_platform.rs b/src/gog/gog_platform.rs index cc8c70a..add7a0a 100644 --- a/src/gog/gog_platform.rs +++ b/src/gog/gog_platform.rs @@ -36,11 +36,19 @@ impl Platform for GogPlatform { return Err(GogErrors::ConfigFileNotFound { path: config_path }); } let install_locations = get_install_locations(config_path)?; + let install_locations = if let Some(wine_c_drive) = &self.settings.wine_c_drive { + fix_paths(&wine_c_drive, install_locations) + } else { + install_locations + }; + dbg!(&install_locations); + let mut game_folders = vec![]; for install_location in install_locations { let path = Path::new(&install_location); if path.exists() { + println!("exists {:?}", &path); let dirs = path.read_dir(); if let Ok(dirs) = dirs { for dir in dirs { @@ -107,12 +115,21 @@ impl Platform for GogPlatform { .to_string(), None => folder_path.to_string(), }; + + #[cfg(target_os = "linux")] + let working_dir = working_dir.replace("\\", "/"); + + let full_path_string = full_path.to_string(); + + #[cfg(target_os = "linux")] + let full_path_string = full_path_string.replace("\\", "/"); + let shortcut = GogShortcut { name: game.name, game_folder: folder_path, working_dir, game_id: game.game_id, - path: full_path.to_string(), + path: full_path_string, }; shortcuts.push(shortcut); } @@ -126,6 +143,25 @@ impl Platform for GogPlatform { } } +fn fix_paths(wine_c_drive: &String, paths: Vec) -> Vec { + #[cfg(not(target_os = "linux"))] + return paths; + #[cfg(target_os = "linux")] + { + paths + .iter() + .flat_map(|path| { + if path.starts_with("C:\\") { + let path_buf = Path::new(wine_c_drive).join(&path[3..]); + path_buf.to_str().map(|s| s.to_string().replace("\\", "/")) + } else { + None + } + }) + .collect() + } +} + fn get_install_locations(path: PathBuf) -> Result, GogErrors> { let data_res = std::fs::read_to_string(&path).map_err(|e| GogErrors::ConfigFileCouldNotBeRead { @@ -137,7 +173,11 @@ fn get_install_locations(path: PathBuf) -> Result, GogErrors> { path, error: format!("{}", e), })?; - Ok(config.installation_paths) + let path_vec = match config.library_path { + Some(path) => vec![path], + None => vec![], + }; + Ok(config.installation_paths.unwrap_or(path_vec)) } pub fn default_location() -> PathBuf { @@ -150,7 +190,7 @@ pub fn default_location() -> PathBuf { #[cfg(target_os = "linux")] { let home = std::env::var("HOME").expect("Expected a home variable to be defined"); - Path::new(&home).join("GOG.com").join("Galaxy") + Path::new(&home).join("Games/gog-galaxy/drive_c/ProgramData/GOG.com/Galaxy") } } diff --git a/src/gog/gog_settings.rs b/src/gog/gog_settings.rs index 2c14c8d..88ea763 100644 --- a/src/gog/gog_settings.rs +++ b/src/gog/gog_settings.rs @@ -4,4 +4,5 @@ use serde::{Deserialize, Serialize}; pub struct GogSettings { pub enabled: bool, pub location: Option, + pub wine_c_drive: Option }