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
+8 -8
View File
@@ -52,7 +52,6 @@ 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;
@@ -60,12 +59,13 @@ mod tests{
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();
@@ -74,13 +74,13 @@ mod tests{
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(
std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr"); "XDG_CONFIG_HOME",
std::env::var("HOME").unwrap() + "/.config/boilr",
);
let config_path = get_config_folder(); let config_path = get_config_folder();
let current_path = std::env::var("HOME").unwrap() + "/.config/boilr"; let current_path = std::env::var("HOME").unwrap() + "/.config/boilr";
+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()
+10 -8
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 { settings: load_settings(s) } AmazonPlatform {
settings: load_settings(s),
}
} }
} }
@@ -56,14 +59,12 @@ impl GamesPlatform for AmazonPlatform{
"Amazon" "Amazon"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
} }
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) {
@@ -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()?;
@@ -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::AmazonPlatform;
pub use amazon_platform::AmazonGame; pub use amazon_platform::AmazonGame;
pub use amazon_platform::AmazonPlatform;
+6 -3
View File
@@ -5,7 +5,9 @@ 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 {
@@ -14,7 +16,9 @@ pub struct BottlesPlatform {
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),
}
} }
} }
@@ -124,7 +128,6 @@ impl BottlesPlatform {
} }
} }
impl GamesPlatform for BottlesPlatform { impl GamesPlatform for BottlesPlatform {
fn name(&self) -> &str { fn name(&self) -> &str {
"Bottles" "Bottles"
+1 -1
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};
-1
View File
@@ -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()
} }
-1
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() {
+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::*;
+3 -4
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};
@@ -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,7 +61,6 @@ 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 {
@@ -74,7 +74,6 @@ impl GamesPlatform for FlatpakPlatform{
"Flatpak" "Flatpak"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
} }
+3 -2
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,
@@ -222,7 +224,6 @@ 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 {
+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;
+20 -22
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;
@@ -107,7 +107,10 @@ 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) {
@@ -199,12 +202,11 @@ 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),
} }
} }
} }
@@ -214,7 +216,6 @@ impl GamesPlatform for HeroicPlatform{
"Heroic" "Heroic"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
} }
@@ -226,8 +227,14 @@ 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,
"Always launch games through Heroic",
);
let safe_mode_header = match (
self.settings.default_launch_through_heroic,
self.settings.launch_games_through_heroic.len(),
) {
(false, 0) => "Force games to launch through Heroic Launcher".to_string(), (false, 0) => "Force games to launch through Heroic Launcher".to_string(),
(false, 1) => "One game forced 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), (false, x) => format!("{} games forced to launch through Heroic Launcher", x),
@@ -235,30 +242,22 @@ impl GamesPlatform for HeroicPlatform{
(true, 0) => "Force games to launch directly".to_string(), (true, 0) => "Force games to launch directly".to_string(),
(true, 1) => "One game forced to launch directly".to_string(), (true, 1) => "One game forced to launch directly".to_string(),
(true, x) => format!("{} games forced to launch directly", x), (true, x) => format!("{} games forced to launch directly", x),
}; };
egui::CollapsingHeader::new(safe_mode_header)
.id_source("Heroic_Launcher_safe_launch")
.show(ui, |ui| {
if
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| {
if 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.");
} else { } 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."); 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 manifests = self.heroic_games.get_or_insert_with(|| {
let heroic_setting = self.settings.clone(); let heroic_setting = self.settings.clone();
let heroic_platform = HeroicPlatform{ settings:heroic_setting, heroic_games:None};
let heroic_platform = HeroicPlatform{
settings:heroic_setting,
heroic_games:None
};
heroic_platform.get_heroic_games().unwrap_or_default() heroic_platform.get_heroic_games().unwrap_or_default()
}); });
let safe_open_games = &mut self.settings.launch_games_through_heroic; let safe_open_games = &mut self.settings.launch_games_through_heroic;
for manifest in manifests{ for manifest in manifests{
let key = manifest.app_name(); let key = manifest.app_name();
let display_name = manifest.title(); let display_name = manifest.title();
@@ -272,7 +271,6 @@ self.settings.default_launch_through_heroic{
} }
} }
}); });
} }
fn get_settings_serilizable(&self) -> String { fn get_settings_serilizable(&self) -> String {
-2
View File
@@ -38,8 +38,6 @@ 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")
+9 -12
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;
@@ -90,8 +92,6 @@ pub fn get_default_location() -> 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,7 +100,6 @@ 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;
} }
}); });
@@ -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;
@@ -76,7 +78,7 @@ 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 settings::LegendarySettings;
pub use legendary_platform::LegendaryPlatform; pub use legendary_platform::LegendaryPlatform;
pub use settings::LegendarySettings;
+6 -5
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)]
@@ -59,7 +61,9 @@ fn get_lutris_command_output(settings: &LutrisSettings) -> eyre::Result<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),
}
} }
} }
@@ -68,14 +72,12 @@ impl GamesPlatform for LutrisPlatform{
"Lutris" "Lutris"
} }
fn enabled(&self) -> bool { fn enabled(&self) -> bool {
self.settings.enabled self.settings.enabled
} }
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) {
@@ -106,5 +108,4 @@ impl GamesPlatform for LutrisPlatform{
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 use settings::OriginSettings;
pub(crate) use origin_platform::OriginPlatform; pub(crate) use origin_platform::OriginPlatform;
pub use settings::OriginSettings;
+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(
+6 -5
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),
}
} }
} }
+1 -3
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
@@ -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;
} }
+1 -5
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 {
@@ -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;
} }
+2 -4
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,7 +98,6 @@ 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"
} }
} }
-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;
} }
} }
+9 -11
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,
@@ -106,7 +106,6 @@ impl MyEguiApp {
} }
} }
} }
}); });
} }
}, },
@@ -114,7 +113,6 @@ impl MyEguiApp {
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,7 +123,6 @@ 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();
@@ -142,7 +139,6 @@ impl MyEguiApp {
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());
@@ -150,7 +146,9 @@ impl MyEguiApp {
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
@@ -168,11 +166,11 @@ 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![];
@@ -184,11 +182,11 @@ fn to_shortcut_owned(shortcuts_to_import: Vec<(String, Vec<ShortcutToImport>)>)
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 (name, shortcuts) in shortcut_infos {
-2
View File
@@ -38,7 +38,6 @@ impl MyEguiApp {
}); });
} }
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| {
@@ -56,7 +55,6 @@ impl MyEguiApp {
} else { } else {
self.settings.steam.location = Some(steam_location.to_string()); self.settings.steam.location = Some(steam_location.to_string());
} }
} }
}); });
ui.checkbox( ui.checkbox(