Skip to content

Commit

Permalink
feat: Added UMSBT file support
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 committed Nov 23, 2024
1 parent 94f20fe commit 3afe54f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'acridotheres'
version = '0.4.1'
version = '0.5.0'
edition = '2021'
description = "Acridotheres Core Library"
license = "MIT"
Expand All @@ -13,4 +13,5 @@ acr = "0.3.2"
chrono = "0.4.38"
crc32fast = "1.4.2"
dh = "0.8.0"
neozip = "0.3.1"
neozip = "0.3.1"
acridotheres-3ds = "0.1.0"
8 changes: 8 additions & 0 deletions src/archive/extract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{io::Result, path::Path};

use crate::{formats::Format, prepare_output_dir};
use acridotheres_3ds::umsbt;
use dh::recommended::*;
use neozip;

Expand All @@ -17,6 +18,13 @@ pub fn extract_all(input: &Path, output: &Path, format: Format, buffer_size: u64
neozip::extract_content(&mut reader, &mut writer, &file, buffer_size)?;
}
}
Format::Umsbt => {
let meta = umsbt::metadata(&mut reader)?;
for file in meta.files {
let mut writer = dh::file::open_w(output.join(&file.path))?;
umsbt::extract(&mut reader, &mut writer, &file, buffer_size)?;
}
}
};

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use dh::Readable;
use std::{io::Result, path::Path};

pub mod auto;
pub mod umsbt;
pub mod zip;

pub enum Format {
Zip,
Umsbt,
}

impl Format {
Expand Down
1 change: 1 addition & 0 deletions src/formats/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn from_str(s: &str) -> Option<Format> {
use Format::*;
match s {
"zip" => Some(Zip),
"umsbt" => Some(Umsbt),
_ => None,
}
}
Empty file added src/formats/umsbt.rs
Empty file.
21 changes: 21 additions & 0 deletions tests/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ fn zip_001() {

std::fs::remove_dir_all(output).unwrap();
}

#[test]
fn umsbt_000() {
let output = Path::new("tests/output/000-umsbt");

extract::extract_all(
Path::new("tests/samples/000.umsbt"),
output,
Format::Umsbt,
1024,
)
.unwrap();

assert!(output.join("00000000.msbt").exists());
assert!(output.join("00000001.msbt").exists());
assert!(output.join("00000002.msbt").exists());
assert!(output.join("00000003.msbt").exists());
assert!(output.join("00000004.msbt").exists());

std::fs::remove_dir_all(output).unwrap();
}
Binary file added tests/samples/000.umsbt
Binary file not shown.

0 comments on commit 3afe54f

Please sign in to comment.