Compare commits
No commits in common. "018eb21ecde04a85a120772845328b661c1fa026" and "2c5db4117bfec3f2481de4e7dabcdf5a679b82b4" have entirely different histories.
018eb21ecd
...
2c5db4117b
4 changed files with 55 additions and 54 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -104,6 +104,12 @@ version = "1.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
|
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "file-format"
|
||||||
|
version = "0.26.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e7ef3d5e8ae27277c8285ac43ed153158178ef0f79567f32024ca8140a0c7cd8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -264,10 +270,11 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xbst"
|
name = "xbst"
|
||||||
version = "0.1.2"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"deunicode",
|
"deunicode",
|
||||||
|
"file-format",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "xbst"
|
name = "xbst"
|
||||||
version = "0.1.2"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -8,3 +8,4 @@ thiserror = "2.0.12"
|
||||||
clap = { version = "4.5.31", features = ["derive"] }
|
clap = { version = "4.5.31", features = ["derive"] }
|
||||||
zerocopy = { version = "0.8.26", features = ["derive"] }
|
zerocopy = { version = "0.8.26", features = ["derive"] }
|
||||||
deunicode = "1.6.2"
|
deunicode = "1.6.2"
|
||||||
|
file-format = "0.26.0"
|
||||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -11,6 +11,7 @@ mod utils;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use deunicode::AsciiChars;
|
use deunicode::AsciiChars;
|
||||||
|
use file_format::{FileFormat, Kind};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use zerocopy::IntoBytes;
|
use zerocopy::IntoBytes;
|
||||||
|
|
||||||
|
@ -139,6 +140,20 @@ fn process(args: &Args) -> Result<(), Errors> {
|
||||||
let song = f.as_ref().unwrap();
|
let song = f.as_ref().unwrap();
|
||||||
let song_path = song.path();
|
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_id[g] = total_songs_count as i32;
|
||||||
song_time_miliseconds[g] = match get_duration(song_path) {
|
song_time_miliseconds[g] = match get_duration(song_path) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
|
@ -358,15 +373,37 @@ fn write_database(
|
||||||
fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?;
|
fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?;
|
||||||
let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?;
|
let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?;
|
||||||
|
|
||||||
database.write_all(header.as_bytes())?;
|
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(soundtracks.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())?;
|
||||||
|
}
|
||||||
|
|
||||||
for _ in 0..100 - &soundtracks.len() {
|
for _ in 0..100 - &soundtracks.len() {
|
||||||
database.write_all(&[0 as u8; 512])?;
|
database.write_all(&[0 as u8; 512])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
database.write_all(songs.as_bytes())?;
|
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())?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
54
src/utils.rs
54
src/utils.rs
|
@ -1,6 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use zerocopy::{Immutable, IntoBytes};
|
use zerocopy::TryFromBytes;
|
||||||
|
|
||||||
pub struct MusicFile {
|
pub struct MusicFile {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
|
@ -10,7 +10,8 @@ pub struct MusicFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://xboxdevwiki.net/Soundtracks#ST.DB
|
// https://xboxdevwiki.net/Soundtracks#ST.DB
|
||||||
#[derive(Debug, Immutable, IntoBytes)]
|
|
||||||
|
#[derive(Debug, TryFromBytes)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
pub magic: i32,
|
pub magic: i32,
|
||||||
|
@ -21,7 +22,7 @@ pub struct Header {
|
||||||
pub padding: [char; 24],
|
pub padding: [char; 24],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Immutable, IntoBytes)]
|
#[derive(Debug, TryFromBytes)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Soundtrack {
|
pub struct Soundtrack {
|
||||||
pub magic: i32,
|
pub magic: i32,
|
||||||
|
@ -33,7 +34,7 @@ pub struct Soundtrack {
|
||||||
pub padding: [char; 24],
|
pub padding: [char; 24],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Immutable, IntoBytes)]
|
#[derive(Debug, TryFromBytes)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Song {
|
pub struct Song {
|
||||||
pub magic: i32,
|
pub magic: i32,
|
||||||
|
@ -45,48 +46,3 @@ pub struct Song {
|
||||||
pub song_name: [[u8; 2]; 192],
|
pub song_name: [[u8; 2]; 192],
|
||||||
pub cpadding: [char; 16],
|
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