mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew
synced 2026-01-12 08:12:36 +08:00
Add ability to set datapath outside of cli args
This commit is contained in:
@@ -1,17 +1,33 @@
|
||||
use crate::lock_onto_mutex;
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
use std::fs;
|
||||
|
||||
lazy_static! {
|
||||
static ref RUNNING: Mutex<bool> = Mutex::new(false);
|
||||
static ref RUNNING: RwLock<bool> = RwLock::new(false);
|
||||
static ref DATAPATH: RwLock<String> = RwLock::new(String::new());
|
||||
}
|
||||
|
||||
pub fn set_running(running: bool) {
|
||||
let mut result = lock_onto_mutex!(RUNNING);
|
||||
*result = running;
|
||||
let mut w = RUNNING.write().unwrap();
|
||||
*w = running;
|
||||
}
|
||||
|
||||
pub fn get_running() -> bool {
|
||||
let result = lock_onto_mutex!(RUNNING);
|
||||
*result
|
||||
*RUNNING.read().unwrap()
|
||||
}
|
||||
|
||||
pub fn get_data_path(file_name: &str) -> String {
|
||||
let mut path = {
|
||||
DATAPATH.read().unwrap().clone()
|
||||
};
|
||||
while path.ends_with('/') {
|
||||
path.pop();
|
||||
}
|
||||
fs::create_dir_all(&path).unwrap();
|
||||
format!("{}/{}", path, file_name)
|
||||
}
|
||||
|
||||
pub fn update_data_path(path: &str) {
|
||||
let mut w = DATAPATH.write().unwrap();
|
||||
*w = path.to_string();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user