This commit is contained in:
Alex Emmet 2026-04-05 00:03:19 +02:00
commit 1ea0b97f6d
49 changed files with 869 additions and 289 deletions

View file

@ -9,7 +9,7 @@ use uuid::Uuid;
use walkdir::WalkDir;
use zip::ZipArchive;
use crate::log;
#[allow(dead_code)]
pub fn delete_directory(path: &str) -> bool {
@ -23,7 +23,7 @@ fn delete_dir_recursive(directory: &Path) -> bool {
return false;
}
if let Err(e) = fs::remove_dir_all(directory) {
log!(
println!(
"[IMPORTANT] Couldn't delete directory {}: {}",
directory.display(),
e,
@ -97,7 +97,7 @@ pub fn load_file(path: &str, name: &str) -> String {
if !dir.exists() {
if let Err(e) = fs::create_dir_all(&dir) {
log!("[IMPORTANT] Couldn't create directories: {}", e);
println!("[IMPORTANT] Couldn't create directories: {}", e);
return String::new();
}
return String::new();
@ -105,7 +105,7 @@ pub fn load_file(path: &str, name: &str) -> String {
if !file_path.exists() {
if let Err(e) = File::create(&file_path) {
log!("[IMPORTANT] Couldn't create file: {}", e);
println!("[IMPORTANT] Couldn't create file: {}", e);
}
return String::new();
}
@ -130,13 +130,13 @@ pub fn save_file(path: &str, name: &str, value: &str) {
if !dir.exists() {
if let Err(e) = fs::create_dir_all(&dir) {
log!("[IMPORTANT] Couldn't create directories: {}", e);
println!("[IMPORTANT] Couldn't create directories: {}", e);
return;
}
}
if let Err(e) = fs::write(&file_path, value) {
log!(
println!(
"[IMPORTANT] Couldn't write file {}: {}",
file_path.display(),
e
@ -231,7 +231,7 @@ pub async fn download_zip(url: &str, zip_path: &Path) -> Result<(), Box<dyn std:
if !response.status().is_success() {
let err_msg = format!("Failed to download file: Status {}", response.status());
log!("{}", err_msg.clone());
println!("{}", err_msg.clone());
return Err(err_msg.into());
}
@ -314,7 +314,7 @@ fn extract_zip_contents_to_folder(
}
}
log!("Extracting directly (no single root folder detected).");
println!("Extracting directly (no single root folder detected).");
let _ = fs::remove_dir_all(target_dir);
fs::rename(&staging_dir, target_dir)?;
@ -323,14 +323,14 @@ fn extract_zip_contents_to_folder(
#[allow(dead_code)]
pub async fn download_and_extract_zip(url: &str, as_name: &str) {
log!("Downloading ZIP file...");
println!("Downloading ZIP file...");
let base_dir = PathBuf::from(get_directory());
let zip_filename = format!("{}.zip", Uuid::new_v4());
let zip_path = base_dir.join(&zip_filename);
let target_dir = base_dir.join(as_name);
if let Err(e) = download_zip(url, &zip_path).await {
log!("Error downloading file: {}", e);
println!("Error downloading file: {}", e);
return;
}
@ -341,14 +341,14 @@ pub async fn download_and_extract_zip(url: &str, as_name: &str) {
let successful = match extract_result {
Ok(()) => true,
Err(e) => {
log!("Error during ZIP extraction: {}", e);
println!("Error during ZIP extraction: {}", e);
false
}
};
if let Err(e) = tokio::fs::remove_file(&zip_path).await {
log!("Error cleaning up ZIP file {}: {}", zip_path.display(), e);
println!("Error cleaning up ZIP file {}: {}", zip_path.display(), e);
} else if successful {
log!("Downloaded and extracted ZIP file successfully.");
println!("Downloaded and extracted ZIP file successfully.");
}
}