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:
@@ -36,7 +36,7 @@ extern "C" fn Java_one_ethanthesleepy_androidew_BackgroundService_startServer<'l
|
|||||||
//crate::runtime::set_easter_mode(easter != 0);
|
//crate::runtime::set_easter_mode(easter != 0);
|
||||||
|
|
||||||
let data_path: String = env.get_string(&data_path).unwrap().into();
|
let data_path: String = env.get_string(&data_path).unwrap().into();
|
||||||
//crate::runtime::set_datapath(data_path);
|
crate::runtime::update_data_path(data_path);
|
||||||
|
|
||||||
let output = env.new_string(String::from("Azunyannnn~")).unwrap();
|
let output = env.new_string(String::from("Azunyannnn~")).unwrap();
|
||||||
thread::spawn(|| {
|
thread::spawn(|| {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pub static INITIALIZER: extern "C" fn() = main;
|
|||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn main() {
|
pub extern "C" fn main() {
|
||||||
let data_path = get_bundle_path().into_os_string().into_string().unwrap();
|
let data_path = get_bundle_path().into_os_string().into_string().unwrap();
|
||||||
//set_datapath(data_path);
|
crate::runtime::update_data_path(data_path);
|
||||||
|
|
||||||
std::thread::spawn(|| {
|
std::thread::spawn(|| {
|
||||||
crate::run_server(true).unwrap();
|
crate::run_server(true).unwrap();
|
||||||
@@ -18,7 +18,7 @@ pub extern "C" fn main() {
|
|||||||
use objc2_foundation::{NSFileManager, NSSearchPathDirectory, NSSearchPathDomainMask};
|
use objc2_foundation::{NSFileManager, NSSearchPathDirectory, NSSearchPathDomainMask};
|
||||||
|
|
||||||
#[cfg(target_os = "ios")]
|
#[cfg(target_os = "ios")]
|
||||||
fn get_bundle_path() -> std::path::PathBuf {
|
pub fn get_bundle_path() -> std::path::PathBuf {
|
||||||
unsafe {
|
unsafe {
|
||||||
let manager = NSFileManager::defaultManager();
|
let manager = NSFileManager::defaultManager();
|
||||||
let application_support = manager.URLsForDirectory_inDomains(NSSearchPathDirectory::ApplicationSupportDirectory, NSSearchPathDomainMask::UserDomainMask);
|
let application_support = manager.URLsForDirectory_inDomains(NSSearchPathDirectory::ApplicationSupportDirectory, NSSearchPathDomainMask::UserDomainMask);
|
||||||
|
|||||||
16
src/lib.rs
16
src/lib.rs
@@ -3,7 +3,7 @@ mod options;
|
|||||||
mod router;
|
mod router;
|
||||||
mod encryption;
|
mod encryption;
|
||||||
mod sql;
|
mod sql;
|
||||||
mod runtime;
|
pub mod runtime;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
@@ -22,9 +22,9 @@ use actix_web::{
|
|||||||
web,
|
web,
|
||||||
dev::Service
|
dev::Service
|
||||||
};
|
};
|
||||||
use std::fs;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use options::get_args;
|
pub use options::get_args;
|
||||||
|
use runtime::get_data_path;
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
pub async fn run_server(in_thread: bool) -> std::io::Result<()> {
|
pub async fn run_server(in_thread: bool) -> std::io::Result<()> {
|
||||||
@@ -78,13 +78,3 @@ pub async fn stop_server() {
|
|||||||
runtime::set_running(false);
|
runtime::set_running(false);
|
||||||
println!("Stopping");
|
println!("Stopping");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_data_path(file_name: &str) -> String {
|
|
||||||
let args = get_args();
|
|
||||||
let mut path = args.path;
|
|
||||||
while path.ends_with('/') {
|
|
||||||
path.pop();
|
|
||||||
}
|
|
||||||
fs::create_dir_all(&path).unwrap();
|
|
||||||
format!("{}/{}", path, file_name)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#[cfg(not(feature = "library"))]
|
#[cfg(not(feature = "library"))]
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
|
ew::runtime::update_data_path(&ew::get_args().path);
|
||||||
ew::run_server(false)
|
ew::run_server(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,33 @@
|
|||||||
use crate::lock_onto_mutex;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::sync::Mutex;
|
use std::sync::RwLock;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
lazy_static! {
|
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) {
|
pub fn set_running(running: bool) {
|
||||||
let mut result = lock_onto_mutex!(RUNNING);
|
let mut w = RUNNING.write().unwrap();
|
||||||
*result = running;
|
*w = running;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_running() -> bool {
|
pub fn get_running() -> bool {
|
||||||
let result = lock_onto_mutex!(RUNNING);
|
*RUNNING.read().unwrap()
|
||||||
*result
|
}
|
||||||
|
|
||||||
|
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