forked from akanyan/STARTLINER
65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
use std::{collections::HashSet, path::PathBuf};
|
|
|
|
use crate::{model::misc, pkg::PkgKey, util};
|
|
use serde::{Deserialize, Serialize};
|
|
use tokio::fs;
|
|
|
|
// {game}-profile-{name}.json
|
|
|
|
#[derive(Deserialize, Serialize, Clone)]
|
|
#[allow(dead_code)]
|
|
pub struct Profile {
|
|
pub game: misc::Game,
|
|
pub exe_dir: PathBuf,
|
|
pub name: String,
|
|
pub mods: HashSet<PkgKey>,
|
|
pub wine_runtime: Option<PathBuf>,
|
|
pub wine_prefix: Option<PathBuf>,
|
|
}
|
|
|
|
impl Profile {
|
|
pub fn new(exe_path: PathBuf) -> Profile {
|
|
Profile {
|
|
game: misc::Game::Ongeki,
|
|
exe_dir: exe_path.parent().unwrap().to_owned(),
|
|
name: "ongeki-default".to_owned(),
|
|
mods: HashSet::new(),
|
|
|
|
#[cfg(target_os = "linux")]
|
|
wine_runtime: Some(Path::new("/usr/bin/wine").to_path_buf()),
|
|
#[cfg(target_os = "windows")]
|
|
wine_runtime: None,
|
|
|
|
#[cfg(target_os = "linux")]
|
|
wine_prefix: Some(
|
|
directories::UserDirs::new()
|
|
.expect("No home directory")
|
|
.home_dir()
|
|
.join(".wine"),
|
|
),
|
|
#[cfg(target_os = "windows")]
|
|
wine_prefix: None,
|
|
}
|
|
}
|
|
|
|
pub fn load() -> Option<Profile> {
|
|
let path = util::get_dirs()
|
|
.config_dir()
|
|
.join("profile-ongeki-default.json");
|
|
if let Ok(s) = std::fs::read_to_string(path) {
|
|
Some(serde_json::from_str(&s).expect("Invalid profile json"))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub async fn save(&self) {
|
|
let path = util::get_dirs()
|
|
.config_dir()
|
|
.join("profile-ongeki-default.json");
|
|
let s = serde_json::to_string_pretty(self).unwrap();
|
|
fs::write(&path, s).await.unwrap();
|
|
log::info!("Written to {}", path.to_string_lossy());
|
|
}
|
|
}
|