From dcaefa0a8a4385c55a8270109f3bc8a57d2f49c3 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 2 Mar 2023 20:33:55 +0100 Subject: [PATCH] fix(dtmm): Fix importing archives on Windows The path separators in zip files are OS-specific. Fix #43. --- crates/dtmm/src/controller/app.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/dtmm/src/controller/app.rs b/crates/dtmm/src/controller/app.rs index d8cb619..b9903cf 100644 --- a/crates/dtmm/src/controller/app.rs +++ b/crates/dtmm/src/controller/app.rs @@ -50,10 +50,18 @@ pub(crate) async fn import_mod(state: State, info: FileInfo) -> Result tracing::info!("Importing mod {}", dir_name); + let names: Vec<_> = archive.file_names().map(|s| s.to_string()).collect(); + let mod_cfg: ModConfig = { + let name = names + .iter() + .find(|name| name.ends_with("dtmt.cfg")) + .ok_or_else(|| eyre::eyre!("archive does not contain mod config"))?; + let mut f = archive - .by_name(&format!("{}/{}", dir_name, "dtmt.cfg")) + .by_name(name) .wrap_err("failed to read mod config from archive")?; + let mut buf = Vec::with_capacity(f.size() as usize); f.read_to_end(&mut buf) .wrap_err("failed to read mod config from archive")?; @@ -66,8 +74,13 @@ pub(crate) async fn import_mod(state: State, info: FileInfo) -> Result tracing::debug!(?mod_cfg); let files: HashMap> = { + let name = names + .iter() + .find(|name| name.ends_with("files.sjson")) + .ok_or_else(|| eyre::eyre!("archive does not contain file index"))?; + let mut f = archive - .by_name(&format!("{}/{}", dir_name, "files.sjson")) + .by_name(name) .wrap_err("failed to read file index from archive")?; let mut buf = Vec::with_capacity(f.size() as usize); f.read_to_end(&mut buf)