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