mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 15:14:35 +01:00
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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -23,4 +23,5 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
# moved lang files
|
# moved lang files
|
||||||
/lang
|
/lang
|
||||||
|
package-lock.json
|
||||||
|
|||||||
20
src-tauri/Cargo.lock
generated
20
src-tauri/Cargo.lock
generated
@@ -712,14 +712,18 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
|||||||
name = "cultivation"
|
name = "cultivation"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"cc",
|
||||||
"duct",
|
"duct",
|
||||||
|
"file_diff",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"http",
|
"http",
|
||||||
"hudsucker",
|
"hudsucker",
|
||||||
"is_elevated",
|
"is_elevated",
|
||||||
|
"libloading",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"open 2.1.3",
|
"open 2.1.3",
|
||||||
"rcgen",
|
"rcgen",
|
||||||
|
"regex",
|
||||||
"registry",
|
"registry",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rustls-pemfile",
|
"rustls-pemfile",
|
||||||
@@ -979,6 +983,12 @@ dependencies = [
|
|||||||
"rustc_version 0.3.3",
|
"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]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
@@ -1877,6 +1887,16 @@ dependencies = [
|
|||||||
"pkg-config",
|
"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]]
|
[[package]]
|
||||||
name = "line-wrap"
|
name = "line-wrap"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -40,9 +40,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::copy_file_with_new_name,
|
|
||||||
system_helpers::delete_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,
|
||||||
@@ -53,6 +50,8 @@ fn main() {
|
|||||||
file_helpers::dir_is_empty,
|
file_helpers::dir_is_empty,
|
||||||
file_helpers::dir_delete,
|
file_helpers::dir_delete,
|
||||||
file_helpers::copy_file,
|
file_helpers::copy_file,
|
||||||
|
file_helpers::copy_file_with_new_name,
|
||||||
|
file_helpers::delete_file,
|
||||||
file_helpers::are_files_identical,
|
file_helpers::are_files_identical,
|
||||||
downloader::download_file,
|
downloader::download_file,
|
||||||
downloader::stop_download,
|
downloader::stop_download,
|
||||||
|
|||||||
@@ -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]
|
#[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