mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Create symlinks on linux
This commit is contained in:
@@ -5,9 +5,11 @@ enabled = false
|
|||||||
|
|
||||||
[gog]
|
[gog]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
create_symlinks = true
|
||||||
|
|
||||||
[epic_games]
|
[epic_games]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
create_symlinks = true
|
||||||
|
|
||||||
[legendary]
|
[legendary]
|
||||||
enabled = false
|
enabled = false
|
||||||
@@ -16,6 +18,7 @@ enabled = false
|
|||||||
|
|
||||||
[itch]
|
[itch]
|
||||||
enabled = false
|
enabled = false
|
||||||
|
create_symlinks = true
|
||||||
|
|
||||||
[steamgrid_db]
|
[steamgrid_db]
|
||||||
enabled = true
|
enabled = true
|
||||||
@@ -27,4 +27,9 @@ impl Platform<ManifestItem, EpicGamesManifestsError> for EpicPlatform {
|
|||||||
fn get_shortcuts(&self) -> Result<Vec<ManifestItem>, EpicGamesManifestsError> {
|
fn get_shortcuts(&self) -> Result<Vec<ManifestItem>, EpicGamesManifestsError> {
|
||||||
get_egs_manifests(&self.settings)
|
get_egs_manifests(&self.settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_symlinks(&self) -> bool {
|
||||||
|
self.settings.create_symlinks
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ use serde::{Serialize,Deserialize};
|
|||||||
pub struct EpicGamesLauncherSettings {
|
pub struct EpicGamesLauncherSettings {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub location: Option<String>,
|
pub location: Option<String>,
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub create_symlinks: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
|
|||||||
"Gog"
|
"Gog"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_symlinks(&self) -> bool {
|
||||||
|
self.settings.create_symlinks
|
||||||
|
}
|
||||||
|
|
||||||
fn get_shortcuts(&self) -> Result<Vec<GogShortcut>, GogErrors> {
|
fn get_shortcuts(&self) -> Result<Vec<GogShortcut>, GogErrors> {
|
||||||
let gog_location = self
|
let gog_location = self
|
||||||
.settings
|
.settings
|
||||||
@@ -36,14 +41,13 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
|
|||||||
return Err(GogErrors::ConfigFileNotFound { path: config_path });
|
return Err(GogErrors::ConfigFileNotFound { path: config_path });
|
||||||
}
|
}
|
||||||
let install_locations = get_install_locations(config_path)?;
|
let install_locations = get_install_locations(config_path)?;
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
let install_locations = if let Some(wine_c_drive) = &self.settings.wine_c_drive {
|
let install_locations = if let Some(wine_c_drive) = &self.settings.wine_c_drive {
|
||||||
fix_paths(&wine_c_drive, install_locations)
|
fix_paths(&wine_c_drive, install_locations)
|
||||||
} else {
|
} else {
|
||||||
install_locations
|
install_locations
|
||||||
};
|
};
|
||||||
|
|
||||||
dbg!(&install_locations);
|
|
||||||
|
|
||||||
let mut game_folders = vec![];
|
let mut game_folders = vec![];
|
||||||
for install_location in install_locations {
|
for install_location in install_locations {
|
||||||
let path = Path::new(&install_location);
|
let path = Path::new(&install_location);
|
||||||
@@ -143,11 +147,8 @@ impl Platform<GogShortcut, GogErrors> for GogPlatform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
fn fix_paths(wine_c_drive: &String, paths: Vec<String>) -> Vec<String> {
|
fn fix_paths(wine_c_drive: &String, paths: Vec<String>) -> Vec<String> {
|
||||||
#[cfg(not(target_os = "linux"))]
|
|
||||||
return paths;
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
{
|
|
||||||
paths
|
paths
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|path| {
|
.flat_map(|path| {
|
||||||
@@ -159,7 +160,6 @@ fn fix_paths(wine_c_drive: &String, paths: Vec<String>) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_install_locations(path: PathBuf) -> Result<Vec<String>, GogErrors> {
|
fn get_install_locations(path: PathBuf) -> Result<Vec<String>, GogErrors> {
|
||||||
|
|||||||
@@ -4,5 +4,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub struct GogSettings {
|
pub struct GogSettings {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub location: Option<String>,
|
pub location: Option<String>,
|
||||||
pub wine_c_drive: Option<String>
|
pub wine_c_drive: Option<String>,
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub create_symlinks: bool,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ impl Platform<ItchGame, ItchErrors> for ItchPlatform {
|
|||||||
let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect();
|
let res = paths.iter().filter_map(|e| dbpath_to_game(*e)).collect();
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_symlinks(&self) -> bool {
|
||||||
|
self.settings.create_symlinks
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dbpath_to_game(paths: &DbPaths<'_>) -> Option<ItchGame> {
|
fn dbpath_to_game(paths: &DbPaths<'_>) -> Option<ItchGame> {
|
||||||
|
|||||||
@@ -4,4 +4,6 @@ use serde::{Serialize,Deserialize};
|
|||||||
pub struct ItchSettings {
|
pub struct ItchSettings {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub location: Option<String>,
|
pub location: Option<String>,
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub create_symlinks: bool,
|
||||||
}
|
}
|
||||||
@@ -32,4 +32,9 @@ impl Platform<LegendaryGame, Box<dyn Error>> for LegendaryPlatform {
|
|||||||
let legendary_ouput = from_str(&json)?;
|
let legendary_ouput = from_str(&json)?;
|
||||||
Ok(legendary_ouput)
|
Ok(legendary_ouput)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_symlinks(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ impl Platform<OriginGame, OriginErrors> for OriginPlatform {
|
|||||||
"Origin"
|
"Origin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_symlinks(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
fn get_shortcuts(&self) -> Result<Vec<OriginGame>, OriginErrors> {
|
fn get_shortcuts(&self) -> Result<Vec<OriginGame>, OriginErrors> {
|
||||||
let origin_folder = Path::new(
|
let origin_folder = Path::new(
|
||||||
&self
|
&self
|
||||||
|
|||||||
@@ -9,4 +9,7 @@ where
|
|||||||
fn name(&self) -> &str;
|
fn name(&self) -> &str;
|
||||||
|
|
||||||
fn get_shortcuts(&self) -> Result<Vec<T>, E>;
|
fn get_shortcuts(&self) -> Result<Vec<T>, E>;
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_symlinks(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-4
@@ -1,5 +1,4 @@
|
|||||||
|
use steam_shortcuts_util::{shortcut::ShortcutOwned, shortcuts_to_bytes, Shortcut};
|
||||||
use steam_shortcuts_util::{Shortcut, shortcut::ShortcutOwned, shortcuts_to_bytes};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
egs::EpicPlatform,
|
egs::EpicPlatform,
|
||||||
@@ -10,14 +9,13 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
|
||||||
use std::{fs::File, io::Write, path::Path};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
gog::GogPlatform,
|
gog::GogPlatform,
|
||||||
itch::ItchPlatform,
|
itch::ItchPlatform,
|
||||||
origin::OriginPlatform,
|
origin::OriginPlatform,
|
||||||
steamgriddb::{download_images, CachedSearch},
|
steamgriddb::{download_images, CachedSearch},
|
||||||
};
|
};
|
||||||
|
use std::{fs::File, io::Write, path::Path};
|
||||||
|
|
||||||
pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
|
pub async fn run_sync(settings: &Settings) -> Result<(), Box<dyn Error>> {
|
||||||
let userinfo_shortcuts = get_shortcuts_paths(&settings.steam)?;
|
let userinfo_shortcuts = get_shortcuts_paths(&settings.steam)?;
|
||||||
@@ -108,6 +106,20 @@ where
|
|||||||
if platform.enabled() {
|
if platform.enabled() {
|
||||||
let shortcuts_to_add_result = platform.get_shortcuts();
|
let shortcuts_to_add_result = platform.get_shortcuts();
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
if platform.create_symlinks() {
|
||||||
|
let boilr_links_path = get_boilr_links_path();
|
||||||
|
if !boilr_links_path.exists() {
|
||||||
|
if let Err(e) = std::fs::create_dir_all(&boilr_links_path) {
|
||||||
|
println!(
|
||||||
|
"Could not create links folder for symlinks at path: {:?} , error: {:?} , you can try to disable creating symlinks for platform {}",
|
||||||
|
boilr_links_path, e, platform.name()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match shortcuts_to_add_result {
|
match shortcuts_to_add_result {
|
||||||
Ok(shortcuts_to_add) => {
|
Ok(shortcuts_to_add) => {
|
||||||
println!(
|
println!(
|
||||||
@@ -115,9 +127,16 @@ where
|
|||||||
shortcuts_to_add.len(),
|
shortcuts_to_add.len(),
|
||||||
platform.name()
|
platform.name()
|
||||||
);
|
);
|
||||||
|
|
||||||
current_shortcuts.retain(|f| !f.tags.contains(&platform.name().to_owned()));
|
current_shortcuts.retain(|f| !f.tags.contains(&platform.name().to_owned()));
|
||||||
for shortcut in shortcuts_to_add {
|
for shortcut in shortcuts_to_add {
|
||||||
let shortcut_owned: ShortcutOwned = shortcut.into();
|
let shortcut_owned: ShortcutOwned = shortcut.into();
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
let shortcut_owned = if platform.create_symlinks() {
|
||||||
|
create_sym_links(&shortcut_owned)
|
||||||
|
} else {
|
||||||
|
shortcut_owned
|
||||||
|
};
|
||||||
current_shortcuts.push(shortcut_owned);
|
current_shortcuts.push(shortcut_owned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,3 +147,47 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn get_boilr_links_path() -> std::path::PathBuf {
|
||||||
|
let home = std::env::var("HOME").expect("Expected a home variable to be defined");
|
||||||
|
let boilr_links_path = Path::new(&home).join(".boilr").join("links");
|
||||||
|
boilr_links_path
|
||||||
|
}
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
fn create_sym_links(shortcut: &ShortcutOwned) -> ShortcutOwned {
|
||||||
|
let links_folder = get_boilr_links_path();
|
||||||
|
|
||||||
|
let target_link = links_folder.join(format!("t{}", shortcut.app_id));
|
||||||
|
let workdir_link = links_folder.join(format!("w{}", shortcut.app_id));
|
||||||
|
|
||||||
|
let target_original = Path::new(&shortcut.exe);
|
||||||
|
let workdir_original = Path::new(&shortcut.start_dir);
|
||||||
|
|
||||||
|
use std::os::unix::fs::symlink;
|
||||||
|
|
||||||
|
match (
|
||||||
|
symlink(&target_original, &target_link),
|
||||||
|
symlink(&workdir_original, &workdir_link),
|
||||||
|
) {
|
||||||
|
(Ok(_), Ok(_)) => {
|
||||||
|
let exe = target_link.to_string_lossy().to_string();
|
||||||
|
let start_dir = workdir_link.to_string_lossy().to_string();
|
||||||
|
let new_shortcut = Shortcut::new(
|
||||||
|
0,
|
||||||
|
shortcut.app_name.as_str(),
|
||||||
|
exe.as_str(),
|
||||||
|
&start_dir.as_str(),
|
||||||
|
shortcut.icon.as_str(),
|
||||||
|
shortcut.shortcut_path.as_str(),
|
||||||
|
shortcut.launch_options.as_str(),
|
||||||
|
);
|
||||||
|
let mut new_shortcut = new_shortcut.to_owned();
|
||||||
|
new_shortcut.tags = shortcut.tags.clone();
|
||||||
|
new_shortcut
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Could not create symlinks for game: {}", shortcut.app_name);
|
||||||
|
shortcut.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user