forked from StrafesNET/asset-tool
debug insanity
This commit is contained in:
parent
9d6780a0b0
commit
e5c7ed6b75
121
src/main.rs
121
src/main.rs
@ -1311,42 +1311,45 @@ async fn model_node(search_name:&str,mut file:tokio::fs::File)->AResult<CompileN
|
|||||||
async fn discern_node(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->AResult<Option<CompileNode>>{
|
async fn discern_node(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->AResult<Option<CompileNode>>{
|
||||||
let contents_folder=entry.path();
|
let contents_folder=entry.path();
|
||||||
let file_name=entry.file_name();
|
let file_name=entry.file_name();
|
||||||
//folder
|
//is folder? else exit flow control
|
||||||
Ok(if tokio::fs::try_exists(contents_folder.as_path()).await?{
|
match tokio::fs::read_dir(contents_folder.as_path()).await{
|
||||||
let search_name=file_name.to_str().unwrap();
|
Ok(_)=>(),//continue flow
|
||||||
//scan inside the folder for an object to define the class of the folder
|
Err(e)=>{println!("{:?}",e.raw_os_error());match e.raw_os_error(){
|
||||||
let script_query=async {match style{
|
Some(0)//std::io::ErrorKind::NotFound
|
||||||
Some(DecompileStyle::Rox)=>QuerySingle::rox(&contents_folder,search_name).resolve().await,
|
|Some(20)=>return Ok(None),//std::io::ErrorKind::NotADirectory (not allowed to be used but returns it anyways)
|
||||||
Some(DecompileStyle::RoxRojo)=>QueryQuad::rox_rojo(&contents_folder,search_name).resolve().await,
|
_=>Err(e)?,
|
||||||
Some(DecompileStyle::Rojo)=>QueryTriple::rojo(&contents_folder).resolve().await,
|
}}
|
||||||
//try all three and complain if there is ambiguity
|
}
|
||||||
None=>mega_triple_join(tokio::join!(
|
let search_name=file_name.to_str().unwrap();
|
||||||
QuerySingle::rox(&contents_folder,search_name).resolve(),
|
//scan inside the folder for an object to define the class of the folder
|
||||||
//true=search for module here to avoid ambiguity with QuerySingle::rox results
|
let script_query=async {match style{
|
||||||
QueryTriple::rox_rojo(&contents_folder,search_name,true).resolve(),
|
Some(DecompileStyle::Rox)=>QuerySingle::rox(&contents_folder,search_name).resolve().await,
|
||||||
QueryTriple::rojo(&contents_folder).resolve(),
|
Some(DecompileStyle::RoxRojo)=>QueryQuad::rox_rojo(&contents_folder,search_name).resolve().await,
|
||||||
))
|
Some(DecompileStyle::Rojo)=>QueryTriple::rojo(&contents_folder).resolve().await,
|
||||||
}};
|
//try all three and complain if there is ambiguity
|
||||||
//model files are rox & rox-rojo only, so it's a lot less work...
|
None=>mega_triple_join(tokio::join!(
|
||||||
let model_query=get_file_async(contents_folder.clone(),format!("{}.rbxmx",search_name));
|
QuerySingle::rox(&contents_folder,search_name).resolve(),
|
||||||
//model? script? both?
|
//true=search for module here to avoid ambiguity with QuerySingle::rox results
|
||||||
Some(match tokio::join!(script_query,model_query){
|
QueryTriple::rox_rojo(&contents_folder,search_name,true).resolve(),
|
||||||
(Ok(FileHint{file,hint}),Err(QueryResolveError::NotFound))=>script_node(search_name,file,hint).await?,
|
QueryTriple::rojo(&contents_folder).resolve(),
|
||||||
(Err(QueryResolveError::NotFound),Ok(file))=>model_node(search_name,file).await?,
|
))
|
||||||
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
|
}};
|
||||||
//neither
|
//model files are rox & rox-rojo only, so it's a lot less work...
|
||||||
(Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{
|
let model_query=get_file_async(contents_folder.clone(),format!("{}.rbxmx",search_name));
|
||||||
name:search_name.to_owned(),
|
//model? script? both?
|
||||||
class:CompileClass::Folder,
|
Ok(Some(match tokio::join!(script_query,model_query){
|
||||||
},
|
(Ok(FileHint{file,hint}),Err(QueryResolveError::NotFound))=>script_node(search_name,file,hint).await?,
|
||||||
//other error
|
(Err(QueryResolveError::NotFound),Ok(file))=>model_node(search_name,file).await?,
|
||||||
(Err(e),_)
|
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
|
||||||
|(_,Err(e))=>Err(e)?
|
//neither
|
||||||
})
|
(Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{
|
||||||
}else{
|
name:search_name.to_owned(),
|
||||||
//a folder of this name does not exist
|
class:CompileClass::Folder,
|
||||||
None
|
},
|
||||||
})
|
//other error
|
||||||
|
(Err(e),_)
|
||||||
|
|(_,Err(e))=>Err(e)?
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1359,11 +1362,11 @@ async fn discern_file(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->
|
|||||||
let path=entry.path();
|
let path=entry.path();
|
||||||
let file_discernment=match path.extension(){
|
let file_discernment=match path.extension(){
|
||||||
Some(extension)=>match extension.to_str(){
|
Some(extension)=>match extension.to_str(){
|
||||||
Some(".lua")=>FileDiscernment::Script(ScriptHint::Undetermined),
|
Some("lua")=>FileDiscernment::Script(ScriptHint::Undetermined),
|
||||||
Some(".module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript),
|
Some("module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript),
|
||||||
Some(".client.lua")=>FileDiscernment::Script(ScriptHint::LocalScript),
|
Some("client.lua")=>FileDiscernment::Script(ScriptHint::LocalScript),
|
||||||
Some(".server.lua")=>FileDiscernment::Script(ScriptHint::Script),
|
Some("server.lua")=>FileDiscernment::Script(ScriptHint::Script),
|
||||||
Some(".rbxlx")=>FileDiscernment::Model,
|
Some("rbxmx")=>FileDiscernment::Model,
|
||||||
other=>Err(anyhow::Error::msg(format!("Weird file extension: {other:?}")))?,
|
other=>Err(anyhow::Error::msg(format!("Weird file extension: {other:?}")))?,
|
||||||
},
|
},
|
||||||
None=>Err(anyhow::Error::msg("No file extension"))?,
|
None=>Err(anyhow::Error::msg("No file extension"))?,
|
||||||
@ -1449,7 +1452,7 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
|||||||
//add in scripts and models
|
//add in scripts and models
|
||||||
let mut folder=config.input_folder.clone();
|
let mut folder=config.input_folder.clone();
|
||||||
folder.push("src");
|
folder.push("src");
|
||||||
let mut stack:Vec<CompileStackInstruction>=dom.root().children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent)).collect();
|
let mut stack:Vec<CompileStackInstruction>=dom.get_by_ref(dom.root().children()[0]).unwrap().children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent)).collect();
|
||||||
while let Some(instruction)=stack.pop(){
|
while let Some(instruction)=stack.pop(){
|
||||||
match instruction{
|
match instruction{
|
||||||
CompileStackInstruction::TraverseReferent(item_ref)=>{
|
CompileStackInstruction::TraverseReferent(item_ref)=>{
|
||||||
@ -1480,24 +1483,26 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
|||||||
if !exist_names.contains(entry.file_name().to_str().unwrap()){
|
if !exist_names.contains(entry.file_name().to_str().unwrap()){
|
||||||
let style=config.style;
|
let style=config.style;
|
||||||
join_set.spawn(async move{
|
join_set.spawn(async move{
|
||||||
|
let met=entry.metadata().await?;
|
||||||
|
let scooby_doo=if met.is_dir(){
|
||||||
|
discern_node(&entry,style).await
|
||||||
|
}else{
|
||||||
|
discern_file(&entry,style).await
|
||||||
|
};
|
||||||
//discern that bad boy
|
//discern that bad boy
|
||||||
match tokio::join!(discern_node(&entry,style),discern_file(&entry,style)){
|
Ok::<_,anyhow::Error>(match scooby_doo?{
|
||||||
(Ok(Some(compile_class)),Ok(None))
|
Some(compile_class)=>{
|
||||||
|(Ok(None),Ok(Some(compile_class)))=>{
|
|
||||||
//prepare data structure
|
//prepare data structure
|
||||||
match compile_class.class{
|
Some(match compile_class.class{
|
||||||
CompileClass::Folder=>Ok(Some(PreparedData::Builder(rbx_dom_weak::InstanceBuilder::new("Folder").with_name(compile_class.name.as_str())))),
|
CompileClass::Folder=>PreparedData::Builder(rbx_dom_weak::InstanceBuilder::new("Folder").with_name(compile_class.name.as_str())),
|
||||||
CompileClass::Script(source)=>Ok(Some(PreparedData::Builder(script_builder("Script",compile_class.name.as_str(),source)))),
|
CompileClass::Script(source)=>PreparedData::Builder(script_builder("Script",compile_class.name.as_str(),source)),
|
||||||
CompileClass::LocalScript(source)=>Ok(Some(PreparedData::Builder(script_builder("LocalScript",compile_class.name.as_str(),source)))),
|
CompileClass::LocalScript(source)=>PreparedData::Builder(script_builder("LocalScript",compile_class.name.as_str(),source)),
|
||||||
CompileClass::ModuleScript(source)=>Ok(Some(PreparedData::Builder(script_builder("ModuleScript",compile_class.name.as_str(),source)))),
|
CompileClass::ModuleScript(source)=>PreparedData::Builder(script_builder("ModuleScript",compile_class.name.as_str(),source)),
|
||||||
CompileClass::Model(buf)=>Ok(Some(PreparedData::Model(rbx_xml::from_reader_default(std::io::Cursor::new(buf))?))),
|
CompileClass::Model(buf)=>PreparedData::Model(rbx_xml::from_reader_default(std::io::Cursor::new(buf))?),
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
(Ok(Some(_)),Ok(Some(_)))=>panic!("File and folder have the same name!"),
|
None=>None,
|
||||||
(Ok(None),Ok(None))=>Ok(None),
|
})
|
||||||
(Err(e),_)
|
|
||||||
|(_,Err(e))=>Err(e),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1523,7 +1528,7 @@ async fn compile(config:CompileConfig)->AResult<()>{
|
|||||||
if output_place.extension().is_none()&&tokio::fs::try_exists(output_place.as_path()).await?{
|
if output_place.extension().is_none()&&tokio::fs::try_exists(output_place.as_path()).await?{
|
||||||
output_place.push("place.rbxl");
|
output_place.push("place.rbxl");
|
||||||
}
|
}
|
||||||
let output=std::io::BufWriter::new(std::fs::File::open(output_place)?);
|
let output=std::io::BufWriter::new(std::fs::File::create(output_place)?);
|
||||||
rbx_binary::to_writer(output,&dom,&[dom.root_ref()])?;
|
rbx_binary::to_writer(output,&dom,&[dom.root_ref()])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user