forked from StrafesNET/asset-tool
async decompile
This commit is contained in:
parent
00f4788169
commit
def0d1a69a
27
src/main.rs
27
src/main.rs
@ -427,8 +427,8 @@ fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{
|
||||
lazy_regex::regex!(r"[^a-zA-Z0-9._-]").replace_all(s,"_")
|
||||
}
|
||||
|
||||
fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:std::path::PathBuf,node:&TreeNode,node_name_override:&str,write_models:bool,write_scripts:bool)->AResult<()>{
|
||||
file.push(sanitize(node_name_override).as_ref());
|
||||
async fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:std::path::PathBuf,node:&TreeNode,node_name_override:String,write_models:bool,write_scripts:bool)->AResult<()>{
|
||||
file.push(sanitize(node_name_override.as_str()).as_ref());
|
||||
match node.class{
|
||||
Class::Folder=>(),
|
||||
Class::ModuleScript|Class::LocalScript|Class::Script=>{
|
||||
@ -565,6 +565,9 @@ struct WriteConfig{
|
||||
}
|
||||
|
||||
async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<()>{
|
||||
let mut write_queue=Vec::new();
|
||||
let mut destroy_queue=Vec::new();
|
||||
|
||||
let mut name_tally=std::collections::HashMap::<String,u32>::new();
|
||||
let mut folder=config.output_folder.clone();
|
||||
let mut stack=vec![WriteStackInstruction::Node(context.tree_refs.get(&context.dom.root_ref()).unwrap(),0)];
|
||||
@ -572,7 +575,7 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<
|
||||
match instruction{
|
||||
WriteStackInstruction::PushFolder(component)=>folder.push(component),
|
||||
WriteStackInstruction::PopFolder=>assert!(folder.pop(),"weirdness"),
|
||||
WriteStackInstruction::Destroy(referent)=>context.dom.destroy(referent),
|
||||
WriteStackInstruction::Destroy(referent)=>destroy_queue.push(referent),
|
||||
WriteStackInstruction::Node(node,name_count)=>{
|
||||
//properties.json to override class or other simple properties
|
||||
let mut properties=PropertiesOverride::default();
|
||||
@ -599,19 +602,19 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<
|
||||
let mut subfolder=folder.clone();
|
||||
subfolder.push(sanitize(name_override.as_str()).as_ref());
|
||||
//make folder
|
||||
std::fs::create_dir(subfolder.clone())?;
|
||||
tokio::fs::create_dir(subfolder.clone()).await?;
|
||||
//write properties
|
||||
if properties.is_some(){
|
||||
let mut file=subfolder.clone();
|
||||
file.push("properties");
|
||||
assert!(file.set_extension("json"),"could not set extension");
|
||||
std::fs::write(file,serde_json::to_string(&properties)?)?
|
||||
tokio::fs::write(file,serde_json::to_string(&properties)?).await?;
|
||||
}
|
||||
//write item in subfolder
|
||||
write_item(&context.dom,subfolder,node,name_override.as_str(),config.write_models,config.write_scripts)?;
|
||||
write_queue.push(write_item(&context.dom,subfolder,node,name_override.clone(),config.write_models,config.write_scripts));
|
||||
}else{
|
||||
//write item
|
||||
write_item(&context.dom,folder.clone(),node,name_override.as_str(),config.write_models,config.write_scripts)?;
|
||||
write_queue.push(write_item(&context.dom,folder.clone(),node,name_override.clone(),config.write_models,config.write_scripts));
|
||||
}
|
||||
//queue item to be deleted from dom after child objects are handled (stack is popped from the back)
|
||||
match node.class{
|
||||
@ -633,6 +636,16 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<
|
||||
}
|
||||
}
|
||||
|
||||
//run the async
|
||||
for result in futures::future::join_all(write_queue).await{
|
||||
result?;
|
||||
}
|
||||
|
||||
//run the destroy
|
||||
for destroy_ref in destroy_queue{
|
||||
context.dom.destroy(destroy_ref);
|
||||
}
|
||||
|
||||
//write what remains in template.rbxlx
|
||||
if config.write_template{
|
||||
let mut file=config.output_folder.clone();
|
||||
|
Loading…
Reference in New Issue
Block a user