diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index 3209ac37..681b1be4 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -1,6 +1,9 @@ +use std::fs; use std::fs::File; +use std::io; use std::io::BufWriter; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::time::SystemTime; mod colour; mod image_loader; @@ -35,6 +38,15 @@ pub struct ImageConverterConfig { } pub fn convert_image(settings: &ImageConverterConfig) { + let source_modified_time = + get_modified_time(&settings.input_image).unwrap_or(SystemTime::now()); + let target_modified_time = + get_modified_time(&settings.output_file).unwrap_or(SystemTime::UNIX_EPOCH); + + if source_modified_time < target_modified_time { + return; + } + let image = Image::load_from_file(&settings.input_image); let tile_size = settings.tile_size.to_size(); @@ -82,3 +94,8 @@ fn optimiser_for_image(image: &Image, tile_size: usize) -> palette16::Palette16O palette_optimiser } + +fn get_modified_time(path: impl AsRef) -> io::Result { + let metadata = fs::metadata(path)?; + metadata.modified() +}