diff --git a/Cargo.lock b/Cargo.lock index b2686f4..b18f728 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,7 +158,7 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "libtlg-rs" -version = "0.1.0" +version = "0.1.1" dependencies = [ "overf", ] @@ -246,7 +246,7 @@ dependencies = [ [[package]] name = "tlg" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "libtlg-rs", diff --git a/libtlg-rs/Cargo.toml b/libtlg-rs/Cargo.toml index fdfc51b..ea3c307 100644 --- a/libtlg-rs/Cargo.toml +++ b/libtlg-rs/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "libtlg-rs" -version = "0.1.0" +version = "0.1.1" description = "Rust version of libtlg" edition = "2024" license = "MIT" +repository = "https://github.com/lifegpc/libtlg-rs" [dependencies] overf = "0.1" diff --git a/libtlg-rs/src/load_tlg.rs b/libtlg-rs/src/load_tlg.rs index 4576f3a..36ca1bd 100644 --- a/libtlg-rs/src/load_tlg.rs +++ b/libtlg-rs/src/load_tlg.rs @@ -205,6 +205,12 @@ pub fn load_tlg(mut src: T) -> Result { if i >= len { break; } + c = tag[i]; + if c != b'=' { + check = false; + break; + } + i += 1; let mut valuelen = 0usize; c = tag[i]; ok = true; diff --git a/tlg/Cargo.toml b/tlg/Cargo.toml index da5da11..e9375db 100644 --- a/tlg/Cargo.toml +++ b/tlg/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "tlg" -version = "0.1.0" +version = "0.1.1" description = "Tools to process TLG image file." edition = "2024" license = "MIT" +repository = "https://github.com/lifegpc/libtlg-rs" [dependencies] clap = { version = "4.5", features = ["derive"] } diff --git a/tlg/src/main.rs b/tlg/src/main.rs index feda7ed..fe1cc9c 100644 --- a/tlg/src/main.rs +++ b/tlg/src/main.rs @@ -1,5 +1,5 @@ mod arg; -use std::io::Seek; +use std::io::{Seek, Write}; fn convert_bgr_to_rgb(data: &mut libtlg_rs::Tlg) { match data.color { @@ -21,6 +21,12 @@ fn convert_bgr_to_rgb(data: &mut libtlg_rs::Tlg) { } } +fn get_relative_path(input: &str, ext: &str) -> String { + let mut pb = std::path::PathBuf::from(input); + pb.set_extension(ext); + pb.to_string_lossy().to_string() +} + fn main() { let args = arg::Arg::parse(); let file = std::fs::File::open(&args.input).expect("Failed to open input file"); @@ -29,11 +35,7 @@ fn main() { let mut tlg = libtlg_rs::load_tlg(&mut file).expect("Failed to load TLG file"); let output = match &args.output { Some(output) => output.clone(), - None => { - let mut pb = std::path::PathBuf::from(&args.input); - pb.set_extension("png"); - pb.to_string_lossy().to_string() - } + None => get_relative_path(&args.input, "png"), }; convert_bgr_to_rgb(&mut tlg); let mut output_file = std::fs::File::create(&output).expect("Failed to create output file"); @@ -48,6 +50,20 @@ fn main() { writer .write_image_data(&tlg.data) .expect("Failed to write PNG image data"); + if !tlg.tags.is_empty() { + let mut tags_file = std::fs::File::create(get_relative_path(&output, "tags")) + .expect("Failed to create tags file"); + for (key, value) in &tlg.tags { + tags_file.write_all(&key).expect("Failed to write tag key"); + tags_file + .write_all(b"=") + .expect("Failed to write tag separator"); + tags_file + .write_all(&value) + .expect("Failed to write tag value"); + tags_file.write_all(b"\n").expect("Failed to write newline"); + } + } } else { file.rewind().expect("Failed to rewind file"); }