mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-13 23:54:48 +01:00
move copy_file to file_helpers
This commit is contained in:
@@ -32,4 +32,24 @@ pub fn dir_is_empty(path: &str) -> bool {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn dir_delete(path: &str) {
|
pub fn dir_delete(path: &str) {
|
||||||
fs::remove_dir_all(path).unwrap();
|
fs::remove_dir_all(path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ fn main() {
|
|||||||
system_helpers::run_program,
|
system_helpers::run_program,
|
||||||
system_helpers::run_jar,
|
system_helpers::run_jar,
|
||||||
system_helpers::open_in_browser,
|
system_helpers::open_in_browser,
|
||||||
system_helpers::copy_file,
|
|
||||||
system_helpers::install_location,
|
system_helpers::install_location,
|
||||||
system_helpers::is_elevated,
|
system_helpers::is_elevated,
|
||||||
proxy::set_proxy_addr,
|
proxy::set_proxy_addr,
|
||||||
@@ -55,6 +54,7 @@ fn main() {
|
|||||||
file_helpers::dir_exists,
|
file_helpers::dir_exists,
|
||||||
file_helpers::dir_is_empty,
|
file_helpers::dir_is_empty,
|
||||||
file_helpers::dir_delete,
|
file_helpers::dir_delete,
|
||||||
|
file_helpers::copy_file,
|
||||||
downloader::download_file,
|
downloader::download_file,
|
||||||
downloader::stop_download,
|
downloader::stop_download,
|
||||||
lang::get_lang,
|
lang::get_lang,
|
||||||
|
|||||||
@@ -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]
|
#[tauri::command]
|
||||||
pub fn install_location() -> String {
|
pub fn install_location() -> String {
|
||||||
let mut exe_path = std::env::current_exe().unwrap();
|
let mut exe_path = std::env::current_exe().unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user