mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-26 21:57:08 +08:00
pack allow empty output
This commit is contained in:
@@ -130,7 +130,7 @@ pub enum Command {
|
|||||||
/// Input directory
|
/// Input directory
|
||||||
input: String,
|
input: String,
|
||||||
/// Output archive file
|
/// Output archive file
|
||||||
output: String,
|
output: Option<String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
src/main.rs
22
src/main.rs
@@ -898,7 +898,7 @@ pub fn import_script(
|
|||||||
|
|
||||||
pub fn pack_archive(
|
pub fn pack_archive(
|
||||||
input: &str,
|
input: &str,
|
||||||
output: &str,
|
output: Option<&str>,
|
||||||
arg: &args::Arg,
|
arg: &args::Arg,
|
||||||
config: &types::ExtraConfig,
|
config: &types::ExtraConfig,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
@@ -926,11 +926,23 @@ pub fn pack_archive(
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let reff = re_files.iter().map(|s| s.as_str()).collect::<Vec<_>>();
|
let reff = re_files.iter().map(|s| s.as_str()).collect::<Vec<_>>();
|
||||||
let mut archive = scripts::BUILDER
|
let builder = scripts::BUILDER
|
||||||
.iter()
|
.iter()
|
||||||
.find(|b| b.script_type() == typ)
|
.find(|b| b.script_type() == typ)
|
||||||
.ok_or_else(|| anyhow::anyhow!("Unsupported script type"))?
|
.ok_or_else(|| anyhow::anyhow!("Unsupported script type"))?;
|
||||||
.create_archive(output, &reff, get_output_encoding(arg), config)?;
|
let output = match output {
|
||||||
|
Some(output) => output.to_string(),
|
||||||
|
None => {
|
||||||
|
let mut pb = std::path::PathBuf::from(input);
|
||||||
|
let ext = builder.extensions().first().unwrap_or(&"unk");
|
||||||
|
pb.set_extension(ext);
|
||||||
|
if pb.to_string_lossy() == input {
|
||||||
|
pb.set_extension(format!("{}.{}", ext, ext));
|
||||||
|
}
|
||||||
|
pb.to_string_lossy().into_owned()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut archive = builder.create_archive(&output, &reff, get_output_encoding(arg), config)?;
|
||||||
for (file, name) in files.iter().zip(reff) {
|
for (file, name) in files.iter().zip(reff) {
|
||||||
let mut f = match std::fs::File::open(file) {
|
let mut f = match std::fs::File::open(file) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
@@ -1067,7 +1079,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args::Command::Pack { input, output } => {
|
args::Command::Pack { input, output } => {
|
||||||
let re = pack_archive(input, output, &arg, &cfg);
|
let re = pack_archive(input, output.as_ref().map(|s| s.as_str()), &arg, &cfg);
|
||||||
if let Err(e) = re {
|
if let Err(e) = re {
|
||||||
COUNTER.inc_error();
|
COUNTER.inc_error();
|
||||||
eprintln!("Error packing archive: {}", e);
|
eprintln!("Error packing archive: {}", e);
|
||||||
|
|||||||
@@ -23,4 +23,6 @@ lazy_static::lazy_static! {
|
|||||||
];
|
];
|
||||||
pub static ref ALL_EXTS: Vec<String> =
|
pub static ref ALL_EXTS: Vec<String> =
|
||||||
BUILDER.iter().flat_map(|b| b.extensions()).map(|s| s.to_string()).collect();
|
BUILDER.iter().flat_map(|b| b.extensions()).map(|s| s.to_string()).collect();
|
||||||
|
pub static ref ARCHIVE_EXTS: Vec<String> =
|
||||||
|
BUILDER.iter().filter(|b| b.is_archive()).flat_map(|b| b.extensions()).map(|s| s.to_string()).collect();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user