Cleared errors in admin.rs

This commit is contained in:
Samuel Walker 2024-09-28 09:12:45 -06:00
parent 7197fabd1e
commit a6411b6034
6 changed files with 66 additions and 18 deletions

View File

@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] } tauri-build = { version = "1", features = [] }
[dependencies] [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 = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
suppaftp = { version = "6.0.1", features = ["native-tls"] } suppaftp = { version = "6.0.1", features = ["native-tls"] }

View File

@ -137,7 +137,7 @@ pub async fn add_pack(id: String, name: String, window: tauri::Window){
} }
#[tauri::command] #[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 modpacks = get_modpacks().await;
let mut index = 0; let mut index = 0;
for pack in modpacks.clone() { for pack in modpacks.clone() {
@ -147,7 +147,10 @@ pub async fn remove_pack(id: String){
} }
index += 1; 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; let ref mut session = *SESSION.lock().await;
if let Some(session) = session{ 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() { for i in 0..archive.len() {
let mut file = archive.by_index(i).or(Err(format!("error reading archive")))?; 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; continue;
} }
out_archive.start_file(file.name(), SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated)); let res = out_archive.start_file(file.name(), SimpleFileOptions::default().compression_method(zip::CompressionMethod::Deflated));
std::io::copy(&mut file, &mut out_archive); 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(); buf.rewind().unwrap();
let timestamp = format!("{:?}", chrono::offset::Utc::now()); let timestamp = format!("{:?}", chrono::offset::Utc::now());
let path = format!("Versions/{}-{}.mrpack", id, timestamp); 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 size = buf.clone().bytes().count();
let upload_path = format!("/ftp/{}/{}", id, path.clone()); let upload_path = format!("/ftp/{}/{}", id, path.clone());
println!("Uploading to {}", upload_path); 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?; let mut versions = get_versions(id.clone()).await?;
versions.push(VersionEntry{Version: version, Date: timestamp.clone(), File: path}); 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 modpacks = get_modpacks().await;
let mut index = 0; let mut index = 0;
for mut pack in modpacks.as_slice(){ for pack in modpacks.as_slice(){
if pack.id == id { if pack.id == id {
modpacks[index].last_updated = timestamp; modpacks[index].last_updated = timestamp;
break; break;
} }
index += 1; 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(()) Ok(())
} }

View File

@ -26,7 +26,8 @@
"dialog": { "dialog": {
"all": false, "all": false,
"ask": true, "ask": true,
"open": true "open": true,
"message": true
}, },
"process": { "process": {
"all": true "all": true

View File

@ -1,9 +1,13 @@
const { invoke } = window.__TAURI__.tauri; const { invoke } = window.__TAURI__.tauri;
const { listen } = window.__TAURI__.event; const { listen } = window.__TAURI__.event;
const { ask, open } = window.__TAURI__.dialog; const { ask, open, message } = window.__TAURI__.dialog;
const downBar = document.querySelector(".progressFinished"); const downBar = document.querySelector(".progressFinished");
//import { listen } from '@tauri-apps/api'; //import { listen } from '@tauri-apps/api';
const error = listen("Error", (error) => {
message(error.payload, {title: "Error", type: "error"});
});
var selected_pack = ""; var selected_pack = "";
var update_menu = document.getElementById("update"); var update_menu = document.getElementById("update");
var create_menu = document.getElementById("create"); var create_menu = document.getElementById("create");

View File

@ -1,9 +1,13 @@
const { invoke } = window.__TAURI__.tauri; const { invoke } = window.__TAURI__.tauri;
const { listen } = window.__TAURI__.event; const { listen } = window.__TAURI__.event;
const { ask } = window.__TAURI__.dialog; const { ask, message } = window.__TAURI__.dialog;
const downBar = document.querySelector(".progressFinished"); const downBar = document.querySelector(".progressFinished");
//import { listen } from '@tauri-apps/api'; //import { listen } from '@tauri-apps/api';
const error = listen("Error", (error) => {
message(error.payload, {title: "Error", type: "error"});
});
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
document.getElementById("back").addEventListener("click", back); document.getElementById("back").addEventListener("click", back);

View File

@ -1,10 +1,14 @@
const { invoke } = window.__TAURI__.tauri; const { invoke } = window.__TAURI__.tauri;
const { listen } = window.__TAURI__.event; const { listen } = window.__TAURI__.event;
const { ask } = window.__TAURI__.dialog; const { ask, message } = window.__TAURI__.dialog;
const { exit } = window.__TAURI__.process; const { exit } = window.__TAURI__.process;
const downBar = document.querySelector(".progressFinished"); const downBar = document.querySelector(".progressFinished");
//import { listen } from '@tauri-apps/api'; //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) => { const download_progress = listen("download_progress", (progress) => {
console.log("Downloading"); console.log("Downloading");
//console.log("Downloaded "+progress.payload.downloaded/(1024*1024) +"MB / " + progress.payload.total/(1024*1024) + "MB"); //console.log("Downloaded "+progress.payload.downloaded/(1024*1024) +"MB / " + progress.payload.total/(1024*1024) + "MB");