Skip to content

Commit

Permalink
feat: Rust 2024 edition update 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTMjugador committed Dec 3, 2024
1 parent 27c936e commit d215d93
Show file tree
Hide file tree
Showing 29 changed files with 147 additions and 168 deletions.
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[workspace]
members = ["packages/*"]
resolver = "2"
resolver = "3"

[workspace.package]
version = "0.4.0"
repository = "https://github.com/ComunidadAylas/PackSquash"
license = "AGPL-3.0-or-later"
edition = "2024"
publish = false

[patch.crates-io]
# Use our fork of glsl-lang that allows it to parse #moj_import directives
Expand Down
10 changes: 5 additions & 5 deletions packages/packsquash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "packsquash"
description = "Minecraft resource and data pack optimizer"
version = "0.4.0"
version.workspace = true
authors = ["Alejandro \"AlexTMjugador\" González"]
repository = "https://github.com/ComunidadAylas/PackSquash"
license = "AGPL-3.0-or-later"
repository.workspace = true
license.workspace = true
readme = "README.md"
publish = false
edition = "2021"
publish.workspace = true
edition.workspace = true

[dependencies]
bytes = "1.9.0"
Expand Down
6 changes: 3 additions & 3 deletions packages/packsquash/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::path::Path;
use std::time::Duration;

use criterion::{measurement::Measurement, BatchSize, BenchmarkGroup, Criterion, SamplingMode};
use criterion::{BatchSize, BenchmarkGroup, Criterion, SamplingMode, measurement::Measurement};
#[cfg(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64")))]
use criterion_perf_events::Perf;
use enumset::EnumSet;
Expand All @@ -16,9 +16,9 @@ use tempfile::NamedTempFile;

use pack_dataset::PackDataset;
use packsquash::{
PackSquasher,
config::{FileOptions, GlobalOptions, ProcessedSquashOptions, SquashOptions},
vfs::os_fs::OsFilesystem,
PackSquasher
vfs::os_fs::OsFilesystem
};

mod pack_dataset;
Expand Down
4 changes: 2 additions & 2 deletions packages/packsquash/benches/pack_dataset.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Contains the definition of the pack dataset struct.
use std::collections::{hash_map::Entry, HashMap};
use std::collections::{HashMap, hash_map::Entry};
use std::fs::File;
use std::io;
use std::path::Path;

use tar::Archive;
use tempfile::{tempdir, TempDir};
use tempfile::{TempDir, tempdir};
use xz2::read::XzDecoder;

/// Represents a pack dataset, which provides access to packs in the dataset.
Expand Down
2 changes: 1 addition & 1 deletion packages/packsquash/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains the configuration options needed to create a `PackSquasher` run.
use std::num::{NonZeroU16, NonZeroU32, NonZeroU8};
use std::num::{NonZeroU8, NonZeroU16, NonZeroU32};
use std::thread::available_parallelism;
use std::{num::NonZeroUsize, path::PathBuf};

Expand Down
12 changes: 6 additions & 6 deletions packages/packsquash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ use std::convert::Infallible;
use std::io::ErrorKind;
use std::panic;
use std::pin::Pin;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::{io, time::SystemTime};

use enumset::EnumSet;
use futures::future;
use futures::StreamExt;
use futures::future;
use thiserror::Error;
use tokio::io::AsyncSeek;
use tokio::io::BufReader;
use tokio::sync::mpsc::Sender;
use tokio::sync::Semaphore;
use tokio::sync::mpsc::Sender;
use tokio::{fs::File, io::AsyncRead, runtime::Builder};

use config::ProcessedSquashOptions;
Expand All @@ -38,12 +38,12 @@ use crate::config::{
CommandFunctionFileOptions, FileOptions, JsonFileOptions, LegacyLanguageFileOptions,
PngFileOptions, ShaderFileOptions, SquashOptions
};
use crate::pack_file::PackFileProcessData;
use crate::pack_file::asset_type::{
tweak_asset_types_mask_from_global_options, PackFileAssetTypeMatcher, PackFileAssetTypeMatches
PackFileAssetTypeMatcher, PackFileAssetTypeMatches, tweak_asset_types_mask_from_global_options
};
use crate::pack_file::PackFileProcessData;
pub use crate::squash_zip::relative_path::RelativePath;
use crate::squash_zip::{system_id, PreviousZipParseError};
use crate::squash_zip::{PreviousZipParseError, system_id};
use crate::vfs::{IteratorTraversalOptions, VfsPackFileIterEntry, VirtualFileSystem};

pub mod config;
Expand Down
4 changes: 2 additions & 2 deletions packages/packsquash/src/pack_file/asset_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::pack_file::properties_file::PropertiesFile;
use crate::pack_file::shader_file::ShaderFile;
use crate::squash_zip::FileListingCircumstances;
use crate::{
config::{compile_pack_file_glob_pattern, CustomFileOptions, FileOptions},
RelativePath
RelativePath,
config::{CustomFileOptions, FileOptions, compile_pack_file_glob_pattern}
};

use super::{AsyncReadAndSizeHint, PackFile, PackFileConstructor, PackFileProcessData};
Expand Down
18 changes: 13 additions & 5 deletions packages/packsquash/src/pack_file/audio_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use tokio_util::codec::{Decoder, FramedRead};
use vorbis_rs::{VorbisBitrateManagementStrategy, VorbisEncoderBuilder};

use crate::config::{AudioBitrateControlMode, AudioFileOptions, ChannelMixingOption};
use crate::pack_file::asset_type::PackFileAssetType;
use crate::pack_file::AsyncReadAndSizeHint;
use crate::pack_file::asset_type::PackFileAssetType;
use signal_processor::decode_and_process_sample_blocks;
use vorbis_stream_mangler::ValidatingAndObfuscatingOggVorbisStreamMangler;

Expand Down Expand Up @@ -80,23 +80,31 @@ pub enum OptimizationError {
Symphonia(#[from] symphonia::core::errors::Error),
#[error("Vorbis error: {0}")]
Vorbis(#[from] vorbis_rs::VorbisError),
#[error("Could not find a decodable audio track. Is this file in a supported format, and its extension correct?")]
#[error(
"Could not find a decodable audio track. Is this file in a supported format, and its extension correct?"
)]
NoAudioTrack,
#[error("Unknown or invalid channel count. Minecraft only supports mono and stereo sounds")]
UnsupportedChannelCount,
#[error("Unknown sampling frequency. Is this file corrupt?")]
UnknownSamplingFrequency,
#[error("Tried to resample from {sampling_frequency} Hz, but that frequency is too high. Please lower it")]
#[error(
"Tried to resample from {sampling_frequency} Hz, but that frequency is too high. Please lower it"
)]
InvalidSourceSamplingFrequency { sampling_frequency: NonZeroU32 },
#[error("Tried to resample to {sampling_frequency} Hz, but that frequency is too high. Please lower it")]
#[error(
"Tried to resample to {sampling_frequency} Hz, but that frequency is too high. Please lower it"
)]
InvalidTargetSamplingFrequency { sampling_frequency: NonZeroU32 },
#[error("An invalid target bitrate was specified in the options")]
InvalidTargetBitrate,
#[error("Resample error: {0}")]
ResamplingFailure(#[from] ResampleError),
#[error("{0}")]
TwoPassOptimization(#[from] ogg_to_ogg::RemuxError),
#[error("The Minecraft sample count limit for audio files was exceeded. Please reduce the sampling frequency or duration")]
#[error(
"The Minecraft sample count limit for audio files was exceeded. Please reduce the sampling frequency or duration"
)]
TooLongForMinecraft,
#[error("I/O error: {0}")]
Io(#[from] std::io::Error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use dasp_interpolate::sinc::Sinc;
use dasp_signal::Signal;
use rubato::{FftFixedIn, Resampler};
use std::io::{ErrorKind, Read};
use std::num::{NonZeroU32, NonZeroU8};
use std::num::{NonZeroU8, NonZeroU32};
use symphonia::core::audio::SampleBuffer;
use symphonia::core::codecs::{Decoder, DecoderOptions, CODEC_TYPE_NULL};
use symphonia::core::codecs::{CODEC_TYPE_NULL, Decoder, DecoderOptions};
use symphonia::core::formats::{FormatOptions, FormatReader};
use symphonia::core::io::{MediaSourceStream, MediaSourceStreamOptions, ReadOnlySource};
use symphonia::core::meta::{Limit, MetadataOptions};
Expand Down
6 changes: 3 additions & 3 deletions packages/packsquash/src/pack_file/command_function_file.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use futures::{future, StreamExt};
use futures::{StreamExt, future};
use thiserror::Error;
use tokio::io::AsyncRead;
use tokio_stream::Stream;
use tokio_util::codec::{FramedRead, LinesCodec, LinesCodecError};

use crate::config::CommandFunctionFileOptions;
use crate::pack_file::asset_type::PackFileAssetType;
use crate::pack_file::util::{prepare_line_for_output, LineNumber, MarkLastDecorator, BOM};
use crate::pack_file::AsyncReadAndSizeHint;
use crate::pack_file::asset_type::PackFileAssetType;
use crate::pack_file::util::{BOM, LineNumber, MarkLastDecorator, prepare_line_for_output};

use super::{OptimizedBytesChunk, PackFile, PackFileConstructor};

Expand Down
4 changes: 2 additions & 2 deletions packages/packsquash/src/pack_file/json_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use tokio::io::AsyncRead;
use tokio_util::codec::{Decoder, FramedRead};

use crate::config::JsonFileOptions;
use crate::pack_file::asset_type::PackFileAssetType;
use crate::pack_file::AsyncReadAndSizeHint;
use crate::pack_file::asset_type::PackFileAssetType;

use super::{util::strip_utf8_bom, PackFile, PackFileConstructor};
use super::{PackFile, PackFileConstructor, util::strip_utf8_bom};

use self::debloater::Debloater;

Expand Down
6 changes: 3 additions & 3 deletions packages/packsquash/src/pack_file/legacy_lang_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::LazyLock;

use futures::{future, StreamExt};
use futures::{StreamExt, future};
use patricia_tree::PatriciaSet;
use regex::Regex;
use thiserror::Error;
Expand All @@ -9,9 +9,9 @@ use tokio_stream::Stream;
use tokio_util::codec::{FramedRead, LinesCodec, LinesCodecError};

use crate::config::LegacyLanguageFileOptions;
use crate::pack_file::asset_type::PackFileAssetType;
use crate::pack_file::util::{prepare_line_for_output, LineNumber, MarkLastDecorator, BOM};
use crate::pack_file::AsyncReadAndSizeHint;
use crate::pack_file::asset_type::PackFileAssetType;
use crate::pack_file::util::{BOM, LineNumber, MarkLastDecorator, prepare_line_for_output};

use super::{OptimizedBytesChunk, PackFile, PackFileConstructor};

Expand Down
9 changes: 3 additions & 6 deletions packages/packsquash/src/pack_file/passthrough_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ impl<T: AsyncRead + Send + Unpin + 'static> PackFile for PassthroughFile<T> {
type OptimizedByteChunksStream = FramedRead<T, PassthroughDecoder>;

fn process(self) -> FramedRead<T, PassthroughDecoder> {
FramedRead::new(
self.read,
PassthroughDecoder {
optimization_strategy_message: self.optimization_strategy_message
}
)
FramedRead::new(self.read, PassthroughDecoder {
optimization_strategy_message: self.optimization_strategy_message
})
}

fn is_compressed(&self) -> bool {
Expand Down
18 changes: 5 additions & 13 deletions packages/packsquash/src/pack_file/png_file/image_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
use crate::config::ColorQuantizationTarget;
use crate::zopfli_iterations_time_model::ZopfliIterationsTimeModel;
use bytes::BytesMut;
use imagequant::{liq_error, Attributes};
use imagequant::{Attributes, liq_error};
use itertools::Itertools;
use obfstr::random;
use oxipng::{indexset, BitDepth, ColorType, Deflaters, Options, RowFilter, StripChunks};
use oxipng::{BitDepth, ColorType, Deflaters, Options, RowFilter, StripChunks, indexset};
use rgb::{AsPixels, RGBA8};
use spng::{ContextFlags, DecodeFlags, Format};
use std::io::Read;
use std::num::{NonZeroU16, NonZeroU8};
use std::num::{NonZeroU8, NonZeroU16};
use std::time::Duration;
use std::{cmp, iter};
use thiserror::Error;
Expand Down Expand Up @@ -131,20 +131,12 @@ pub fn obfuscate_png(png: &mut [u8]) {
const CRC32_KEY: u32 = {
let k = random!(u32);

if k == 0 {
0xCAFEBABE
} else {
k
}
if k == 0 { 0xCAFEBABE } else { k }
};
const ADLER32_KEY: u32 = {
let k = random!(u32);

if k == 0 {
0xCAFEBABE
} else {
k
}
if k == 0 { 0xCAFEBABE } else { k }
};

let mut i = 8;
Expand Down
4 changes: 2 additions & 2 deletions packages/packsquash/src/pack_file/shader_file/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use glsl_lang::ast::{
};
use glsl_lang::parse::{Extractable, Parse};
use glsl_lang::transpiler::glsl::{FormattingSettings, FormattingState};
use glsl_lang_lexer::v2_full::fs::PreprocessorExt;
use glsl_lang_lexer::v2_full::LexicalError;
use glsl_lang_lexer::ParseOptions;
use glsl_lang_lexer::v2_full::LexicalError;
use glsl_lang_lexer::v2_full::fs::PreprocessorExt;
use glsl_lang_pp::processor::fs::{FileSystem, Processor};
use regex::Regex;
use std::any::TypeId;
Expand Down
10 changes: 5 additions & 5 deletions packages/packsquash/src/pack_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl PackMeta {
_ => {
return Err(PackMetaError::MalformedMeta(
PACK_FORMAT_VERSION_IS_NOT_INTEGER
))
));
}
};

Expand All @@ -125,26 +125,26 @@ impl PackMeta {
Some(_) => {
return Err(PackMetaError::MalformedMeta(
"The \"description\" key value is not a text component"
))
));
}
None => {
return Err(PackMetaError::MalformedMeta(
"Missing \"description\" key in pack metadata object"
))
));
}
};
}
_ => {
return Err(PackMetaError::MalformedMeta(
"The \"pack\" key value is not a JSON object"
))
));
}
}
}
_ => {
return Err(PackMetaError::MalformedMeta(
"The JSON value is not an object"
))
));
}
};

Expand Down
23 changes: 10 additions & 13 deletions packages/packsquash/src/squash_zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{

use aes::Aes128;
use ahash::AHashMap;
use futures::{future, StreamExt, TryStreamExt};
use futures::{StreamExt, TryStreamExt, future};
use thiserror::Error;
use tokio::{
fs::File,
Expand All @@ -25,7 +25,7 @@ use tokio_util::io::ReaderStream;
use zopfli::Format;

use crate::{
config::PercentageInteger, zopfli_iterations_time_model::ZopfliIterationsTimeModel, RelativePath
RelativePath, config::PercentageInteger, zopfli_iterations_time_model::ZopfliIterationsTimeModel
};

use self::{
Expand Down Expand Up @@ -1015,17 +1015,14 @@ async fn read_previous_zip_contents<F: AsyncRead + AsyncSeek + Unpin>(
}

// After all this work, we can finally insert the file data in the map :)
previous_zip_contents.insert(
relative_path,
PreviousFile {
squash_time,
data_offset: local_file_header_offset + 30 + local_header_file_name_length,
crc32: crc,
compression_method,
uncompressed_size,
compressed_size
}
);
previous_zip_contents.insert(relative_path, PreviousFile {
squash_time,
data_offset: local_file_header_offset + 30 + local_header_file_name_length,
crc32: crc,
compression_method,
uncompressed_size,
compressed_size
});

// Make sure the seek position points to the next central directory header for the
// next iteration
Expand Down
Loading

0 comments on commit d215d93

Please sign in to comment.