11use chunk:: ModpkgChunk ;
2- use serde :: { Deserialize , Serialize } ;
3- use std :: collections :: HashMap ;
4-
2+ use error :: ModpkgError ;
3+ use metadata :: ModpkgMetadata ;
4+ use std :: { collections :: HashMap , fmt :: Display , io } ;
55mod chunk;
66mod error;
7+ mod license;
8+ mod metadata;
79mod read;
10+ mod utils;
11+
12+ pub const METADATA_CHUNK_NAME : & str = "__metadata__" ;
13+ pub const LAYERS_CHUNK_NAME : & str = "__layers__" ;
14+ pub const WADS_CHUNK_NAME : & str = "__wads__" ;
15+ pub const CHUNK_PATHS_CHUNK_NAME : & str = "__chunk_paths__" ;
16+
17+ pub const METADATA_CHUNK_HASH : u64 = 0xc3b02c1cbcdff91f ;
18+ pub const LAYERS_CHUNK_HASH : u64 = 0xe8f354f18f398ee1 ;
19+ pub const WADS_CHUNK_HASH : u64 = 0x67c34d7d3d2900df ;
20+ pub const CHUNK_PATHS_CHUNK_HASH : u64 = 0xbe4dc608d6e153c0 ;
821
922#[ derive( Debug , PartialEq ) ]
10- pub struct Modpkg {
23+ pub struct Modpkg < TSource : io :: Read + io :: Seek > {
1124 metadata : ModpkgMetadata ,
1225 chunk_paths : Vec < String > ,
1326 wad_paths : Vec < String > ,
1427 chunks : HashMap < u64 , ModpkgChunk > ,
28+
29+ source : TSource ,
1530}
1631
17- impl Modpkg {
32+ impl < TSource : io :: Read + io :: Seek > Modpkg < TSource > {
1833 pub fn metadata ( & self ) -> & ModpkgMetadata {
1934 & self . metadata
2035 }
@@ -23,68 +38,33 @@ impl Modpkg {
2338 }
2439}
2540
26- #[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
27- pub struct ModpkgMetadata {
28- name : String ,
29- display_name : String ,
30- description : Option < String > ,
31- version : String ,
32- distributor : Option < String > ,
33- authors : Vec < ModpkgAuthor > ,
34- license : ModpkgLicense ,
35- }
36-
37- impl ModpkgMetadata {
38- pub fn name ( & self ) -> & str {
39- & self . name
40- }
41- pub fn display_name ( & self ) -> & str {
42- & self . display_name
43- }
44- pub fn description ( & self ) -> Option < & str > {
45- self . description . as_deref ( )
46- }
47- pub fn version ( & self ) -> & str {
48- & self . version
49- }
50- pub fn distributor ( & self ) -> Option < & str > {
51- self . distributor . as_deref ( )
52- }
53- pub fn authors ( & self ) -> & [ ModpkgAuthor ] {
54- & self . authors
55- }
56- pub fn license ( & self ) -> & ModpkgLicense {
57- & self . license
58- }
59- }
60-
61- #[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
62- pub enum ModpkgLicense {
63- None ,
64- Spdx { spdx_id : String } ,
65- Custom { name : String , url : String } ,
66- }
67-
68- #[ derive( Debug , PartialEq , Serialize , Deserialize ) ]
69- pub struct ModpkgAuthor {
70- name : String ,
71- role : Option < String > ,
72- }
73-
74- #[ derive( Debug , PartialEq , Eq ) ]
41+ #[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Clone , Copy ) ]
7542pub enum ModpkgCompression {
7643 None = 0 ,
7744 Zstd = 1 ,
7845}
7946
47+ impl Display for ModpkgCompression {
48+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
49+ write ! (
50+ f,
51+ "{:?}" ,
52+ match self {
53+ ModpkgCompression :: None => "none" ,
54+ ModpkgCompression :: Zstd => "zstd" ,
55+ }
56+ )
57+ }
58+ }
59+
8060impl TryFrom < u8 > for ModpkgCompression {
81- type Error = & ' static str ;
61+ type Error = ModpkgError ;
8262
8363 fn try_from ( value : u8 ) -> Result < Self , Self :: Error > {
8464 Ok ( match value {
8565 0 => ModpkgCompression :: None ,
8666 1 => ModpkgCompression :: Zstd ,
87- _ => return Err ( "Invalid modpkg compression value" ) ,
67+ _ => return Err ( ModpkgError :: InvalidCompressionType ( value) ) ,
8868 } )
8969 }
9070}
0 commit comments