mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 19:26:43 +01:00
add uw8 pack command
This commit is contained in:
8
uw8-tool/Cargo.lock
generated
8
uw8-tool/Cargo.lock
generated
@@ -4,9 +4,9 @@ version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.45"
|
||||
version = "1.0.52"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"
|
||||
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
@@ -70,9 +70,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.108"
|
||||
version = "0.2.112"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
|
||||
@@ -15,12 +15,12 @@ fn main() -> Result<()> {
|
||||
}
|
||||
"pack" => {
|
||||
let mut config = uw8_tool::PackConfig::default();
|
||||
if args.contains(["-c", "--compress"]) {
|
||||
config = config.with_compression();
|
||||
if args.contains(["-u", "--uncompressed"]) {
|
||||
config = config.uncompressed();
|
||||
}
|
||||
let source: PathBuf = args.free_from_str()?;
|
||||
let dest: PathBuf = args.free_from_str()?;
|
||||
uw8_tool::pack_file(&source, &dest, config)?;
|
||||
uw8_tool::pack_file(&source, &dest, &config)?;
|
||||
}
|
||||
"unpack" => {
|
||||
let source: PathBuf = args.free_from_str()?;
|
||||
|
||||
@@ -18,8 +18,8 @@ pub struct PackConfig {
|
||||
}
|
||||
|
||||
impl PackConfig {
|
||||
pub fn with_compression(mut self) -> Self {
|
||||
self.compression = Some(2);
|
||||
pub fn uncompressed(mut self) -> Self {
|
||||
self.compression = None;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ impl PackConfig {
|
||||
|
||||
impl Default for PackConfig {
|
||||
fn default() -> PackConfig {
|
||||
PackConfig { compression: None }
|
||||
PackConfig { compression: Some(2) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pack_file(source: &Path, dest: &Path, config: PackConfig) -> Result<()> {
|
||||
pub fn pack_file(source: &Path, dest: &Path, config: &PackConfig) -> Result<()> {
|
||||
let mut source_data = vec![];
|
||||
File::open(source)?.read_to_end(&mut source_data)?;
|
||||
|
||||
@@ -45,7 +45,7 @@ pub fn pack_file(source: &Path, dest: &Path, config: PackConfig) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn pack(data: &[u8], config: PackConfig) -> Result<Vec<u8>> {
|
||||
pub fn pack(data: &[u8], config: &PackConfig) -> Result<Vec<u8>> {
|
||||
let base = BaseModule::for_format_version(1)?;
|
||||
|
||||
let parsed_module = ParsedModule::parse(data)?;
|
||||
@@ -66,6 +66,7 @@ pub fn pack(data: &[u8], config: PackConfig) -> Result<Vec<u8>> {
|
||||
}),
|
||||
));
|
||||
pb.finish();
|
||||
std::io::stdout().flush()?;
|
||||
Ok(uw8)
|
||||
} else {
|
||||
let mut uw8 = vec![1];
|
||||
|
||||
Reference in New Issue
Block a user