mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-04 07:17:50 +00:00
create cache module
This commit is contained in:
20
src/misc.rs
20
src/misc.rs
@@ -2,7 +2,7 @@ use std::{fs, path::Path};
|
||||
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
|
||||
use crate::{global, structs};
|
||||
use crate::global;
|
||||
|
||||
pub fn stdin() -> String {
|
||||
let mut input = String::new();
|
||||
@@ -140,24 +140,6 @@ pub fn prefix(tag_name: &str) -> String {
|
||||
.map_or_else(|| tag_name.to_string(), |tag| tag.formatted())
|
||||
}
|
||||
|
||||
pub fn get_cache(dir: &Path) -> structs::Cache {
|
||||
let cache_path = dir.join("awcache.json");
|
||||
let cache_content = fs::read_to_string(cache_path).unwrap_or_default();
|
||||
if cache_content.trim().is_empty() {
|
||||
structs::Cache::default()
|
||||
} else {
|
||||
serde_json::from_str(&cache_content).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_cache(dir: &Path, cache: structs::Cache) {
|
||||
let cache_path = dir.join("awcache.json");
|
||||
let cache_serialized = serde_json::to_string_pretty(&cache).unwrap();
|
||||
fs::write(cache_path, cache_serialized).unwrap_or_else(|e| {
|
||||
println_error!("Failed to save cache: {}", e);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn random_string(length: u32) -> String {
|
||||
use rand::Rng;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
Reference in New Issue
Block a user