misc fixes
This commit is contained in:
parent
b8d5efe168
commit
7ad7fa3d41
40
src/main.rs
40
src/main.rs
@ -71,7 +71,7 @@ enum Commands{
|
|||||||
DownloadAndDecompileHistoryIntoGit,
|
DownloadAndDecompileHistoryIntoGit,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy)]
|
#[derive(Clone,Copy,Debug)]
|
||||||
enum DecompileStyle{
|
enum DecompileStyle{
|
||||||
Rox,
|
Rox,
|
||||||
Rojo,
|
Rojo,
|
||||||
@ -118,7 +118,7 @@ async fn main()->AResult<()>{
|
|||||||
(None,Some(env_var),None)=>Some(Cookie::Environment(env_var)),
|
(None,Some(env_var),None)=>Some(Cookie::Environment(env_var)),
|
||||||
(None,None,Some(path))=>Some(Cookie::File(path)),
|
(None,None,Some(path))=>Some(Cookie::File(path)),
|
||||||
(None,None,None)=>None,
|
(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{
|
let cookie=match cookie_enum{
|
||||||
@ -142,7 +142,7 @@ async fn main()->AResult<()>{
|
|||||||
|Some("RoxRojo")
|
|Some("RoxRojo")
|
||||||
|Some("RojoRox")=>Some(DecompileStyle::RoxRojo),
|
|Some("RojoRox")=>Some(DecompileStyle::RoxRojo),
|
||||||
None=>None,
|
None=>None,
|
||||||
_=>return Err(anyhow::Error::msg("Invalid style")),
|
_=>Err(anyhow::Error::msg("Invalid style"))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
match cli.command{
|
match cli.command{
|
||||||
@ -250,7 +250,7 @@ async fn upload_list(cookie:String,group:Option<u64>,asset_id_file_map:AssetIDFi
|
|||||||
.body(body)
|
.body(body)
|
||||||
.send().await?;
|
.send().await?;
|
||||||
}else{
|
}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){
|
match std::fs::File::open(versions_path){
|
||||||
Ok(versions_file)=>asset_list.append(&mut serde_json::from_reader(versions_file)?),
|
Ok(versions_file)=>asset_list.append(&mut serde_json::from_reader(versions_file)?),
|
||||||
Err(e)=>match e.kind(){
|
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)?,
|
_=>Err(e)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -568,28 +568,28 @@ enum WriteStackInstruction<'a>{
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct PropertiesOverride{
|
struct PropertiesOverride{
|
||||||
name:Option<String>,
|
name:Option<String>,
|
||||||
class_name:Option<String>,
|
class:Option<String>,
|
||||||
}
|
}
|
||||||
impl PropertiesOverride{
|
impl PropertiesOverride{
|
||||||
fn is_some(&self)->bool{
|
fn is_some(&self)->bool{
|
||||||
self.name.is_some()
|
self.name.is_some()
|
||||||
||self.class_name.is_some()
|
||self.class.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for PropertiesOverride{
|
impl std::fmt::Display for PropertiesOverride{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
if let Some(name)=self.name.as_deref(){
|
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(){
|
if let Some(class)=self.class.as_deref(){
|
||||||
writeln!(f,"--! Properties.ClassName=\"{}\"",class_name)?;
|
writeln!(f,"--!Properties.ClassName = \"{}\"",class)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sanitize<'a>(s:&'a str)->std::borrow::Cow<'a,str>{
|
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<()>{
|
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{
|
match style{
|
||||||
DecompileStyle::Rox=>assert!(file.set_extension("lua"),"could not set extension"),
|
DecompileStyle::Rox=>assert!(file.set_extension("lua"),"could not set extension"),
|
||||||
DecompileStyle::RoxRojo|DecompileStyle::Rojo=>{
|
DecompileStyle::RoxRojo|DecompileStyle::Rojo=>{
|
||||||
match properties.class_name.as_deref(){
|
match properties.class.as_deref(){
|
||||||
Some("LocalScript")=>{
|
Some("LocalScript")=>{
|
||||||
file.set_extension("client.lua");
|
file.set_extension("client.lua");
|
||||||
properties.class_name=None;
|
properties.class=None;
|
||||||
},
|
},
|
||||||
Some("Script")=>{
|
Some("Script")=>{
|
||||||
file.set_extension("server.lua");
|
file.set_extension("server.lua");
|
||||||
properties.class_name=None;
|
properties.class=None;
|
||||||
},
|
},
|
||||||
// Some("ModuleScript")=>{
|
// Some("ModuleScript")=>{
|
||||||
// file.set_extension("module");
|
// file.set_extension("module");
|
||||||
// properties.class_name=None;
|
// properties.class=None;
|
||||||
// },
|
// },
|
||||||
None=>assert!(file.set_extension("lua"),"could not set extension"),
|
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<R:Read>(input:R)->AResult<DecompiledContext>{
|
|||||||
|
|
||||||
let mut tree_refs=std::collections::HashMap::new();
|
let mut tree_refs=std::collections::HashMap::new();
|
||||||
tree_refs.insert(dom.root_ref(),TreeNode::new(
|
tree_refs.insert(dom.root_ref(),TreeNode::new(
|
||||||
"src".to_string(),
|
"src".to_owned(),
|
||||||
dom.root_ref(),
|
dom.root_ref(),
|
||||||
Ref::none(),
|
Ref::none(),
|
||||||
Class::Folder
|
Class::Folder
|
||||||
@ -778,8 +778,8 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<
|
|||||||
match node.class{
|
match node.class{
|
||||||
Class::Folder=>(),
|
Class::Folder=>(),
|
||||||
Class::ModuleScript=>(),//.lua files are ModuleScript by default
|
Class::ModuleScript=>(),//.lua files are ModuleScript by default
|
||||||
Class::LocalScript=>properties.class_name=Some("LocalScript".to_string()),
|
Class::LocalScript=>properties.class=Some("LocalScript".to_owned()),
|
||||||
Class::Script=>properties.class_name=Some("Script".to_string()),
|
Class::Script=>properties.class=Some("Script".to_owned()),
|
||||||
Class::Model=>(),
|
Class::Model=>(),
|
||||||
}
|
}
|
||||||
let name_override=if 0<name_count{
|
let name_override=if 0<name_count{
|
||||||
@ -852,7 +852,7 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult<
|
|||||||
file.push("template");
|
file.push("template");
|
||||||
assert!(file.set_extension("rbxlx"));
|
assert!(file.set_extension("rbxlx"));
|
||||||
let output=std::io::BufWriter::new(std::fs::File::create(file)?);
|
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(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user