aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src
diff options
context:
space:
mode:
authorGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-20 02:21:25 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2023-07-20 02:21:25 +0200
commitd335e7483dfd1959945ee06038c02877a349ef66 (patch)
treec6148781073a3567ec6122801341b178ff6b5135 /src-tauri/src
parent8ae71ef5f04cab43b19b2b17a26012eeffa62566 (diff)
downloadFlightCore-d335e7483dfd1959945ee06038c02877a349ef66.tar.gz
FlightCore-d335e7483dfd1959945ee06038c02877a349ef66.zip
feat: Add sanity check for package install
Diffstat (limited to 'src-tauri/src')
-rw-r--r--src-tauri/src/mod_management/mod.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs
index afed9692..cef7ff71 100644
--- a/src-tauri/src/mod_management/mod.rs
+++ b/src-tauri/src/mod_management/mod.rs
@@ -2,6 +2,7 @@
use crate::constants::{BLACKLISTED_MODS, CORE_MODS};
use async_recursion::async_recursion;
+use thermite::prelude::ThermiteError;
use crate::NorthstarMod;
use anyhow::{anyhow, Result};
@@ -459,6 +460,41 @@ fn delete_older_versions(
Ok(())
}
+/// Checks whether some mod is correctly formatted
+/// Currently checks whether
+/// - Some `mod.json` exists under `mods/*/mod.json`
+fn fc_sanity_check(input: &&fs::File) -> bool {
+ let mut archive = match zip::read::ZipArchive::new(*input) {
+ Ok(archive) => archive,
+ Err(_) => return false,
+ };
+
+ let mut has_mods = false;
+ let mut mod_json_exists = false;
+
+ // Checks for `mods/*/mod.json`
+ for i in 0..archive.len() {
+ let file = match archive.by_index(i) {
+ Ok(file) => file,
+ Err(_) => continue,
+ };
+ let file_path = file.mangled_name();
+ if file_path.starts_with("mods/") {
+ has_mods = true;
+ if let Some(name) = file_path.file_name() {
+ if name == "mod.json" {
+ let parent_path = file_path.parent().unwrap();
+ if parent_path.parent().unwrap().to_str().unwrap() == "mods" {
+ mod_json_exists = true;
+ }
+ }
+ }
+ }
+ }
+
+ has_mods && mod_json_exists
+}
+
// Copied from `libtermite` source code and modified
// Should be replaced with a library call to libthermite in the future
/// Download and install mod to the specified target.
@@ -544,14 +580,21 @@ pub async fn fc_download_mod_and_install(
);
// Extract the mod to the mods directory
- match thermite::core::manage::install_mod(
+ match thermite::core::manage::install_with_sanity(
temp_file.file(),
std::path::Path::new(&install_directory),
+ fc_sanity_check,
) {
Ok(_) => (),
Err(err) => {
log::warn!("libthermite couldn't install mod {thunderstore_mod_string} due to {err:?}",);
- return Err(err.to_string());
+ return match err {
+ ThermiteError::SanityError => Err(
+ "Mod failed sanity check during install. It's probably not correctly formatted"
+ .to_string(),
+ ),
+ _ => Err(err.to_string()),
+ };
}
};