feat: new config format

This commit is contained in:
2025-03-13 23:26:00 +00:00
parent 48dc9ec4df
commit fd27000c05
30 changed files with 1447 additions and 833 deletions

View File

@ -1,7 +1,8 @@
use std::hash::{DefaultHasher, Hash, Hasher};
use crate::profiles::AnyProfile;
use crate::{model::misc::Game, pkg::PkgKey};
use crate::pkg_store::PackageStore;
use crate::{util, Profile};
use crate::util;
use anyhow::{anyhow, Result};
use serde::{Deserialize, Serialize};
use tauri::AppHandle;
@ -11,11 +12,15 @@ pub struct GlobalConfig {
pub recent_profile: Option<(Game, String)>
}
pub struct GlobalState {
pub remain_open: bool
}
pub struct AppData {
pub profile: Option<Profile>,
pub profile: Option<AnyProfile>,
pub pkgs: PackageStore,
pub cfg: GlobalConfig,
pub remain_open: bool,
pub state: GlobalState,
}
impl AppData {
@ -25,15 +30,15 @@ impl AppData {
.unwrap_or_default();
let profile = match cfg.recent_profile {
Some((ref game, ref name)) => Profile::load(game.clone(), name.clone()).ok(),
Some((ref game, ref name)) => AnyProfile::load(game.clone(), name.clone()).ok(),
None => None
};
AppData {
profile,
profile: profile,
pkgs: PackageStore::new(apph.clone()),
cfg,
remain_open: true
state: GlobalState { remain_open: true }
}
}
@ -42,7 +47,7 @@ impl AppData {
}
pub fn switch_profile(&mut self, game: Game, name: String) -> Result<()> {
match Profile::load(game.clone(), name.clone()) {
match AnyProfile::load(game.clone(), name.clone()) {
Ok(profile) => {
self.profile = Some(profile);
self.cfg.recent_profile = Some((game, name));
@ -67,12 +72,12 @@ impl AppData {
let loc = pkg.loc
.clone()
.ok_or_else(|| anyhow!("Attempted to enable a non-existent package"))?;
profile.data.mods.insert(key);
profile.pkgs_mut().insert(key);
for d in &loc.dependencies {
_ = self.toggle_package(d.clone(), true);
}
} else {
profile.data.mods.remove(&key);
profile.pkgs_mut().remove(&key);
for (ckey, pkg) in self.pkgs.get_all() {
if let Some(loc) = pkg.loc {
if loc.dependencies.contains(&key) {
@ -85,10 +90,10 @@ impl AppData {
Ok(())
}
pub fn sum_packages(&self, p: &Profile) -> String {
pub fn sum_packages(&self, p: &AnyProfile) -> String {
let mut hasher = DefaultHasher::new();
for pkg in &p.data.mods {
let x = self.pkgs.get(pkg).unwrap().loc.as_ref().unwrap();
for pkg in p.pkgs().into_iter() {
let x = self.pkgs.get(&pkg).unwrap().loc.as_ref().unwrap();
pkg.hash(&mut hasher);
x.version.hash(&mut hasher);
}