mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-05 07:47:49 +00:00
offline mode, expanded logging
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::structs::PrintPrefix;
|
||||
use crate::misc;
|
||||
use crate::structs::{PrintPrefix, StoredGameData};
|
||||
use colored::Colorize;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::collections::HashMap;
|
||||
@@ -12,6 +13,8 @@ pub const GH_IW4X_REPO: &str = "iw4x-client";
|
||||
pub static MASTER: Lazy<Mutex<String>> =
|
||||
Lazy::new(|| Mutex::new("https://cdn.alterware.ovh".to_owned()));
|
||||
|
||||
pub static IS_OFFLINE: Lazy<Mutex<bool>> = Lazy::new(|| Mutex::new(false));
|
||||
|
||||
pub static PREFIXES: Lazy<HashMap<&'static str, PrintPrefix>> = Lazy::new(|| {
|
||||
HashMap::from([
|
||||
(
|
||||
@@ -51,3 +54,29 @@ pub static PREFIXES: Lazy<HashMap<&'static str, PrintPrefix>> = Lazy::new(|| {
|
||||
),
|
||||
])
|
||||
});
|
||||
|
||||
pub async fn check_connectivity() -> bool {
|
||||
let master_url = MASTER.lock().unwrap().clone();
|
||||
|
||||
match crate::http_async::get_body_string(&master_url).await {
|
||||
Ok(_) => true,
|
||||
Err(_) => {
|
||||
*IS_OFFLINE.lock().unwrap() = true;
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_stored_data() -> Option<StoredGameData> {
|
||||
let dir = std::env::current_dir().ok()?;
|
||||
let cache = misc::get_cache(&dir);
|
||||
cache.stored_data
|
||||
}
|
||||
|
||||
pub fn store_game_data(data: &StoredGameData) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let dir = std::env::current_dir()?;
|
||||
let mut cache = misc::get_cache(&dir);
|
||||
cache.stored_data = Some((*data).clone());
|
||||
misc::save_cache(&dir, cache);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user