feat: skeleton of proper local package support

This commit is contained in:
2025-04-10 14:07:44 +00:00
parent d63d81e349
commit ff0a37dfdc
2 changed files with 26 additions and 9 deletions

View File

@ -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<Local>,
pub rmt: Option<Remote>
pub rmt: Option<Remote>,
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<Package> {
pub async fn from_dir(dir: PathBuf, source: PackageSource) -> Result<Package> {
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<String> {

View File

@ -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));
}
}