diff --git a/Cargo.lock b/Cargo.lock index 119ea0c5..dc44474b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,7 +344,7 @@ dependencies = [ [[package]] name = "hemtt" -version = "0.3.0" +version = "0.4.0" dependencies = [ "armake2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 9cefffd0..e4428e93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hemtt" -version = "0.3.1" +version = "0.4.0" authors = ["Brett "] edition = "2018" diff --git a/src/build.rs b/src/build.rs index 8a1a8fa1..8d8a64d8 100644 --- a/src/build.rs +++ b/src/build.rs @@ -49,4 +49,55 @@ pub fn build(p: &crate::project::Project) -> Result<(), std::io::Error> { )?; } Ok(()) +} + +pub fn release(p: &crate::project::Project) -> Result<(), std::io::Error> { + let version = crate::project::get_version()?; + println!("Building Release Version: {}", version); + build(&p)?; + if !Path::new("releases").exists() { + fs::create_dir("releases")?; + } + if !Path::new(&format!("releases/{}", version)).exists() { + fs::create_dir(format!("releases/{}", version))?; + } + if !Path::new(&format!("releases/{}/@{}", version, p.prefix)).exists() { + fs::create_dir(format!("releases/{}/@{}", version, p.prefix))?; + } + if !Path::new(&format!("releases/{}/@{}/addons", version, p.prefix)).exists() { + fs::create_dir(format!("releases/{}/@{}/addons", version, p.prefix))?; + } + if !Path::new(&format!("releases/{}/@{}/keys", version, p.prefix)).exists() { + fs::create_dir(format!("releases/{}/@{}/keys", version, p.prefix))?; + } + for file in &p.files { + fs::copy(file, format!("releases/{}/@{}/{}", version, p.prefix, file))?; + } + if !Path::new("keys").exists() { + fs::create_dir("keys")?; + } + if !Path::new(&format!("keys/{}.bikey", p.prefix)).exists() { + armake2::sign::cmd_keygen(PathBuf::from(&p.prefix))?; + fs::rename(format!("{}.bikey", p.prefix), format!("keys/{}.bikey", p.prefix))?; + fs::rename(format!("{}.biprivatekey", p.prefix), format!("keys/{}.biprivatekey", p.prefix))?; + } + fs::copy(format!("keys/{}.bikey", p.prefix), format!("releases/{0}/@{1}/keys/{1}.bikey", version, p.prefix))?; + for entry in fs::read_dir("addons").unwrap() { + let entry = entry.unwrap(); + let path = entry.path(); + let cpath = path.clone(); + let cpath = cpath.to_str().unwrap().replace(r#"\"#,"/"); + if !path.ends_with(".pbo") && !cpath.contains(p.prefix.as_str()) { + continue; + } + fs::copy(&cpath, format!("releases/{}/@{}/{}", version, p.prefix, cpath))?; + armake2::sign::cmd_sign( + PathBuf::from(format!("keys/{}.biprivatekey", p.prefix)), + PathBuf::from(format!("releases/{}/@{}/{}", version, p.prefix, cpath)), + Some(PathBuf::from(format!("releases/{0}/@{1}/{2}.{0}.bisign", version, p.prefix, cpath))), + armake2::sign::BISignVersion::V3 + )?; + println!(" {} {}", "Signed", cpath); + } + Ok(()) } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 50c0cebd..f44e1fc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ Usage: hemtt init hemtt create hemtt addon - hemtt build + hemtt build [--release] hemtt update hemtt (-h | --help) hemtt --version @@ -49,6 +49,7 @@ struct Args { flag_verbose: bool, flag_force: bool, flag_version: bool, + flag_release: bool, arg_name: String, } @@ -112,7 +113,11 @@ fn main() { if args.flag_force { files::clear_pbos(&p).unwrap(); } - build::build(&p).unwrap(); + if args.flag_release { + build::release(&p).unwrap() + } else { + build::build(&p).unwrap(); + } } else if args.cmd_update { let target = self_update::get_target().unwrap(); let status = self_update::backends::github::Update::configure().unwrap() @@ -124,7 +129,7 @@ fn main() { .current_version(VERSION) .build().unwrap() .update().unwrap(); - println!("Update: {}", status.version()); + println!("Using Version: {}", status.version()); } }