refactor: allow using only the model without any logic
This commit is contained in:
parent
a193c7f657
commit
3efba26a86
41
Cargo.toml
41
Cargo.toml
|
@ -6,18 +6,37 @@ autoexamples = true
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[features]
|
||||||
|
model = [
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
logic = [
|
||||||
|
"model",
|
||||||
|
"blake3",
|
||||||
|
"crossbeam-channel",
|
||||||
|
"crossbeam-utils",
|
||||||
|
"flate2",
|
||||||
|
"num_cpus",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"sqpack",
|
||||||
|
"tempfile",
|
||||||
|
"thiserror",
|
||||||
|
"zip",
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
blake3 = { version = "1", features = ["traits-preview"] }
|
blake3 = { version = "1", features = ["traits-preview"], optional = true }
|
||||||
crossbeam-channel = "0.5"
|
crossbeam-channel = { version = "0.5", optional = true }
|
||||||
crossbeam-utils = "0.8"
|
crossbeam-utils = { version = "0.8", optional = true }
|
||||||
flate2 = { version = "1", default-features = false, features = ["zlib-ng"] }
|
flate2 = { version = "1", default-features = false, features = ["zlib-ng"], optional = true }
|
||||||
num_cpus = "1"
|
num_cpus = { version = "1", optional = true }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
serde_json = "1"
|
serde_json = { version = "1", optional = true }
|
||||||
sqpack = { git = "https://git.anna.lgbt/ascclemens/sqpack-rs", features = ["read", "write"] }
|
sqpack = { git = "https://git.anna.lgbt/ascclemens/sqpack-rs", features = ["read", "write"], optional = true }
|
||||||
tempfile = "3"
|
tempfile = { version = "3", optional = true }
|
||||||
thiserror = "1"
|
thiserror = { version = "1", optional = true }
|
||||||
zip = { version = "0.6", default-features = false, features = ["deflate-zlib"] }
|
zip = { version = "0.6", default-features = false, features = ["deflate-zlib"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|
32
src/lib.rs
32
src/lib.rs
|
@ -1,22 +1,41 @@
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
use std::io::{Read, Seek};
|
use std::io::{Read, Seek};
|
||||||
|
|
||||||
use serde::de::Error as _;
|
#[cfg(feature = "logic")]
|
||||||
use serde::Deserialize;
|
use serde::{
|
||||||
use serde_json::StreamDeserializer;
|
de::Error as _,
|
||||||
use serde_json::de::IoRead;
|
Deserialize,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
|
use serde_json::{
|
||||||
|
de::IoRead,
|
||||||
|
StreamDeserializer,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub use zip::{read::ZipFile, ZipArchive};
|
pub use zip::{read::ZipFile, ZipArchive};
|
||||||
|
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
|
use crate::{
|
||||||
|
model::{ModPack, SimpleMod},
|
||||||
|
model::manifest_kind::ManifestKind,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::model::{ModPack, SimpleMod};
|
|
||||||
use crate::model::manifest_kind::ManifestKind;
|
|
||||||
|
|
||||||
|
#[cfg(feature = "model")]
|
||||||
pub mod model;
|
pub mod model;
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub(crate) mod tracking_reader;
|
pub(crate) mod tracking_reader;
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub mod ttmp_extractor;
|
pub mod ttmp_extractor;
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub mod mpd_encoder;
|
pub mod mpd_encoder;
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub(crate) mod util;
|
pub(crate) mod util;
|
||||||
|
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub fn from_value(value: serde_json::Value) -> Result<ManifestKind> {
|
pub fn from_value(value: serde_json::Value) -> Result<ManifestKind> {
|
||||||
let manifest = if value.is_array() {
|
let manifest = if value.is_array() {
|
||||||
ManifestKind::V1(serde_json::from_value(value).map_err(Error::InvalidManifest)?)
|
ManifestKind::V1(serde_json::from_value(value).map_err(Error::InvalidManifest)?)
|
||||||
|
@ -27,6 +46,7 @@ pub fn from_value(value: serde_json::Value) -> Result<ManifestKind> {
|
||||||
Ok(manifest)
|
Ok(manifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "logic")]
|
||||||
pub fn from_reader<R: Read + Seek>(reader: R) -> Result<(ManifestKind, ZipArchive<R>)> {
|
pub fn from_reader<R: Read + Seek>(reader: R) -> Result<(ManifestKind, ZipArchive<R>)> {
|
||||||
let mut zip = ZipArchive::new(reader).map_err(Error::Zip)?;
|
let mut zip = ZipArchive::new(reader).map_err(Error::Zip)?;
|
||||||
let manifest = zip.by_name("TTMPL.mpl").map_err(Error::Zip)?;
|
let manifest = zip.by_name("TTMPL.mpl").map_err(Error::Zip)?;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::model::{ModPack, SimpleMod};
|
use crate::model::{ModPack, SimpleMod};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
|
||||||
pub enum ManifestKind {
|
pub enum ManifestKind {
|
||||||
V1(Vec<SimpleMod>),
|
V1(Vec<SimpleMod>),
|
||||||
V2(ModPack),
|
V2(ModPack),
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::model::{ModOption, SelectionType};
|
use crate::model::{ModOption, SelectionType};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
|
||||||
pub struct ModGroup {
|
pub struct ModGroup {
|
||||||
pub group_name: String,
|
pub group_name: String,
|
||||||
pub selection_type: SelectionType,
|
pub selection_type: SelectionType,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::model::{SelectionType, SimpleMod};
|
use crate::model::{SelectionType, SimpleMod};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
|
||||||
pub struct ModOption {
|
pub struct ModOption {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::model::{ModPackPage, SimpleMod};
|
use crate::model::{ModPackPage, SimpleMod};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
|
||||||
pub struct ModPack {
|
pub struct ModPack {
|
||||||
pub minimum_framework_version: Option<String>,
|
pub minimum_framework_version: Option<String>,
|
||||||
#[serde(rename = "TTMPVersion")]
|
#[cfg_attr(feature = "serde", serde(rename = "TTMPVersion"))]
|
||||||
pub ttmp_version: String,
|
pub ttmp_version: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::model::ModGroup;
|
use crate::model::ModGroup;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
|
||||||
pub struct ModPackPage {
|
pub struct ModPackPage {
|
||||||
pub page_index: i32,
|
pub page_index: i32,
|
||||||
pub mod_groups: Vec<ModGroup>,
|
pub mod_groups: Vec<ModGroup>,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use serde::{Deserialize, Serialize};
|
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
#[derive(Debug, Deserialize, Serialize, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
|
||||||
pub enum SelectionType {
|
pub enum SelectionType {
|
||||||
Single,
|
Single,
|
||||||
Multi,
|
Multi,
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::model::ModPack;
|
use crate::model::ModPack;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
|
#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
|
||||||
pub struct SimpleMod {
|
pub struct SimpleMod {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub category: String,
|
pub category: String,
|
||||||
pub full_path: String,
|
pub full_path: String,
|
||||||
pub dat_file: String,
|
pub dat_file: String,
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub is_default: bool,
|
pub is_default: bool,
|
||||||
pub mod_offset: usize,
|
pub mod_offset: usize,
|
||||||
pub mod_size: usize,
|
pub mod_size: usize,
|
||||||
#[serde(default)]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub mod_pack_entry: Option<serde_json::Value>,
|
pub mod_pack_entry: Option<serde_json::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue