You've already forked AstralRinth
forked from didirus/AstralRinth
Profile mod management
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use super::settings::{Hooks, MemorySettings, WindowSize};
|
||||
use crate::config::BINCODE_CONFIG;
|
||||
use crate::data::DirectoryInfo;
|
||||
use crate::state::projects::Project;
|
||||
use daedalus::modded::LoaderVersion;
|
||||
use futures::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -27,6 +29,7 @@ pub struct Profile {
|
||||
#[serde(skip)]
|
||||
pub path: PathBuf,
|
||||
pub metadata: ProfileMetadata,
|
||||
pub projects: HashMap<PathBuf, Project>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub java: Option<JavaSettings>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -107,6 +110,7 @@ impl Profile {
|
||||
loader_version: None,
|
||||
format_version: CURRENT_FORMAT_VERSION,
|
||||
},
|
||||
projects: HashMap::new(),
|
||||
java: None,
|
||||
memory: None,
|
||||
resolution: None,
|
||||
@@ -200,7 +204,10 @@ impl Profile {
|
||||
|
||||
impl Profiles {
|
||||
#[tracing::instrument(skip(db))]
|
||||
pub async fn init(db: &sled::Db) -> crate::Result<Self> {
|
||||
pub async fn init(
|
||||
db: &sled::Db,
|
||||
dirs: &DirectoryInfo,
|
||||
) -> crate::Result<Self> {
|
||||
let profile_db = db.get(PROFILE_SUBTREE)?.map_or(
|
||||
Ok(Default::default()),
|
||||
|bytes| {
|
||||
@@ -212,7 +219,7 @@ impl Profiles {
|
||||
},
|
||||
)?;
|
||||
|
||||
let profiles = stream::iter(profile_db.iter())
|
||||
let mut profiles = stream::iter(profile_db.iter())
|
||||
.then(|it| async move {
|
||||
let path = PathBuf::from(it);
|
||||
let prof = match Self::read_profile_from_dir(&path).await {
|
||||
@@ -227,6 +234,15 @@ impl Profiles {
|
||||
.collect::<HashMap<PathBuf, Option<Profile>>>()
|
||||
.await;
|
||||
|
||||
// {
|
||||
// for (path, profile_opt) in profiles.iter_mut() {
|
||||
// if let Some(profile) = profile_opt {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// dirs.caches_dir()
|
||||
|
||||
Ok(Self(profiles))
|
||||
}
|
||||
|
||||
@@ -296,63 +312,3 @@ impl Profiles {
|
||||
Ok(profile)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::{assert_eq, assert_str_eq};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
fn profile_test() -> Result<(), serde_json::Error> {
|
||||
let profile = Profile {
|
||||
path: PathBuf::new(),
|
||||
metadata: ProfileMetadata {
|
||||
name: String::from("Example Pack"),
|
||||
icon: None,
|
||||
game_version: String::from("1.18.2"),
|
||||
loader: ModLoader::Vanilla,
|
||||
loader_version: None,
|
||||
format_version: CURRENT_FORMAT_VERSION,
|
||||
},
|
||||
java: Some(JavaSettings {
|
||||
install: Some(PathBuf::from("/usr/bin/java")),
|
||||
extra_arguments: Some(Vec::new()),
|
||||
}),
|
||||
memory: Some(MemorySettings {
|
||||
minimum: None,
|
||||
maximum: 8192,
|
||||
}),
|
||||
resolution: Some(WindowSize(1920, 1080)),
|
||||
hooks: Some(Hooks {
|
||||
pre_launch: HashSet::new(),
|
||||
wrapper: None,
|
||||
post_exit: HashSet::new(),
|
||||
}),
|
||||
};
|
||||
let json = serde_json::json!({
|
||||
"metadata": {
|
||||
"name": "Example Pack",
|
||||
"game_version": "1.18.2",
|
||||
"format_version": 1u32,
|
||||
"loader": "vanilla",
|
||||
},
|
||||
"java": {
|
||||
"extra_arguments": [],
|
||||
"install": "/usr/bin/java",
|
||||
},
|
||||
"memory": {
|
||||
"maximum": 8192u32,
|
||||
},
|
||||
"resolution": (1920u16, 1080u16),
|
||||
"hooks": {},
|
||||
});
|
||||
|
||||
assert_eq!(serde_json::to_value(profile.clone())?, json.clone());
|
||||
assert_str_eq!(
|
||||
format!("{:?}", serde_json::from_value::<Profile>(json)?),
|
||||
format!("{:?}", profile),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user