forked from akanyan/STARTLINER
feat: start checks
This commit is contained in:
@ -1,19 +1,14 @@
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use crate::model::config::GlobalConfig;
|
||||
use crate::profiles::AnyProfile;
|
||||
use crate::{model::misc::Game, pkg::PkgKey};
|
||||
use crate::pkg_store::PackageStore;
|
||||
use crate::util;
|
||||
use anyhow::{anyhow, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tauri::AppHandle;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
pub struct GlobalConfig {
|
||||
pub recent_profile: Option<(Game, String)>
|
||||
}
|
||||
|
||||
pub struct GlobalState {
|
||||
pub remain_open: bool
|
||||
pub remain_open: bool,
|
||||
}
|
||||
|
||||
pub struct AppData {
|
||||
@ -34,6 +29,8 @@ impl AppData {
|
||||
None => None
|
||||
};
|
||||
|
||||
log::debug!("Recent profile: {:?}", profile);
|
||||
|
||||
AppData {
|
||||
profile: profile,
|
||||
pkgs: PackageStore::new(apph.clone()),
|
||||
@ -43,7 +40,7 @@ impl AppData {
|
||||
}
|
||||
|
||||
pub fn write(&self) -> Result<(), std::io::Error> {
|
||||
std::fs::write(util::config_dir().join("config.json"), serde_json::to_string(&self.cfg)?)
|
||||
std::fs::write(util::config_dir().join("config.json"), serde_json::to_string_pretty(&self.cfg)?)
|
||||
}
|
||||
|
||||
pub fn switch_profile(&mut self, game: Game, name: String) -> Result<()> {
|
||||
@ -72,12 +69,12 @@ impl AppData {
|
||||
let loc = pkg.loc
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow!("Attempted to enable a non-existent package"))?;
|
||||
profile.pkgs_mut().insert(key);
|
||||
profile.mod_pkgs_mut().insert(key);
|
||||
for d in &loc.dependencies {
|
||||
_ = self.toggle_package(d.clone(), true);
|
||||
}
|
||||
} else {
|
||||
profile.pkgs_mut().remove(&key);
|
||||
profile.mod_pkgs_mut().remove(&key);
|
||||
for (ckey, pkg) in self.pkgs.get_all() {
|
||||
if let Some(loc) = pkg.loc {
|
||||
if loc.dependencies.contains(&key) {
|
||||
@ -92,10 +89,13 @@ impl AppData {
|
||||
|
||||
pub fn sum_packages(&self, p: &AnyProfile) -> String {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
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);
|
||||
for key in p.mod_pkgs().into_iter() {
|
||||
if let Ok(pkg) = self.pkgs.get(&key) {
|
||||
if let Some(loc) = &pkg.loc {
|
||||
key.hash(&mut hasher);
|
||||
loc.version.hash(&mut hasher);
|
||||
}
|
||||
}
|
||||
}
|
||||
hasher.finish().to_string()
|
||||
}
|
||||
|
Reference in New Issue
Block a user