Add utility to help format the code (#247)

Signed-off-by: Aisuko <urakiny@gmail.com>
This commit is contained in:
Aisuko
2022-10-11 06:17:10 +02:00
committed by GitHub
parent fac58803cc
commit 40c55e542d
39 changed files with 415 additions and 421 deletions
+9
View File
@@ -106,6 +106,15 @@ If you want to revert back to the original name, just clear the name and click r
### How can I help/contribute? ### How can I help/contribute?
If you are a coder, you are very welcome! You can fork this repo and then create a pull request. If you are a coder, you are very welcome! You can fork this repo and then create a pull request.
To check formats and errors of code before run the code:
```shell
cargo fmt
cargo check
```
To run BoilR just write: To run BoilR just write:
```shell ```shell
+19 -19
View File
@@ -52,39 +52,39 @@ pub fn get_boilr_links_path() -> PathBuf {
get_config_folder().join("links") get_config_folder().join("links")
} }
#[cfg(test)] #[cfg(test)]
mod tests{ mod tests {
use std::path::PathBuf; use std::path::PathBuf;
use super::get_config_folder; use super::get_config_folder;
#[test] #[test]
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
fn check_return_xdg_config_path(){ fn check_return_xdg_config_path() {
// Parameters for set environment 'XDG_CONFIG_HOME' // Parameters for set environment 'XDG_CONFIG_HOME'
std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr"); std::env::set_var(
"XDG_CONFIG_HOME",
std::env::var("HOME").unwrap() + "/.config/boilr",
);
let xdg_config_home=std::env::var("XDG_CONFIG_HOME").unwrap(); let xdg_config_home = std::env::var("XDG_CONFIG_HOME").unwrap();
let config_path=get_config_folder(); let config_path = get_config_folder();
let test_path=PathBuf::from(xdg_config_home); let test_path = PathBuf::from(xdg_config_home);
assert_eq!(config_path,test_path); assert_eq!(config_path, test_path);
} }
#[test] #[test]
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
fn check_return_config_path(){ fn check_return_config_path() {
std::env::set_var(
"XDG_CONFIG_HOME",
std::env::var("HOME").unwrap() + "/.config/boilr",
);
std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr"); let config_path = get_config_folder();
let current_path = std::env::var("HOME").unwrap() + "/.config/boilr";
let config_path=get_config_folder();
let current_path=std::env::var("HOME").unwrap()+"/.config/boilr";
assert_eq!(config_path,PathBuf::from(current_path)); assert_eq!(config_path, PathBuf::from(current_path));
} }
} }
+1 -1
View File
@@ -9,7 +9,7 @@ mod ui;
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
fn main() -> Result<()>{ fn main() -> Result<()> {
color_eyre::install()?; color_eyre::install()?;
ensure_config_folder(); ensure_config_folder();
migration::migrate_config(); migration::migrate_config();
+1 -1
View File
@@ -1,6 +1,6 @@
use std::path::Path; use std::path::Path;
use crate::{settings::save_settings, platforms::get_platforms}; use crate::{platforms::get_platforms, settings::save_settings};
pub fn migrate_config() { pub fn migrate_config() {
let version = &crate::settings::Settings::new() let version = &crate::settings::Settings::new()
+16 -14
View File
@@ -3,17 +3,20 @@ use sqlite::State;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut}; use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
use crate::platforms::{to_shortcuts_simple, ShortcutToImport, FromSettingsString, load_settings, GamesPlatform}; use crate::platforms::{
load_settings, to_shortcuts_simple, FromSettingsString, GamesPlatform, ShortcutToImport,
};
#[derive(Clone)] #[derive(Clone)]
pub struct AmazonPlatform { pub struct AmazonPlatform {
pub settings: AmazonSettings, pub settings: AmazonSettings,
} }
impl FromSettingsString for AmazonPlatform {
impl FromSettingsString for AmazonPlatform{ fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
fn from_settings_string<S:AsRef<str>>(s:S) -> Self { AmazonPlatform {
AmazonPlatform { settings: load_settings(s) } settings: load_settings(s),
}
} }
} }
@@ -51,11 +54,10 @@ fn get_launcher_path() -> eyre::Result<PathBuf> {
} }
} }
impl GamesPlatform for AmazonPlatform{ impl GamesPlatform for AmazonPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"Amazon" "Amazon"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
@@ -63,14 +65,13 @@ impl GamesPlatform for AmazonPlatform{
fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>> { fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>> {
to_shortcuts_simple(self.get_amazon_games()) to_shortcuts_simple(self.get_amazon_games())
} }
fn render_ui(&mut self, ui: &mut egui::Ui) { fn render_ui(&mut self, ui: &mut egui::Ui) {
ui.heading("Amazon"); ui.heading("Amazon");
ui.checkbox(&mut self.settings.enabled, "Import from Amazon"); ui.checkbox(&mut self.settings.enabled, "Import from Amazon");
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
@@ -80,9 +81,7 @@ impl GamesPlatform for AmazonPlatform{
} }
} }
impl AmazonPlatform { impl AmazonPlatform {
fn get_amazon_games(&self) -> eyre::Result<Vec<AmazonGame>> { fn get_amazon_games(&self) -> eyre::Result<Vec<AmazonGame>> {
let sqllite_path = get_sqlite_path()?; let sqllite_path = get_sqlite_path()?;
let launcher_path = get_launcher_path()?; let launcher_path = get_launcher_path()?;
@@ -141,7 +140,7 @@ pub struct AmazonSettings {
pub launcher_location: Option<String>, pub launcher_location: Option<String>,
} }
impl Default for AmazonSettings{ impl Default for AmazonSettings {
fn default() -> Self { fn default() -> Self {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
let enabled = false; let enabled = false;
@@ -149,6 +148,9 @@ impl Default for AmazonSettings{
#[cfg(not(target_family = "unix"))] #[cfg(not(target_family = "unix"))]
let enabled = true; let enabled = true;
Self { enabled, launcher_location: Default::default() } Self {
enabled,
launcher_location: Default::default(),
}
} }
} }
+1 -1
View File
@@ -1,4 +1,4 @@
mod amazon_platform; mod amazon_platform;
pub use amazon_platform::AmazonGame;
pub use amazon_platform::AmazonPlatform; pub use amazon_platform::AmazonPlatform;
pub use amazon_platform::AmazonGame;
+11 -8
View File
@@ -5,16 +5,20 @@ use serde::{Deserialize, Serialize};
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut}; use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
use crate::platforms::{to_shortcuts_simple, ShortcutToImport, FromSettingsString, load_settings, GamesPlatform}; use crate::platforms::{
load_settings, to_shortcuts_simple, FromSettingsString, GamesPlatform, ShortcutToImport,
};
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct BottlesPlatform { pub struct BottlesPlatform {
pub settings: BottlesSettings, pub settings: BottlesSettings,
} }
impl FromSettingsString for BottlesPlatform{ impl FromSettingsString for BottlesPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
BottlesPlatform { settings: load_settings(s) } BottlesPlatform {
settings: load_settings(s),
}
} }
} }
@@ -29,7 +33,7 @@ pub struct BottlesSettings {
pub enabled: bool, pub enabled: bool,
} }
impl Default for BottlesSettings{ impl Default for BottlesSettings {
fn default() -> Self { fn default() -> Self {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
let enabled = true; let enabled = true;
@@ -124,8 +128,7 @@ impl BottlesPlatform {
} }
} }
impl GamesPlatform for BottlesPlatform {
impl GamesPlatform for BottlesPlatform{
fn name(&self) -> &str { fn name(&self) -> &str {
"Bottles" "Bottles"
} }
@@ -142,7 +145,7 @@ impl GamesPlatform for BottlesPlatform{
ui.heading("Bottles"); ui.heading("Bottles");
ui.checkbox(&mut self.settings.enabled, "Import from Bottles"); ui.checkbox(&mut self.settings.enabled, "Import from Bottles");
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
@@ -150,4 +153,4 @@ impl GamesPlatform for BottlesPlatform{
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"bottles" "bottles"
} }
} }
+4 -4
View File
@@ -1,5 +1,5 @@
use crate::platforms::{ use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, NeedsPorton, ShortcutToImport, GamesPlatform, load_settings, to_shortcuts, FromSettingsString, GamesPlatform, NeedsPorton, ShortcutToImport,
}; };
use super::{get_egs_manifests, settings::EpicGamesLauncherSettings, ManifestItem}; use super::{get_egs_manifests, settings::EpicGamesLauncherSettings, ManifestItem};
@@ -32,7 +32,7 @@ impl NeedsPorton<EpicPlatform> for ManifestItem {
} }
} }
impl GamesPlatform for EpicPlatform{ impl GamesPlatform for EpicPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"Epic" "Epic"
} }
@@ -52,8 +52,8 @@ impl GamesPlatform for EpicPlatform{
fn render_ui(&mut self, ui: &mut egui::Ui) { fn render_ui(&mut self, ui: &mut egui::Ui) {
self.render_epic_settings(ui) self.render_epic_settings(ui)
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
} }
+1 -2
View File
@@ -42,7 +42,7 @@ pub(crate) fn get_egs_manifests(
} }
} }
} }
let mut manifests :Vec<ManifestItem> = all_manifests let mut manifests: Vec<ManifestItem> = all_manifests
.filter(is_game_installed) .filter(is_game_installed)
.filter(is_game_launchable) .filter(is_game_launchable)
.collect(); .collect();
@@ -71,7 +71,6 @@ pub(crate) fn get_egs_manifests(
} }
} }
fn is_game_installed(manifest: &ManifestItem) -> bool { fn is_game_installed(manifest: &ManifestItem) -> bool {
Path::new(manifest.manifest_location.as_str()).exists() Path::new(manifest.manifest_location.as_str()).exists()
} }
+2 -3
View File
@@ -124,7 +124,6 @@ fn launcher_shortcut(manifest: ManifestItem) -> ShortcutOwned {
.to_owned() .to_owned()
} }
impl From<ManifestItem> for ShortcutOwned { impl From<ManifestItem> for ShortcutOwned {
fn from(manifest: ManifestItem) -> Self { fn from(manifest: ManifestItem) -> Self {
let mut owned_shortcut = if manifest.needs_launcher() { let mut owned_shortcut = if manifest.needs_launcher() {
@@ -163,8 +162,8 @@ impl ManifestItem {
self.catalog_namespace, self.catalog_item_id, self.app_name self.catalog_namespace, self.catalog_item_id, self.app_name
) )
} }
pub fn dedupe_key(&self)-> String { pub fn dedupe_key(&self) -> String {
format!( format!(
"{}-{}-{}", "{}-{}-{}",
self.install_location, self.launch_executable, self.is_managed self.install_location, self.launch_executable, self.is_managed
+1 -2
View File
@@ -1,12 +1,11 @@
mod epic_platform; mod epic_platform;
mod epic_ui;
mod get_manifests; mod get_manifests;
mod manifest_item; mod manifest_item;
mod paths; mod paths;
mod settings; mod settings;
mod epic_ui;
pub use epic_platform::*; pub use epic_platform::*;
use get_manifests::get_egs_manifests; use get_manifests::get_egs_manifests;
pub(crate) use manifest_item::*; pub(crate) use manifest_item::*;
use paths::*; use paths::*;
+9 -10
View File
@@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::platforms::{NeedsPorton, to_shortcuts, ShortcutToImport, GamesPlatform, FromSettingsString, load_settings}; use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, GamesPlatform, NeedsPorton, ShortcutToImport,
};
use super::FlatpakSettings; use super::FlatpakSettings;
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut}; use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
@@ -23,7 +25,7 @@ impl From<FlatpakApp> for ShortcutOwned {
} }
} }
impl NeedsPorton<FlatpakPlatform> for FlatpakApp{ impl NeedsPorton<FlatpakPlatform> for FlatpakApp {
fn needs_proton(&self, _platform: &FlatpakPlatform) -> bool { fn needs_proton(&self, _platform: &FlatpakPlatform) -> bool {
false false
} }
@@ -34,7 +36,6 @@ impl NeedsPorton<FlatpakPlatform> for FlatpakApp{
} }
impl FlatpakPlatform { impl FlatpakPlatform {
fn get_flatpak_apps(&self) -> eyre::Result<Vec<FlatpakApp>> { fn get_flatpak_apps(&self) -> eyre::Result<Vec<FlatpakApp>> {
use std::process::Command; use std::process::Command;
let mut command = Command::new("flatpak"); let mut command = Command::new("flatpak");
@@ -60,20 +61,18 @@ impl FlatpakPlatform {
} }
} }
impl FromSettingsString for FlatpakPlatform {
impl FromSettingsString for FlatpakPlatform{
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
FlatpakPlatform { FlatpakPlatform {
settings: load_settings(s), settings: load_settings(s),
} }
} }
} }
impl GamesPlatform for FlatpakPlatform{ impl GamesPlatform for FlatpakPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"Flatpak" "Flatpak"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
@@ -87,7 +86,7 @@ impl GamesPlatform for FlatpakPlatform{
ui.heading("Flatpak"); ui.heading("Flatpak");
ui.checkbox(&mut self.settings.enabled, "Import from Flatpak"); ui.checkbox(&mut self.settings.enabled, "Import from Flatpak");
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
@@ -95,4 +94,4 @@ impl GamesPlatform for FlatpakPlatform{
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"flatpak" "flatpak"
} }
} }
+2 -2
View File
@@ -5,7 +5,7 @@ pub struct FlatpakSettings {
pub enabled: bool, pub enabled: bool,
} }
impl Default for FlatpakSettings{ impl Default for FlatpakSettings {
fn default() -> Self { fn default() -> Self {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
let enabled = true; let enabled = true;
@@ -15,4 +15,4 @@ impl Default for FlatpakSettings{
Self { enabled } Self { enabled }
} }
} }
+9 -8
View File
@@ -1,6 +1,8 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use crate::platforms::{to_shortcuts, ShortcutToImport, NeedsPorton, GamesPlatform, FromSettingsString, load_settings}; use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, GamesPlatform, NeedsPorton, ShortcutToImport,
};
use super::{ use super::{
gog_config::GogConfig, gog_config::GogConfig,
@@ -161,7 +163,7 @@ fn get_games_from_game_folders(game_folders: Vec<PathBuf>) -> Vec<(GogGame, Path
games games
} }
impl NeedsPorton<GogPlatform> for GogShortcut{ impl NeedsPorton<GogPlatform> for GogShortcut {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
fn needs_proton(&self, _platform: &GogPlatform) -> bool { fn needs_proton(&self, _platform: &GogPlatform) -> bool {
true true
@@ -171,7 +173,7 @@ impl NeedsPorton<GogPlatform> for GogShortcut{
fn needs_proton(&self, _platform: &GogPlatform) -> bool { fn needs_proton(&self, _platform: &GogPlatform) -> bool {
false false
} }
#[cfg(not(target_family = "unix"))] #[cfg(not(target_family = "unix"))]
fn create_symlinks(&self, _platform: &GogPlatform) -> bool { fn create_symlinks(&self, _platform: &GogPlatform) -> bool {
false false
@@ -222,8 +224,7 @@ pub fn default_location() -> PathBuf {
} }
} }
impl FromSettingsString for GogPlatform {
impl FromSettingsString for GogPlatform{
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
GogPlatform { GogPlatform {
settings: load_settings(s), settings: load_settings(s),
@@ -231,7 +232,7 @@ impl FromSettingsString for GogPlatform{
} }
} }
impl GamesPlatform for GogPlatform{ impl GamesPlatform for GogPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"GOG" "GOG"
} }
@@ -258,7 +259,7 @@ impl GamesPlatform for GogPlatform{
}); });
} }
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
@@ -266,4 +267,4 @@ impl GamesPlatform for GogPlatform{
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"gog" "gog"
} }
} }
+2 -2
View File
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GogSettings { pub struct GogSettings {
pub enabled: bool, pub enabled: bool,
pub location: Option<String>, pub location: Option<String>,
@@ -16,7 +16,7 @@ impl Default for GogSettings {
enabled: false, enabled: false,
#[cfg(not(target_family = "unix"))] #[cfg(not(target_family = "unix"))]
enabled: true, enabled: true,
location:None, location: None,
wine_c_drive: None, wine_c_drive: None,
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
create_symlinks: true, create_symlinks: true,
+2 -2
View File
@@ -3,7 +3,7 @@ mod gog_game;
mod gog_platform; mod gog_platform;
mod gog_settings; mod gog_settings;
pub(crate) use gog_settings::GogSettings; pub use gog_game::GogShortcut;
pub use gog_platform::get_gog_shortcuts_from_game_folders; pub use gog_platform::get_gog_shortcuts_from_game_folders;
pub use gog_platform::GogPlatform; pub use gog_platform::GogPlatform;
pub use gog_game::GogShortcut; pub(crate) use gog_settings::GogSettings;
+4 -4
View File
@@ -21,9 +21,9 @@ impl HeroicGameType {
HeroicGameType::Epic(g) => g.app_name.as_ref(), HeroicGameType::Epic(g) => g.app_name.as_ref(),
HeroicGameType::Gog(g, _) => g.game_id.as_ref(), HeroicGameType::Gog(g, _) => g.game_id.as_ref(),
HeroicGameType::Heroic { HeroicGameType::Heroic {
title:_, title: _,
app_name, app_name,
install_mode:_, install_mode: _,
} => app_name, } => app_name,
} }
} }
@@ -34,8 +34,8 @@ impl HeroicGameType {
HeroicGameType::Gog(g, _) => g.name.as_ref(), HeroicGameType::Gog(g, _) => g.name.as_ref(),
HeroicGameType::Heroic { HeroicGameType::Heroic {
title, title,
app_name:_, app_name: _,
install_mode:_, install_mode: _,
} => title.as_ref(), } => title.as_ref(),
} }
} }
+72 -74
View File
@@ -1,7 +1,7 @@
use serde::Deserialize; use serde::Deserialize;
use super::{HeroicGame, HeroicGameType, HeroicSettings}; use super::{HeroicGame, HeroicGameType, HeroicSettings};
use crate::platforms::{GamesPlatform, FromSettingsString, load_settings}; use crate::platforms::{load_settings, FromSettingsString, GamesPlatform};
use crate::platforms::{to_shortcuts, NeedsPorton, ShortcutToImport}; use crate::platforms::{to_shortcuts, NeedsPorton, ShortcutToImport};
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path; use std::path::Path;
@@ -86,14 +86,14 @@ impl HeroicPlatform {
} }
} }
impl NeedsPorton<HeroicPlatform> for HeroicGameType{ impl NeedsPorton<HeroicPlatform> for HeroicGameType {
#[cfg(not(target_family = "unix"))] #[cfg(not(target_family = "unix"))]
fn needs_proton(&self, _platform: &HeroicPlatform) -> bool { fn needs_proton(&self, _platform: &HeroicPlatform) -> bool {
false false
} }
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
fn needs_proton(&self, _platform: &HeroicPlatform) -> bool { fn needs_proton(&self, _platform: &HeroicPlatform) -> bool {
match self { match self {
HeroicGameType::Epic(_game) => true, HeroicGameType::Epic(_game) => true,
HeroicGameType::Gog(_, is_windows) => *is_windows, HeroicGameType::Gog(_, is_windows) => *is_windows,
@@ -107,30 +107,33 @@ impl NeedsPorton<HeroicPlatform> for HeroicGameType{
} }
impl HeroicPlatform { impl HeroicPlatform {
pub fn get_epic_games(&self, install_modes: &[InstallationMode]) -> eyre::Result<Vec<HeroicGameType>> { pub fn get_epic_games(
&self,
install_modes: &[InstallationMode],
) -> eyre::Result<Vec<HeroicGameType>> {
let mut shortcuts = vec![]; let mut shortcuts = vec![];
for install_mode in install_modes { for install_mode in install_modes {
if let Ok(mut games) = get_shortcuts_from_install_mode(install_mode) { if let Ok(mut games) = get_shortcuts_from_install_mode(install_mode) {
games.sort_by_key(|m| { games.sort_by_key(|m| {
format!("{}-{}-{}", m.launch_parameters, m.executable, &m.app_name) format!("{}-{}-{}", m.launch_parameters, m.executable, &m.app_name)
}); });
games.dedup_by_key(|m| { games.dedup_by_key(|m| {
format!("{}-{}-{}", m.launch_parameters, m.executable, &m.app_name) format!("{}-{}-{}", m.launch_parameters, m.executable, &m.app_name)
}); });
for game in games { for game in games {
if self.settings.is_heroic_launch(&game.app_name) { if self.settings.is_heroic_launch(&game.app_name) {
shortcuts.push(HeroicGameType::Heroic { shortcuts.push(HeroicGameType::Heroic {
title: game.title, title: game.title,
app_name: game.app_name, app_name: game.app_name,
install_mode: *install_mode, install_mode: *install_mode,
}); });
} else if game.is_installed() { } else if game.is_installed() {
shortcuts.push(HeroicGameType::Epic(game)); shortcuts.push(HeroicGameType::Epic(game));
}
} }
} }
} }
}
Ok(shortcuts) Ok(shortcuts)
} }
} }
@@ -199,21 +202,19 @@ fn get_gog_games(
Ok(gog_shortcuts) Ok(gog_shortcuts)
} }
impl FromSettingsString for HeroicPlatform {
impl FromSettingsString for HeroicPlatform{
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
HeroicPlatform{ HeroicPlatform {
heroic_games: None, heroic_games: None,
settings : load_settings(s) settings: load_settings(s),
} }
} }
} }
impl GamesPlatform for HeroicPlatform{ impl GamesPlatform for HeroicPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"Heroic" "Heroic"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
@@ -226,53 +227,50 @@ impl GamesPlatform for HeroicPlatform{
fn render_ui(&mut self, ui: &mut egui::Ui) { fn render_ui(&mut self, ui: &mut egui::Ui) {
ui.heading("Heroic"); ui.heading("Heroic");
ui.checkbox(&mut self.settings.enabled, "Import from Heroic"); ui.checkbox(&mut self.settings.enabled, "Import from Heroic");
ui.checkbox(&mut self.settings.default_launch_through_heroic, "Always launch games through Heroic"); ui.checkbox(
let safe_mode_header = match (self.settings.default_launch_through_heroic,self.settings.launch_games_through_heroic.len()) { &mut self.settings.default_launch_through_heroic,
(false,0) => "Force games to launch through Heroic Launcher".to_string(), "Always launch games through Heroic",
(false,1) => "One game forced to launch through Heroic Launcher".to_string(), );
(false,x) => format!("{} games forced to launch through Heroic Launcher", x), let safe_mode_header = match (
self.settings.default_launch_through_heroic,
(true,0) => "Force games to launch directly".to_string(), self.settings.launch_games_through_heroic.len(),
(true,1) => "One game forced to launch directly".to_string(), ) {
(true,x) => format!("{} games forced to launch directly", x), (false, 0) => "Force games to launch through Heroic Launcher".to_string(),
(false, 1) => "One game forced to launch through Heroic Launcher".to_string(),
}; (false, x) => format!("{} games forced to launch through Heroic Launcher", x),
egui::CollapsingHeader::new(safe_mode_header)
.id_source("Heroic_Launcher_safe_launch") (true, 0) => "Force games to launch directly".to_string(),
.show(ui, |ui| { (true, 1) => "One game forced to launch directly".to_string(),
if (true, x) => format!("{} games forced to launch directly", x),
self.settings.default_launch_through_heroic{ };
ui.label("Some games work best when launched directly, select those games below and BoilR will create shortcuts that launch the games directly.");
egui::CollapsingHeader::new(safe_mode_header).id_source("Heroic_Launcher_safe_launch").show(ui, |ui| {
} else{ if self.settings.default_launch_through_heroic{
ui.label("Some games must be started from the Heroic Launcher, select those games below and BoilR will create shortcuts that opens the games through the Heroic Launcher."); ui.label("Some games work best when launched directly, select those games below and BoilR will create shortcuts that launch the games directly.");
} else {
ui.label("Some games must be started from the Heroic Launcher, select those games below and BoilR will create shortcuts that opens the games through the Heroic Launcher.");
}
let manifests = self.heroic_games.get_or_insert_with(|| {
let heroic_setting = self.settings.clone();
let heroic_platform = HeroicPlatform{ settings:heroic_setting, heroic_games:None};
heroic_platform.get_heroic_games().unwrap_or_default()
});
let safe_open_games = &mut self.settings.launch_games_through_heroic;
for manifest in manifests{
let key = manifest.app_name();
let display_name = manifest.title();
let mut safe_open = safe_open_games.contains(&display_name.to_string()) || safe_open_games.contains(&key.to_string());
if ui.checkbox(&mut safe_open, display_name).clicked(){
if safe_open{
safe_open_games.push(key.to_string());
}else{
safe_open_games.retain(|m| m!= display_name && m!= key);
}
} }
let manifests =self.heroic_games.get_or_insert_with(||{ }
let heroic_setting = self.settings.clone(); });
let heroic_platform = HeroicPlatform{
settings:heroic_setting,
heroic_games:None
};
heroic_platform.get_heroic_games().unwrap_or_default()
});
let safe_open_games = &mut self.settings.launch_games_through_heroic;
for manifest in manifests{
let key = manifest.app_name();
let display_name = manifest.title();
let mut safe_open = safe_open_games.contains(&display_name.to_string()) || safe_open_games.contains(&key.to_string());
if ui.checkbox(&mut safe_open, display_name).clicked(){
if safe_open{
safe_open_games.push(key.to_string());
}else{
safe_open_games.retain(|m| m!= display_name && m!= key);
}
}
}
}) ;
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
@@ -282,4 +280,4 @@ self.settings.default_launch_through_heroic{
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"heroic" "heroic"
} }
} }
+3 -5
View File
@@ -38,13 +38,11 @@ impl From<ItchGame> for ShortcutOwned {
} }
} }
impl NeedsPorton<ItchPlatform> for ItchGame {
impl NeedsPorton<ItchPlatform> for ItchGame{
fn needs_proton(&self, _platform: &ItchPlatform) -> bool { fn needs_proton(&self, _platform: &ItchPlatform) -> bool {
self.executable.ends_with("exe") self.executable.ends_with("exe")
} }
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
fn create_symlinks(&self, platform: &ItchPlatform) -> bool { fn create_symlinks(&self, platform: &ItchPlatform) -> bool {
platform.settings.create_symlinks platform.settings.create_symlinks
@@ -54,4 +52,4 @@ impl NeedsPorton<ItchPlatform> for ItchGame{
fn create_symlinks(&self, _platform: &ItchPlatform) -> bool { fn create_symlinks(&self, _platform: &ItchPlatform) -> bool {
false false
} }
} }
+12 -15
View File
@@ -1,8 +1,10 @@
use crate::platforms::{to_shortcuts, ShortcutToImport, load_settings, FromSettingsString, GamesPlatform}; use super::butler_db_parser::*;
use super::itch_game::ItchGame; use super::itch_game::ItchGame;
use super::receipt::Receipt; use super::receipt::Receipt;
use super::ItchSettings; use super::ItchSettings;
use super::{butler_db_parser::*}; use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, GamesPlatform, ShortcutToImport,
};
use flate2::read::GzDecoder; use flate2::read::GzDecoder;
use is_executable::IsExecutable; use is_executable::IsExecutable;
use std::collections::HashSet; use std::collections::HashSet;
@@ -87,11 +89,9 @@ pub fn get_default_location() -> String {
.to_str() .to_str()
.unwrap() .unwrap()
.to_string() .to_string()
//C:\Users\phili\AppData\Local\itch //C:\Users\phili\AppData\Local\itch
} }
impl FromSettingsString for ItchPlatform { impl FromSettingsString for ItchPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
ItchPlatform { ItchPlatform {
@@ -100,8 +100,7 @@ impl FromSettingsString for ItchPlatform {
} }
} }
impl GamesPlatform for ItchPlatform {
impl GamesPlatform for ItchPlatform{
fn name(&self) -> &str { fn name(&self) -> &str {
"Itch" "Itch"
} }
@@ -120,11 +119,7 @@ impl GamesPlatform for ItchPlatform{
if self.settings.enabled { if self.settings.enabled {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let mut empty_string = "".to_string(); let mut empty_string = "".to_string();
let itch_location = self let itch_location = self.settings.location.as_mut().unwrap_or(&mut empty_string);
.settings
.location
.as_mut()
.unwrap_or(&mut empty_string);
ui.label("Itch.io Folder: "); ui.label("Itch.io Folder: ");
if ui.text_edit_singleline(itch_location).changed() { if ui.text_edit_singleline(itch_location).changed() {
self.settings.location = if itch_location.is_empty() { self.settings.location = if itch_location.is_empty() {
@@ -132,10 +127,12 @@ impl GamesPlatform for ItchPlatform{
} else { } else {
Some(itch_location.to_string()) Some(itch_location.to_string())
}; };
} else if !itch_location.is_empty() && ui } else if !itch_location.is_empty()
&& ui
.button("Reset") .button("Reset")
.on_hover_text("Reset the itch path, let BoilR guess again") .on_hover_text("Reset the itch path, let BoilR guess again")
.clicked() { .clicked()
{
self.settings.location = None; self.settings.location = None;
} }
}); });
@@ -145,7 +142,7 @@ impl GamesPlatform for ItchPlatform{
} }
} }
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
+1 -1
View File
@@ -5,4 +5,4 @@ mod receipt;
mod settings; mod settings;
pub use itch_platform::ItchPlatform; pub use itch_platform::ItchPlatform;
pub use settings::ItchSettings; pub use settings::ItchSettings;
@@ -1,6 +1,8 @@
use super::legendary_game::LegendaryGame; use super::legendary_game::LegendaryGame;
use super::LegendarySettings; use super::LegendarySettings;
use crate::platforms::{to_shortcuts_simple, GamesPlatform, ShortcutToImport, FromSettingsString, load_settings}; use crate::platforms::{
load_settings, to_shortcuts_simple, FromSettingsString, GamesPlatform, ShortcutToImport,
};
use serde_json::from_str; use serde_json::from_str;
use std::process::Command; use std::process::Command;
@@ -64,8 +66,8 @@ impl GamesPlatform for LegendaryPlatform {
} }
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
@@ -73,10 +75,10 @@ impl GamesPlatform for LegendaryPlatform {
} }
} }
impl FromSettingsString for LegendaryPlatform{ impl FromSettingsString for LegendaryPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
LegendaryPlatform{ LegendaryPlatform {
settings:load_settings(s) settings: load_settings(s),
} }
} }
} }
+1 -2
View File
@@ -2,6 +2,5 @@ mod legendary_game;
mod legendary_platform; mod legendary_platform;
mod settings; mod settings;
pub use legendary_platform::LegendaryPlatform;
pub use settings::LegendarySettings; pub use settings::LegendarySettings;
pub use legendary_platform::LegendaryPlatform;
+10 -9
View File
@@ -1,7 +1,9 @@
use super::game_list_parser::parse_lutris_games; use super::game_list_parser::parse_lutris_games;
use super::lutris_game::LutrisGame; use super::lutris_game::LutrisGame;
use super::settings::LutrisSettings; use super::settings::LutrisSettings;
use crate::platforms::{to_shortcuts_simple, ShortcutToImport, FromSettingsString, load_settings, GamesPlatform}; use crate::platforms::{
load_settings, to_shortcuts_simple, FromSettingsString, GamesPlatform, ShortcutToImport,
};
use std::process::Command; use std::process::Command;
#[derive(Clone)] #[derive(Clone)]
@@ -57,17 +59,18 @@ fn get_lutris_command_output(settings: &LutrisSettings) -> eyre::Result<String>
Ok(String::from_utf8_lossy(&output.stdout).to_string()) Ok(String::from_utf8_lossy(&output.stdout).to_string())
} }
impl FromSettingsString for LutrisPlatform{ impl FromSettingsString for LutrisPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
LutrisPlatform { settings: load_settings(s) } LutrisPlatform {
settings: load_settings(s),
}
} }
} }
impl GamesPlatform for LutrisPlatform{ impl GamesPlatform for LutrisPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"Lutris" "Lutris"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
@@ -75,7 +78,6 @@ impl GamesPlatform for LutrisPlatform{
fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>> { fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>> {
to_shortcuts_simple(self.get_shortcuts()) to_shortcuts_simple(self.get_shortcuts())
} }
fn render_ui(&mut self, ui: &mut egui::Ui) { fn render_ui(&mut self, ui: &mut egui::Ui) {
@@ -100,11 +102,10 @@ impl GamesPlatform for LutrisPlatform{
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default() toml::to_string(&self.settings).unwrap_or_default()
} }
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"lutris" "lutris"
} }
}
}
+9 -9
View File
@@ -1,22 +1,22 @@
mod platform;
mod egs;
mod amazon; mod amazon;
mod bottles; mod bottles;
mod uplay; mod egs;
mod itch;
mod flatpak; mod flatpak;
mod origin;
mod gog; mod gog;
mod heroic; mod heroic;
mod lutris; mod itch;
mod legendary; mod legendary;
mod lutris;
mod origin;
mod platform;
mod platforms_load; mod platforms_load;
mod uplay;
pub(crate) use platform::*; pub(crate) use platform::*;
pub(crate) use gog::get_gog_shortcuts_from_game_folders; pub(crate) use gog::get_gog_shortcuts_from_game_folders;
pub(crate) use gog::GogShortcut; pub(crate) use gog::GogShortcut;
pub(crate) use platforms_load::FromSettingsString;
pub(crate) use platforms_load::load_settings;
pub use platforms_load::Platforms;
pub use platforms_load::get_platforms; pub use platforms_load::get_platforms;
pub(crate) use platforms_load::load_settings;
pub(crate) use platforms_load::FromSettingsString;
pub use platforms_load::Platforms;
+1 -1
View File
@@ -2,5 +2,5 @@ mod origin_game;
mod origin_platform; mod origin_platform;
mod settings; mod settings;
pub(crate) use origin_platform::OriginPlatform;
pub use settings::OriginSettings; pub use settings::OriginSettings;
pub(crate) use origin_platform::OriginPlatform;
+4 -6
View File
@@ -13,12 +13,10 @@ pub struct OriginGame {
impl From<OriginGame> for ShortcutOwned { impl From<OriginGame> for ShortcutOwned {
fn from(game: OriginGame) -> Self { fn from(game: OriginGame) -> Self {
let launch = match game.origin_compat_folder{ let launch = match game.origin_compat_folder{
Some(compat_folder) => Some(compat_folder) => format!
format!("STEAM_COMPAT_DATA_PATH=\"{}\" %command% \"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"", compat_folder.to_string_lossy(), game.id) ("STEAM_COMPAT_DATA_PATH=\"{}\" %command% \"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"",
, compat_folder.to_string_lossy(), game.id),
None => format!( None => format!("\"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"",game.id)
"\"origin2://game/launch?offerIds={}&autoDownload=1&authCode=&cmdParams=\"",
game.id)
}; };
let origin_location = format!("\"{}\"", game.origin_location.to_string_lossy()); let origin_location = format!("\"{}\"", game.origin_location.to_string_lossy());
let mut owned_shortcut = Shortcut::new( let mut owned_shortcut = Shortcut::new(
+8 -7
View File
@@ -1,4 +1,6 @@
use crate::platforms::{to_shortcuts, GamesPlatform, NeedsPorton, ShortcutToImport, FromSettingsString, load_settings}; use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, GamesPlatform, NeedsPorton, ShortcutToImport,
};
use nom::bytes::complete::take_until; use nom::bytes::complete::take_until;
use std::{ use std::{
fs::DirEntry, fs::DirEntry,
@@ -205,13 +207,12 @@ impl GamesPlatform for OriginPlatform {
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"origin" "origin"
} }
} }
impl FromSettingsString for OriginPlatform {
impl FromSettingsString for OriginPlatform{
fn from_settings_string<S: AsRef<str>>(s: S) -> Self { fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
OriginPlatform { settings: load_settings(s) } OriginPlatform {
settings: load_settings(s),
}
} }
} }
+3 -3
View File
@@ -1,13 +1,13 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct OriginSettings { pub struct OriginSettings {
pub enabled: bool, pub enabled: bool,
} }
impl Default for OriginSettings{ impl Default for OriginSettings {
fn default() -> Self { fn default() -> Self {
Self { enabled: true } Self { enabled: true }
} }
} }
+2 -4
View File
@@ -1,5 +1,5 @@
use steam_shortcuts_util::shortcut::ShortcutOwned;
use dyn_clone::DynClone; use dyn_clone::DynClone;
use steam_shortcuts_util::shortcut::ShortcutOwned;
pub trait GamesPlatform pub trait GamesPlatform
where where
@@ -14,7 +14,7 @@ where
fn enabled(&self) -> bool; fn enabled(&self) -> bool;
fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>>; fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>>;
fn get_settings_serilizable(&self) -> String; fn get_settings_serilizable(&self) -> String;
fn render_ui(&mut self, ui: &mut egui::Ui); fn render_ui(&mut self, ui: &mut egui::Ui);
@@ -29,7 +29,6 @@ pub struct ShortcutToImport {
pub needs_symlinks: bool, pub needs_symlinks: bool,
} }
pub(crate) fn to_shortcuts<T, P>( pub(crate) fn to_shortcuts<T, P>(
platform: &P, platform: &P,
into_shortcuts: Result<Vec<T>, eyre::ErrReport>, into_shortcuts: Result<Vec<T>, eyre::ErrReport>,
@@ -79,4 +78,3 @@ pub trait NeedsPorton<P> {
fn create_symlinks(&self, platform: &P) -> bool; fn create_symlinks(&self, platform: &P) -> bool;
} }
+3 -7
View File
@@ -1,11 +1,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use crate::settings::load_setting_sections; use crate::settings::load_setting_sections;
use super::GamesPlatform;
use super::amazon::AmazonPlatform; use super::amazon::AmazonPlatform;
use super::bottles::BottlesPlatform; use super::bottles::BottlesPlatform;
use super::egs::EpicPlatform; use super::egs::EpicPlatform;
@@ -17,6 +15,7 @@ use super::legendary::LegendaryPlatform;
use super::lutris::LutrisPlatform; use super::lutris::LutrisPlatform;
use super::origin::OriginPlatform; use super::origin::OriginPlatform;
use super::uplay::UplayPlatform; use super::uplay::UplayPlatform;
use super::GamesPlatform;
const PLATFORM_NAMES: [&str; 11] = [ const PLATFORM_NAMES: [&str; 11] = [
"amazon", "amazon",
@@ -56,7 +55,6 @@ pub fn load_platform<A: AsRef<str>, B: AsRef<str>>(
} }
} }
pub fn get_platforms() -> Platforms { pub fn get_platforms() -> Platforms {
let sections = load_setting_sections(); let sections = load_setting_sections();
let sections = match sections { let sections = match sections {
@@ -72,7 +70,7 @@ pub fn get_platforms() -> Platforms {
let mut platforms = vec![]; let mut platforms = vec![];
for name in PLATFORM_NAMES { for name in PLATFORM_NAMES {
let default =String::from(""); let default = String::from("");
let settings = sections.get(name).unwrap_or(&default); let settings = sections.get(name).unwrap_or(&default);
match load_platform(name, settings) { match load_platform(name, settings) {
Ok(platform) => platforms.push(platform), Ok(platform) => platforms.push(platform),
@@ -91,7 +89,7 @@ where
match toml::from_str(str) { match toml::from_str(str) {
Ok(k) => k, Ok(k) => k,
Err(err) => { Err(err) => {
if !str.is_empty(){ if !str.is_empty() {
eprintln!("Error reading settings file {:?}", err); eprintln!("Error reading settings file {:?}", err);
} }
Setting::default() Setting::default()
@@ -99,7 +97,6 @@ where
} }
} }
fn load<T>(s: &str) -> eyre::Result<Box<dyn GamesPlatform>> fn load<T>(s: &str) -> eyre::Result<Box<dyn GamesPlatform>>
where where
T: FromSettingsString, T: FromSettingsString,
@@ -109,7 +106,6 @@ where
Ok(Box::new(T::from_settings_string(s))) Ok(Box::new(T::from_settings_string(s)))
} }
pub trait FromSettingsString { pub trait FromSettingsString {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self; fn from_settings_string<S: AsRef<str>>(s: S) -> Self;
} }
+1 -1
View File
@@ -21,4 +21,4 @@ impl From<UplayGame> for ShortcutOwned {
let exe = format!("\"{}\"", game.launcher.to_string_lossy()); let exe = format!("\"{}\"", game.launcher.to_string_lossy());
Shortcut::new("0", &game.name, &exe, &start_dir, &game.icon, "", &launch).to_owned() Shortcut::new("0", &game.name, &exe, &start_dir, &game.icon, "", &launch).to_owned()
} }
} }
+1 -1
View File
@@ -3,4 +3,4 @@ mod platform;
mod settings; mod settings;
pub use platform::UplayPlatform; pub use platform::UplayPlatform;
pub use settings::UplaySettings; pub use settings::UplaySettings;
+4 -6
View File
@@ -3,10 +3,10 @@ use std::path::Path;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::path::PathBuf; use std::path::PathBuf;
use crate::platforms::FromSettingsString;
use crate::platforms::GamesPlatform;
use crate::platforms::load_settings; use crate::platforms::load_settings;
use crate::platforms::to_shortcuts_simple; use crate::platforms::to_shortcuts_simple;
use crate::platforms::FromSettingsString;
use crate::platforms::GamesPlatform;
use crate::platforms::ShortcutToImport; use crate::platforms::ShortcutToImport;
use super::{game::UplayGame, settings::UplaySettings}; use super::{game::UplayGame, settings::UplaySettings};
@@ -98,8 +98,7 @@ impl FromSettingsString for UplayPlatform {
} }
} }
impl GamesPlatform for UplayPlatform {
impl GamesPlatform for UplayPlatform{
fn name(&self) -> &str { fn name(&self) -> &str {
"Uplay" "Uplay"
} }
@@ -124,5 +123,4 @@ impl GamesPlatform for UplayPlatform{
fn code_name(&self) -> &str { fn code_name(&self) -> &str {
"uplay" "uplay"
} }
}
}
+1 -1
View File
@@ -106,4 +106,4 @@ fn sanitize_auth_key(result: &mut Settings) {
result.steamgrid_db.auth_key = None; result.steamgrid_db.auth_key = None;
} }
} }
} }
-2
View File
@@ -7,5 +7,3 @@ pub use synchronization::download_images;
pub use synchronization::IsBoilRShortcut; pub use synchronization::IsBoilRShortcut;
pub use synchronization::SyncProgress; pub use synchronization::SyncProgress;
pub use synchronization::*; pub use synchronization::*;
+4 -1
View File
@@ -57,7 +57,10 @@ impl MyEguiApp {
ui.heading(&user.path.to_string_lossy().to_string()); ui.heading(&user.path.to_string_lossy().to_string());
} }
for shortcut in user.shortcuts.iter() { for shortcut in user.shortcuts.iter() {
if shortcut.is_boilr_shortcut() && ui.button(&shortcut.app_name).clicked() && disconnect_shortcut(&self.settings, shortcut.app_id).is_ok() { if shortcut.is_boilr_shortcut()
&& ui.button(&shortcut.app_name).clicked()
&& disconnect_shortcut(&self.settings, shortcut.app_id).is_ok()
{
redraw = shortcut.app_id; redraw = shortcut.app_id;
} }
} }
+49 -51
View File
@@ -13,7 +13,7 @@ use crate::sync;
use crate::sync::{download_images, SyncProgress}; use crate::sync::{download_images, SyncProgress};
use super::{backup_shortcuts, all_ready, get_all_games}; use super::{all_ready, backup_shortcuts, get_all_games};
use super::{ use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR}, ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp, MyEguiApp,
@@ -60,7 +60,7 @@ impl MyEguiApp {
FetcStatus::NeedsFetched => {ui.label("Need to find games");}, FetcStatus::NeedsFetched => {ui.label("Need to find games");},
FetcStatus::Fetching => { FetcStatus::Fetching => {
ui.horizontal(|ui|{ ui.horizontal(|ui|{
ui.spinner(); ui.spinner();
ui.label("Finding installed games"); ui.label("Finding installed games");
}); });
}, },
@@ -90,31 +90,29 @@ impl MyEguiApp {
} }
} }
} }
} else { } else {
let name = self.rename_map.get(&shortcut.app_id).unwrap_or(&shortcut.app_name); let name = self.rename_map.get(&shortcut.app_id).unwrap_or(&shortcut.app_name);
let checkbox = egui::Checkbox::new(&mut import_game,name); let checkbox = egui::Checkbox::new(&mut import_game,name);
let response = ui.add(checkbox); let response = ui.add(checkbox);
if response.double_clicked(){ if response.double_clicked(){
self.rename_map.entry(shortcut.app_id).or_insert_with(|| shortcut.app_name.to_owned()); self.rename_map.entry(shortcut.app_id).or_insert_with(|| shortcut.app_name.to_owned());
self.current_edit = Option::Some(shortcut.app_id); self.current_edit = Option::Some(shortcut.app_id);
} }
if response.clicked(){ if response.clicked(){
if !self.settings.blacklisted_games.contains(&shortcut.app_id){ if !self.settings.blacklisted_games.contains(&shortcut.app_id){
self.settings.blacklisted_games.push(shortcut.app_id); self.settings.blacklisted_games.push(shortcut.app_id);
}else{ } else {
self.settings.blacklisted_games.retain(|id| *id != shortcut.app_id); self.settings.blacklisted_games.retain(|id| *id != shortcut.app_id);
}
} }
} }
} });
});
} }
}, },
Err(err) => { Err(err) => {
ui.label("Failed finding games").on_hover_text(format!("Error message: {err}")); ui.label("Failed finding games").on_hover_text(format!("Error message: {err}"));
}, },
}; };
}, },
} }
@@ -125,8 +123,7 @@ impl MyEguiApp {
}); });
} }
pub fn run_sync(&mut self, wait: bool) {
pub fn run_sync(&mut self, wait: bool ) {
let (sender, reciever) = watch::channel(SyncProgress::NotStarted); let (sender, reciever) = watch::channel(SyncProgress::NotStarted);
let settings = self.settings.clone(); let settings = self.settings.clone();
if settings.steam.stop_steam { if settings.steam.stop_steam {
@@ -137,25 +134,26 @@ impl MyEguiApp {
self.status_reciever = reciever; self.status_reciever = reciever;
let renames = self.rename_map.clone(); let renames = self.rename_map.clone();
let all_ready= all_ready(&self.games_to_sync); let all_ready = all_ready(&self.games_to_sync);
let _ = sender.send(SyncProgress::Starting); let _ = sender.send(SyncProgress::Starting);
if all_ready{ if all_ready {
let shortcuts_to_import = get_all_games(&self.games_to_sync); let shortcuts_to_import = get_all_games(&self.games_to_sync);
let handle = self.rt.spawn_blocking(move || { let handle = self.rt.spawn_blocking(move || {
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
setup_proton(shortcuts_to_import.iter()); setup_proton(shortcuts_to_import.iter());
let import_games = to_shortcut_owned(shortcuts_to_import); let import_games = to_shortcut_owned(shortcuts_to_import);
let mut some_sender = Some(sender); let mut some_sender = Some(sender);
backup_shortcuts(&settings.steam); backup_shortcuts(&settings.steam);
let usersinfo = sync::sync_shortcuts(&settings, &import_games, &mut some_sender,&renames).unwrap(); let usersinfo =
sync::sync_shortcuts(&settings, &import_games, &mut some_sender, &renames)
.unwrap();
let task = download_images(&settings, &usersinfo, &mut some_sender); let task = download_images(&settings, &usersinfo, &mut some_sender);
block_on(task); block_on(task);
//Run a second time to fix up shortcuts after images are downloaded //Run a second time to fix up shortcuts after images are downloaded
sync::sync_shortcuts(&settings, &import_games, &mut some_sender,&renames).unwrap(); sync::sync_shortcuts(&settings, &import_games, &mut some_sender, &renames).unwrap();
if let Some(sender) = some_sender { if let Some(sender) = some_sender {
let _ = sender.send(SyncProgress::Done); let _ = sender.send(SyncProgress::Done);
} }
@@ -168,42 +166,42 @@ impl MyEguiApp {
} }
} }
} }
} }
fn to_shortcut_owned(shortcuts_to_import: Vec<(String, Vec<ShortcutToImport>)>) -> Vec<(String, Vec<ShortcutOwned>)> { fn to_shortcut_owned(
shortcuts_to_import: Vec<(String, Vec<ShortcutToImport>)>,
) -> Vec<(String, Vec<ShortcutOwned>)> {
let mut import_games = vec![]; let mut import_games = vec![];
for(name,infos) in shortcuts_to_import{ for (name, infos) in shortcuts_to_import {
let mut shortcuts = vec![]; let mut shortcuts = vec![];
for info in infos{ for info in infos {
shortcuts.push(info.shortcut); shortcuts.push(info.shortcut);
} }
import_games.push((name,shortcuts)); import_games.push((name, shortcuts));
} }
import_games import_games
} }
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
fn setup_proton<'a, I>(shortcut_infos: I) fn setup_proton<'a, I>(shortcut_infos: I)
where where
I: IntoIterator<Item = &'a (String,Vec<ShortcutToImport>)>{ I: IntoIterator<Item = &'a (String, Vec<ShortcutToImport>)>,
let mut shortcuts_to_proton = vec![]; {
let mut shortcuts_to_proton = vec![];
for (name,shortcuts) in shortcut_infos {
for shortcut_info in shortcuts{
if shortcut_info.needs_proton {
crate::sync::symlinks::ensure_links_folder_created(name);
}
if shortcut_info.needs_proton {
shortcuts_to_proton.push(format!("{}", shortcut_info.shortcut.app_id));
}
if shortcut_info.needs_symlinks { for (name, shortcuts) in shortcut_infos {
crate::sync::symlinks::create_sym_links(&shortcut_info.shortcut); for shortcut_info in shortcuts {
if shortcut_info.needs_proton {
crate::sync::symlinks::ensure_links_folder_created(name);
}
if shortcut_info.needs_proton {
shortcuts_to_proton.push(format!("{}", shortcut_info.shortcut.app_id));
}
if shortcut_info.needs_symlinks {
crate::sync::symlinks::create_sym_links(&shortcut_info.shortcut);
}
} }
setup_proton_games(&shortcuts_to_proton);
} }
setup_proton_games(&shortcuts_to_proton);
}
} }
+123 -125
View File
@@ -1,125 +1,123 @@
use copypasta::ClipboardProvider; use copypasta::ClipboardProvider;
use eframe::egui; use eframe::egui;
use egui::ScrollArea; use egui::ScrollArea;
use super::{ use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR}, ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp, MyEguiApp,
}; };
pub const SECTION_SPACING: f32 = 25.0; pub const SECTION_SPACING: f32 = 25.0;
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
impl MyEguiApp { impl MyEguiApp {
pub(crate) fn render_settings(&mut self, ui: &mut egui::Ui) { pub(crate) fn render_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Settings"); ui.heading("Settings");
let mut scroll_style = ui.style_mut(); let mut scroll_style = ui.style_mut();
scroll_style.visuals.extreme_bg_color = BACKGROUND_COLOR; scroll_style.visuals.extreme_bg_color = BACKGROUND_COLOR;
scroll_style.visuals.widgets.inactive.bg_fill = EXTRA_BACKGROUND_COLOR; scroll_style.visuals.widgets.inactive.bg_fill = EXTRA_BACKGROUND_COLOR;
scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR; scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR;
scroll_style.visuals.selection.bg_fill = EXTRA_BACKGROUND_COLOR; scroll_style.visuals.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR; scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
ScrollArea::vertical() ScrollArea::vertical()
.stick_to_right(true) .stick_to_right(true)
.auto_shrink([false, true]) .auto_shrink([false, true])
.show(ui, |ui| { .show(ui, |ui| {
ui.reset_style(); ui.reset_style();
self.render_steamgriddb_settings(ui); self.render_steamgriddb_settings(ui);
self.render_steam_settings(ui); self.render_steam_settings(ui);
for platform in &mut self.platforms{ for platform in &mut self.platforms {
platform.render_ui(ui); platform.render_ui(ui);
ui.add_space(SECTION_SPACING); ui.add_space(SECTION_SPACING);
} }
ui.label(format!("Version: {}", VERSION)); ui.label(format!("Version: {}", VERSION));
}); });
} }
fn render_steam_settings(&mut self, ui: &mut egui::Ui) {
fn render_steam_settings(&mut self, ui: &mut egui::Ui) { ui.heading("Steam");
ui.heading("Steam"); ui.horizontal(|ui| {
ui.horizontal(|ui| { let mut empty_string = "".to_string();
let mut empty_string = "".to_string(); let steam_location = self
let steam_location = self .settings
.settings .steam
.steam .location
.location .as_mut()
.as_mut() .unwrap_or(&mut empty_string);
.unwrap_or(&mut empty_string); ui.label("Steam Location: ");
ui.label("Steam Location: "); if ui.text_edit_singleline(steam_location).changed() {
if ui.text_edit_singleline(steam_location).changed() { if steam_location.trim().is_empty() {
if steam_location.trim().is_empty(){ self.settings.steam.location = None;
self.settings.steam.location = None; } else {
}else{ self.settings.steam.location = Some(steam_location.to_string());
self.settings.steam.location = Some(steam_location.to_string()); }
} }
});
} ui.checkbox(
}); &mut self.settings.steam.create_collections,
ui.checkbox( "Create collections",
&mut self.settings.steam.create_collections, )
"Create collections", .on_hover_text("Tries to create a games collection for each platform");
) ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
.on_hover_text("Tries to create a games collection for each platform"); ui.checkbox(
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode"); &mut self.settings.steam.stop_steam,
ui.checkbox( "Stop Steam before import",
&mut self.settings.steam.stop_steam, )
"Stop Steam before import", .on_hover_text("Stops Steam if it is running when import starts");
) ui.checkbox(
.on_hover_text("Stops Steam if it is running when import starts"); &mut self.settings.steam.start_steam,
ui.checkbox( "Start Steam after import",
&mut self.settings.steam.start_steam, )
"Start Steam after import", .on_hover_text("Starts Steam is it is not running after the import");
) ui.add_space(SECTION_SPACING);
.on_hover_text("Starts Steam is it is not running after the import"); }
ui.add_space(SECTION_SPACING);
} fn render_steamgriddb_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("SteamGridDB");
fn render_steamgriddb_settings(&mut self, ui: &mut egui::Ui) { ui.checkbox(&mut self.settings.steamgrid_db.enabled, "Download images");
ui.heading("SteamGridDB"); if self.settings.steamgrid_db.enabled {
ui.checkbox(&mut self.settings.steamgrid_db.enabled, "Download images"); ui.horizontal(|ui| {
if self.settings.steamgrid_db.enabled { let mut auth_key = self
ui.horizontal(|ui| { .settings
let mut auth_key = self .steamgrid_db
.settings .auth_key
.steamgrid_db .clone()
.auth_key .unwrap_or_default();
.clone() ui.label("Authentication key: ");
.unwrap_or_default(); if ui.text_edit_singleline(&mut auth_key).changed() {
ui.label("Authentication key: "); if auth_key.is_empty() {
if ui.text_edit_singleline(&mut auth_key).changed() { self.settings.steamgrid_db.auth_key = None;
if auth_key.is_empty() { } else {
self.settings.steamgrid_db.auth_key = None; self.settings.steamgrid_db.auth_key = Some(auth_key.to_string());
} else { }
self.settings.steamgrid_db.auth_key = Some(auth_key.to_string()); }
} if auth_key.is_empty() && ui.button("Paste from clipboard").clicked() {
} if let Ok(mut clipboard_ctx) = copypasta::ClipboardContext::new() {
if auth_key.is_empty() && ui.button("Paste from clipboard").clicked(){ if let Ok(content) = clipboard_ctx.get_contents() {
if let Ok(mut clipboard_ctx) = copypasta::ClipboardContext::new() { self.settings.steamgrid_db.auth_key = Some(content);
if let Ok(content) = clipboard_ctx.get_contents() { }
self.settings.steamgrid_db.auth_key = Some(content); }
} }
} });
} ui.horizontal(|ui| {
}); ui.label(
ui.horizontal(|ui| { "To download images you need an API Key from SteamGridDB, you can find yours",
ui.label( );
"To download images you need an API Key from SteamGridDB, you can find yours", ui.hyperlink_to(
); "here",
ui.hyperlink_to( "https://www.steamgriddb.com/profile/preferences/api",
"here", )
"https://www.steamgriddb.com/profile/preferences/api", });
) ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)");
}); ui.checkbox(
ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)"); &mut self.settings.steamgrid_db.only_download_boilr_images,
ui.checkbox( "Only download images for BoilR shortcuts",
&mut self.settings.steamgrid_db.only_download_boilr_images, );
"Only download images for BoilR shortcuts", }
); ui.add_space(SECTION_SPACING);
} }
ui.add_space(SECTION_SPACING); }
}
}