use std::collections::HashMap;
use std::io::Read;
use std::path::Path;
use yog_sync::Mutex;
use yog_registry::REGISTRATIONS_FILE;
static STARTUP: Mutex<Option<HashMap<String, String>>> = Mutex::new(None);
fn read_entry(path: &Path, name: &str) -> Option<String> {
let mut archive = zip::ZipArchive::new(std::fs::File::open(path).ok()?).ok()?;
let mut text = String::new();
archive.by_name(name).ok()?.read_to_string(&mut text).ok()?;
Some(text)
}
pub(crate) fn record(mod_id: &str, yog: &Path) {
let text = read_entry(yog, REGISTRATIONS_FILE).unwrap_or_default();
STARTUP
.lock()
.get_or_insert_with(HashMap::new)
.insert(mod_id.to_string(), text);
}
pub(crate) fn changes(mod_id: &str, new_yog: &Path) -> yog_hot_reload::control::Changes {
let started = STARTUP
.lock()
.as_ref()
.and_then(|m| m.get(mod_id).cloned())
.unwrap_or_default();
let new = read_entry(new_yog, REGISTRATIONS_FILE).unwrap_or_default();
let (added, removed, changed) = yog_registry::registration_changes(&started, &new);
yog_hot_reload::control::Changes {
added,
removed,
changed,
}
}
pub(crate) fn reload_game_resources() {
unsafe {
let _: Option<()> = host!("dev/yog/server/YogDevReload", "reloadData", []);
let _: Option<()> = host!("dev/yog/client/YogDevReloadClient", "reloadResources", []);
}
}