diff options
Diffstat (limited to 'src-tauri/src/core/modpack/parser.rs')
| -rw-r--r-- | src-tauri/src/core/modpack/parser.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src-tauri/src/core/modpack/parser.rs b/src-tauri/src/core/modpack/parser.rs new file mode 100644 index 0000000..397d696 --- /dev/null +++ b/src-tauri/src/core/modpack/parser.rs @@ -0,0 +1,23 @@ +use std::path::Path; + +use super::{archive, formats, types::ParsedModpack}; + +pub(crate) trait ModpackParser: Send + Sync { + fn parse(&self, path: &Path) -> Result<ParsedModpack, String>; +} + +#[derive(Debug, Default, Clone, Copy)] +pub(crate) struct ZipModpackParser; + +impl ZipModpackParser { + pub(crate) fn new() -> Self { + Self + } +} + +impl ModpackParser for ZipModpackParser { + fn parse(&self, path: &Path) -> Result<ParsedModpack, String> { + let mut archive = archive::open(path)?; + Ok(formats::parse(&mut archive).unwrap_or_else(|_| ParsedModpack::unknown(path))) + } +} |