@@ -6,15 +6,15 @@ use enginelib::events::ID;
66// For coloring the output
77use enginelib:: Registry ;
88use enginelib:: prelude:: error;
9- use enginelib:: task:: { StoredTask , Task } ;
9+ use enginelib:: task:: { StoredTask , Task , TaskQueue } ;
1010use enginelib:: { api:: EngineAPI , event:: info} ;
1111use serde:: Deserialize ;
1212use std:: collections:: BTreeMap ;
1313use std:: collections:: HashMap ;
1414use std:: ffi:: OsString ;
1515use std:: fs:: File ;
16- use std:: io;
1716use std:: io:: Write ;
17+ use std:: io:: { self , Read } ;
1818use std:: path:: PathBuf ;
1919use toml:: Value ;
2020
@@ -69,6 +69,8 @@ struct Cli {
6969enum Commands {
7070 #[ command( ) ]
7171 Pack ( PackArgs ) ,
72+ #[ command( ) ]
73+ Unpack ( PackArgs ) ,
7274}
7375#[ derive( Args , Debug , PartialEq ) ]
7476struct PackArgs {
@@ -93,11 +95,45 @@ async fn main() {
9395 }
9496 let mut api = EngineAPI :: default ( ) ;
9597 EngineAPI :: init_packer ( & mut api) ;
98+ for ( id, tsk) in api. task_registry . tasks . iter ( ) {
99+ api. task_queue . tasks . entry ( id. clone ( ) ) . or_default ( ) ;
100+ }
96101 if let Some ( command) = cli. command {
97102 match command {
103+ Commands :: Unpack ( input) => {
104+ if input. input . exists ( ) {
105+ let mut final_out: Vec < String > = Vec :: new ( ) ;
106+ info ! ( "Unpacking File: {}" , input. input. to_string_lossy( ) ) ;
107+ let mut buf = Vec :: new ( ) ;
108+ File :: open ( input. input )
109+ . unwrap ( )
110+ . read_to_end ( & mut buf)
111+ . unwrap ( ) ;
112+ let k: TaskQueue = bincode:: deserialize ( & buf) . unwrap ( ) ;
113+ for tasks in k. tasks {
114+ let tt = api. task_registry . tasks . get ( & tasks. 0 . clone ( ) ) . unwrap ( ) ;
115+ for task in tasks. 1 {
116+ if tt. verify ( task. bytes . clone ( ) ) {
117+ let tmp_nt = tt. from_bytes ( & task. bytes ) ;
118+ final_out. push ( format ! [
119+ r#"[["{}:{}"]]"# ,
120+ tasks. 0.0 . clone( ) ,
121+ tasks. 0.1 . clone( )
122+ ] ) ;
123+ final_out. push ( tmp_nt. to_toml ( ) ) ;
124+ info ! ( "{:?}" , tmp_nt)
125+ //todo write to file
126+ } ;
127+ }
128+ }
129+ for s in final_out {
130+ println ! ( "{s}" ) ;
131+ }
132+ }
133+ }
98134 Commands :: Pack ( input) => {
99135 if input. input . exists ( ) {
100- info ! ( "Parsing File: {}" , input. input. to_string_lossy( ) ) ;
136+ info ! ( "Packing File: {}" , input. input. to_string_lossy( ) ) ;
101137 let toml_str = std:: fs:: read_to_string ( input. input ) . unwrap ( ) ;
102138 let raw: RawDoc = toml:: from_str ( & toml_str) . unwrap ( ) ;
103139 let entries = parse_entries ( raw) ;
@@ -108,14 +144,19 @@ async fn main() {
108144 . unwrap ( ) ;
109145 let toml_string = toml:: to_string ( & entry. data ) . unwrap ( ) ;
110146 let t = template. from_toml ( toml_string) ;
111- api. task_queue
147+ let mut tmp = api
148+ . task_queue
112149 . tasks
113- . get_mut ( & ID ( entry. namespace . as_str ( ) , entry. id . as_str ( ) ) )
150+ . get ( & ID ( entry. namespace . as_str ( ) , entry. id . as_str ( ) ) )
114151 . unwrap ( )
115- . push ( StoredTask {
116- id : "" . into ( ) , //ids are minted on the server
117- bytes : t. to_bytes ( ) ,
118- } ) ;
152+ . clone ( ) ;
153+ tmp. push ( StoredTask {
154+ id : "" . into ( ) , //ids are minted on the server
155+ bytes : t. to_bytes ( ) ,
156+ } ) ;
157+ api. task_queue
158+ . tasks
159+ . insert ( ID ( entry. namespace . as_str ( ) , entry. id . as_str ( ) ) , tmp) ;
119160 }
120161 let data = bincode:: serialize ( & api. task_queue ) . unwrap ( ) ;
121162 let mut file = File :: create ( "output.rustforge.bin" ) . unwrap ( ) ;
0 commit comments