forked from akanyan/STARTLINER
feat: phase 2
Newfound motivation
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashSet, path::{Path, PathBuf}};
|
||||
|
||||
use crate::{model::misc, pkg::PkgKey, util};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::fs;
|
||||
use crate::{model::misc, util};
|
||||
|
||||
// {game}-profile-{name}.json
|
||||
|
||||
@ -12,22 +12,53 @@ pub struct Profile {
|
||||
pub game: misc::Game,
|
||||
pub path: PathBuf,
|
||||
pub name: String,
|
||||
pub mods: Vec<String>,
|
||||
pub mods: HashSet<PkgKey>,
|
||||
pub wine_runtime: Option<PathBuf>,
|
||||
pub wine_prefix: Option<PathBuf>,
|
||||
}
|
||||
|
||||
impl Profile {
|
||||
pub fn new(path: PathBuf) -> Profile {
|
||||
Profile {
|
||||
game: misc::Game::Ongeki,
|
||||
path: path,
|
||||
path: path.parent().unwrap().to_owned(),
|
||||
name: "ongeki-default".to_owned(),
|
||||
mods: [].to_vec()
|
||||
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 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user