From df4ed29e5025ae6d05a6233e2d35e91f42371c74 Mon Sep 17 00:00:00 2001 From: Caleb Smith Date: Thu, 4 Jul 2024 16:41:20 -0500 Subject: [PATCH] Handle Switch BNPs with rules.txt (Also Clippy) --- CHANGELOG.md | 5 +++ crates/uk-content/src/actor/params/rgbw.rs | 10 +++--- crates/uk-editor/src/project.rs | 2 +- crates/uk-manager/src/bnp.rs | 6 ++-- crates/uk-mod/src/lib.rs | 12 ++++++- crates/uk-mod/src/pack.rs | 26 +++++++------- crates/uk-mod/src/unpack.rs | 41 +++++++++++----------- src/logger.rs | 3 +- 8 files changed, 61 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5454cead..9734db3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## Added + +- Added `cargo dist` integration to provide simpler install and update methods + ### Fixed - Restored missing Package button to Window menu - Fixed option descriptions not showing on multiple choice +- Fixed misidentification of Switch BNPs with a `rules.txt` as Wii U mods ## [0.12.0] diff --git a/crates/uk-content/src/actor/params/rgbw.rs b/crates/uk-content/src/actor/params/rgbw.rs index 383ec79c..12b4945b 100644 --- a/crates/uk-content/src/actor/params/rgbw.rs +++ b/crates/uk-content/src/actor/params/rgbw.rs @@ -22,14 +22,14 @@ use crate::{ )] pub struct Key { #[name = "StateKey"] - pub state_key: String32, + pub state_key: String32, #[name = "SystemKey"] pub system_key: String32, } -impl ToString for Key { - fn to_string(&self) -> std::string::String { - jstr!("StateKey: {&self.state_key} :: SystemKey: {&self.system_key}") +impl std::fmt::Display for Key { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + jstr!("StateKey: {&self.state_key} :: SystemKey: {&self.system_key}").fmt(f) } } @@ -129,7 +129,7 @@ impl From for ParameterIO { jstr!("State_{&lexical::to_string(idx + 1)}"), ParameterList { objects: objs!("Setting" => key.into()), - lists: lists!( + lists: lists!( "InputWeightList" => ParameterList::new() .with_objects(state.into_iter().enumerate().map( |(i, (name, rate))| { diff --git a/crates/uk-editor/src/project.rs b/crates/uk-editor/src/project.rs index 51a6bb4e..3391eaf3 100644 --- a/crates/uk-editor/src/project.rs +++ b/crates/uk-editor/src/project.rs @@ -8,7 +8,7 @@ use fs_err as fs; use rayon::prelude::*; use uk_content::{resource::ResourceData, util::IndexMap}; use uk_manager::{core::Manager, settings::Platform}; -use uk_mod::{pack::sanitise, unpack::ParallelZipReader, zstd::zstd_safe::WriteBuf, Meta}; +use uk_mod::{pack::sanitise, unpack::ParallelZipReader, Meta}; #[derive(Debug, Clone)] pub struct Project { diff --git a/crates/uk-manager/src/bnp.rs b/crates/uk-manager/src/bnp.rs index ff2648cf..71967fa9 100644 --- a/crates/uk-manager/src/bnp.rs +++ b/crates/uk-manager/src/bnp.rs @@ -526,10 +526,10 @@ pub fn convert_bnp(core: &crate::core::Manager, path: &Path) -> Result ) })?; let tempfile = std::env::temp_dir(); - let meta = if let Some(rules_path) = tempdir.join("rules.txt").exists_then() { - ModPacker::parse_rules(rules_path)? + let meta = if let Some(info_path) = tempdir.join("info.json").exists_then() { + ModPacker::parse_info(info_path)? } else { - ModPacker::parse_info(tempdir.join("info.json")).context("Failed to parse BNP metadata")? + ModPacker::parse_rules(tempdir.join("rules.txt")).context("Failed to parse BNP metadata")? }; let name = meta.name.clone(); let new_mod = ModPacker::new(tempdir, tempfile.as_path(), Some(meta), vec![ diff --git a/crates/uk-mod/src/lib.rs b/crates/uk-mod/src/lib.rs index fea8122a..cfa49c41 100644 --- a/crates/uk-mod/src/lib.rs +++ b/crates/uk-mod/src/lib.rs @@ -22,7 +22,7 @@ pub struct Manifest { #[serde(rename = "content")] pub content_files: BTreeSet, #[serde(rename = "aoc")] - pub aoc_files: BTreeSet, + pub aoc_files: BTreeSet, } impl Manifest { @@ -216,6 +216,16 @@ pub enum ModPlatform { Universal, } +impl std::fmt::Display for ModPlatform { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ModPlatform::Specific(Endian::Big) => "Wii U".fmt(f), + ModPlatform::Specific(Endian::Little) => "Switch".fmt(f), + ModPlatform::Universal => "any platform".fmt(f), + } + } +} + #[inline(always)] fn default_api() -> String { env!("CARGO_PKG_VERSION").into() diff --git a/crates/uk-mod/src/pack.rs b/crates/uk-mod/src/pack.rs index b0ba2dc7..7ea58a2d 100644 --- a/crates/uk-mod/src/pack.rs +++ b/crates/uk-mod/src/pack.rs @@ -75,27 +75,27 @@ impl std::fmt::Debug for ModPacker { #[serde(default)] #[serde_as] struct InfoJson { - name: String, - desc: String, + name: String, + desc: String, #[serde(deserialize_with = "serde_with::As::::deserialize")] - version: String, + version: String, platform: String, - options: BnpOptions, + options: BnpOptions, } #[derive(Debug, Deserialize, Default)] struct BnpOptions { #[serde(default)] - multi: Vec, + multi: Vec, #[serde(default)] single: Vec, } #[derive(Debug, Deserialize)] struct BnpOption { - name: String, - desc: String, - folder: PathBuf, + name: String, + desc: String, + folder: PathBuf, default: Option, } @@ -141,10 +141,10 @@ impl RequireValue { #[derive(Debug, Deserialize)] struct BnpGroup { - name: String, - desc: String, + name: String, + desc: String, required: Option, - options: Vec, + options: Vec, } impl From for ExclusiveOptionGroup { @@ -582,7 +582,7 @@ impl ModPacker { }) .transpose()? .unwrap_or_default(), - aoc_files: aoc_dir + aoc_files: aoc_dir .map(|aoc| { log::info!("Collecting DLC resources"); self_.collect_resources(aoc) @@ -660,7 +660,7 @@ impl ModPacker { )?)); log::info!("Collecting resources for options"); for root in self.collect_roots() { - self.current_root = root.clone(); + self.current_root.clone_from(&root); self.pack_root(root).with_context(|| { format!( "Failed to package mod root at {} for mod {}", diff --git a/crates/uk-mod/src/unpack.rs b/crates/uk-mod/src/unpack.rs index b4d0b88d..cf4de7a3 100644 --- a/crates/uk-mod/src/unpack.rs +++ b/crates/uk-mod/src/unpack.rs @@ -77,10 +77,10 @@ impl std::fmt::Debug for ZipData { #[self_referencing] pub struct ParallelZipReader { - data: ZipData, + data: ZipData, #[borrows(data)] #[covariant] - zip: piz::ZipArchive<'this>, + zip: piz::ZipArchive<'this>, #[borrows(zip)] #[covariant] files: HashMap<&'this Path, &'this piz::read::FileMetadata<'this>>, @@ -477,14 +477,14 @@ static RSTB_EXCLUDE_NAMES: &[&str] = &["ActorInfo.product.byml"]; // #[derive(Debug)] pub struct ModUnpacker { - dump: Arc, + dump: Arc, manifest: Option, - mods: Vec, - endian: Endian, - lang: Language, - rstb: DashMap>, - hashes: StockHashTable, - out_dir: PathBuf, + mods: Vec, + endian: Endian, + lang: Language, + rstb: DashMap>, + hashes: StockHashTable, + out_dir: PathBuf, } impl ModUnpacker { @@ -566,18 +566,19 @@ impl ModUnpacker { Ok(Err(e)) => anyhow_ext::bail!(e), Ok(Ok(_)) => (), Err(e) => { - anyhow::bail!(e - .downcast::() - .or_else(|e| { - e.downcast::<&'static str>().map(|s| Box::new((*s).into())) - }) - .unwrap_or_else(|_| { - Box::new( - "An unknown error occured, check the log for possible \ + anyhow::bail!( + e.downcast::() + .or_else(|e| { + e.downcast::<&'static str>().map(|s| Box::new((*s).into())) + }) + .unwrap_or_else(|_| { + Box::new( + "An unknown error occured, check the log for possible \ details." - .to_string(), - ) - })) + .to_string(), + ) + }) + ) } } } diff --git a/src/logger.rs b/src/logger.rs index 80d08098..1d01ccbf 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -44,7 +44,8 @@ impl Logger { let mut file = if path.exists() { fs_err::OpenOptions::new().append(true).open(path) } else { - fs_err::create_dir_all(path.parent().expect("Weird log path")).expect("Yikes, folder problem"); + fs_err::create_dir_all(path.parent().expect("Weird log path")) + .expect("Yikes, folder problem"); fs_err::File::create(path) } .unwrap();