maikor_vm_file/
manifest.rs1use crate::read_write_impl::validate_file;
2use crate::GameFileError;
3use serde::{Deserialize, Serialize};
4use std::fs;
5use std::path::Path;
6
7#[derive(Debug, Default, Serialize, Deserialize)]
8pub struct Manifest {
9 pub id: String,
10 pub name: String,
11 pub author: String,
12 pub version: String,
13 pub build: u32,
14 pub main_code: String,
15 pub min_maikor_version: u16,
16 pub code_files: Vec<String>,
17 pub atlas_files: Vec<String>,
18 pub ram_banks: u8,
19}
20
21impl Manifest {
22 pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Manifest, GameFileError> {
23 let path = path.as_ref();
24 validate_file(path, false)?;
25 let text = fs::read_to_string(path)
26 .map_err(|e| GameFileError::FileAccessError(e, "reading manifest"))?;
27 let manifest = serde_json::from_str(&text)
28 .map_err(|e| GameFileError::ManifestParsingError(e.to_string()))?;
29 Ok(manifest)
30 }
31
32 pub fn from_string(text: &str) -> Result<Manifest, GameFileError> {
33 let manifest = serde_json::from_str(text)
34 .map_err(|e| GameFileError::ManifestParsingError(e.to_string()))?;
35 Ok(manifest)
36 }
37}