From 2efac086d0dc4fba3679daa39ebf4e10a0ea73b4 Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 24 Feb 2026 11:26:16 +0300 Subject: [PATCH] feat(rclone.exe): Rewrite rclone This rewriting is important because the old version of code can`t use system rclone (if it hed been installed already) --- src/rcloneInstall.rs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/rcloneInstall.rs b/src/rcloneInstall.rs index 7011e11..4b568f4 100644 --- a/src/rcloneInstall.rs +++ b/src/rcloneInstall.rs @@ -4,10 +4,20 @@ use std::process::Command; pub struct RcloneApp { rclone_path: PathBuf, + using_system_rclone: bool, } impl RcloneApp { pub fn new() -> Result> { + if let Some(system_rclone) = Self::check_system_rclone() { + println!("Найден системный rclone: {:?}", system_rclone); + return Ok(Self { + rclone_path: system_rclone, + using_system_rclone: true, + }); + } + println!("Системный rclone не найден, использую встроенную версию"); + let app_dir = dirs::data_dir() .ok_or("Не удалось найти папку для данных")? .join("rclone-ui"); @@ -23,7 +33,25 @@ impl RcloneApp { Self::extract_rclone(&rclone_path)?; } - Ok(Self { rclone_path }) + Ok(Self { + rclone_path, + using_system_rclone: false, + }) + } + + fn check_system_rclone() -> Option { + if let Ok(path) = which::which("rclone") { + return Some(path); + } + + #[cfg(windows)] + { + if let Ok(path) = which::which("rclone.exe") { + return Some(path); + } + } + + None } fn extract_rclone(dest_path: &PathBuf) -> Result<(), Box> { @@ -45,7 +73,7 @@ impl RcloneApp { { use std::os::unix::fs::PermissionsExt; let mut perms = fs::metadata(dest_path)?.permissions(); - perms.set_mode(0o755); // rwxr-xr-x + perms.set_mode(0o755); fs::set_permissions(dest_path, perms)?; } @@ -53,13 +81,7 @@ impl RcloneApp { Ok(()) } - pub fn run_command(&self, args: &[&str]) -> Result { - println!( - "Запускаю: {} {}", - self.rclone_path.display(), - args.join(" ") - ); - + fn run_command(&self, args: &[&str]) -> Result { let output = Command::new(&self.rclone_path) .args(args) .output()