mirror of
https://github.com/lifegpc/msg-tool.git
synced 2026-06-08 13:58:50 +08:00
Add library and documents
This commit is contained in:
@@ -1 +1,2 @@
|
||||
//! Artemis Engine Archive
|
||||
pub mod pfs;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Artemis Engine PFS Archive (pf6 and pf8)
|
||||
use crate::ext::io::*;
|
||||
use crate::scripts::base::*;
|
||||
use crate::types::*;
|
||||
@@ -10,9 +11,11 @@ use std::io::{Read, Seek, SeekFrom, Write};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The builder for Artemis PFS archive scripts.
|
||||
pub struct ArtemisArcBuilder {}
|
||||
|
||||
impl ArtemisArcBuilder {
|
||||
/// Creates a new instance of `ArtemisArcBuilder`.
|
||||
pub fn new() -> Self {
|
||||
ArtemisArcBuilder {}
|
||||
}
|
||||
@@ -125,6 +128,7 @@ struct PfsEntryHeader {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The Artemis PFS archive script.
|
||||
pub struct ArtemisArc<T: Read + Seek + std::fmt::Debug> {
|
||||
reader: Arc<Mutex<T>>,
|
||||
entries: Vec<PfsEntryHeader>,
|
||||
@@ -133,6 +137,12 @@ pub struct ArtemisArc<T: Read + Seek + std::fmt::Debug> {
|
||||
}
|
||||
|
||||
impl<T: Read + Seek + std::fmt::Debug> ArtemisArc<T> {
|
||||
/// Creates a new Artemis PFS archive script.
|
||||
///
|
||||
/// * `reader` - The reader for the archive.
|
||||
/// * `archive_encoding` - The encoding used for the archive.
|
||||
/// * `config` - Extra configuration options.
|
||||
/// * `filename` - The name of the archive file.
|
||||
pub fn new(
|
||||
mut reader: T,
|
||||
archive_encoding: Encoding,
|
||||
@@ -336,6 +346,7 @@ fn detect_script_type(buf: &[u8], buf_len: usize, filename: &str) -> Option<Scri
|
||||
None
|
||||
}
|
||||
|
||||
/// The Artemis PFS archive writer.
|
||||
pub struct ArtemisArcWriter<T: Write + Seek + Read> {
|
||||
writer: T,
|
||||
headers: HashMap<String, PfsEntryHeader>,
|
||||
@@ -345,6 +356,12 @@ pub struct ArtemisArcWriter<T: Write + Seek + Read> {
|
||||
}
|
||||
|
||||
impl<T: Write + Seek + Read> ArtemisArcWriter<T> {
|
||||
/// Creates a new Artemis PFS archive writer.
|
||||
///
|
||||
/// * `writer` - The writer for the archive.
|
||||
/// * `files` - The list of files to include in the archive.
|
||||
/// * `encoding` - The encoding used for the archive.
|
||||
/// * `config` - Extra configuration options.
|
||||
pub fn new(
|
||||
mut writer: T,
|
||||
files: &[&str],
|
||||
@@ -445,6 +462,7 @@ impl<T: Write + Seek + Read> Archive for ArtemisArcWriter<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Artemis PFS archive file writer.
|
||||
pub struct ArtemisArcFile<'a, T: Write + Seek> {
|
||||
header: &'a mut PfsEntryHeader,
|
||||
writer: &'a mut T,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Artemis Engine ASB file (.asb)
|
||||
use crate::ext::io::*;
|
||||
use crate::scripts::base::*;
|
||||
use crate::types::*;
|
||||
@@ -11,9 +12,11 @@ use std::ops::Index;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The builder for Artemis ASB scripts.
|
||||
pub struct ArtemisAsbBuilder {}
|
||||
|
||||
impl ArtemisAsbBuilder {
|
||||
/// Creates a new instance of `ArtemisAsbBuilder`.
|
||||
pub fn new() -> Self {
|
||||
ArtemisAsbBuilder {}
|
||||
}
|
||||
@@ -408,11 +411,17 @@ impl<'a> TextParser<'a> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The Artemis ASB script.
|
||||
pub struct Asb {
|
||||
items: Vec<Item>,
|
||||
}
|
||||
|
||||
impl Asb {
|
||||
/// Creates a new Artemis ASB script from the given buffer.
|
||||
///
|
||||
/// * `buf` - The buffer containing the ASB data.
|
||||
/// * `encoding` - The encoding used for the ASB data.
|
||||
/// * `config` - Extra configuration options.
|
||||
pub fn new(buf: Vec<u8>, encoding: Encoding, _config: &ExtraConfig) -> Result<Self> {
|
||||
let mut data = MemReader::new(buf);
|
||||
let mut magic = [0; 5];
|
||||
@@ -654,6 +663,12 @@ impl Script for Asb {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new ASB file.
|
||||
///
|
||||
/// * `custom_filename` - The path ot the input file.
|
||||
/// * `writer` - The writer to write the ASB script.
|
||||
/// * `encoding` - The encoding used for the ASB script.
|
||||
/// * `output_encoding` - The encoding used for the input file.
|
||||
pub fn create_file<'a>(
|
||||
custom_filename: &'a str,
|
||||
mut writer: Box<dyn WriteSeek + 'a>,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Artemis Engine AST file (.ast)
|
||||
mod dump;
|
||||
mod parser;
|
||||
mod text;
|
||||
@@ -11,9 +12,11 @@ use std::io::Write;
|
||||
use types::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The builder for Artemis AST scripts.
|
||||
pub struct AstScriptBuilder {}
|
||||
|
||||
impl AstScriptBuilder {
|
||||
/// Creates a new instance of `AstScriptBuilder`.
|
||||
pub fn new() -> Self {
|
||||
AstScriptBuilder {}
|
||||
}
|
||||
@@ -55,6 +58,7 @@ impl ScriptBuilder for AstScriptBuilder {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// The Artemis AST script.
|
||||
pub struct AstScript {
|
||||
ast: AstFile,
|
||||
indent: Option<usize>,
|
||||
@@ -64,6 +68,11 @@ pub struct AstScript {
|
||||
}
|
||||
|
||||
impl AstScript {
|
||||
/// Creates a new Artemis AST script from the given buffer.
|
||||
///
|
||||
/// * `buf` - The buffer containing the AST data.
|
||||
/// * `encoding` - The encoding used for the AST data.
|
||||
/// * `config` - Extra configuration options.
|
||||
pub fn new(buf: Vec<u8>, encoding: Encoding, config: &ExtraConfig) -> Result<Self> {
|
||||
let parser = parser::Parser::new(&buf, encoding);
|
||||
let ast = parser.parse()?;
|
||||
@@ -680,6 +689,11 @@ impl Script for AstScript {
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the given buffer is in the Artemis AST format.
|
||||
///
|
||||
/// * `filename` - The name of the file.
|
||||
/// * `buf` - The buffer containing the data.
|
||||
/// * `buf_len` - The length of the buffer.
|
||||
pub fn is_this_format(_filename: &str, buf: &[u8], buf_len: usize) -> bool {
|
||||
let parser = parser::Parser::new(&buf[..buf_len], Encoding::Utf8);
|
||||
parser.try_parse_header().is_ok()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Artemis Engine Scripts
|
||||
#[cfg(feature = "artemis-arc")]
|
||||
pub mod archive;
|
||||
pub mod asb;
|
||||
|
||||
Reference in New Issue
Block a user