diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 318b942..00dcdc0 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -563,6 +563,74 @@ fn count_dir(state: tauri::State<'_, AppState>, dir: &str) -> usize { } } +#[tauri::command] +fn get_dir_size(state: tauri::State<'_, AppState>, dir: &str) -> usize { + let state_guard = state.inner.lock().unwrap(); + + match state_guard.loaded_format { + Some(PakFormat::VPKRespawn) => { + let vpk = state_guard.revpk.as_ref().unwrap(); + + vpk.tree + .files + .iter() + .map(|(f, e)| { + if f.starts_with(dir) { + e.file_parts.iter().map(|e| e.entry_length as usize).sum() + } else { + 0 + } + }) + .sum() + } + Some(PakFormat::VPKVersion1) => { + let vpk = state_guard.vpk_version1.as_ref().unwrap(); + + vpk.tree + .files + .iter() + .map(|(f, e)| { + if f.starts_with(dir) { + e.entry_length as usize + } else { + 0 + } + }) + .sum() + } + _ => 0, + } +} + +#[tauri::command] +fn get_dir_size_uncompressed(state: tauri::State<'_, AppState>, dir: &str) -> Option { + let state_guard = state.inner.lock().unwrap(); + + match state_guard.loaded_format { + Some(PakFormat::VPKRespawn) => { + let vpk = state_guard.revpk.as_ref().unwrap(); + + Some( + vpk.tree + .files + .iter() + .map(|(f, e)| { + if f.starts_with(dir) { + e.file_parts + .iter() + .map(|e| e.entry_length_uncompressed as usize) + .sum() + } else { + 0 + } + }) + .sum(), + ) + } + _ => None, + } +} + #[tauri::command] async fn extract_dir( window: Window, @@ -1004,6 +1072,8 @@ fn main() { extract_file, extract_files, count_dir, + get_dir_size, + get_dir_size_uncompressed, extract_cancel, read_file, ]) diff --git a/src/components/FileTree.vue b/src/components/FileTree.vue index 5d97e15..5907c45 100644 --- a/src/components/FileTree.vue +++ b/src/components/FileTree.vue @@ -21,6 +21,10 @@ let previewPath = ref(''); let previewURL = ref(null); let previewText = ref(''); +let selectedDirCount = ref(0); +let selectedDirSize = ref(0); +let selectedDirDecompressedSize = ref(null); + async function selectFile(path: string) { selectedEntry.value = undefined; selectedPath.value = path; @@ -28,6 +32,13 @@ async function selectFile(path: string) { if (!path.includes('/')) { path = ' /' + path; } + + if (path.endsWith('/')) { + selectedDirCount.value = await invoke('count_dir', { dir: path }); + selectedDirSize.value = await invoke('get_dir_size', { dir: path }); + selectedDirDecompressedSize.value = await invoke('get_dir_size_uncompressed', { dir: path }); + } + selectedEntry.value = await invoke('get_file_entry', { path }); } @@ -43,7 +54,7 @@ async function previewFile(path: string) { try { if (isTextFile(previewPath.value)) { previewLoading.value = true; - const arr = new Uint8Array(await invoke('read_file', { path })); + const arr = new Uint8Array(await invoke('read_file', { path })); previewText.value = new TextDecoder(getTextEncoding(arr)).decode(arr); previewLoading.value = false; } else if (isAudioFile(previewPath.value)) { @@ -51,7 +62,7 @@ async function previewFile(path: string) { previewURL.value = convertFileSrc(path, 'preview'); } else { previewLoading.value = true; - const arr = new Uint8Array(await invoke('read_file', { path })); + const arr = new Uint8Array(await invoke('read_file', { path })); const blob = new Blob([arr]); previewURL.value = URL.createObjectURL(blob); previewLoading.value = false; @@ -105,7 +116,8 @@ watch(selectMode, (newVal) => {