GH actions + finish

This commit is contained in:
Jai A
2023-03-30 13:45:26 -07:00
parent 59b835d374
commit 7cd8205a3b
9 changed files with 155 additions and 35 deletions

View File

@@ -65,7 +65,7 @@ impl State {
// Launcher data
let (metadata, profiles) = tokio::try_join! {
Metadata::init(&database),
Profiles::init(&database),
Profiles::init(&database, &directories),
}?;
let users = Users::init(&database)?;

View File

@@ -234,14 +234,38 @@ 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()
// project path, parent profile path
let mut files: HashMap<PathBuf, PathBuf> = HashMap::new();
{
for (profile_path, _profile_optZA) in profiles.iter() {
let mut read_paths = |path: &str| {
for path in std::fs::read_dir(profile_path.join(path))? {
files.insert(path?.path(), profile_path.clone());
}
Ok::<(), crate::Error>(())
};
read_paths("mods")?;
read_paths("shaders")?;
read_paths("resourcepacks")?;
read_paths("datapacks")?;
}
}
let inferred = super::projects::infer_data_from_files(
files.keys().into_iter().cloned().collect(),
dirs.caches_dir(),
)
.await?;
for (key, value) in inferred {
if let Some(profile_path) = files.get(&key) {
if let Some(profile) = profiles.get_mut(profile_path) {
if let Some(profile) = profile {
profile.projects.insert(key, value);
}
}
}
}
Ok(Self(profiles))
}

View File

@@ -200,29 +200,36 @@ pub async fn infer_data_from_files(
let mut file_str = String::new();
if file.read_to_string(&mut file_str).is_ok() {
if let Ok(pack) = serde_json::from_str::<ForgeMod>(&file_str) {
let icon = read_icon_from_file(pack.logo_file)?;
if let Ok(pack) =
serde_json::from_str::<ForgeModInfo>(&file_str)
{
if let Some(pack) = pack.mods.first() {
let icon = read_icon_from_file(pack.logo_file.clone())?;
return_projects.insert(
path.clone(),
Project {
sha512: hash,
disabled: false,
metadata: ProjectMetadata::Inferred {
title: Some(
pack.display_name.unwrap_or(pack.mod_id),
),
description: pack.description,
authors: pack
.authors
.map(|x| vec![x])
.unwrap_or_default(),
version: pack.version,
icon,
return_projects.insert(
path.clone(),
Project {
sha512: hash,
disabled: false,
metadata: ProjectMetadata::Inferred {
title: Some(
pack.display_name
.clone()
.unwrap_or(pack.mod_id.clone()),
),
description: pack.description.clone(),
authors: pack
.authors
.clone()
.map(|x| vec![x])
.unwrap_or_default(),
version: pack.version.clone(),
icon,
},
},
},
);
continue;
);
continue;
}
}
}
}