66 lines
1.4 KiB
Rust
66 lines
1.4 KiB
Rust
use std::path::PathBuf;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
|
pub enum AppMode {
|
|
Game,
|
|
System,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Cartridge {
|
|
pub app_id: u32,
|
|
pub title: String,
|
|
pub app_version: String,
|
|
pub app_mode: AppMode,
|
|
pub entrypoint: String,
|
|
pub program: Vec<u8>,
|
|
pub assets_path: Option<PathBuf>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
pub struct CartridgeDTO {
|
|
pub app_id: u32,
|
|
pub title: String,
|
|
pub app_version: String,
|
|
pub app_mode: AppMode,
|
|
pub entrypoint: String,
|
|
pub program: Vec<u8>,
|
|
pub assets_path: Option<PathBuf>,
|
|
}
|
|
|
|
impl From<CartridgeDTO> for Cartridge {
|
|
fn from(dto: CartridgeDTO) -> Self {
|
|
Self {
|
|
app_id: dto.app_id,
|
|
title: dto.title,
|
|
app_version: dto.app_version,
|
|
app_mode: dto.app_mode,
|
|
entrypoint: dto.entrypoint,
|
|
program: dto.program,
|
|
assets_path: dto.assets_path,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum CartridgeError {
|
|
NotFound,
|
|
InvalidFormat,
|
|
InvalidManifest,
|
|
UnsupportedVersion,
|
|
MissingProgram,
|
|
IoError,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CartridgeManifest {
|
|
pub magic: String,
|
|
pub cartridge_version: u32,
|
|
pub app_id: u32,
|
|
pub title: String,
|
|
pub app_version: String,
|
|
pub app_mode: AppMode,
|
|
pub entrypoint: String,
|
|
}
|