modified: Cargo.lock

modified:   Cargo.toml
	modified:   src/lib.rs
This commit is contained in:
Michael Wain 2025-03-18 17:15:47 +03:00
parent 07756c75cd
commit b2f64a06b7
3 changed files with 14 additions and 7 deletions

2
Cargo.lock generated
View File

@ -323,7 +323,7 @@ dependencies = [
[[package]] [[package]]
name = "nicotine" name = "nicotine"
version = "0.1.6" version = "0.1.7"
dependencies = [ dependencies = [
"walkdir", "walkdir",
"zip", "zip",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "nicotine" name = "nicotine"
version = "0.1.6" version = "0.1.7"
edition = "2024" edition = "2024"
description = "A small rust crate for patching mojang's Authlib" description = "A small rust crate for patching mojang's Authlib"
authors = ["alterwain"] authors = ["alterwain"]
@ -10,5 +10,5 @@ crate-type = ["staticlib", "cdylib", "lib"]
[dependencies] [dependencies]
zip-extract = "0.2.1" zip-extract = "0.2.1"
zip = "2.2.3" zip = { version = "2.2.3", features = ["deflate"] }
walkdir = "2" walkdir = "2"

View File

@ -74,8 +74,14 @@ fn zip_dir<T: Write + Seek>(
writer: T, writer: T,
) -> zip::result::ZipResult<()> { ) -> zip::result::ZipResult<()> {
let mut zip = ZipWriter::new(writer); let mut zip = ZipWriter::new(writer);
let options = SimpleFileOptions::default()
.compression_method(CompressionMethod::Stored); let file_options = SimpleFileOptions::default()
.compression_method(CompressionMethod::Deflated)
.unix_permissions(0o644); // Simulating a DOS file attribute
let dir_options = SimpleFileOptions::default()
.compression_method(CompressionMethod::Deflated)
.unix_permissions(0o755);
let mut buffer = Vec::new(); let mut buffer = Vec::new();
@ -83,15 +89,16 @@ fn zip_dir<T: Write + Seek>(
let entry = entry.unwrap(); let entry = entry.unwrap();
let path = entry.path(); let path = entry.path();
let name = path.strip_prefix(prefix).unwrap(); let name = path.strip_prefix(prefix).unwrap();
let dos_path = name.to_string_lossy().replace("/", "\\");
if path.is_file() { if path.is_file() {
let mut f = File::open(path)?; let mut f = File::open(path)?;
f.read_to_end(&mut buffer)?; f.read_to_end(&mut buffer)?;
zip.start_file(name.to_string_lossy(), options)?; zip.start_file(dos_path, file_options)?;
zip.write_all(&buffer)?; zip.write_all(&buffer)?;
buffer.clear(); buffer.clear();
} else if path.is_dir() { } else if path.is_dir() {
zip.add_directory(name.to_string_lossy(), options)?; zip.add_directory(dos_path, dir_options)?;
} }
} }
zip.finish()?; zip.finish()?;