renaming and extraction display

This commit is contained in:
SpikeHD
2022-05-15 21:32:20 -07:00
parent f8af7caaff
commit 167e13c941
7 changed files with 64 additions and 11 deletions

View File

@@ -0,0 +1,25 @@
use std::fs;
#[tauri::command]
pub fn rename(path: String, new_name: String) {
let mut new_path = path.clone();
// Check if file/folder to replace exists
if !fs::metadata(&path).is_ok() {
return;
}
// Check if path uses forward or back slashes
if new_path.contains("\\") {
new_path = path.replace("\\", "/");
}
let path_replaced = &path.replace(&new_path.split("/").last().unwrap(), &new_name);
fs::rename(path, &path_replaced).unwrap();
}
#[tauri::command]
pub fn dir_exists(path: String) -> bool {
return fs::metadata(&path).is_ok();
}

View File

@@ -6,6 +6,7 @@ windows_subsystem = "windows"
use open;
use structs::{APIQuery};
mod file_helpers;
mod unzip;
mod downloader;
mod lang;
@@ -21,6 +22,8 @@ fn main() {
run_program,
run_jar,
unzip::unzip,
file_helpers::rename,
file_helpers::dir_exists,
open_in_browser,
req_get,
get_bg_file,

View File

@@ -20,8 +20,6 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
thread::spawn(move || {
let fullPath = writePath;
println!("Unzipping file! {}", &zipfile);
window.emit("extract_start", &zipfile);
match zip_extract::extract(f, &fullPath, true) {
@@ -33,8 +31,6 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
}
};
println!("Unzipping done!");
window.emit("extract_end", &zipfile);
});
}