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:
1 parent
ac81699556
commit
2efac086d0
1 file changed
+31
-9
+31
-9
@@ -4,10 +4,20 @@ use std::process::Command;
|
|||||||
|
|
||||||
pub struct RcloneApp {
|
pub struct RcloneApp {
|
||||||
rclone_path: PathBuf,
|
rclone_path: PathBuf,
|
||||||
|
using_system_rclone: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RcloneApp {
|
impl RcloneApp {
|
||||||
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
|
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()
|
let app_dir = dirs::data_dir()
|
||||||
.ok_or("Не удалось найти папку для данных")?
|
.ok_or("Не удалось найти папку для данных")?
|
||||||
.join("rclone-ui");
|
.join("rclone-ui");
|
||||||
@@ -23,7 +33,25 @@ impl RcloneApp {
|
|||||||
Self::extract_rclone(&rclone_path)?;
|
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>> {
|
fn extract_rclone(dest_path: &PathBuf) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -45,7 +73,7 @@ impl RcloneApp {
|
|||||||
{
|
{
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
let mut perms = fs::metadata(dest_path)?.permissions();
|
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)?;
|
fs::set_permissions(dest_path, perms)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,13 +81,7 @@ impl RcloneApp {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_command(&self, args: &[&str]) -> Result<String, String> {
|
fn run_command(&self, args: &[&str]) -> Result<String, String> {
|
||||||
println!(
|
|
||||||
"Запускаю: {} {}",
|
|
||||||
self.rclone_path.display(),
|
|
||||||
args.join(" ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let output = Command::new(&self.rclone_path)
|
let output = Command::new(&self.rclone_path)
|
||||||
.args(args)
|
.args(args)
|
||||||
.output()
|
.output()
|
||||||
|
|||||||
Reference in new issue
Block a user