Compare commits
2 commits
2c5db4117b
...
018eb21ecd
Author | SHA1 | Date | |
---|---|---|---|
018eb21ecd | |||
8575b80136 |
4 changed files with 54 additions and 55 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -104,12 +104,6 @@ version = "1.6.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
|
||||
|
||||
[[package]]
|
||||
name = "file-format"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7ef3d5e8ae27277c8285ac43ed153158178ef0f79567f32024ca8140a0c7cd8"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
|
@ -270,11 +264,10 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
|||
|
||||
[[package]]
|
||||
name = "xbst"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"deunicode",
|
||||
"file-format",
|
||||
"thiserror",
|
||||
"zerocopy",
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "xbst"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
@ -8,4 +8,3 @@ thiserror = "2.0.12"
|
|||
clap = { version = "4.5.31", features = ["derive"] }
|
||||
zerocopy = { version = "0.8.26", features = ["derive"] }
|
||||
deunicode = "1.6.2"
|
||||
file-format = "0.26.0"
|
||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -11,7 +11,6 @@ mod utils;
|
|||
|
||||
use clap::Parser;
|
||||
use deunicode::AsciiChars;
|
||||
use file_format::{FileFormat, Kind};
|
||||
use thiserror::Error;
|
||||
use zerocopy::IntoBytes;
|
||||
|
||||
|
@ -140,20 +139,6 @@ fn process(args: &Args) -> Result<(), Errors> {
|
|||
let song = f.as_ref().unwrap();
|
||||
let song_path = song.path();
|
||||
|
||||
// Get file format kind for the files inside soundtracks
|
||||
let format = match FileFormat::from_file(&song_path).map_err(Errors::UnknownIO) {
|
||||
Ok(f) => f.kind(),
|
||||
Err(e) => {
|
||||
eprintln!("\x1b[0;31m{}\x1b[0;20m", e);
|
||||
Kind::Other
|
||||
}
|
||||
};
|
||||
|
||||
// Ignore non audio kind
|
||||
if format != Kind::Audio {
|
||||
continue;
|
||||
}
|
||||
|
||||
song_id[g] = total_songs_count as i32;
|
||||
song_time_miliseconds[g] = match get_duration(song_path) {
|
||||
Ok(s) => s,
|
||||
|
@ -373,37 +358,15 @@ fn write_database(
|
|||
fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?;
|
||||
let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?;
|
||||
|
||||
database.write_all(&header.magic.as_bytes())?;
|
||||
database.write_all(&header.num_soundtracks.as_bytes())?;
|
||||
database.write_all(&header.next_soundtrack_id.as_bytes())?;
|
||||
database.write_all(&header.soundtrack_ids.as_bytes())?;
|
||||
database.write_all(&header.next_song_id.as_bytes())?;
|
||||
database.write_all(&header.padding.as_bytes())?;
|
||||
database.write_all(header.as_bytes())?;
|
||||
|
||||
for st in &soundtracks {
|
||||
database.write_all(&st.magic.as_bytes())?;
|
||||
database.write_all(&st.id.as_bytes())?;
|
||||
database.write_all(&st.num_songs.as_bytes())?;
|
||||
database.write_all(&st.song_groups_ids.as_bytes())?;
|
||||
database.write_all(&st.total_time_miliseconds.as_bytes())?;
|
||||
database.write_all(&st.name.as_bytes())?;
|
||||
database.write_all(&st.padding.as_bytes())?;
|
||||
}
|
||||
database.write_all(soundtracks.as_bytes())?;
|
||||
|
||||
for _ in 0..100 - &soundtracks.len() {
|
||||
database.write_all(&[0 as u8; 512])?;
|
||||
}
|
||||
|
||||
for s in songs {
|
||||
database.write_all(&s.magic.as_bytes())?;
|
||||
database.write_all(&s.soundtrack_id.as_bytes())?;
|
||||
database.write_all(&s.id.as_bytes())?;
|
||||
database.write_all(&s.ipadding.as_bytes())?;
|
||||
database.write_all(&s.song_id.as_bytes())?;
|
||||
database.write_all(&s.song_time_miliseconds.as_bytes())?;
|
||||
database.write_all(&s.song_name.as_bytes())?;
|
||||
database.write_all(&s.cpadding.as_bytes())?;
|
||||
}
|
||||
database.write_all(songs.as_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
54
src/utils.rs
54
src/utils.rs
|
@ -1,6 +1,6 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use zerocopy::TryFromBytes;
|
||||
use zerocopy::{Immutable, IntoBytes};
|
||||
|
||||
pub struct MusicFile {
|
||||
pub path: PathBuf,
|
||||
|
@ -10,8 +10,7 @@ pub struct MusicFile {
|
|||
}
|
||||
|
||||
// https://xboxdevwiki.net/Soundtracks#ST.DB
|
||||
|
||||
#[derive(Debug, TryFromBytes)]
|
||||
#[derive(Debug, Immutable, IntoBytes)]
|
||||
#[repr(C)]
|
||||
pub struct Header {
|
||||
pub magic: i32,
|
||||
|
@ -22,7 +21,7 @@ pub struct Header {
|
|||
pub padding: [char; 24],
|
||||
}
|
||||
|
||||
#[derive(Debug, TryFromBytes)]
|
||||
#[derive(Debug, Immutable, IntoBytes)]
|
||||
#[repr(C)]
|
||||
pub struct Soundtrack {
|
||||
pub magic: i32,
|
||||
|
@ -34,7 +33,7 @@ pub struct Soundtrack {
|
|||
pub padding: [char; 24],
|
||||
}
|
||||
|
||||
#[derive(Debug, TryFromBytes)]
|
||||
#[derive(Debug, Immutable, IntoBytes)]
|
||||
#[repr(C)]
|
||||
pub struct Song {
|
||||
pub magic: i32,
|
||||
|
@ -46,3 +45,48 @@ pub struct Song {
|
|||
pub song_name: [[u8; 2]; 192],
|
||||
pub cpadding: [char; 16],
|
||||
}
|
||||
|
||||
impl Default for Header {
|
||||
#[inline]
|
||||
fn default() -> Header {
|
||||
Header {
|
||||
magic: 0,
|
||||
num_soundtracks: 0,
|
||||
next_soundtrack_id: 0,
|
||||
soundtrack_ids: [0; 100],
|
||||
next_song_id: 0,
|
||||
padding: [char::MIN; 24],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Soundtrack {
|
||||
#[inline]
|
||||
fn default() -> Soundtrack {
|
||||
Soundtrack {
|
||||
magic: 0,
|
||||
id: 0,
|
||||
num_songs: 0,
|
||||
song_groups_ids: [0; 84],
|
||||
total_time_miliseconds: 0,
|
||||
name: [[0; 2]; 32],
|
||||
padding: [char::MIN; 24],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Song {
|
||||
#[inline]
|
||||
fn default() -> Song {
|
||||
Song {
|
||||
magic: 0,
|
||||
soundtrack_id: 0,
|
||||
id: 0,
|
||||
ipadding: 0,
|
||||
song_id: [0; 6],
|
||||
song_time_miliseconds: [0; 6],
|
||||
song_name: [[0; 2]; 192],
|
||||
cpadding: [char::MIN; 16],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue