Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-read cams #12

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ To build only the executable, instead run `yarn tauri build -b none`.
## Details:
Uses [sourcepak](https://github.com/barnabwhy/sourcepak-rs) to unpack files from VPKs.

sourcepak version: [v0.1.1](https://crates.io/crates/sourcepak/0.1.1)
sourcepak version: [v0.2.0](https://crates.io/crates/sourcepak/0.2.0)
5 changes: 2 additions & 3 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
tauri = { version = "2.0.0-beta.22", features = ["linux-ipc-protocol"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sourcepak = { version = "0.1.1", features = ["respawn"] }
sourcepak = { version = "0.2.0", features = ["respawn"] }
urlencoding = "2.1.3"
rayon = "1.8.1"
tauri-plugin-dialog = "2.0.0-beta.9"
Expand Down
15 changes: 13 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ async fn select_vpk(window: Window) -> Option<String> {
}

#[tauri::command]
async fn load_vpk(state: tauri::State<'_, AppState>, vpk_path: String) -> Result<(), String> {
async fn load_vpk(
state: tauri::State<'_, AppState>,
window: tauri::Window,
vpk_path: String,
) -> Result<(), String> {
let mut file = File::open(&vpk_path).expect("Failed to open file");

let pak_format = detect_pak_format(&mut file);
Expand All @@ -92,11 +96,18 @@ async fn load_vpk(state: tauri::State<'_, AppState>, vpk_path: String) -> Result
let vpk = VPKRespawn::try_from(&mut file);

match vpk {
Ok(vpk) => {
Ok(mut vpk) => {
let mut state_guard = state.inner.lock().unwrap();

println!("VPK loaded: {}", &vpk_path);

let archive_path = vpk_archive_path(&vpk_path);
let vpk_name = get_vpk_name(&vpk_path);
println!("Attempting to read VPK CAM files from: {}", &archive_path);

let _ = window.emit("load_step", "Reading CAM files...");
vpk.read_all_cams(&archive_path, &vpk_name)?;

state_guard.vpk_path = Some(vpk_path);
state_guard.loaded_format = Some(PakFormat::VPKRespawn);
state_guard.revpk = Some(vpk);
Expand Down
1 change: 1 addition & 0 deletions src/components/Error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mainStore = useStore();
height: 100%;
grid-template-rows: 1fr auto 1fr 56px;
line-height: 1.5;
padding: 2rem;
}

.error-text {
Expand Down
5 changes: 5 additions & 0 deletions src/components/Loading.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { useStore } from '../stores/main';
import { listen } from '@tauri-apps/api/event';

const mainStore = useStore();

let step = ref("Parsing VPK directory tree...");

listen<string>('load_step', (event) => {
step.value = event.payload;
});
</script>

<template>
Expand Down