From a6411b603407553ee592562425f36e4b092b5f9d Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Sat, 28 Sep 2024 09:12:45 -0600 Subject: [PATCH] Cleared errors in admin.rs --- FCLauncher/src-tauri/Cargo.toml | 2 +- FCLauncher/src-tauri/src/admin.rs | 61 ++++++++++++++++++++++------ FCLauncher/src-tauri/tauri.conf.json | 3 +- FCLauncher/src/admin.js | 6 ++- FCLauncher/src/login.js | 6 ++- FCLauncher/src/main.js | 6 ++- 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/FCLauncher/src-tauri/Cargo.toml b/FCLauncher/src-tauri/Cargo.toml index a35076f..12ce30b 100644 --- a/FCLauncher/src-tauri/Cargo.toml +++ b/FCLauncher/src-tauri/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" tauri-build = { version = "1", features = [] } [dependencies] -tauri = { version = "1", features = [ "process-all", "dialog-open", "updater", "dialog-ask", "shell-open"] } +tauri = { version = "1", features = [ "dialog-message", "process-all", "dialog-open", "updater", "dialog-ask", "shell-open"] } serde = { version = "1", features = ["derive"] } serde_json = "1" suppaftp = { version = "6.0.1", features = ["native-tls"] } diff --git a/FCLauncher/src-tauri/src/admin.rs b/FCLauncher/src-tauri/src/admin.rs index 935ff5a..a9135dc 100644 --- a/FCLauncher/src-tauri/src/admin.rs +++ b/FCLauncher/src-tauri/src/admin.rs @@ -124,7 +124,7 @@ pub async fn add_pack(id: String, name: String, window: tauri::Window){ } } let versions: Vec = Vec::new(); - let res = update_versions(id.clone(), versions).await; + let res = update_versions(id.clone(), versions).await; if !res.is_ok() { emit("Error", res.unwrap_err(), window.clone()); } @@ -137,7 +137,7 @@ pub async fn add_pack(id: String, name: String, window: tauri::Window){ } #[tauri::command] -pub async fn remove_pack(id: String){ +pub async fn remove_pack(id: String, window: tauri::Window){ let mut modpacks = get_modpacks().await; let mut index = 0; for pack in modpacks.clone() { @@ -147,7 +147,10 @@ pub async fn remove_pack(id: String){ } index += 1; } - update_modpacks(modpacks).await; + let res = update_modpacks(modpacks).await; + if !res.is_ok() { + emit("Error", res.unwrap_err(), window); + } { let ref mut session = *SESSION.lock().await; if let Some(session) = session{ @@ -166,15 +169,35 @@ pub async fn update_pack(window: tauri::Window, id: String, path: String, versio for i in 0..archive.len() { let mut file = archive.by_index(i).or(Err(format!("error reading archive")))?; - if(file.name() == "overrides/version.txt"){ + if file.name() == "overrides/version.txt" { continue; } - out_archive.start_file(file.name(), SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated)); - std::io::copy(&mut file, &mut out_archive); + let res = out_archive.start_file(file.name(), SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated)); + if !res.is_ok(){ + emit("Error", format!("Unable to start zip archive"), window); + return Err(format!("Unable to start zip archive")); + } + let res = std::io::copy(&mut file, &mut out_archive); + if !res.is_ok(){ + emit("Error", format!("Unable to copy archive to ram"), window); + return Err(format!("Unable to copy archive to ram")); + } + } + let res = out_archive.start_file("overrides/version.txt", SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated)); + if !res.is_ok(){ + emit("Error", format!("Unable to create version file"), window); + return Err(format!("Unable to create version file")); + } + let res = out_archive.write_all(version.as_bytes()); + if !res.is_ok(){ + emit("Error", format!("Unable to write to zip"), window); + return Err(format!("Unable to write to zip")); + } + let res = out_archive.finish(); + if !res.is_ok(){ + emit("Error", format!("Unable to finish zip"), window); + return Err(format!("Unable to finish zip")); } - out_archive.start_file("overrides/version.txt", SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated)); - out_archive.write_all(version.as_bytes()); - out_archive.finish(); buf.rewind().unwrap(); let timestamp = format!("{:?}", chrono::offset::Utc::now()); let path = format!("Versions/{}-{}.mrpack", id, timestamp); @@ -184,23 +207,35 @@ pub async fn update_pack(window: tauri::Window, id: String, path: String, versio let size = buf.clone().bytes().count(); let upload_path = format!("/ftp/{}/{}", id, path.clone()); println!("Uploading to {}", upload_path); - sftp::uplaod(Some(window), session.clone(), PathBuf::from(upload_path), &mut buf, path.clone(), size).await; + let res = sftp::uplaod(Some(window.clone()), session.clone(), PathBuf::from(upload_path), &mut buf, path.clone(), size).await; + if !res.is_ok(){ + emit("Error", res.clone().unwrap_err(), window.clone()); + return res; + } } } let mut versions = get_versions(id.clone()).await?; versions.push(VersionEntry{Version: version, Date: timestamp.clone(), File: path}); - update_versions(id.clone(), versions).await; + let res = update_versions(id.clone(), versions).await; + if !res.is_ok(){ + emit("Error", res.clone().unwrap_err(), window.clone()); + return res; + } let mut modpacks = get_modpacks().await; let mut index = 0; - for mut pack in modpacks.as_slice(){ + for pack in modpacks.as_slice(){ if pack.id == id { modpacks[index].last_updated = timestamp; break; } index += 1; } - update_modpacks(modpacks).await; + let res = update_modpacks(modpacks).await; + if !res.is_ok(){ + emit("Error", res.clone().unwrap_err(), window.clone()); + return res; + } Ok(()) } \ No newline at end of file diff --git a/FCLauncher/src-tauri/tauri.conf.json b/FCLauncher/src-tauri/tauri.conf.json index 5ab6480..ad7cc49 100644 --- a/FCLauncher/src-tauri/tauri.conf.json +++ b/FCLauncher/src-tauri/tauri.conf.json @@ -26,7 +26,8 @@ "dialog": { "all": false, "ask": true, - "open": true + "open": true, + "message": true }, "process": { "all": true diff --git a/FCLauncher/src/admin.js b/FCLauncher/src/admin.js index 11565a5..d1f072b 100644 --- a/FCLauncher/src/admin.js +++ b/FCLauncher/src/admin.js @@ -1,9 +1,13 @@ const { invoke } = window.__TAURI__.tauri; const { listen } = window.__TAURI__.event; -const { ask, open } = window.__TAURI__.dialog; +const { ask, open, message } = window.__TAURI__.dialog; const downBar = document.querySelector(".progressFinished"); //import { listen } from '@tauri-apps/api'; +const error = listen("Error", (error) => { + message(error.payload, {title: "Error", type: "error"}); +}); + var selected_pack = ""; var update_menu = document.getElementById("update"); var create_menu = document.getElementById("create"); diff --git a/FCLauncher/src/login.js b/FCLauncher/src/login.js index 137b754..6f80b14 100644 --- a/FCLauncher/src/login.js +++ b/FCLauncher/src/login.js @@ -1,9 +1,13 @@ const { invoke } = window.__TAURI__.tauri; const { listen } = window.__TAURI__.event; -const { ask } = window.__TAURI__.dialog; +const { ask, message } = window.__TAURI__.dialog; const downBar = document.querySelector(".progressFinished"); //import { listen } from '@tauri-apps/api'; +const error = listen("Error", (error) => { + message(error.payload, {title: "Error", type: "error"}); +}); + window.addEventListener("DOMContentLoaded", () => { document.getElementById("back").addEventListener("click", back); diff --git a/FCLauncher/src/main.js b/FCLauncher/src/main.js index fdf6b24..4081878 100644 --- a/FCLauncher/src/main.js +++ b/FCLauncher/src/main.js @@ -1,10 +1,14 @@ const { invoke } = window.__TAURI__.tauri; const { listen } = window.__TAURI__.event; -const { ask } = window.__TAURI__.dialog; +const { ask, message } = window.__TAURI__.dialog; const { exit } = window.__TAURI__.process; const downBar = document.querySelector(".progressFinished"); //import { listen } from '@tauri-apps/api'; +const error = listen("Error", (error) => { + message(error.payload, {title: "Error", type: "error"}); +}); + const download_progress = listen("download_progress", (progress) => { console.log("Downloading"); //console.log("Downloaded "+progress.payload.downloaded/(1024*1024) +"MB / " + progress.payload.total/(1024*1024) + "MB");