feat: skeleton of proper local package support
This commit is contained in:
@ -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> {
|
||||
|
Reference in New Issue
Block a user