From e5c7ed6b752233197d7ba5834d7bb20c075c4e63 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 24 Jan 2024 01:44:18 -0800 Subject: [PATCH] debug insanity --- src/main.rs | 121 +++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 58 deletions(-) diff --git a/src/main.rs b/src/main.rs index a176714..f6ffb20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1311,42 +1311,45 @@ async fn model_node(search_name:&str,mut file:tokio::fs::File)->AResult)->AResult>{ let contents_folder=entry.path(); let file_name=entry.file_name(); - //folder - Ok(if tokio::fs::try_exists(contents_folder.as_path()).await?{ - let search_name=file_name.to_str().unwrap(); - //scan inside the folder for an object to define the class of the folder - let script_query=async {match style{ - Some(DecompileStyle::Rox)=>QuerySingle::rox(&contents_folder,search_name).resolve().await, - 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 - None=>mega_triple_join(tokio::join!( - QuerySingle::rox(&contents_folder,search_name).resolve(), - //true=search for module here to avoid ambiguity with QuerySingle::rox results - QueryTriple::rox_rojo(&contents_folder,search_name,true).resolve(), - QueryTriple::rojo(&contents_folder).resolve(), - )) - }}; - //model files are rox & rox-rojo only, so it's a lot less work... - let model_query=get_file_async(contents_folder.clone(),format!("{}.rbxmx",search_name)); - //model? script? both? - Some(match tokio::join!(script_query,model_query){ - (Ok(FileHint{file,hint}),Err(QueryResolveError::NotFound))=>script_node(search_name,file,hint).await?, - (Err(QueryResolveError::NotFound),Ok(file))=>model_node(search_name,file).await?, - (Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?, - //neither - (Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{ - name:search_name.to_owned(), - class:CompileClass::Folder, - }, - //other error - (Err(e),_) - |(_,Err(e))=>Err(e)? - }) - }else{ - //a folder of this name does not exist - None - }) + //is folder? else exit flow control + match tokio::fs::read_dir(contents_folder.as_path()).await{ + Ok(_)=>(),//continue flow + Err(e)=>{println!("{:?}",e.raw_os_error());match e.raw_os_error(){ + Some(0)//std::io::ErrorKind::NotFound + |Some(20)=>return Ok(None),//std::io::ErrorKind::NotADirectory (not allowed to be used but returns it anyways) + _=>Err(e)?, + }} + } + let search_name=file_name.to_str().unwrap(); + //scan inside the folder for an object to define the class of the folder + let script_query=async {match style{ + Some(DecompileStyle::Rox)=>QuerySingle::rox(&contents_folder,search_name).resolve().await, + 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 + None=>mega_triple_join(tokio::join!( + QuerySingle::rox(&contents_folder,search_name).resolve(), + //true=search for module here to avoid ambiguity with QuerySingle::rox results + QueryTriple::rox_rojo(&contents_folder,search_name,true).resolve(), + QueryTriple::rojo(&contents_folder).resolve(), + )) + }}; + //model files are rox & rox-rojo only, so it's a lot less work... + let model_query=get_file_async(contents_folder.clone(),format!("{}.rbxmx",search_name)); + //model? script? both? + Ok(Some(match tokio::join!(script_query,model_query){ + (Ok(FileHint{file,hint}),Err(QueryResolveError::NotFound))=>script_node(search_name,file,hint).await?, + (Err(QueryResolveError::NotFound),Ok(file))=>model_node(search_name,file).await?, + (Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?, + //neither + (Err(QueryResolveError::NotFound),Err(QueryResolveError::NotFound))=>CompileNode{ + name:search_name.to_owned(), + class:CompileClass::Folder, + }, + //other error + (Err(e),_) + |(_,Err(e))=>Err(e)? + })) } @@ -1359,11 +1362,11 @@ async fn discern_file(entry:&tokio::fs::DirEntry,style:Option)-> let path=entry.path(); let file_discernment=match path.extension(){ Some(extension)=>match extension.to_str(){ - Some(".lua")=>FileDiscernment::Script(ScriptHint::Undetermined), - Some(".module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript), - Some(".client.lua")=>FileDiscernment::Script(ScriptHint::LocalScript), - Some(".server.lua")=>FileDiscernment::Script(ScriptHint::Script), - Some(".rbxlx")=>FileDiscernment::Model, + Some("lua")=>FileDiscernment::Script(ScriptHint::Undetermined), + Some("module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript), + Some("client.lua")=>FileDiscernment::Script(ScriptHint::LocalScript), + Some("server.lua")=>FileDiscernment::Script(ScriptHint::Script), + Some("rbxmx")=>FileDiscernment::Model, other=>Err(anyhow::Error::msg(format!("Weird file extension: {other:?}")))?, }, None=>Err(anyhow::Error::msg("No file extension"))?, @@ -1449,7 +1452,7 @@ async fn compile(config:CompileConfig)->AResult<()>{ //add in scripts and models let mut folder=config.input_folder.clone(); folder.push("src"); - let mut stack:Vec=dom.root().children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent)).collect(); + let mut stack:Vec=dom.get_by_ref(dom.root().children()[0]).unwrap().children().into_iter().map(|&referent|CompileStackInstruction::TraverseReferent(referent)).collect(); while let Some(instruction)=stack.pop(){ match instruction{ CompileStackInstruction::TraverseReferent(item_ref)=>{ @@ -1480,24 +1483,26 @@ async fn compile(config:CompileConfig)->AResult<()>{ if !exist_names.contains(entry.file_name().to_str().unwrap()){ let style=config.style; 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 - match tokio::join!(discern_node(&entry,style),discern_file(&entry,style)){ - (Ok(Some(compile_class)),Ok(None)) - |(Ok(None),Ok(Some(compile_class)))=>{ + Ok::<_,anyhow::Error>(match scooby_doo?{ + Some(compile_class)=>{ //prepare data structure - match compile_class.class{ - CompileClass::Folder=>Ok(Some(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::LocalScript(source)=>Ok(Some(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::Model(buf)=>Ok(Some(PreparedData::Model(rbx_xml::from_reader_default(std::io::Cursor::new(buf))?))), - } + Some(match compile_class.class{ + CompileClass::Folder=>PreparedData::Builder(rbx_dom_weak::InstanceBuilder::new("Folder").with_name(compile_class.name.as_str())), + CompileClass::Script(source)=>PreparedData::Builder(script_builder("Script",compile_class.name.as_str(),source)), + CompileClass::LocalScript(source)=>PreparedData::Builder(script_builder("LocalScript",compile_class.name.as_str(),source)), + CompileClass::ModuleScript(source)=>PreparedData::Builder(script_builder("ModuleScript",compile_class.name.as_str(),source)), + 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!"), - (Ok(None),Ok(None))=>Ok(None), - (Err(e),_) - |(_,Err(e))=>Err(e), - } + None=>None, + }) }); } } @@ -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?{ 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()])?; Ok(()) }