From 7ad7fa3d413e80ba4abd83056034238bca39fac0 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 8 Mar 2024 09:39:57 -0800 Subject: [PATCH] misc fixes --- src/main.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index b61a306..c8eb690 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ enum Commands{ DownloadAndDecompileHistoryIntoGit, } -#[derive(Clone,Copy)] +#[derive(Clone,Copy,Debug)] enum DecompileStyle{ Rox, Rojo, @@ -118,7 +118,7 @@ async fn main()->AResult<()>{ (None,Some(env_var),None)=>Some(Cookie::Environment(env_var)), (None,None,Some(path))=>Some(Cookie::File(path)), (None,None,None)=>None, - _=>return Err(anyhow::Error::msg("Cookie was specified multiple times.")), + _=>Err(anyhow::Error::msg("Cookie was specified multiple times."))?, } }; let cookie=match cookie_enum{ @@ -142,7 +142,7 @@ async fn main()->AResult<()>{ |Some("RoxRojo") |Some("RojoRox")=>Some(DecompileStyle::RoxRojo), None=>None, - _=>return Err(anyhow::Error::msg("Invalid style")), + _=>Err(anyhow::Error::msg("Invalid style"))?, }; match cli.command{ @@ -250,7 +250,7 @@ async fn upload_list(cookie:String,group:Option,asset_id_file_map:AssetIDFi .body(body) .send().await?; }else{ - return Err(anyhow::Error::msg("Roblox returned 403 with no CSRF")); + Err(anyhow::Error::msg("Roblox returned 403 with no CSRF"))?; } } @@ -389,7 +389,7 @@ async fn download_history(mut config:DownloadHistoryConfig)->AResult<()>{ match std::fs::File::open(versions_path){ Ok(versions_file)=>asset_list.append(&mut serde_json::from_reader(versions_file)?), Err(e)=>match e.kind(){ - std::io::ErrorKind::NotFound=>return Err(anyhow::Error::msg("Cannot continue from versions.json - file does not exist")), + std::io::ErrorKind::NotFound=>Err(anyhow::Error::msg("Cannot continue from versions.json - file does not exist"))?, _=>Err(e)?, } } @@ -568,28 +568,28 @@ enum WriteStackInstruction<'a>{ #[derive(Default)] struct PropertiesOverride{ name:Option, - class_name:Option, + class:Option, } impl PropertiesOverride{ fn is_some(&self)->bool{ self.name.is_some() - ||self.class_name.is_some() + ||self.class.is_some() } } impl std::fmt::Display for PropertiesOverride{ fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ if let Some(name)=self.name.as_deref(){ - writeln!(f,"--! Properties.Name=\"{}\"",name)?; + writeln!(f,"--!Properties.Name = \"{}\"",name)?; } - if let Some(class_name)=self.class_name.as_deref(){ - writeln!(f,"--! Properties.ClassName=\"{}\"",class_name)?; + if let Some(class)=self.class.as_deref(){ + writeln!(f,"--!Properties.ClassName = \"{}\"",class)?; } Ok(()) } } fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{ - lazy_regex::regex!(r"[^a-zA-Z0-9._-]").replace_all(s,"_") + lazy_regex::regex!(r"[^A-z0-9.-]").replace_all(s,"_") } fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:std::path::PathBuf,node:&TreeNode,node_name_override:String,mut properties:PropertiesOverride,style:DecompileStyle,write_models:bool,write_scripts:bool)->AResult<()>{ @@ -605,21 +605,21 @@ fn write_item(dom:&rbx_dom_weak::WeakDom,mut file:std::path::PathBuf,node:&TreeN match style{ DecompileStyle::Rox=>assert!(file.set_extension("lua"),"could not set extension"), DecompileStyle::RoxRojo|DecompileStyle::Rojo=>{ - match properties.class_name.as_deref(){ + match properties.class.as_deref(){ Some("LocalScript")=>{ file.set_extension("client.lua"); - properties.class_name=None; + properties.class=None; }, Some("Script")=>{ file.set_extension("server.lua"); - properties.class_name=None; + properties.class=None; }, // Some("ModuleScript")=>{ // file.set_extension("module"); - // properties.class_name=None; + // properties.class=None; // }, None=>assert!(file.set_extension("lua"),"could not set extension"), - Some(other)=>return Err(anyhow::Error::msg(format!("Attempt to write a {} as a script",other))), + Some(other)=>Err(anyhow::Error::msg(format!("Attempt to write a {} as a script",other)))?, } } } @@ -659,7 +659,7 @@ fn generate_decompiled_context(input:R)->AResult{ let mut tree_refs=std::collections::HashMap::new(); tree_refs.insert(dom.root_ref(),TreeNode::new( - "src".to_string(), + "src".to_owned(), dom.root_ref(), Ref::none(), Class::Folder @@ -778,8 +778,8 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult< match node.class{ Class::Folder=>(), Class::ModuleScript=>(),//.lua files are ModuleScript by default - Class::LocalScript=>properties.class_name=Some("LocalScript".to_string()), - Class::Script=>properties.class_name=Some("Script".to_string()), + Class::LocalScript=>properties.class=Some("LocalScript".to_owned()), + Class::Script=>properties.class=Some("Script".to_owned()), Class::Model=>(), } let name_override=if 0AResult< file.push("template"); assert!(file.set_extension("rbxlx")); let output=std::io::BufWriter::new(std::fs::File::create(file)?); - rbx_xml::to_writer_default(output,&context.dom,&[context.dom.root_ref()])?; + rbx_xml::to_writer_default(output,&context.dom,context.dom.root().children())?; } Ok(())