From b4c3bd7356b68e74e23748db0dad7ceb3997fb68 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Tue, 20 Apr 2021 21:07:57 +0100 Subject: [PATCH] Don't generate if source hasn't been modified --- agb-image-converter/src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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() +}