modified: Cargo.lock
modified: Cargo.toml modified: src/lib.rs
This commit is contained in:
parent
07756c75cd
commit
b2f64a06b7
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -323,7 +323,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nicotine"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
dependencies = [
|
||||
"walkdir",
|
||||
"zip",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nicotine"
|
||||
version = "0.1.6"
|
||||
version = "0.1.7"
|
||||
edition = "2024"
|
||||
description = "A small rust crate for patching mojang's Authlib"
|
||||
authors = ["alterwain"]
|
||||
@ -10,5 +10,5 @@ crate-type = ["staticlib", "cdylib", "lib"]
|
||||
|
||||
[dependencies]
|
||||
zip-extract = "0.2.1"
|
||||
zip = "2.2.3"
|
||||
zip = { version = "2.2.3", features = ["deflate"] }
|
||||
walkdir = "2"
|
15
src/lib.rs
15
src/lib.rs
@ -74,8 +74,14 @@ fn zip_dir<T: Write + Seek>(
|
||||
writer: T,
|
||||
) -> zip::result::ZipResult<()> {
|
||||
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();
|
||||
|
||||
@ -83,15 +89,16 @@ fn zip_dir<T: Write + Seek>(
|
||||
let entry = entry.unwrap();
|
||||
let path = entry.path();
|
||||
let name = path.strip_prefix(prefix).unwrap();
|
||||
let dos_path = name.to_string_lossy().replace("/", "\\");
|
||||
if path.is_file() {
|
||||
let mut f = File::open(path)?;
|
||||
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)?;
|
||||
buffer.clear();
|
||||
} else if path.is_dir() {
|
||||
zip.add_directory(name.to_string_lossy(), options)?;
|
||||
zip.add_directory(dos_path, dir_options)?;
|
||||
}
|
||||
}
|
||||
zip.finish()?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user