diff --git a/src-tauri/src/file_helpers.rs b/src-tauri/src/file_helpers.rs index c47f63b..9e99a72 100644 --- a/src-tauri/src/file_helpers.rs +++ b/src-tauri/src/file_helpers.rs @@ -32,4 +32,24 @@ pub fn dir_is_empty(path: &str) -> bool { #[tauri::command] pub fn dir_delete(path: &str) { fs::remove_dir_all(path).unwrap(); -} \ No newline at end of file +} + +#[tauri::command] +pub fn copy_file(path: String, new_path: String) -> bool { + let filename = &path.split("/").last().unwrap(); + let mut new_path_buf = std::path::PathBuf::from(&new_path); + + // If the new path doesn't exist, create it. + if !file_helpers::dir_exists(new_path_buf.pop().to_string().as_str()) { + std::fs::create_dir_all(&new_path).unwrap(); + } + + // Copy old to new + match std::fs::copy(&path, format!("{}/{}", new_path, filename)) { + Ok(_) => true, + Err(e) => { + println!("Failed to copy file: {}", e); + false + } + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index afa2e8f..d236ef9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -45,7 +45,6 @@ fn main() { system_helpers::run_program, system_helpers::run_jar, system_helpers::open_in_browser, - system_helpers::copy_file, system_helpers::install_location, system_helpers::is_elevated, proxy::set_proxy_addr, @@ -55,6 +54,7 @@ fn main() { file_helpers::dir_exists, file_helpers::dir_is_empty, file_helpers::dir_delete, + file_helpers::copy_file, downloader::download_file, downloader::stop_download, lang::get_lang, diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 329243f..932042d 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -46,26 +46,6 @@ pub fn open_in_browser(url: String) { }; } -#[tauri::command] -pub fn copy_file(path: String, new_path: String) -> bool { - let filename = &path.split("/").last().unwrap(); - let mut new_path_buf = std::path::PathBuf::from(&new_path); - - // If the new path doesn't exist, create it. - if !file_helpers::dir_exists(new_path_buf.pop().to_string().as_str()) { - std::fs::create_dir_all(&new_path).unwrap(); - } - - // Copy old to new - match std::fs::copy(&path, format!("{}/{}", new_path, filename)) { - Ok(_) => true, - Err(e) => { - println!("Failed to copy file: {}", e); - false - } - } -} - #[tauri::command] pub fn install_location() -> String { let mut exe_path = std::env::current_exe().unwrap();