Skip to content

Commit

Permalink
Avoid using weird characters for Windows file name
Browse files Browse the repository at this point in the history
  • Loading branch information
wwylele committed Mar 15, 2021
1 parent 6efa1d8 commit b738a48
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,15 @@ fn read_msg(msg: String) -> Result<()> {

fn scan_msg(pak: Vec<String>, output: String) -> Result<()> {
let mut pak = PakReader::new(open_pak_files(pak)?)?;
std::fs::create_dir_all(&output)?;
for i in pak.all_file_indexs() {
let file = pak.read_file(i)?;
if file.len() < 8 || file[4..8] != b"GMSG"[..] {
continue;
}
let msg = Msg::new(Cursor::new(&file)).context(format!("at {:?}", i))?;
std::fs::write(
PathBuf::from(&output).join(format!("{:?}.txt", i)),
PathBuf::from(&output).join(format!("{}.txt", i.short_string())),
serde_json::to_string_pretty(&msg)?,
)?;
}
Expand Down Expand Up @@ -509,7 +510,7 @@ fn dump_tree(pak: Vec<String>, list: String, output: String) -> Result<()> {
for index in unvisited {
let path = PathBuf::from(&output)
.join("_unknown")
.join(format!("{:?}", index));
.join(index.short_string());
std::fs::create_dir_all(path.parent().context("no parent")?)?;
std::fs::write(path, &pak.read_file(index)?)?;
}
Expand Down
6 changes: 6 additions & 0 deletions src/pak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ pub struct PakFileIndex {
index: u32,
}

impl PakFileIndex {
pub fn short_string(&self) -> String {
format!("{:02}-{:06}", self.version, self.index)
}
}

#[derive(Debug)]
pub struct PakReader<F> {
files: Vec<F>,
Expand Down

0 comments on commit b738a48

Please sign in to comment.