This commit is contained in:
Quaternions 2024-01-06 11:13:52 -08:00
parent 589c1b044e
commit 03ae57e2e1

View File

@ -264,7 +264,7 @@ enum TrimStackInstruction{
enum WriteStackInstruction<'a>{ enum WriteStackInstruction<'a>{
Node(&'a TreeNode), Node(&'a TreeNode),
PushFolder(std::path::Component<'a>), PushFolder(String),
PopFolder, PopFolder,
Destroy(Ref), Destroy(Ref),
} }
@ -280,8 +280,12 @@ impl PropertiesOverride{
} }
} }
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)->AResult<()>{ fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:std::path::PathBuf,node:&TreeNode)->AResult<()>{
file.push(node.name.as_str()); file.push(sanitize(node.name.as_str()).as_ref());
match node.class{ match node.class{
Class::Folder=>(), Class::Folder=>(),
Class::ModuleScript|Class::LocalScript|Class::Script=>{ Class::ModuleScript|Class::LocalScript|Class::Script=>{
@ -429,7 +433,7 @@ fn decompile(input_file:std::path::PathBuf,output_folder:std::path::PathBuf)->AR
if has_children||properties.is_some(){ if has_children||properties.is_some(){
//push temp subfolder //push temp subfolder
let mut subfolder=folder.clone(); let mut subfolder=folder.clone();
subfolder.push(node.name.as_str()); subfolder.push(sanitize(node.name.as_str()).as_ref());
//make folder //make folder
std::fs::create_dir(subfolder.clone())?; std::fs::create_dir(subfolder.clone())?;
//write properties //write properties
@ -457,7 +461,7 @@ fn decompile(input_file:std::path::PathBuf,output_folder:std::path::PathBuf)->AR
stack.push(WriteStackInstruction::Node(c)); stack.push(WriteStackInstruction::Node(c));
} }
} }
stack.push(WriteStackInstruction::PushFolder(std::path::Component::Normal(std::ffi::OsStr::new(node.name.as_str())))); stack.push(WriteStackInstruction::PushFolder(sanitize(node.name.as_str()).to_string()));
} }
}, },
} }