use std::collections::HashMap;
use std::io::Read;
use std::path::Path;
use std::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().unwrap_or_else(|e| e.into_inner()).get_or_insert_with(HashMap::new).insert(mod_id.to_string(), text);
}
pub(crate) fn changes(mod_id: &str, new_yog: &Path) -> (Vec<String>, Vec<String>, Vec<String>) {
let started = STARTUP.lock().unwrap_or_else(|e| e.into_inner()).as_ref().and_then(|m| m.get(mod_id).cloned()).unwrap_or_default();
let new = read_entry(new_yog, REGISTRATIONS_FILE).unwrap_or_default();
yog_registry::registration_changes(&started, &new)
}
pub(crate) fn reload_game_resources() {
unsafe {
let _: Option<()> = host!("dev/yog/YogDevReload", "reloadData", []);
let _: Option<()> = host!("dev/yog/YogDevReloadClient", "reloadResources", []);
}
}