Skip to content

Commit

Permalink
zip
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Jan 15, 2023
1 parent 44370e4 commit d9f640b
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 50 deletions.
98 changes: 54 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 3 additions & 2 deletions bin/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ 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"
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"
2 changes: 1 addition & 1 deletion bin/app/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
41 changes: 41 additions & 0 deletions bin/app/src/modules/archive.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
1 change: 1 addition & 0 deletions bin/app/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use hemtt_bin_error::Error;

use crate::context::Context;

pub mod archive;
pub mod pbo;

mod binarize;
Expand Down
2 changes: 1 addition & 1 deletion bin/libs/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
3 changes: 2 additions & 1 deletion bin/libs/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 2 additions & 0 deletions bin/libs/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum Error {
Version(#[from] hemtt_version::Error),
#[error("Vfs Error {0}")]
Vfs(Box<vfs::VfsError>),
#[error("Zip Error: {0}")]
Zip(#[from] zip::result::ZipError),
}

impl From<vfs::VfsError> for Error {
Expand Down
Loading

0 comments on commit d9f640b

Please sign in to comment.