Skip to content

Commit a120241

Browse files
committed
unpacker support
1 parent 41de038 commit a120241

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ debug/
55
target/
66
engine_db
77
mods
8+
*.rustforge.bin
89
# These are backup files generated by rustfmt
910
**/*.rs.bk
1011
config.toml

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/packer.rs

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ use enginelib::events::ID;
66
// For coloring the output
77
use enginelib::Registry;
88
use enginelib::prelude::error;
9-
use enginelib::task::{StoredTask, Task};
9+
use enginelib::task::{StoredTask, Task, TaskQueue};
1010
use enginelib::{api::EngineAPI, event::info};
1111
use serde::Deserialize;
1212
use std::collections::BTreeMap;
1313
use std::collections::HashMap;
1414
use std::ffi::OsString;
1515
use std::fs::File;
16-
use std::io;
1716
use std::io::Write;
17+
use std::io::{self, Read};
1818
use std::path::PathBuf;
1919
use toml::Value;
2020

@@ -69,6 +69,8 @@ struct Cli {
6969
enum Commands {
7070
#[command()]
7171
Pack(PackArgs),
72+
#[command()]
73+
Unpack(PackArgs),
7274
}
7375
#[derive(Args, Debug, PartialEq)]
7476
struct 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

Comments
 (0)