diff --git a/Readme.md b/Readme.md index 086a23d..a84381c 100644 --- a/Readme.md +++ b/Readme.md @@ -72,6 +72,7 @@ BoilR can import games from many platforms, but there are limits based | [Amazon Games](https://gaming.amazon.com) | Yes | No | No | | [Flatpaks](https://flathub.org/) | No | Yes | [No](https://github.com/PhilipK/BoilR/issues/184#issuecomment-1192680467) | | [Bottles](https://usebottles.com/) | No | Yes | Yes | +| [MiniGalaxy](https://sharkwouter.github.io/minigalaxy/) | No | Yes | Yes | ## Getting cover art for your shortcuts diff --git a/src/platforms/minigalaxy/mod.rs b/src/platforms/minigalaxy/mod.rs new file mode 100644 index 0000000..1cbd039 --- /dev/null +++ b/src/platforms/minigalaxy/mod.rs @@ -0,0 +1,3 @@ +mod platform; + +pub use platform::MiniGalaxyPlatform; \ No newline at end of file diff --git a/src/platforms/minigalaxy/platform.rs b/src/platforms/minigalaxy/platform.rs new file mode 100644 index 0000000..d933e20 --- /dev/null +++ b/src/platforms/minigalaxy/platform.rs @@ -0,0 +1,122 @@ +use serde::{Deserialize, Serialize}; + +use crate::platforms::{GamesPlatform, FromSettingsString, load_settings, GogShortcut, NeedsPorton}; + +#[derive(Clone)] +pub struct MiniGalaxyPlatform { + settings: Settings, +} + +#[derive(Deserialize, Serialize, Clone)] +struct Settings { + enabled: bool, + create_symlinks: bool, + games_folder: Option, +} + +impl Default for Settings{ + fn default() -> Self { + #[cfg(target_family = "unix")] + let enabled = true; + #[cfg(target_family = "windows")] + let enabled = false; + Self { enabled, create_symlinks:false, games_folder:None } + } +} + + +impl NeedsPorton for GogShortcut{ + #[cfg(target_family = "unix")] + fn needs_proton(&self, _platform: &MiniGalaxyPlatform) -> bool { + //TODO check if we can do better than just always true + //this might be a linux game + true + } + + #[cfg(not(target_family = "unix"))] + fn needs_proton(&self, _platform: &MiniGalaxyPlatform) -> bool { + false + } + + #[cfg(not(target_family = "unix"))] + fn create_symlinks(&self, _platform: &MiniGalaxyPlatform) -> bool { + false + } + + #[cfg(target_family = "unix")] + fn create_symlinks(&self, platform: &MiniGalaxyPlatform) -> bool { + platform.settings.create_symlinks + } +} + +impl FromSettingsString for MiniGalaxyPlatform { + fn from_settings_string>(s: S) -> Self { + MiniGalaxyPlatform { + settings: load_settings(s), + } + } +} + +impl GamesPlatform for MiniGalaxyPlatform{ + fn name(&self) -> &str { + "Mini Galaxy" + } + + fn code_name(&self) -> &str { + "minigalaxy" + } + + fn enabled(&self) -> bool { + self.settings.enabled + } + + fn get_shortcut_info(&self) -> eyre::Result> { + + let games_folder = match &self.settings.games_folder{ + Some(custom_folder) => std::path::Path::new(&custom_folder).to_path_buf(), + None => { + get_default_folder_path()? + }, + }; + let dirs = games_folder.read_dir()?; + let mut game_folders = vec![]; + for game_folder in dirs{ + if let Ok(game_folder) = game_folder{ + game_folders.push(game_folder.path().to_owned()); + } + } + let gog_games = crate::platforms::get_gog_shortcuts_from_game_folders(game_folders); + crate::platforms::to_shortcuts(self, Ok(gog_games)) + } + + fn get_settings_serilizable(&self) -> String { + toml::to_string(&self.settings).unwrap_or_default() + } + + fn render_ui(&mut self, ui: &mut egui::Ui) { + ui.heading("Mini Galaxy"); + ui.checkbox(&mut self.settings.enabled, "Import from Mini Galaxy"); + let mut path_text = self.settings.games_folder.clone().unwrap_or_else(get_default_folder_string); + if ui.text_edit_singleline(&mut path_text).changed(){ + if path_text.trim().is_empty(){ + self.settings.games_folder = None; + }else{ + self.settings.games_folder = Some(path_text); + } + } + + #[cfg(target_family = "unix")] + if self.settings.enabled { + ui.checkbox(&mut self.settings.create_symlinks, "Create symlinks"); + } + } +} + +fn get_default_folder_string() -> String { + get_default_folder_path().unwrap_or_default().to_string_lossy().to_string() +} + +fn get_default_folder_path() -> eyre::Result { + let home = std::env::var("HOME")?; + Ok(std::path::Path::new(&home).join("GOG Games")) +} \ No newline at end of file diff --git a/src/platforms/mod.rs b/src/platforms/mod.rs index daff43a..b85feaf 100644 --- a/src/platforms/mod.rs +++ b/src/platforms/mod.rs @@ -11,6 +11,7 @@ mod origin; mod platform; mod platforms_load; mod uplay; +mod minigalaxy; pub(crate) use platform::*; diff --git a/src/platforms/platforms_load.rs b/src/platforms/platforms_load.rs index 3ff1c41..57cc0ca 100644 --- a/src/platforms/platforms_load.rs +++ b/src/platforms/platforms_load.rs @@ -13,11 +13,12 @@ use super::heroic::HeroicPlatform; use super::itch::ItchPlatform; use super::legendary::LegendaryPlatform; use super::lutris::LutrisPlatform; +use super::minigalaxy::MiniGalaxyPlatform; use super::origin::OriginPlatform; use super::uplay::UplayPlatform; use super::GamesPlatform; -const PLATFORM_NAMES: [&str; 11] = [ +const PLATFORM_NAMES: [&str; 12] = [ "amazon", "bottles", "epic_games", @@ -29,6 +30,7 @@ const PLATFORM_NAMES: [&str; 11] = [ "lutris", "origin", "uplay", + "minigalaxy" ]; pub type Platforms = Vec>; @@ -51,6 +53,7 @@ pub fn load_platform, B: AsRef>( "legendary" => load::(s), "lutris" => load::(s), "origin" => load::(s), + "minigalaxy" => load::(s), _ => Err(eyre::format_err!("Unknown platform named {name}")), } }