Skip to content

Commit

Permalink
Make iconforge call create_dir_all, flush, and sync_all to deal with …
Browse files Browse the repository at this point in the history
…file system caches
  • Loading branch information
tigercat2000 committed Dec 29, 2024
1 parent 8ae447a commit 0af5f99
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/iconforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ use image::{Pixel, RgbaImage};
use once_cell::sync::Lazy;
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::sync::RwLock;
use std::{
collections::HashMap,
fs::File,
hash::BuildHasherDefault,
io::BufReader,
path::PathBuf,
sync::{Arc, Mutex},
};
use std::{collections::HashSet, io::BufWriter};
use std::{io::Write, sync::RwLock};
use tracy_full::{frame, zone};
use twox_hash::XxHash64;
type SpriteJsonMap = HashMap<String, HashMap<String, IconObjectIO>, BuildHasherDefault<XxHash64>>;
Expand Down Expand Up @@ -552,7 +553,34 @@ fn generate_spritesheet(
}
{
zone!("write_spritesheet");
final_image.save(file_path).err();
let path: PathBuf = file_path.into();

if let Some(parent) = path.parent() {
let _ = std::fs::create_dir_all(parent);
}

let mut file = match File::create(path) {
Ok(file) => file,
Err(err) => {
error.lock().unwrap().push(err.to_string());
return;
}
};

let mut writer = BufWriter::new(&mut file);
if let Err(e) = final_image.write_to(&mut writer, image::ImageFormat::Png) {
error.lock().unwrap().push(e.to_string());
}

if let Err(e) = writer.flush() {
error.lock().unwrap().push(e.to_string());
}

std::mem::forget(writer);

if let Err(e) = file.sync_all() {
error.lock().unwrap().push(e.to_string());
}
}
});

Expand Down

0 comments on commit 0af5f99

Please sign in to comment.