From ff0a37dfdc833885066bc034c5dd0072840c0b46 Mon Sep 17 00:00:00 2001 From: akanyan Date: Thu, 10 Apr 2025 14:07:44 +0000 Subject: [PATCH] feat: skeleton of proper local package support --- rust/src/pkg.rs | 29 +++++++++++++++++++++++------ rust/src/pkg_store.rs | 6 +++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/rust/src/pkg.rs b/rust/src/pkg.rs index ee6794e..1aa503d 100644 --- a/rust/src/pkg.rs +++ b/rust/src/pkg.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use std::{collections::BTreeSet, path::{Path, PathBuf}}; use tokio::fs; use enumflags2::{bitflags, make_bitflags, BitFlags}; -use crate::{model::{local::{self, PackageManifest}, rainy}, util}; +use crate::{model::{local::{self, PackageManifest}, misc::Game, rainy}, util}; // {namespace}-{name} #[derive(Eq, Hash, PartialEq, PartialOrd, Ord, Clone, Serialize, Deserialize, Display, Debug)] @@ -14,6 +14,12 @@ pub struct PkgKey(pub String); #[derive(Eq, Hash, PartialEq, PartialOrd, Ord, Clone, Serialize, Deserialize, Display, Debug)] pub struct PkgKeyVersion(String); +#[derive(Copy, Clone, Display, Debug, Serialize, Deserialize, Default)] +pub enum PackageSource { + #[default] Rainy, + Local(Game) +} + #[derive(Clone, Default, Serialize, Deserialize)] #[allow(dead_code)] pub struct Package { @@ -21,7 +27,8 @@ pub struct Package { pub name: String, pub description: String, pub loc: Option, - pub rmt: Option + pub rmt: Option, + pub source: PackageSource, } #[derive(Clone, PartialEq, Serialize, Deserialize)] @@ -88,11 +95,12 @@ impl Package { version: v.version_number, categories: p.categories, dependencies: Self::sanitize_deps(v.dependencies) - }) + }), + source: PackageSource::Rainy, }) } - pub async fn from_dir(dir: PathBuf) -> Result { + pub async fn from_dir(dir: PathBuf, source: PackageSource) -> Result { let str = fs::read_to_string(dir.join("manifest.json")).await?; let mft: local::PackageManifest = serde_json::from_str(&str)?; @@ -116,7 +124,8 @@ impl Package { status, dependencies }), - rmt: None + rmt: None, + source }) } @@ -125,7 +134,15 @@ impl Package { } pub fn path(&self) -> PathBuf { - util::pkg_dir().join(self.key().0) + match self.source { + PackageSource::Rainy => util::pkg_dir().join(self.key().0), + PackageSource::Local(game) => + util::pkg_dir() + .parent() + .unwrap() + .join(format!("pkg-{game}")) + .join(&self.name), + } } pub fn _dir_to_key(dir: &Path) -> Result { diff --git a/rust/src/pkg_store.rs b/rust/src/pkg_store.rs index d1988b1..cec1488 100644 --- a/rust/src/pkg_store.rs +++ b/rust/src/pkg_store.rs @@ -8,7 +8,7 @@ use tokio::task::JoinSet; use crate::model::local::{PackageList, PackageListEntry}; use crate::model::misc::Game; use crate::model::rainy; -use crate::pkg::{Package, PkgKey, Remote, Status}; +use crate::pkg::{Package, PackageSource, PkgKey, Remote, Status}; use crate::util; use crate::download_handler::DownloadHandler; @@ -69,7 +69,7 @@ impl PackageStore { pub async fn reload_package(&mut self, key: PkgKey) { let dir = util::pkg_dir().join(&key.0); - if let Ok(pkg) = Package::from_dir(dir).await { + if let Ok(pkg) = Package::from_dir(dir, PackageSource::Rainy).await { self.update_nonremote(key, pkg); } else { log::error!("couldn't reload {}", key); @@ -83,7 +83,7 @@ impl PackageStore { for dir in dirents { if let Ok(dir) = dir { let path = dir.path(); - futures.spawn(Package::from_dir(path)); + futures.spawn(Package::from_dir(path, PackageSource::Rainy)); } }