From eb56ebbdf58fff4b7120c3cab535337e2063ff69 Mon Sep 17 00:00:00 2001 From: Lucas van Beek Date: Mon, 2 Jan 2023 17:48:54 +0100 Subject: [PATCH] Fix old files not being deleted & progress reporting --- src-tauri/src/main.rs | 8 +++----- src-tauri/src/mrpack/modrinthpack.rs | 6 +++++- src-tauri/tauri.conf.json | 2 +- src/api/filesystem.ts | 3 ++- src/pages/DirectorySelector.vue | 10 +++------- src/pages/Installing.vue | 7 ++++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 88e3210..5ddbce4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -15,7 +15,7 @@ use std::{fs::File, path::PathBuf}; use chrono::{DateTime, Utc}; use futures_util::StreamExt; use image::DynamicImage; -use mrpack::modrinthpack::ModrinthPack; +use mrpack::modrinthpack::{ModrinthPack, ModrinthFileEnvTypes}; use reqwest::Response; use serde_json::{Map, Value}; use types::*; @@ -281,9 +281,7 @@ async fn install_modpack( if is_in_prev_paths && !(is_in_manifest || is_in_overrides || is_in_client_overrides) { println!("{}", &path_str); - if path.starts_with(gamepath) { - fs::remove_file(path).expect("Unable to remove old file"); - } + fs::remove_file(&modpack_dir.join(path)).expect("Unable to remove old file"); } } } @@ -295,7 +293,7 @@ async fn install_modpack( changed_paths.push(file.path.to_owned()); let file_path = &modpack_dir.join(file.path.to_owned()); - if file_path.starts_with(&modpack_dir) { + if file_path.starts_with(&modpack_dir) && file.env.client != ModrinthFileEnvTypes::Unsupported { fs::create_dir_all(file_path.parent().unwrap()).expect("Error creating parent directory"); download_file(&file.downloads[0], file_path, &window, true).await; } diff --git a/src-tauri/src/mrpack/modrinthpack.rs b/src-tauri/src/mrpack/modrinthpack.rs index 3f24a2a..8f9a8dc 100644 --- a/src-tauri/src/mrpack/modrinthpack.rs +++ b/src-tauri/src/mrpack/modrinthpack.rs @@ -9,10 +9,13 @@ pub struct ModrinthFileHashes { pub sha512: String, } -#[derive(Serialize, Deserialize, Clone, Debug)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub enum ModrinthFileEnvTypes { + #[serde(alias = "required")] Required, + #[serde(alias = "optional")] Optional, + #[serde(alias = "unsupported")] Unsupported } @@ -29,6 +32,7 @@ pub struct ModrinthFile { pub downloads: Vec, #[serde(alias = "fileSize")] pub file_size: u64, + pub env: ModrinthFileEnv } #[derive(Deserialize, Serialize, Clone, Debug)] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 31d732f..ed42f7e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -58,7 +58,7 @@ "fs": { "readDir": true, "all": false, - "scope": ["*"] + "scope": [] } }, "windows": [ diff --git a/src/api/filesystem.ts b/src/api/filesystem.ts index e859a8c..4d7fceb 100644 --- a/src/api/filesystem.ts +++ b/src/api/filesystem.ts @@ -20,7 +20,8 @@ export const isMinecraftDirectory = async (directory: string): Promise if (!entries.find(x => x.name == "versions" && x.children)) return false; return true; - } catch { + } catch (e) { + console.log(e) return false; } diff --git a/src/pages/DirectorySelector.vue b/src/pages/DirectorySelector.vue index cf4c6f2..7352ff0 100644 --- a/src/pages/DirectorySelector.vue +++ b/src/pages/DirectorySelector.vue @@ -32,12 +32,8 @@ async function validateAndContinue() { isChecking.value = true; store.error = undefined; - console.log(store.gamePath); - const isMinecraftDir: boolean = await isMinecraftDirectory(store.gamePath); - console.log(isMinecraftDir); if (!isMinecraftDir) { - console.log('nee') isChecking.value = false; store.error = 'This directory is not a valid Minecraft folder.' return; @@ -63,9 +59,9 @@ async function validateAndContinue() { diff --git a/src/pages/Installing.vue b/src/pages/Installing.vue index cf2e057..0b12606 100644 --- a/src/pages/Installing.vue +++ b/src/pages/Installing.vue @@ -5,8 +5,9 @@
-
+
+
@@ -20,7 +21,7 @@ const store = useModpackStore(); const bytes = ref(0); -const total_btyes = ref(0); +const total_bytes = ref(null); interface payload { @@ -51,7 +52,7 @@ onMounted(async () => { await listen('total-filesize', event => { const payload = event.payload as total_filesizepayload; - total_btyes.value = payload.total_bytes; + total_bytes.value = payload.total_bytes; }) await listen('install-done', event => {