Skip to content

Commit

Permalink
Fix old files not being deleted & progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvbeek committed Jan 2, 2023
1 parent b84d9bc commit eb56ebb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 3 additions & 5 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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");
}
}
}
Expand All @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src-tauri/src/mrpack/modrinthpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -29,6 +32,7 @@ pub struct ModrinthFile {
pub downloads: Vec<String>,
#[serde(alias = "fileSize")]
pub file_size: u64,
pub env: ModrinthFileEnv
}

#[derive(Deserialize, Serialize, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"fs": {
"readDir": true,
"all": false,
"scope": ["*"]
"scope": []
}
},
"windows": [
Expand Down
3 changes: 2 additions & 1 deletion src/api/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const isMinecraftDirectory = async (directory: string): Promise<boolean>
if (!entries.find(x => x.name == "versions" && x.children)) return false;

return true;
} catch {
} catch (e) {
console.log(e)
return false;
}

Expand Down
10 changes: 3 additions & 7 deletions src/pages/DirectorySelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,9 +59,9 @@ async function validateAndContinue() {
</div>
<input
v-model="store.gamePath"
type="email"
name="email"
id="email"
name="path"
id="path"
disabled
class="focus:ring-teal-500 focus:border-teal-500 block w-full rounded-none rounded-l-md pl-10 sm:text-sm text-neutral-200 border border-neutral-500 bg-neutral-700"
/>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/pages/Installing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<span v-text="store.selectedModpack?.name"></span>
</h2>
<div class="bg-gray-200 rounded-full overflow-hidden">
<div class="h-2 bg-teal-600 rounded-full" v-bind:style="{ width: (bytes / total_btyes * 100) + '%' }" />
<div class="h-2 bg-teal-600 rounded-full" v-bind:style="{ width: (total_bytes ? (bytes / total_bytes * 100) : 0 )+ '%' }" />
</div>
<span class="text-gray-300 text-xs tracking-wider font-medium" v-text="(total_bytes ? (bytes / total_bytes * 100).toFixed(0) : 0 )+ '%'"></span>
</div>
</template>

Expand All @@ -20,7 +21,7 @@ const store = useModpackStore();
const bytes = ref<number>(0);
const total_btyes = ref<number>(0);
const total_bytes = ref<number|null>(null);
interface payload {
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit eb56ebb

Please sign in to comment.