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)
This commit is contained in:
Black_Raven committed 2026-02-24 11:26:16 +03:00
1 parent ac81699556
commit 2efac086d0
1 file changed
+31 -9
+31 -9
View File
@@ -4,10 +4,20 @@ use std::process::Command;
pub struct RcloneApp {
rclone_path: PathBuf,
using_system_rclone: bool,
}
impl RcloneApp {
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
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<PathBuf> {
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<dyn std::error::Error>> {
@@ -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<String, String> {
println!(
"Запускаю: {} {}",
self.rclone_path.display(),
args.join(" ")
);
fn run_command(&self, args: &[&str]) -> Result<String, String> {
let output = Command::new(&self.rclone_path)
.args(args)
.output()