mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
Don't generate if source hasn't been modified
This commit is contained in:
parent
d1412fb709
commit
b4c3bd7356
|
@ -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<Path>) -> io::Result<SystemTime> {
|
||||
let metadata = fs::metadata(path)?;
|
||||
metadata.modified()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue