diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index d366d8b..49a411d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - toolchain: [ stable, 1.81.0, nightly ] + toolchain: [ stable, 1.85.0, nightly ] fail-fast: false env: RUSTFLAGS: -D warnings diff --git a/Cargo.toml b/Cargo.toml index c6ea6ce..d3b2298 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = ["nod", "nodtool"] -resolver = "2" +resolver = "3" [profile.release] debug = 1 @@ -13,8 +13,8 @@ codegen-units = 1 [workspace.package] version = "2.0.0-alpha.1" -edition = "2021" -rust-version = "1.81" +edition = "2024" +rust-version = "1.85" authors = ["Luke Street "] license = "MIT OR Apache-2.0" repository = "https://github.com/encounter/nod" diff --git a/README.md b/README.md index 34af72f..c0a5a45 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [crates.io]: https://crates.io/crates/nod [Api Rustdoc]: https://img.shields.io/badge/api-rustdoc-blue.svg [rustdoc]: https://docs.rs/nod -[Rust Version]: https://img.shields.io/badge/rust-1.81+-blue.svg?maxAge=3600 +[Rust Version]: https://img.shields.io/badge/rust-1.85+-blue.svg?maxAge=3600 Library for reading and writing Nintendo Optical Disc (GameCube and Wii) images. diff --git a/nod/src/build/gc.rs b/nod/src/build/gc.rs index d616b87..a8ebedc 100644 --- a/nod/src/build/gc.rs +++ b/nod/src/build/gc.rs @@ -9,14 +9,14 @@ use tracing::debug; use zerocopy::{FromZeros, IntoBytes}; use crate::{ + Error, Result, ResultContext, disc::{ - fst::{Fst, FstBuilder}, - BootHeader, DiscHeader, BI2_SIZE, BOOT_SIZE, GCN_MAGIC, MINI_DVD_SIZE, SECTOR_SIZE, + BI2_SIZE, BOOT_SIZE, BootHeader, DiscHeader, GCN_MAGIC, MINI_DVD_SIZE, SECTOR_SIZE, WII_MAGIC, + fst::{Fst, FstBuilder}, }, read::DiscStream, - util::{array_ref, array_ref_mut, lfg::LaggedFibonacci, Align}, - Error, Result, ResultContext, + util::{Align, array_ref, array_ref_mut, lfg::LaggedFibonacci}, }; pub trait FileCallback: Clone + Send + Sync { diff --git a/nod/src/common.rs b/nod/src/common.rs index fa97f06..e4883f0 100644 --- a/nod/src/common.rs +++ b/nod/src/common.rs @@ -5,12 +5,12 @@ use std::{borrow::Cow, fmt, str::FromStr, sync::Arc}; use zerocopy::FromBytes; use crate::{ + Error, Result, disc::{ - fst::Fst, wii::WiiPartitionHeader, BootHeader, DebugHeader, DiscHeader, BB2_OFFSET, - BOOT_SIZE, SECTOR_SIZE, + BB2_OFFSET, BOOT_SIZE, BootHeader, DebugHeader, DiscHeader, SECTOR_SIZE, fst::Fst, + wii::WiiPartitionHeader, }, util::array_ref, - Error, Result, }; /// SHA-1 hash bytes diff --git a/nod/src/disc/direct.rs b/nod/src/disc/direct.rs index 2fc6dcf..5ae90b7 100644 --- a/nod/src/disc/direct.rs +++ b/nod/src/disc/direct.rs @@ -7,11 +7,11 @@ use std::{ use zerocopy::FromZeros; use crate::{ + Result, common::KeyBytes, - disc::{wii::SECTOR_DATA_SIZE, DiscHeader, SECTOR_SIZE}, + disc::{DiscHeader, SECTOR_SIZE, wii::SECTOR_DATA_SIZE}, io::block::{Block, BlockReader}, util::impl_read_for_bufread, - Result, }; #[derive(Clone)] diff --git a/nod/src/disc/fst.rs b/nod/src/disc/fst.rs index 3e69f90..142ab24 100644 --- a/nod/src/disc/fst.rs +++ b/nod/src/disc/fst.rs @@ -4,11 +4,11 @@ use std::{borrow::Cow, ffi::CStr, mem::size_of}; use encoding_rs::SHIFT_JIS; use itertools::Itertools; -use zerocopy::{big_endian::*, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, big_endian::*}; use crate::{ - util::{array_ref, static_assert}, Error, Result, + util::{array_ref, static_assert}, }; /// File system node kind. @@ -39,13 +39,14 @@ impl Node { /// Create a new node. #[inline] pub fn new(kind: NodeKind, name_offset: u32, offset: u64, length: u32, is_wii: bool) -> Self { + let name_offset_bytes = name_offset.to_be_bytes(); Self { kind: match kind { NodeKind::File => 0, NodeKind::Directory => 1, NodeKind::Invalid => u8::MAX, }, - name_offset: *array_ref![name_offset.to_be_bytes(), 1, 3], + name_offset: *array_ref![name_offset_bytes, 1, 3], offset: U32::new(match kind { NodeKind::File if is_wii => (offset / 4) as u32, _ => offset as u32, @@ -91,7 +92,8 @@ impl Node { /// Set the name offset of the node. #[inline] pub fn set_name_offset(&mut self, name_offset: u32) { - self.name_offset = *array_ref![name_offset.to_be_bytes(), 1, 3]; + let name_offset_bytes = name_offset.to_be_bytes(); + self.name_offset = *array_ref![name_offset_bytes, 1, 3]; } /// For files, this is the partition offset of the file data. (Wii: >> 2) diff --git a/nod/src/disc/gcn.rs b/nod/src/disc/gcn.rs index 7e29149..7c656b9 100644 --- a/nod/src/disc/gcn.rs +++ b/nod/src/disc/gcn.rs @@ -8,10 +8,11 @@ use std::{ use zerocopy::{FromBytes, FromZeros, IntoBytes}; use crate::{ + Result, ResultContext, disc::{ - preloader::{fetch_sector_group, Preloader, SectorGroup, SectorGroupRequest}, - ApploaderHeader, BootHeader, DolHeader, BB2_OFFSET, BI2_SIZE, BOOT_SIZE, SECTOR_GROUP_SIZE, + ApploaderHeader, BB2_OFFSET, BI2_SIZE, BOOT_SIZE, BootHeader, DolHeader, SECTOR_GROUP_SIZE, SECTOR_SIZE, + preloader::{Preloader, SectorGroup, SectorGroupRequest, fetch_sector_group}, }, io::block::BlockReader, read::{DiscStream, PartitionEncryption, PartitionMeta, PartitionReader}, @@ -19,7 +20,6 @@ use crate::{ impl_read_for_bufread, read::{read_arc, read_arc_slice, read_from}, }, - Result, ResultContext, }; pub struct PartitionReaderGC { diff --git a/nod/src/disc/hashes.rs b/nod/src/disc/hashes.rs index 433b35f..5033fcc 100644 --- a/nod/src/disc/hashes.rs +++ b/nod/src/disc/hashes.rs @@ -4,8 +4,8 @@ use zerocopy::{FromZeros, IntoBytes}; use crate::{ common::HashBytes, disc::{ - wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, SECTOR_GROUP_SIZE, SECTOR_SIZE, + wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, }, util::{array_ref, array_ref_mut, digest::sha1_hash}, }; diff --git a/nod/src/disc/mod.rs b/nod/src/disc/mod.rs index d5c05fc..573fb0a 100644 --- a/nod/src/disc/mod.rs +++ b/nod/src/disc/mod.rs @@ -2,7 +2,7 @@ use std::{ffi::CStr, str::from_utf8}; -use zerocopy::{big_endian::*, FromBytes, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, big_endian::*}; use crate::{common::MagicBytes, util::static_assert}; @@ -166,11 +166,7 @@ impl BootHeader { /// Offset within the partition to the main DOL. #[inline] pub fn dol_offset(&self, is_wii: bool) -> u64 { - if is_wii { - self.dol_offset.get() as u64 * 4 - } else { - self.dol_offset.get() as u64 - } + if is_wii { self.dol_offset.get() as u64 * 4 } else { self.dol_offset.get() as u64 } } /// Set the offset within the partition to the main DOL. @@ -186,11 +182,7 @@ impl BootHeader { /// Offset within the partition to the file system table (FST). #[inline] pub fn fst_offset(&self, is_wii: bool) -> u64 { - if is_wii { - self.fst_offset.get() as u64 * 4 - } else { - self.fst_offset.get() as u64 - } + if is_wii { self.fst_offset.get() as u64 * 4 } else { self.fst_offset.get() as u64 } } /// Set the offset within the partition to the file system table (FST). @@ -206,11 +198,7 @@ impl BootHeader { /// Size of the file system table (FST). #[inline] pub fn fst_size(&self, is_wii: bool) -> u64 { - if is_wii { - self.fst_size.get() as u64 * 4 - } else { - self.fst_size.get() as u64 - } + if is_wii { self.fst_size.get() as u64 * 4 } else { self.fst_size.get() as u64 } } /// Set the size of the file system table (FST). @@ -226,11 +214,7 @@ impl BootHeader { /// Maximum size of the file system table (FST) across multi-disc games. #[inline] pub fn fst_max_size(&self, is_wii: bool) -> u64 { - if is_wii { - self.fst_max_size.get() as u64 * 4 - } else { - self.fst_max_size.get() as u64 - } + if is_wii { self.fst_max_size.get() as u64 * 4 } else { self.fst_max_size.get() as u64 } } /// Set the maximum size of the file system table (FST) across multi-disc games. diff --git a/nod/src/disc/preloader.rs b/nod/src/disc/preloader.rs index f3e6977..8276809 100644 --- a/nod/src/disc/preloader.rs +++ b/nod/src/disc/preloader.rs @@ -13,16 +13,17 @@ use crossbeam_channel::{Receiver, Sender}; use crossbeam_utils::sync::WaitGroup; use lru::LruCache; use polonius_the_crab::{polonius, polonius_return}; -use simple_moving_average::{SingleSumSMA, SMA}; -use tracing::{debug, error, instrument, span, Level}; +use simple_moving_average::{SMA, SingleSumSMA}; +use tracing::{Level, debug, error, instrument, span}; use zerocopy::FromZeros; use crate::{ + IoResultContext, common::PartitionInfo, disc::{ - hashes::{hash_sector_group, GroupHashes}, - wii::HASHES_SIZE, DiscHeader, SECTOR_GROUP_SIZE, SECTOR_SIZE, + hashes::{GroupHashes, hash_sector_group}, + wii::HASHES_SIZE, }, io::{ block::{Block, BlockKind, BlockReader}, @@ -33,7 +34,6 @@ use crate::{ aes::{decrypt_sector, encrypt_sector}, array_ref_mut, }, - IoResultContext, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/nod/src/disc/reader.rs b/nod/src/disc/reader.rs index 4384550..a589af1 100644 --- a/nod/src/disc/reader.rs +++ b/nod/src/disc/reader.rs @@ -10,20 +10,21 @@ use tracing::warn; use zerocopy::{FromBytes, IntoBytes}; use crate::{ + Error, Result, ResultContext, common::{PartitionInfo, PartitionKind}, disc::{ + BB2_OFFSET, BOOT_SIZE, BootHeader, DL_DVD_SIZE, DiscHeader, MINI_DVD_SIZE, + SECTOR_GROUP_SIZE, SECTOR_SIZE, SL_DVD_SIZE, direct::{DirectDiscReader, DirectDiscReaderMode}, fst::{Fst, NodeKind}, - gcn::{read_fst, PartitionReaderGC}, + gcn::{PartitionReaderGC, read_fst}, preloader::{ - fetch_sector_group, Preloader, SectorGroup, SectorGroupLoader, SectorGroupRequest, + Preloader, SectorGroup, SectorGroupLoader, SectorGroupRequest, fetch_sector_group, }, wii::{ - PartitionReaderWii, WiiPartEntry, WiiPartGroup, WiiPartitionHeader, REGION_OFFSET, - REGION_SIZE, WII_PART_GROUP_OFF, + PartitionReaderWii, REGION_OFFSET, REGION_SIZE, WII_PART_GROUP_OFF, WiiPartEntry, + WiiPartGroup, WiiPartitionHeader, }, - BootHeader, DiscHeader, BB2_OFFSET, BOOT_SIZE, DL_DVD_SIZE, MINI_DVD_SIZE, - SECTOR_GROUP_SIZE, SECTOR_SIZE, SL_DVD_SIZE, }, io::block::BlockReader, read::{DiscMeta, DiscOptions, PartitionEncryption, PartitionOptions, PartitionReader}, @@ -31,7 +32,6 @@ use crate::{ array_ref, impl_read_for_bufread, read::{read_arc, read_from, read_vec}, }, - Error, Result, ResultContext, }; pub struct DiscReader { diff --git a/nod/src/disc/wii.rs b/nod/src/disc/wii.rs index 643e131..b09e2d0 100644 --- a/nod/src/disc/wii.rs +++ b/nod/src/disc/wii.rs @@ -8,14 +8,15 @@ use std::{ sync::Arc, }; -use zerocopy::{big_endian::*, FromBytes, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, big_endian::*}; use crate::{ + Error, Result, ResultContext, common::{HashBytes, KeyBytes, PartitionInfo}, disc::{ - gcn::{read_part_meta, PartitionReaderGC}, - preloader::{fetch_sector_group, Preloader, SectorGroup, SectorGroupRequest}, SECTOR_GROUP_SIZE, SECTOR_SIZE, + gcn::{PartitionReaderGC, read_part_meta}, + preloader::{Preloader, SectorGroup, SectorGroupRequest, fetch_sector_group}, }, io::block::BlockReader, read::{PartitionEncryption, PartitionMeta, PartitionOptions, PartitionReader}, @@ -27,7 +28,6 @@ use crate::{ read::{read_arc, read_arc_slice}, static_assert, }, - Error, Result, ResultContext, }; /// Size in bytes of the hashes block in a Wii disc sector diff --git a/nod/src/disc/writer.rs b/nod/src/disc/writer.rs index 80fc756..78767ed 100644 --- a/nod/src/disc/writer.rs +++ b/nod/src/disc/writer.rs @@ -8,15 +8,15 @@ use dyn_clone::DynClone; use rayon::prelude::*; use crate::{ + Error, Result, ResultContext, common::PartitionInfo, disc::{ + SECTOR_SIZE, reader::DiscReader, wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, - SECTOR_SIZE, }, util::{aes::decrypt_sector_b2b, array_ref, array_ref_mut, lfg::LaggedFibonacci}, write::{DiscFinalization, DiscWriterWeight, ProcessOptions}, - Error, Result, ResultContext, }; /// A callback for writing disc data. diff --git a/nod/src/io/block.rs b/nod/src/io/block.rs index 171b826..31cc98c 100644 --- a/nod/src/io/block.rs +++ b/nod/src/io/block.rs @@ -3,10 +3,11 @@ use std::{fs, io, io::Read, path::Path}; use dyn_clone::DynClone; use crate::{ + Error, Result, ResultContext, common::{Format, KeyBytes, MagicBytes, PartitionInfo}, disc::{ - wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, DiscHeader, GCN_MAGIC, SECTOR_SIZE, WII_MAGIC, + wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, }, io::{ split::SplitFileReader, @@ -14,7 +15,6 @@ use crate::{ }, read::{DiscMeta, DiscStream}, util::{aes::decrypt_sector, array_ref, array_ref_mut, lfg::LaggedFibonacci, read::read_from}, - Error, Result, ResultContext, }; /// Block reader trait for reading disc images. @@ -45,7 +45,7 @@ pub fn new(mut stream: Box) -> Result> { return Err(Error::DiscFormat("GCZ support is disabled".to_string())); } Some(Format::Nfs) => { - return Err(Error::DiscFormat("NFS requires a filesystem path".to_string())) + return Err(Error::DiscFormat("NFS requires a filesystem path".to_string())); } Some(Format::Wbfs) => crate::io::wbfs::BlockReaderWBFS::new(stream)?, Some(Format::Wia | Format::Rvz) => crate::io::wia::BlockReaderWIA::new(stream)?, diff --git a/nod/src/io/ciso.rs b/nod/src/io/ciso.rs index 206ada4..7eaa05d 100644 --- a/nod/src/io/ciso.rs +++ b/nod/src/io/ciso.rs @@ -6,17 +6,18 @@ use std::{ }; use bytes::{BufMut, Bytes, BytesMut}; -use zerocopy::{little_endian::*, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, little_endian::*}; use crate::{ + Error, Result, ResultContext, common::{Compression, Format, MagicBytes}, disc::{ + SECTOR_SIZE, reader::DiscReader, writer::{ - check_block, par_process, read_block, BlockProcessor, BlockResult, CheckBlockResult, - DataCallback, DiscWriter, + BlockProcessor, BlockResult, CheckBlockResult, DataCallback, DiscWriter, check_block, + par_process, read_block, }, - SECTOR_SIZE, }, io::{ block::{Block, BlockKind, BlockReader, CISO_MAGIC}, @@ -31,7 +32,6 @@ use crate::{ static_assert, }, write::{DiscFinalization, DiscWriterWeight, FormatOptions, ProcessOptions}, - Error, Result, ResultContext, }; pub const CISO_MAP_SIZE: usize = SECTOR_SIZE - 8; diff --git a/nod/src/io/gcz.rs b/nod/src/io/gcz.rs index 4299ca9..d072a97 100644 --- a/nod/src/io/gcz.rs +++ b/nod/src/io/gcz.rs @@ -7,14 +7,15 @@ use std::{ use adler::adler32_slice; use bytes::{BufMut, Bytes, BytesMut}; -use zerocopy::{little_endian::*, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, little_endian::*}; use crate::{ + Error, Result, ResultContext, common::{Compression, Format, MagicBytes}, disc::{ - reader::DiscReader, - writer::{par_process, read_block, BlockProcessor, BlockResult, DataCallback, DiscWriter}, SECTOR_SIZE, + reader::DiscReader, + writer::{BlockProcessor, BlockResult, DataCallback, DiscWriter, par_process, read_block}, }, io::block::{Block, BlockKind, BlockReader, GCZ_MAGIC}, read::{DiscMeta, DiscStream}, @@ -25,7 +26,6 @@ use crate::{ static_assert, }, write::{DiscFinalization, DiscWriterWeight, FormatOptions, ProcessOptions}, - Error, Result, ResultContext, }; /// GCZ header (little endian) diff --git a/nod/src/io/iso.rs b/nod/src/io/iso.rs index 98b6e4f..68c7668 100644 --- a/nod/src/io/iso.rs +++ b/nod/src/io/iso.rs @@ -4,17 +4,17 @@ use std::{ }; use crate::{ + Result, ResultContext, common::Format, disc::{ + SECTOR_SIZE, reader::DiscReader, writer::{DataCallback, DiscWriter}, - SECTOR_SIZE, }, io::block::{Block, BlockKind, BlockReader}, read::{DiscMeta, DiscStream}, util::digest::DigestManager, write::{DiscFinalization, DiscWriterWeight, ProcessOptions}, - Result, ResultContext, }; #[derive(Clone)] diff --git a/nod/src/io/nfs.rs b/nod/src/io/nfs.rs index 1c08447..861acea 100644 --- a/nod/src/io/nfs.rs +++ b/nod/src/io/nfs.rs @@ -7,9 +7,10 @@ use std::{ sync::Arc, }; -use zerocopy::{big_endian::U32, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, big_endian::U32}; use crate::{ + Error, Result, ResultContext, common::{Format, KeyBytes, MagicBytes}, disc::SECTOR_SIZE, io::{ @@ -18,7 +19,6 @@ use crate::{ }, read::DiscMeta, util::{aes::aes_cbc_decrypt, array_ref_mut, read::read_arc, static_assert}, - Error, Result, ResultContext, }; pub const NFS_END_MAGIC: MagicBytes = *b"SGGE"; diff --git a/nod/src/io/tgc.rs b/nod/src/io/tgc.rs index 958cd61..d18fac2 100644 --- a/nod/src/io/tgc.rs +++ b/nod/src/io/tgc.rs @@ -5,27 +5,27 @@ use std::{ }; use bytes::{BufMut, Bytes, BytesMut}; -use zerocopy::{big_endian::U32, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, big_endian::U32}; use crate::{ - build::gc::{insert_junk_data, FileCallback, GCPartitionStream, WriteInfo, WriteKind}, + Error, Result, ResultContext, + build::gc::{FileCallback, GCPartitionStream, WriteInfo, WriteKind, insert_junk_data}, common::{Compression, Format, MagicBytes, PartitionKind}, disc::{ + BB2_OFFSET, BootHeader, DiscHeader, SECTOR_SIZE, fst::Fst, gcn::{read_dol, read_fst}, reader::DiscReader, writer::{DataCallback, DiscWriter}, - BootHeader, DiscHeader, BB2_OFFSET, SECTOR_SIZE, }, io::block::{Block, BlockKind, BlockReader, TGC_MAGIC}, read::{DiscMeta, DiscStream, PartitionOptions, PartitionReader}, util::{ - array_ref, + Align, array_ref, read::{read_arc, read_arc_slice, read_from, read_with_zero_fill}, - static_assert, Align, + static_assert, }, write::{DiscFinalization, DiscWriterWeight, FormatOptions, ProcessOptions}, - Error, Result, ResultContext, }; /// TGC header (big endian) diff --git a/nod/src/io/wbfs.rs b/nod/src/io/wbfs.rs index 53b28d1..a977cd4 100644 --- a/nod/src/io/wbfs.rs +++ b/nod/src/io/wbfs.rs @@ -6,17 +6,18 @@ use std::{ }; use bytes::{BufMut, Bytes, BytesMut}; -use zerocopy::{big_endian::*, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, big_endian::*}; use crate::{ + Error, Result, ResultContext, common::{Compression, Format, MagicBytes}, disc::{ + SECTOR_SIZE, reader::DiscReader, writer::{ - check_block, par_process, read_block, BlockProcessor, BlockResult, CheckBlockResult, - DataCallback, DiscWriter, + BlockProcessor, BlockResult, CheckBlockResult, DataCallback, DiscWriter, check_block, + par_process, read_block, }, - SECTOR_SIZE, }, io::{ block::{Block, BlockKind, BlockReader, WBFS_MAGIC}, @@ -30,7 +31,6 @@ use crate::{ read::{read_arc_slice, read_box_slice, read_from}, }, write::{DiscFinalization, DiscWriterWeight, FormatOptions, ProcessOptions}, - Error, Result, ResultContext, }; #[derive(Debug, Clone, PartialEq, FromBytes, IntoBytes, Immutable, KnownLayout)] diff --git a/nod/src/io/wia.rs b/nod/src/io/wia.rs index 37be8fe..2d8c8c6 100644 --- a/nod/src/io/wia.rs +++ b/nod/src/io/wia.rs @@ -1,6 +1,6 @@ use std::{ borrow::Cow, - collections::{hash_map::Entry, BTreeSet, HashMap}, + collections::{BTreeSet, HashMap, hash_map::Entry}, io, io::{Read, Seek, SeekFrom}, mem::size_of, @@ -10,16 +10,17 @@ use std::{ use bytes::{Buf, BufMut, Bytes, BytesMut}; use tracing::{debug, instrument, warn}; -use zerocopy::{big_endian::*, FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout}; +use zerocopy::{FromBytes, FromZeros, Immutable, IntoBytes, KnownLayout, big_endian::*}; use crate::{ + Error, IoResultContext, Result, ResultContext, common::{Compression, Format, HashBytes, KeyBytes, MagicBytes}, disc::{ + BootHeader, DiscHeader, SECTOR_SIZE, fst::Fst, reader::DiscReader, wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, - writer::{par_process, read_block, BlockProcessor, BlockResult, DataCallback, DiscWriter}, - BootHeader, DiscHeader, SECTOR_SIZE, + writer::{BlockProcessor, BlockResult, DataCallback, DiscWriter, par_process, read_block}, }, io::{ block::{Block, BlockKind, BlockReader, RVZ_MAGIC, WIA_MAGIC}, @@ -27,16 +28,16 @@ use crate::{ }, read::{DiscMeta, DiscStream}, util::{ + Align, aes::decrypt_sector_data_b2b, array_ref, array_ref_mut, compress::{Compressor, DecompressionKind, Decompressor}, - digest::{sha1_hash, xxh64_hash, DigestManager}, + digest::{DigestManager, sha1_hash, xxh64_hash}, lfg::{LaggedFibonacci, SEED_SIZE, SEED_SIZE_BYTES}, read::{read_arc_slice, read_from, read_vec}, - static_assert, Align, + static_assert, }, write::{DiscFinalization, DiscWriterWeight, FormatOptions, ProcessOptions}, - Error, IoResultContext, Result, ResultContext, }; const WIA_VERSION: u32 = 0x01000000; @@ -1492,7 +1493,7 @@ impl DiscWriterWIA { return Err(Error::Other(format!( "Unsupported compression for WIA/RVZ: {}", options.compression - ))) + ))); } }; let compr_data = compr_data(options.compression).context("Building compression data")?; diff --git a/nod/src/read.rs b/nod/src/read.rs index ee1cea5..ca21a3d 100644 --- a/nod/src/read.rs +++ b/nod/src/read.rs @@ -9,17 +9,17 @@ use dyn_clone::DynClone; use zerocopy::FromBytes; use crate::{ + Result, common::{Compression, Format, PartitionInfo, PartitionKind}, disc, disc::{ + ApploaderHeader, BB2_OFFSET, BI2_SIZE, BOOT_SIZE, BootHeader, DebugHeader, DiscHeader, + DolHeader, fst::{Fst, Node}, - wii::{ContentMetadata, Ticket, TmdHeader, H3_TABLE_SIZE, REGION_SIZE}, - ApploaderHeader, BootHeader, DebugHeader, DiscHeader, DolHeader, BB2_OFFSET, BI2_SIZE, - BOOT_SIZE, + wii::{ContentMetadata, H3_TABLE_SIZE, REGION_SIZE, Ticket, TmdHeader}, }, io::block, - util::{array_ref, WindowedReader}, - Result, + util::{WindowedReader, array_ref}, }; /// Wii partition encryption mode. diff --git a/nod/src/util/aes.rs b/nod/src/util/aes.rs index 1acf827..8711765 100644 --- a/nod/src/util/aes.rs +++ b/nod/src/util/aes.rs @@ -3,8 +3,8 @@ use tracing::instrument; use crate::{ common::KeyBytes, disc::{ - wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, SECTOR_SIZE, + wii::{HASHES_SIZE, SECTOR_DATA_SIZE}, }, util::array_ref, }; @@ -32,7 +32,7 @@ pub fn aes_cbc_encrypt(key: &KeyBytes, iv: &KeyBytes, data: &mut [u8]) { assert_eq!(data.len() % 16, 0); #[cfg(not(feature = "openssl"))] { - use aes::cipher::{block_padding::NoPadding, BlockModeEncrypt, KeyIvInit}; + use aes::cipher::{BlockModeEncrypt, KeyIvInit, block_padding::NoPadding}; >::new(key.into(), iv.into()) .encrypt_padded::(data, data.len()) .unwrap(); @@ -57,7 +57,7 @@ pub fn aes_cbc_decrypt(key: &KeyBytes, iv: &KeyBytes, data: &mut [u8]) { assert_eq!(data.len() % 16, 0); #[cfg(not(feature = "openssl"))] { - use aes::cipher::{block_padding::NoPadding, BlockModeDecrypt, KeyIvInit}; + use aes::cipher::{BlockModeDecrypt, KeyIvInit, block_padding::NoPadding}; >::new(key.into(), iv.into()) .decrypt_padded::(data) .unwrap(); @@ -83,7 +83,7 @@ pub fn aes_cbc_decrypt_b2b(key: &KeyBytes, iv: &KeyBytes, data: &[u8], out: &mut assert_eq!(data.len(), out.len()); #[cfg(not(feature = "openssl"))] { - use aes::cipher::{block_padding::NoPadding, BlockModeDecrypt, KeyIvInit}; + use aes::cipher::{BlockModeDecrypt, KeyIvInit, block_padding::NoPadding}; >::new(key.into(), iv.into()) .decrypt_padded_b2b::(data, out) .unwrap(); diff --git a/nod/src/util/compress.rs b/nod/src/util/compress.rs index 428d4b8..9644af1 100644 --- a/nod/src/util/compress.rs +++ b/nod/src/util/compress.rs @@ -3,9 +3,9 @@ use std::{io, io::Read}; use tracing::instrument; use crate::{ + Error, Result, common::Compression, io::wia::{WIACompression, WIADisc}, - Error, Result, }; pub struct Decompressor { diff --git a/nod/src/util/lfg.rs b/nod/src/util/lfg.rs index 5b6b9e0..35a0dee 100644 --- a/nod/src/util/lfg.rs +++ b/nod/src/util/lfg.rs @@ -7,7 +7,7 @@ use std::{ use bytes::Buf; use tracing::instrument; -use zerocopy::{transmute_ref, IntoBytes}; +use zerocopy::{IntoBytes, transmute_ref}; use crate::{disc::SECTOR_SIZE, util::array_ref_mut}; diff --git a/nod/src/write.rs b/nod/src/write.rs index 7131e48..d74bab1 100644 --- a/nod/src/write.rs +++ b/nod/src/write.rs @@ -3,10 +3,10 @@ use bytes::Bytes; use crate::{ + Error, Result, common::{Compression, Format}, disc, read::DiscReader, - Error, Result, }; /// Options for writing a disc image. diff --git a/nodtool/src/argp_version.rs b/nodtool/src/argp_version.rs index eccce05..21a9a49 100644 --- a/nodtool/src/argp_version.rs +++ b/nodtool/src/argp_version.rs @@ -4,7 +4,7 @@ //! For now, this only adds a --version/-V option which causes early-exit. use std::ffi::OsStr; -use argp::{parser::ParseGlobalOptions, EarlyExit, FromArgs, TopLevelCommand}; +use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions}; struct ArgsOrVersion(T) where T: FromArgs; diff --git a/nodtool/src/cmd/convert.rs b/nodtool/src/cmd/convert.rs index a720607..065ef34 100644 --- a/nodtool/src/cmd/convert.rs +++ b/nodtool/src/cmd/convert.rs @@ -47,7 +47,9 @@ pub fn run(args: Args) -> nod::Result<()> { (false, true) => PartitionEncryption::ForceEncrypted, (false, false) => PartitionEncryption::Original, (true, true) => { - return Err(nod::Error::Other("Both --decrypt and --encrypt specified".to_string())) + return Err(nod::Error::Other( + "Both --decrypt and --encrypt specified".to_string(), + )); } }, preloader_threads: 4, @@ -70,7 +72,7 @@ pub fn run(args: Args) -> nod::Result<()> { return Err(nod::Error::Other(format!( "Unknown file extension: {}", path_display(&args.out) - ))) + ))); } None => Format::Iso, }; diff --git a/nodtool/src/cmd/dat.rs b/nodtool/src/cmd/dat.rs index f974c65..dc3ffd6 100644 --- a/nodtool/src/cmd/dat.rs +++ b/nodtool/src/cmd/dat.rs @@ -7,9 +7,9 @@ use std::{ use argp::FromArgs; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use nod::{ + Result, ResultContext, read::{DiscOptions, DiscReader, PartitionEncryption}, write::{DiscWriter, FormatOptions, ProcessOptions}, - Result, ResultContext, }; use crate::util::{redump, redump::GameResult}; diff --git a/nodtool/src/cmd/extract.rs b/nodtool/src/cmd/extract.rs index 7990d6b..3c8eacf 100644 --- a/nodtool/src/cmd/extract.rs +++ b/nodtool/src/cmd/extract.rs @@ -7,10 +7,10 @@ use std::{ use argp::FromArgs; use nod::{ + ResultContext, common::PartitionKind, disc::fst::{Fst, Node}, read::{DiscOptions, DiscReader, PartitionMeta, PartitionOptions, PartitionReader}, - ResultContext, }; use size::{Base, Size}; use zerocopy::IntoBytes; diff --git a/nodtool/src/cmd/gen.rs b/nodtool/src/cmd/gen.rs index bbdaccd..8d064da 100644 --- a/nodtool/src/cmd/gen.rs +++ b/nodtool/src/cmd/gen.rs @@ -10,11 +10,12 @@ use std::{ use argp::FromArgs; use nod::{ + ResultContext, build::gc::{FileCallback, FileInfo, GCPartitionBuilder, PartitionOverrides}, common::PartitionKind, disc::{ - fst::Fst, BootHeader, DiscHeader, BB2_OFFSET, BI2_SIZE, BOOT_SIZE, MINI_DVD_SIZE, - SECTOR_SIZE, + BB2_OFFSET, BI2_SIZE, BOOT_SIZE, BootHeader, DiscHeader, MINI_DVD_SIZE, SECTOR_SIZE, + fst::Fst, }, read::{ DiscOptions, DiscReader, PartitionEncryption, PartitionMeta, PartitionOptions, @@ -22,7 +23,6 @@ use nod::{ }, util::lfg::LaggedFibonacci, write::{DiscWriter, FormatOptions, ProcessOptions}, - ResultContext, }; use tracing::{debug, error, info, warn}; use zerocopy::{FromBytes, FromZeros}; @@ -188,7 +188,7 @@ pub fn run(args: Args) -> nod::Result<()> { } Err(e) => { return Err(e) - .context(format!("Failed to get metadata for {}", file_path.display())) + .context(format!("Failed to get metadata for {}", file_path.display())); } }; if metadata.is_dir() { diff --git a/nodtool/src/cmd/mod.rs b/nodtool/src/cmd/mod.rs index 364ebee..d5afd72 100644 --- a/nodtool/src/cmd/mod.rs +++ b/nodtool/src/cmd/mod.rs @@ -1,6 +1,6 @@ pub mod convert; pub mod dat; pub mod extract; -pub mod gen; +pub mod r#gen; pub mod info; pub mod verify; diff --git a/nodtool/src/cmd/verify.rs b/nodtool/src/cmd/verify.rs index c6acb1d..fb23480 100644 --- a/nodtool/src/cmd/verify.rs +++ b/nodtool/src/cmd/verify.rs @@ -41,7 +41,9 @@ pub fn run(args: Args) -> nod::Result<()> { (false, true) => PartitionEncryption::ForceEncrypted, (false, false) => PartitionEncryption::Original, (true, true) => { - return Err(nod::Error::Other("Both --decrypt and --encrypt specified".to_string())) + return Err(nod::Error::Other( + "Both --decrypt and --encrypt specified".to_string(), + )); } }, preloader_threads: 4.min(cpus), diff --git a/nodtool/src/lib.rs b/nodtool/src/lib.rs index c60c1aa..2478263 100644 --- a/nodtool/src/lib.rs +++ b/nodtool/src/lib.rs @@ -13,7 +13,7 @@ pub enum SubCommand { Dat(cmd::dat::Args), Extract(cmd::extract::Args), // Gen(cmd::gen::Args), - GenTest(cmd::gen::TestArgs), + GenTest(cmd::r#gen::TestArgs), Info(cmd::info::Args), Verify(cmd::verify::Args), } @@ -24,7 +24,7 @@ pub fn run(command: SubCommand) -> nod::Result<()> { SubCommand::Dat(c_args) => cmd::dat::run(c_args), SubCommand::Extract(c_args) => cmd::extract::run(c_args), // SubCommand::Gen(c_args) => cmd::gen::run(c_args), - SubCommand::GenTest(c_args) => cmd::gen::run_test(c_args), + SubCommand::GenTest(c_args) => cmd::r#gen::run_test(c_args), SubCommand::Info(c_args) => cmd::info::run(c_args), SubCommand::Verify(c_args) => cmd::verify::run(c_args), } diff --git a/nodtool/src/main.rs b/nodtool/src/main.rs index 2efe9d7..2a8e026 100644 --- a/nodtool/src/main.rs +++ b/nodtool/src/main.rs @@ -10,7 +10,7 @@ use std::{env, error::Error, ffi::OsStr, fmt, path::PathBuf, str::FromStr}; use argp::{FromArgValue, FromArgs}; use enable_ansi_support::enable_ansi_support; -use nodtool::{run, SubCommand}; +use nodtool::{SubCommand, run}; use supports_color::Stream; #[derive(FromArgs, Debug)] @@ -93,7 +93,7 @@ fn main() { // Try to enable ANSI support on Windows. let _ = enable_ansi_support(); // Disable isatty check for supports-color. (e.g. when used with ninja) - env::set_var("IGNORE_IS_TERMINAL", "1"); + unsafe { env::set_var("IGNORE_IS_TERMINAL", "1") }; supports_color::on(Stream::Stdout).is_some_and(|c| c.has_basic) }; diff --git a/nodtool/src/util/mod.rs b/nodtool/src/util/mod.rs index 26c3fa4..917e1f8 100644 --- a/nodtool/src/util/mod.rs +++ b/nodtool/src/util/mod.rs @@ -5,7 +5,7 @@ pub mod shared; use std::{ fmt, fmt::Write, - path::{Path, MAIN_SEPARATOR}, + path::{MAIN_SEPARATOR, Path}, }; pub fn path_display(path: &Path) -> PathDisplay { PathDisplay { path } } diff --git a/nodtool/src/util/shared.rs b/nodtool/src/util/shared.rs index ab60235..b98e285 100644 --- a/nodtool/src/util/shared.rs +++ b/nodtool/src/util/shared.rs @@ -7,11 +7,11 @@ use std::{ use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use nod::{ + Result, ResultContext, common::Compression, disc::DiscHeader, read::{DiscMeta, DiscOptions, DiscReader, PartitionEncryption}, write::{DiscWriter, DiscWriterWeight, FormatOptions, ProcessOptions}, - Result, ResultContext, }; use size::Size;