mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-10-11 09:04:27 +08:00
Ability to load masterdata from a folder
This commit is contained in:
+38
-1
@@ -1,10 +1,14 @@
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::RwLock;
|
||||
use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
use std::sync::{Mutex, RwLock};
|
||||
use std::fs;
|
||||
|
||||
lazy_static! {
|
||||
static ref RUNNING: RwLock<bool> = RwLock::new(false);
|
||||
static ref DATAPATH: RwLock<String> = RwLock::new(String::new());
|
||||
static ref MASTERDATA_PATH: RwLock<String> = RwLock::new(String::new());
|
||||
static ref MASTERDATA_WARNED: Mutex<HashSet<String>> = Mutex::new(HashSet::new());
|
||||
static ref EASTER: RwLock<bool> = RwLock::new(false);
|
||||
}
|
||||
|
||||
@@ -33,6 +37,39 @@ pub fn update_data_path(path: &str) {
|
||||
*w = path.to_string();
|
||||
}
|
||||
|
||||
pub fn update_masterdata_path(path: &str) {
|
||||
let trimmed = path.trim_end_matches('/').to_string();
|
||||
let mut w = MASTERDATA_PATH.write().unwrap();
|
||||
if trimmed.is_empty() {
|
||||
*w = String::new();
|
||||
return;
|
||||
}
|
||||
if !Path::new(&trimmed).is_dir() {
|
||||
println!("Couldn't find masterdata directory {}", trimmed);
|
||||
*w = String::new();
|
||||
return;
|
||||
}
|
||||
*w = trimmed;
|
||||
}
|
||||
|
||||
pub fn read_masterdata_file(rel_path: &str) -> Option<Vec<u8>> {
|
||||
let base = MASTERDATA_PATH.read().unwrap().clone();
|
||||
if base.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let full_path = format!("{}/{}", base, rel_path);
|
||||
match fs::read(&full_path) {
|
||||
Ok(bytes) => Some(bytes),
|
||||
Err(_) => {
|
||||
let mut warned = MASTERDATA_WARNED.lock().unwrap();
|
||||
if warned.insert(rel_path.to_string()) {
|
||||
println!("Couldn't find masterdata {}", rel_path);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only currently editable by the android so
|
||||
pub fn set_easter_mode(enabled: bool) {
|
||||
let mut w = EASTER.write().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user