From d9f640bc4d59419fc5c08a0d75374cd6c47111de Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Sat, 14 Jan 2023 20:19:22 -0600 Subject: [PATCH] zip --- Cargo.lock | 98 +++++++++++++++++++--------------- Cargo.toml | 4 +- bin/app/Cargo.toml | 5 +- bin/app/src/executor.rs | 2 +- bin/app/src/modules/archive.rs | 41 ++++++++++++++ bin/app/src/modules/mod.rs | 1 + bin/libs/config/Cargo.toml | 2 +- bin/libs/error/Cargo.toml | 3 +- bin/libs/error/src/lib.rs | 2 + book/commands-release.md | 2 + 10 files changed, 110 insertions(+), 50 deletions(-) create mode 100644 bin/app/src/modules/archive.rs diff --git a/Cargo.lock b/Cargo.lock index 61cbdaad..a605dcf5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,12 +183,12 @@ dependencies = [ [[package]] name = "clap" -version = "4.0.32" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +checksum = "4ec7a4128863c188deefe750ac1d1dfe66c236909f845af04beed823638dc1b2" dependencies = [ "bitflags", - "clap_lex 0.3.0", + "clap_lex 0.3.1", "is-terminal", "strsim", "termcolor", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +checksum = "783fe232adfca04f90f56201b26d79682d4cd2625e0bc7290b95123afe558ade" dependencies = [ "os_str_bytes", ] @@ -225,9 +225,9 @@ dependencies = [ [[package]] name = "console" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9b6515d269224923b26b5febea2ed42b2d5f2ce37284a4dd670fedd6cb8347a" +checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" dependencies = [ "encode_unicode", "lazy_static", @@ -368,11 +368,12 @@ dependencies = [ [[package]] name = "dialoguer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92e7e37ecef6857fdc0c0c5d42fd5b0938e46590c2183cc92dd310a6d078eb1" +checksum = "af3c796f3b0b408d9fd581611b47fa850821fcb84aa640b83a3c1a5be2d691f2" dependencies = [ "console", + "shell-words", "tempfile", "zeroize", ] @@ -499,9 +500,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2994bee4a3a6a51eb90c218523be382fd7ea09b16380b9312e9dbe955ff7c7d1" +checksum = "be36bc9e0546df253c0cc41fd0af34f5e92845ad8509462ec76672fac6997f5b" dependencies = [ "bitflags", "libc", @@ -536,7 +537,7 @@ version = "0.10.0" dependencies = [ "anyhow", "atty", - "clap 4.0.32", + "clap 4.1.1", "dialoguer", "fs_extra", "git2", @@ -557,6 +558,7 @@ dependencies = [ "steamlocate", "time", "vfs", + "walkdir", "winreg", "zip", ] @@ -593,13 +595,14 @@ dependencies = [ "serde", "toml", "vfs", + "zip", ] [[package]] name = "hemtt-bin-internal" version = "0.10.0" dependencies = [ - "clap 4.0.32", + "clap 4.1.1", "hemtt-config", "hemtt-error", "hemtt-preprocessor", @@ -744,9 +747,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", "windows-sys", @@ -839,9 +842,9 @@ checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libgit2-sys" -version = "0.14.0+1.5.0" +version = "0.14.1+1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47a00859c70c8a4f7218e6d1cc32875c4b55f6799445b842b0d8ed5e4c3d959b" +checksum = "4a07fb2692bc3593bda59de45a502bb3071659f2c515e28c71e728306b038e17" dependencies = [ "cc", "libc", @@ -1076,9 +1079,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6e86fb9e7026527a0d46bc308b841d73170ef8f443e1807f6ef88526a816d4" +checksum = "4257b4a04d91f7e9e6290be5d3da4804dd5784fafde3a497d73eb2b4a158c30a" dependencies = [ "thiserror", "ucd-trie", @@ -1086,9 +1089,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96504449aa860c8dcde14f9fba5c58dc6658688ca1fe363589d6327b8662c603" +checksum = "241cda393b0cdd65e62e07e12454f1f25d57017dcc514b1514cd3c4645e3a0a6" dependencies = [ "pest", "pest_generator", @@ -1096,9 +1099,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "798e0220d1111ae63d66cb66a5dcb3fc2d986d520b98e49e1852bfdb11d7c5e7" +checksum = "46b53634d8c8196302953c74d5352f33d0c512a9499bd2ce468fc9f4128fa27c" dependencies = [ "pest", "pest_meta", @@ -1109,13 +1112,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984298b75898e30a843e278a9f2452c31e349a073a0ce6fd950a12a74464e065" +checksum = "0ef4f1332a8d4678b41966bb4cc1d0676880e84183a1ecc3f4b69f03e99c7a51" dependencies = [ "once_cell", "pest", - "sha1", + "sha2", ] [[package]] @@ -1272,9 +1275,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -1450,6 +1453,12 @@ dependencies = [ "digest", ] +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + [[package]] name = "signature" version = "1.6.4" @@ -1824,45 +1833,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winreg" @@ -1920,10 +1929,11 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.4+zstd.1.5.2" +version = "2.0.5+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0" +checksum = "edc50ffce891ad571e9f9afe5039c4837bede781ac4bb13052ed7ae695518596" dependencies = [ "cc", "libc", + "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index c3994280..0808f23b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,10 @@ members = [ ] [workspace.dependencies] +clap = "4.0.32" +git2 = "0.16.0" pest = "2.5.2" pest_derive = "2.5.2" -clap = "4.0.32" serde = { version = "1.0.152", features = ["derive"] } sha-1 = "0.10.1" +zip = "0.6.3" diff --git a/bin/app/Cargo.toml b/bin/app/Cargo.toml index 2e18ee96..df2e21f8 100644 --- a/bin/app/Cargo.toml +++ b/bin/app/Cargo.toml @@ -22,7 +22,7 @@ atty = "0.2.14" clap = { workspace = true } dialoguer = "0.10.2" fs_extra = "1.2.0" -git2 = "0.15.0" +git2 = { workspace = true } glob = "0.3.1" lazy_static = "1.4.0" peekmore = "1.0.0" @@ -30,8 +30,9 @@ rayon = "1.6.1" rust-embed = "6.4.2" steamlocate = { git = "https://github.com/LovecraftianHorror/steamlocate-rs/", branch = "fully-switch-from-steamy-vdf" } time = "0.3.17" +walkdir = "2.3.2" vfs = "0.9.0" -zip = "0.6.3" +zip = { workspace = true } [target.'cfg(windows)'.dependencies] winreg = "0.10.1" diff --git a/bin/app/src/executor.rs b/bin/app/src/executor.rs index 9796c5d4..9f062070 100644 --- a/bin/app/src/executor.rs +++ b/bin/app/src/executor.rs @@ -57,7 +57,7 @@ impl<'a> Executor<'a> { for module in &self.modules { module.pre_release(self.ctx)?; } - // TODO: Release + modules::archive::release(self.ctx)?; for module in &self.modules { module.post_release(self.ctx)?; } diff --git a/bin/app/src/modules/archive.rs b/bin/app/src/modules/archive.rs new file mode 100644 index 00000000..f72f25fd --- /dev/null +++ b/bin/app/src/modules/archive.rs @@ -0,0 +1,41 @@ +use hemtt_bin_error::Error; + +use crate::context::Context; + +pub fn release(ctx: &Context) -> Result<(), Error> { + let output = ctx + .hemtt_folder() + .parent() + .expect("HEMTT creates two folders, so a parent should always exist") + .join(ctx.config().name()) + .with_extension("zip"); + let options = zip::write::FileOptions::default().compression_level(Some(9)); + + let mut zip = zip::ZipWriter::new(std::fs::File::create(&output)?); + for entry in walkdir::WalkDir::new(ctx.hemtt_folder()) { + let Ok(entry) = entry else { + continue; + }; + let path = entry.path(); + if path.is_dir() { + let path = path + .strip_prefix(ctx.hemtt_folder()) + .expect("We are in the HEMTT folder, the prefix should always exist") + .display() + .to_string(); + if path.is_empty() { + continue; + } + zip.add_directory(path, options)?; + continue; + } + let name = path + .strip_prefix(ctx.hemtt_folder()) + .expect("We are in the HEMTT folder, the prefix should always exist"); + zip.start_file(name.display().to_string(), options)?; + std::io::copy(&mut std::fs::File::open(path)?, &mut zip)?; + } + zip.finish()?; + println!("Created release: {output:?}"); + Ok(()) +} diff --git a/bin/app/src/modules/mod.rs b/bin/app/src/modules/mod.rs index c857e901..2909a08a 100644 --- a/bin/app/src/modules/mod.rs +++ b/bin/app/src/modules/mod.rs @@ -2,6 +2,7 @@ use hemtt_bin_error::Error; use crate::context::Context; +pub mod archive; pub mod pbo; mod binarize; diff --git a/bin/libs/config/Cargo.toml b/bin/libs/config/Cargo.toml index b95416e5..630d14ee 100644 --- a/bin/libs/config/Cargo.toml +++ b/bin/libs/config/Cargo.toml @@ -14,7 +14,7 @@ hemtt-preprocessor = { path = "../../../libs/preprocessor" } hemtt-signing = { path = "../../../libs/signing" } hemtt-version = { path = "../../../libs/version" } -git2 = "0.15.0" +git2 = { workspace = true } glob = "0.3.1" serde = { workspace = true, features = ["derive"] } toml = { version = "0.5.10" } diff --git a/bin/libs/error/Cargo.toml b/bin/libs/error/Cargo.toml index 9f00ca05..aca70eaf 100644 --- a/bin/libs/error/Cargo.toml +++ b/bin/libs/error/Cargo.toml @@ -13,8 +13,9 @@ hemtt-preprocessor = { path = "../../../libs/preprocessor" } hemtt-signing = { path = "../../../libs/signing" } hemtt-version = { path = "../../../libs/version" } -git2 = "0.15.0" +git2 = { workspace = true } glob = "0.3.1" serde = { workspace = true, features = ["derive"] } toml = { version = "0.5.10" } vfs = "0.9.0" +zip = { workspace = true } diff --git a/bin/libs/error/src/lib.rs b/bin/libs/error/src/lib.rs index 1711605e..5bf2954b 100644 --- a/bin/libs/error/src/lib.rs +++ b/bin/libs/error/src/lib.rs @@ -51,6 +51,8 @@ pub enum Error { Version(#[from] hemtt_version::Error), #[error("Vfs Error {0}")] Vfs(Box), + #[error("Zip Error: {0}")] + Zip(#[from] zip::result::ZipError), } impl From for Error { diff --git a/book/commands-release.md b/book/commands-release.md index 8156a95a..74615216 100644 --- a/book/commands-release.md +++ b/book/commands-release.md @@ -10,6 +10,8 @@ hemtt release It is intended to be used for releasing your mod. +It will create a zip archive in the `.hemtt` folder, named `{project name}.zip`. + ## Configuration `hemtt release` is built the same way as [`hemtt build`](commands-build.md), and will use its configuration.