diff --git a/src/defaultconfig.toml b/src/defaultconfig.toml index fd754db..5ac16e7 100644 --- a/src/defaultconfig.toml +++ b/src/defaultconfig.toml @@ -5,9 +5,11 @@ enabled = false [gog] enabled = false +create_symlinks = true [epic_games] enabled = false +create_symlinks = true [legendary] enabled = false @@ -16,6 +18,7 @@ enabled = false [itch] enabled = false +create_symlinks = true [steamgrid_db] enabled = true \ No newline at end of file diff --git a/src/egs/epic_platform.rs b/src/egs/epic_platform.rs index 5ecb1eb..6bb4974 100644 --- a/src/egs/epic_platform.rs +++ b/src/egs/epic_platform.rs @@ -27,4 +27,9 @@ impl Platform for EpicPlatform { fn get_shortcuts(&self) -> Result, EpicGamesManifestsError> { get_egs_manifests(&self.settings) } + + #[cfg(target_os = "linux")] + fn create_symlinks(&self) -> bool { + self.settings.create_symlinks + } } diff --git a/src/egs/settings.rs b/src/egs/settings.rs index ced0e99..5bef498 100644 --- a/src/egs/settings.rs +++ b/src/egs/settings.rs @@ -4,6 +4,9 @@ use serde::{Serialize,Deserialize}; pub struct EpicGamesLauncherSettings { pub enabled: bool, pub location: Option, + + #[cfg(target_os = "linux")] + pub create_symlinks: bool, } diff --git a/src/gog/gog_platform.rs b/src/gog/gog_platform.rs index add7a0a..e052cc0 100644 --- a/src/gog/gog_platform.rs +++ b/src/gog/gog_platform.rs @@ -21,6 +21,11 @@ impl Platform for GogPlatform { "Gog" } + #[cfg(target_os = "linux")] + fn create_symlinks(&self) -> bool { + self.settings.create_symlinks + } + fn get_shortcuts(&self) -> Result, GogErrors> { let gog_location = self .settings @@ -36,14 +41,13 @@ impl Platform for GogPlatform { return Err(GogErrors::ConfigFileNotFound { path: config_path }); } let install_locations = get_install_locations(config_path)?; + #[cfg(target_os = "linux")] 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); @@ -143,11 +147,8 @@ impl Platform for GogPlatform { } } +#[cfg(target_os = "linux")] 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| { @@ -159,7 +160,6 @@ fn fix_paths(wine_c_drive: &String, paths: Vec) -> Vec { } }) .collect() - } } fn get_install_locations(path: PathBuf) -> Result, GogErrors> { diff --git a/src/gog/gog_settings.rs b/src/gog/gog_settings.rs index 88ea763..59d3f17 100644 --- a/src/gog/gog_settings.rs +++ b/src/gog/gog_settings.rs @@ -4,5 +4,8 @@ use serde::{Deserialize, Serialize}; pub struct GogSettings { pub enabled: bool, pub location: Option, - pub wine_c_drive: Option + pub wine_c_drive: Option, + #[cfg(target_os = "linux")] + pub create_symlinks: bool, + } diff --git a/src/itch/itch_platform.rs b/src/itch/itch_platform.rs index 0b5aea1..60d3589 100644 --- a/src/itch/itch_platform.rs +++ b/src/itch/itch_platform.rs @@ -55,6 +55,11 @@ impl Platform for ItchPlatform { let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect(); Ok(res) } + + #[cfg(target_os = "linux")] + fn create_symlinks(&self) -> bool { + self.settings.create_symlinks + } } fn dbpath_to_game(paths: &DbPaths<'_>) -> Option { diff --git a/src/itch/settings.rs b/src/itch/settings.rs index 6ef8ef4..afd71d2 100644 --- a/src/itch/settings.rs +++ b/src/itch/settings.rs @@ -4,4 +4,6 @@ use serde::{Serialize,Deserialize}; pub struct ItchSettings { pub enabled: bool, pub location: Option, + #[cfg(target_os = "linux")] + pub create_symlinks: bool, } \ No newline at end of file diff --git a/src/legendary/legendary_platform.rs b/src/legendary/legendary_platform.rs index e7d1fc9..65f7750 100644 --- a/src/legendary/legendary_platform.rs +++ b/src/legendary/legendary_platform.rs @@ -32,4 +32,9 @@ impl Platform> for LegendaryPlatform { let legendary_ouput = from_str(&json)?; Ok(legendary_ouput) } + + #[cfg(target_os = "linux")] + fn create_symlinks(&self) -> bool { + false + } } diff --git a/src/origin/origin_platform.rs b/src/origin/origin_platform.rs index f64bb2b..25039c9 100644 --- a/src/origin/origin_platform.rs +++ b/src/origin/origin_platform.rs @@ -21,6 +21,11 @@ impl Platform for OriginPlatform { "Origin" } + #[cfg(target_os = "linux")] + fn create_symlinks(&self) -> bool { + false + } + fn get_shortcuts(&self) -> Result, OriginErrors> { let origin_folder = Path::new( &self diff --git a/src/platform.rs b/src/platform.rs index d64909a..449422c 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -9,4 +9,7 @@ where fn name(&self) -> &str; fn get_shortcuts(&self) -> Result, E>; + + #[cfg(target_os = "linux")] + fn create_symlinks(&self) -> bool; } diff --git a/src/sync/sync.rs b/src/sync/sync.rs index d2c93dd..d39b16d 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -1,5 +1,4 @@ - -use steam_shortcuts_util::{Shortcut, shortcut::ShortcutOwned, shortcuts_to_bytes}; +use steam_shortcuts_util::{shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut}; use crate::{ egs::EpicPlatform, @@ -10,14 +9,13 @@ use crate::{ }; use std::error::Error; - -use std::{fs::File, io::Write, path::Path}; use crate::{ gog::GogPlatform, itch::ItchPlatform, origin::OriginPlatform, steamgriddb::{download_images, CachedSearch}, }; +use std::{fs::File, io::Write, path::Path}; pub async fn run_sync(settings: &Settings) -> Result<(), Box> { let userinfo_shortcuts = get_shortcuts_paths(&settings.steam)?; @@ -108,6 +106,20 @@ where if platform.enabled() { let shortcuts_to_add_result = platform.get_shortcuts(); + #[cfg(target_os = "linux")] + if platform.create_symlinks() { + let boilr_links_path = get_boilr_links_path(); + if !boilr_links_path.exists() { + if let Err(e) = std::fs::create_dir_all(&boilr_links_path) { + println!( + "Could not create links folder for symlinks at path: {:?} , error: {:?} , you can try to disable creating symlinks for platform {}", + boilr_links_path, e, platform.name() + ); + return; + } + } + } + match shortcuts_to_add_result { Ok(shortcuts_to_add) => { println!( @@ -115,9 +127,16 @@ where shortcuts_to_add.len(), platform.name() ); + current_shortcuts.retain(|f| !f.tags.contains(&platform.name().to_owned())); for shortcut in shortcuts_to_add { let shortcut_owned: ShortcutOwned = shortcut.into(); + #[cfg(target_os = "linux")] + let shortcut_owned = if platform.create_symlinks() { + create_sym_links(&shortcut_owned) + } else { + shortcut_owned + }; current_shortcuts.push(shortcut_owned); } } @@ -128,3 +147,47 @@ where } } } +#[cfg(target_os = "linux")] +fn get_boilr_links_path() -> std::path::PathBuf { + let home = std::env::var("HOME").expect("Expected a home variable to be defined"); + let boilr_links_path = Path::new(&home).join(".boilr").join("links"); + boilr_links_path +} +#[cfg(target_os = "linux")] +fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned { + let links_folder = get_boilr_links_path(); + + let target_link = links_folder.join(format!("t{}", shortcut.app_id)); + let workdir_link = links_folder.join(format!("w{}", shortcut.app_id)); + + let target_original = Path::new(&shortcut.exe); + let workdir_original = Path::new(&shortcut.start_dir); + + use std::os::unix::fs::symlink; + + match ( + symlink(&target_original, &target_link), + symlink(&workdir_original, &workdir_link), + ) { + (Ok(_), Ok(_)) => { + let exe = target_link.to_string_lossy().to_string(); + let start_dir = workdir_link.to_string_lossy().to_string(); + let new_shortcut = Shortcut::new( + 0, + shortcut.app_name.as_str(), + exe.as_str(), + &start_dir.as_str(), + shortcut.icon.as_str(), + shortcut.shortcut_path.as_str(), + shortcut.launch_options.as_str(), + ); + let mut new_shortcut = new_shortcut.to_owned(); + new_shortcut.tags = shortcut.tags.clone(); + new_shortcut + } + _ => { + println!("Could not create symlinks for game: {}", shortcut.app_name); + shortcut.clone() + } + } +}