mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-11 15:38:48 +08:00
Add escude LIST file export
This commit is contained in:
@@ -65,3 +65,13 @@ pub fn write_file<F: AsRef<Path> + ?Sized>(f: &F) -> io::Result<Box<dyn Write>>
|
||||
Box::new(fs::File::create(f)?)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn make_sure_dir_exists<F: AsRef<Path> + ?Sized>(f: &F) -> io::Result<()> {
|
||||
let path = f.as_ref();
|
||||
if let Some(parent) = path.parent() {
|
||||
if !parent.exists() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -4,3 +4,4 @@ pub mod encoding;
|
||||
mod encoding_win;
|
||||
pub mod files;
|
||||
pub mod name_replacement;
|
||||
pub mod struct_pack;
|
||||
|
||||
34
src/utils/struct_pack.rs
Normal file
34
src/utils/struct_pack.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use crate::types::Encoding;
|
||||
use anyhow::Result;
|
||||
use msg_tool_macro::struct_unpack_impl_for_num;
|
||||
use std::io::{Read, Seek, Write};
|
||||
|
||||
pub trait StructUnpack: Sized {
|
||||
fn unpack<R: Read + Seek>(reader: R, big: bool, encoding: Encoding) -> Result<Self>;
|
||||
}
|
||||
|
||||
pub trait StructPack: Sized {
|
||||
fn pack<W: Write>(&self, writer: &mut W, big: bool, encoding: Encoding) -> Result<()>;
|
||||
}
|
||||
|
||||
impl<T: StructPack> StructPack for Vec<T> {
|
||||
fn pack<W: Write>(&self, writer: &mut W, big: bool, encoding: Encoding) -> Result<()> {
|
||||
for item in self {
|
||||
item.pack(writer, big, encoding)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct_unpack_impl_for_num!(u8);
|
||||
struct_unpack_impl_for_num!(u16);
|
||||
struct_unpack_impl_for_num!(u32);
|
||||
struct_unpack_impl_for_num!(u64);
|
||||
struct_unpack_impl_for_num!(u128);
|
||||
struct_unpack_impl_for_num!(i8);
|
||||
struct_unpack_impl_for_num!(i16);
|
||||
struct_unpack_impl_for_num!(i32);
|
||||
struct_unpack_impl_for_num!(i64);
|
||||
struct_unpack_impl_for_num!(i128);
|
||||
struct_unpack_impl_for_num!(f32);
|
||||
struct_unpack_impl_for_num!(f64);
|
||||
Reference in New Issue
Block a user