Move things to file_helpers

These were meant to be here anyway but I didn't put it here because other similar methods were in system_helpers
This commit is contained in:
Benj 2022-07-12 14:28:08 +08:00
parent ba2a8b7fec
commit a703843eed
5 changed files with 54 additions and 35 deletions

3
.gitignore vendored
View File

@ -23,4 +23,5 @@ yarn-debug.log*
yarn-error.log*
# moved lang files
/lang
/lang
package-lock.json

20
src-tauri/Cargo.lock generated
View File

@ -712,14 +712,18 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
name = "cultivation"
version = "0.1.0"
dependencies = [
"cc",
"duct",
"file_diff",
"futures-util",
"http",
"hudsucker",
"is_elevated",
"libloading",
"once_cell",
"open 2.1.3",
"rcgen",
"regex",
"registry",
"reqwest",
"rustls-pemfile",
@ -979,6 +983,12 @@ dependencies = [
"rustc_version 0.3.3",
]
[[package]]
name = "file_diff"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31a7a908b8f32538a2143e59a6e4e2508988832d5d4d6f7c156b3cbc762643a5"
[[package]]
name = "filetime"
version = "0.2.17"
@ -1877,6 +1887,16 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "libloading"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
"cfg-if 1.0.0",
"winapi",
]
[[package]]
name = "line-wrap"
version = "0.1.1"

View File

@ -59,3 +59,33 @@ pub fn copy_file(path: String, new_path: String) -> bool {
}
}
}
#[tauri::command]
pub fn copy_file_with_new_name(path: String, new_path: String, new_name: String) -> bool {
let mut new_path_buf = std::path::PathBuf::from(&new_path);
// If the new path doesn't exist, create it.
if !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, new_name)) {
Ok(_) => true,
Err(e) => {
println!("Failed to copy file: {}", e);
false
}
}
}
#[tauri::command]
pub fn delete_file(path: String) -> bool {
match std::fs::remove_file(path) {
Ok(_) => return true,
Err(e) => {
println!("Failed to delete file: {}", e);
return false
}
};
}

View File

@ -40,9 +40,6 @@ fn main() {
system_helpers::run_program,
system_helpers::run_jar,
system_helpers::open_in_browser,
system_helpers::copy_file,
system_helpers::copy_file_with_new_name,
system_helpers::delete_file,
system_helpers::install_location,
system_helpers::is_elevated,
proxy::set_proxy_addr,
@ -53,6 +50,8 @@ fn main() {
file_helpers::dir_is_empty,
file_helpers::dir_delete,
file_helpers::copy_file,
file_helpers::copy_file_with_new_name,
file_helpers::delete_file,
file_helpers::are_files_identical,
downloader::download_file,
downloader::stop_download,

View File

@ -38,37 +38,6 @@ pub fn open_in_browser(url: String) {
};
}
#[tauri::command]
pub fn copy_file_with_new_name(path: String, new_path: String, new_name: String) -> bool {
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, new_name)) {
Ok(_) => true,
Err(e) => {
println!("Failed to copy file: {}", e);
false
}
}
}
#[tauri::command]
pub fn delete_file(path: String) -> bool {
match std::fs::remove_file(path) {
Ok(_) => return true,
Err(e) => {
println!("Failed to delete file: {}", e);
return false
}
};
}
#[tauri::command]
pub fn install_location() -> String {
let mut exe_path = std::env::current_exe().unwrap();