feat: phase 2

Newfound motivation
This commit is contained in:
2025-02-23 05:12:21 +01:00
parent fdf3679fbe
commit a29bce2227
36 changed files with 1367 additions and 615 deletions

33
rust/src/appdata.rs Normal file
View File

@ -0,0 +1,33 @@
use anyhow::{anyhow, Result};
use crate::pkg::PkgKey;
use crate::Profile;
use crate::pkg_store::PackageStore;
pub struct AppData {
pub profile: Option<Profile>,
pub pkgs: PackageStore,
}
impl AppData {
pub fn toggle_package(&mut self, key: PkgKey, enable: bool) -> Result<()> {
log::debug!("toggle: {} {}", key, enable);
let profile = self.profile.as_mut()
.ok_or_else(|| anyhow!("No profile"))?;
if enable {
let pkg = self.pkgs.get(key.clone())?;
let loc = pkg.loc
.clone()
.ok_or_else(|| anyhow!("Attempted to enable a non-existent package"))?;
profile.mods.insert(key);
for d in &loc.dependencies {
self.toggle_package(d.clone(), true)?;
}
} else {
profile.mods.remove(&key);
}
Ok(())
}
}