Find gog games on linux

This commit is contained in:
Philip Kristoffersen
2021-10-05 17:21:52 +02:00
parent 0658021306
commit 206d900ef1
3 changed files with 48 additions and 4 deletions
+4 -1
View File
@@ -3,5 +3,8 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub(crate) struct GogConfig { pub(crate) struct GogConfig {
#[serde(alias = "installationPaths")] #[serde(alias = "installationPaths")]
pub installation_paths: Vec<String>, pub installation_paths: Option<Vec<String>>,
#[serde(alias = "libraryPath")]
pub library_path: Option<String>,
} }
+43 -3
View File
@@ -36,11 +36,19 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
return Err(GogErrors::ConfigFileNotFound { path: config_path }); return Err(GogErrors::ConfigFileNotFound { path: config_path });
} }
let install_locations = get_install_locations(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); dbg!(&install_locations);
let mut game_folders = vec![]; let mut game_folders = vec![];
for install_location in install_locations { for install_location in install_locations {
let path = Path::new(&install_location); let path = Path::new(&install_location);
if path.exists() { if path.exists() {
println!("exists {:?}", &path);
let dirs = path.read_dir(); let dirs = path.read_dir();
if let Ok(dirs) = dirs { if let Ok(dirs) = dirs {
for dir in dirs { for dir in dirs {
@@ -107,12 +115,21 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
.to_string(), .to_string(),
None => folder_path.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 { let shortcut = GogShortcut {
name: game.name, name: game.name,
game_folder: folder_path, game_folder: folder_path,
working_dir, working_dir,
game_id: game.game_id, game_id: game.game_id,
path: full_path.to_string(), path: full_path_string,
}; };
shortcuts.push(shortcut); shortcuts.push(shortcut);
} }
@@ -126,6 +143,25 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
} }
} }
fn fix_paths(wine_c_drive: &String, paths: Vec<String>) -> Vec<String> {
#[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<Vec<String>, GogErrors> { fn get_install_locations(path: PathBuf) -> Result<Vec<String>, GogErrors> {
let data_res = let data_res =
std::fs::read_to_string(&path).map_err(|e| GogErrors::ConfigFileCouldNotBeRead { std::fs::read_to_string(&path).map_err(|e| GogErrors::ConfigFileCouldNotBeRead {
@@ -137,7 +173,11 @@ fn get_install_locations(path: PathBuf) -> Result<Vec<String>, GogErrors> {
path, path,
error: format!("{}", e), 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 { pub fn default_location() -> PathBuf {
@@ -150,7 +190,7 @@ pub fn default_location() -> PathBuf {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
let home = std::env::var("HOME").expect("Expected a home variable to be defined"); 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")
} }
} }
+1
View File
@@ -4,4 +4,5 @@ use serde::{Deserialize, Serialize};
pub struct GogSettings { pub struct GogSettings {
pub enabled: bool, pub enabled: bool,
pub location: Option<String>, pub location: Option<String>,
pub wine_c_drive: Option<String>
} }