diff --git a/.ci/tasks/build.sh b/.ci/tasks/build.sh index 68c61a0..0b4f2aa 100755 --- a/.ci/tasks/build.sh +++ b/.ci/tasks/build.sh @@ -24,7 +24,7 @@ PR=${PR:-} if [ -n "$PR" ]; then title "PR: $(echo "$PR" | jq '.number') - $(echo "$PR" | jq '.title')" ref="pr-$(echo "$PR" | jq '.number')-$(git rev-parse --short "$(cat .git/ref || echo "HEAD")" 2>/dev/null || echo 'manual')" -elif [ -f ".git/branch" ]; then +elif [ -f ".git/branch"]; then ref=$(cat .git/branch)-$(git rev-parse --short $ref) else ref=$(git rev-parse --short "$(cat .git/ref || echo "HEAD")") diff --git a/.ci/tasks/clippy.sh b/.ci/tasks/clippy.sh index 7c27b5f..33901a9 100755 --- a/.ci/tasks/clippy.sh +++ b/.ci/tasks/clippy.sh @@ -10,6 +10,6 @@ title "Install clippy" rustup component add clippy title "Run clippy" -cargo clippy --color always --no-deps -- -D warnings +cargo clippy --color always --no-deps title "Done" diff --git a/.gitmodules b/.gitmodules index e1964a8..a03eebf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ +[submodule "lib/serde_sjson"] + path = lib/serde_sjson + url = https://git.sclu1034.dev/lucas/serde_sjson.git [submodule "lib/luajit2-sys"] path = lib/luajit2-sys url = https://github.com/sclu1034/luajit2-sys.git diff --git a/Cargo.lock b/Cargo.lock index 378b9e3..b687bb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c43e7fd8284f025d0bd143c2855618ecdf697db55bde39211e5c9faec7669173" dependencies = [ "heapless", - "nom 7.1.3", + "nom", ] [[package]] @@ -383,7 +383,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ - "nom 7.1.3", + "nom", ] [[package]] @@ -2273,24 +2273,15 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "nom" -version = "8.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" -dependencies = [ - "memchr", -] - [[package]] name = "nom_locate" -version = "5.0.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b577e2d69827c4740cba2b52efaad1c4cc7c73042860b199710b3575c68438d" +checksum = "1e3c83c053b0713da60c5b8de47fe8e494fe3ece5267b2f23090a07a053ba8f3" dependencies = [ "bytecount", "memchr", - "nom 8.0.0", + "nom", ] [[package]] @@ -3278,11 +3269,9 @@ dependencies = [ [[package]] name = "serde_sjson" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c5b0d7af37492e99b8559436ee76b9ec8935c75449b1c2ef08c205a9e92ae6f" +version = "1.0.0" dependencies = [ - "nom 8.0.0", + "nom", "nom_locate", "serde", ] diff --git a/Cargo.toml b/Cargo.toml index b5fd830..2adf375 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "lib/dtmt-shared", "lib/oodle", "lib/sdk", + "lib/serde_sjson", "lib/luajit2-sys", "lib/color-eyre", ] @@ -34,7 +35,7 @@ glob = "0.3.0" interprocess = "2.1.0" lazy_static = "1.4.0" luajit2-sys = { path = "lib/luajit2-sys" } -minijinja = { version = "2.0.1", default-features = false, features = ["serde"] } +minijinja = { version = "2.0.1", default-features = false } nanorand = "0.7.0" nexusmods = { path = "lib/nexusmods" } notify = "8.0.0" @@ -46,7 +47,7 @@ pin-project-lite = "0.2.9" promptly = "0.3.1" sdk = { path = "lib/sdk" } serde = { version = "1.0.152", features = ["derive", "rc"] } -serde_sjson = "1.2.1" +serde_sjson = { path = "lib/serde_sjson" } steamlocate = "2.0.0-beta.2" strip-ansi-escapes = "0.2.0" time = { version = "0.3.20", features = ["serde", "serde-well-known", "local-offset", "formatting", "macros"] } diff --git a/crates/dtmm/src/controller/deploy.rs b/crates/dtmm/src/controller/deploy.rs index 481b07c..02b6860 100644 --- a/crates/dtmm/src/controller/deploy.rs +++ b/crates/dtmm/src/controller/deploy.rs @@ -116,14 +116,14 @@ async fn patch_game_settings(state: Arc) -> Result<()> { eyre::bail!("couldn't find 'boot_script' field"); }; - f.write_all(&settings.as_bytes()[0..i]).await?; + f.write_all(settings[0..i].as_bytes()).await?; f.write_all(b"boot_script = \"scripts/mod_main\"").await?; let Some(j) = settings[i..].find('\n') else { eyre::bail!("couldn't find end of 'boot_script' field"); }; - f.write_all(&settings.as_bytes()[(i + j)..]).await?; + f.write_all(settings[(i + j)..].as_bytes()).await?; Ok(()) } @@ -453,7 +453,10 @@ async fn build_bundles(state: Arc) -> Result> { } #[tracing::instrument(skip_all)] -async fn patch_boot_bundle(state: Arc, deployment_info: &str) -> Result> { +async fn patch_boot_bundle( + state: Arc, + deployment_info: &String, +) -> Result> { let bundle_dir = Arc::new(state.game_dir.join("bundle")); let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()))); @@ -587,7 +590,11 @@ fn build_deployment_data( .map(|bundle| format!("{:x}", bundle.name().to_murmur64())) .collect(), // TODO: - mod_folders: mod_folders.as_ref().to_vec(), + mod_folders: mod_folders + .as_ref() + .iter() + .map(|folder| folder.clone()) + .collect(), }; serde_sjson::to_string(&info).wrap_err("Failed to serizalize deployment data") } diff --git a/crates/dtmm/src/controller/game.rs b/crates/dtmm/src/controller/game.rs index b93d985..6b91169 100644 --- a/crates/dtmm/src/controller/game.rs +++ b/crates/dtmm/src/controller/game.rs @@ -91,14 +91,14 @@ async fn patch_game_settings(state: Arc) -> Result<()> { eyre::bail!("couldn't find 'boot_script' field"); }; - f.write_all(&settings.as_bytes()[0..i]).await?; + f.write_all(settings[0..i].as_bytes()).await?; f.write_all(b"boot_script = \"scripts/mod_main\"").await?; let Some(j) = settings[i..].find('\n') else { eyre::bail!("couldn't find end of 'boot_script' field"); }; - f.write_all(&settings.as_bytes()[(i + j)..]).await?; + f.write_all(settings[(i + j)..].as_bytes()).await?; Ok(()) } @@ -208,7 +208,7 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> { for p in paths { let path = bundle_dir.join(p); - let backup = bundle_dir.join(format!("{}.bak", p)); + let backup = bundle_dir.join(&format!("{}.bak", p)); let res = async { tracing::debug!( diff --git a/crates/dtmm/src/controller/import.rs b/crates/dtmm/src/controller/import.rs index 6fc9693..2f5f90b 100644 --- a/crates/dtmm/src/controller/import.rs +++ b/crates/dtmm/src/controller/import.rs @@ -397,7 +397,7 @@ fn extract_legacy_mod( tracing::trace!("Writing file '{}'", name.display()); let mut out = std::fs::OpenOptions::new() .write(true) - .truncate(true) + .create(true) .open(&name) .wrap_err_with(|| format!("Failed to open file '{}'", name.display()))?; diff --git a/crates/dtmt/src/cmd/bundle/extract.rs b/crates/dtmt/src/cmd/bundle/extract.rs index 75f1360..9a0f1dd 100644 --- a/crates/dtmt/src/cmd/bundle/extract.rs +++ b/crates/dtmt/src/cmd/bundle/extract.rs @@ -150,7 +150,7 @@ async fn parse_command_line_template(tmpl: &String) -> Result { String::from_utf8_unchecked(bytes.to_vec()) }); - for arg in parsed.by_ref() { + while let Some(arg) = parsed.next() { // Safety: See above. cmd.arg(unsafe { String::from_utf8_unchecked(arg.to_vec()) }); } diff --git a/crates/dtmt/src/shell_parse.rs b/crates/dtmt/src/shell_parse.rs index 13b3c4d..6f35a5f 100644 --- a/crates/dtmt/src/shell_parse.rs +++ b/crates/dtmt/src/shell_parse.rs @@ -54,11 +54,17 @@ impl<'a> ShellParser<'a> { } _ => {} }, - ParserState::SingleQuote => if c == b'\'' { - return Some(&self.bytes[start..(self.offset - 1)]); + ParserState::SingleQuote => match c { + b'\'' => { + return Some(&self.bytes[start..(self.offset - 1)]); + } + _ => {} }, - ParserState::DoubleQuote => if c == b'"' { - return Some(&self.bytes[start..(self.offset - 1)]); + ParserState::DoubleQuote => match c { + b'"' => { + return Some(&self.bytes[start..(self.offset - 1)]); + } + _ => {} }, } } diff --git a/lib/sdk/src/bundle/mod.rs b/lib/sdk/src/bundle/mod.rs index 075f4d2..ca36393 100644 --- a/lib/sdk/src/bundle/mod.rs +++ b/lib/sdk/src/bundle/mod.rs @@ -237,7 +237,7 @@ impl Bundle { // Ceiling division (or division toward infinity) to calculate // the number of chunks required to fit the unpacked data. - let num_chunks = unpacked_data.len().div_ceil(CHUNK_SIZE); + let num_chunks = (unpacked_data.len() + CHUNK_SIZE - 1) / CHUNK_SIZE; tracing::trace!(num_chunks); w.write_u32(num_chunks as u32)?; diff --git a/lib/sdk/src/filetype/lua.rs b/lib/sdk/src/filetype/lua.rs index dd0494e..14f0d6b 100644 --- a/lib/sdk/src/filetype/lua.rs +++ b/lib/sdk/src/filetype/lua.rs @@ -125,7 +125,7 @@ pub fn compile(name: impl Into, code: impl AsRef) -> Result, code: impl AsRef) -> Result unreachable!(), } - lua::lua_setglobal(state, c"fn".as_ptr()); + lua::lua_setglobal(state, b"fn\0".as_ptr() as _); - let run = c"return string.dump(fn, false)"; - match lua::luaL_loadstring(state, run.as_ptr()) as u32 { + let run = b"return string.dump(fn, false)\0"; + match lua::luaL_loadstring(state, run.as_ptr() as _) as u32 { lua::LUA_OK => {} lua::LUA_ERRSYNTAX => { let err = lua::lua_tostring(state, -1); diff --git a/lib/sdk/src/filetype/strings.rs b/lib/sdk/src/filetype/strings.rs index 8643266..ca2ed8c 100644 --- a/lib/sdk/src/filetype/strings.rs +++ b/lib/sdk/src/filetype/strings.rs @@ -28,14 +28,10 @@ impl Language { #[derive(serde::Serialize)] pub struct Strings(HashMap>); -#[inline(always)] fn read_string(r: R) -> Result where R: Read, { - // We can safely ignore the warning here, as all data is already in memory, and no additional - // `BufReader` should be needed. - #[allow(clippy::unbuffered_bytes)] r.bytes() .take_while(|b| b.as_ref().map(|b| *b != 0).unwrap_or(false)) .map(|b| b.map_err(Report::new)) @@ -45,7 +41,7 @@ where impl Strings { #[tracing::instrument(skip_all, fields(languages = variants.len()))] - pub fn from_variants(ctx: &crate::Context, variants: &[BundleFileVariant]) -> Result { + pub fn from_variants(ctx: &crate::Context, variants: &Vec) -> Result { let mut map: HashMap> = HashMap::new(); for (i, variant) in variants.iter().enumerate() { @@ -80,7 +76,7 @@ impl Strings { } #[tracing::instrument(skip_all)] -pub fn decompile(ctx: &crate::Context, variants: &[BundleFileVariant]) -> Result> { +pub fn decompile(ctx: &crate::Context, variants: &Vec) -> Result> { let strings = Strings::from_variants(ctx, variants)?; let content = strings.to_sjson()?; diff --git a/lib/serde_sjson b/lib/serde_sjson new file mode 160000 index 0000000..73d2b23 --- /dev/null +++ b/lib/serde_sjson @@ -0,0 +1 @@ +Subproject commit 73d2b23ce50e75b184f5092ad515e97a0adbe6da