forked from StrafesNET/asset-tool
debug insanity
This commit is contained in:
parent
9d6780a0b0
commit
e5c7ed6b75
65
src/main.rs
65
src/main.rs
@ -1311,8 +1311,15 @@ 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{
|
||||||
|
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();
|
let search_name=file_name.to_str().unwrap();
|
||||||
//scan inside the folder for an object to define the class of the folder
|
//scan inside the folder for an object to define the class of the folder
|
||||||
let script_query=async {match style{
|
let script_query=async {match style{
|
||||||
@ -1330,7 +1337,7 @@ async fn discern_node(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->
|
|||||||
//model files are rox & rox-rojo only, so it's a lot less work...
|
//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));
|
let model_query=get_file_async(contents_folder.clone(),format!("{}.rbxmx",search_name));
|
||||||
//model? script? both?
|
//model? script? both?
|
||||||
Some(match tokio::join!(script_query,model_query){
|
Ok(Some(match tokio::join!(script_query,model_query){
|
||||||
(Ok(FileHint{file,hint}),Err(QueryResolveError::NotFound))=>script_node(search_name,file,hint).await?,
|
(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?,
|
(Err(QueryResolveError::NotFound),Ok(file))=>model_node(search_name,file).await?,
|
||||||
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
|
(Ok(_),Ok(_))=>Err(QueryResolveError::Ambiguous)?,
|
||||||
@ -1342,11 +1349,7 @@ async fn discern_node(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->
|
|||||||
//other error
|
//other error
|
||||||
(Err(e),_)
|
(Err(e),_)
|
||||||
|(_,Err(e))=>Err(e)?
|
|(_,Err(e))=>Err(e)?
|
||||||
})
|
}))
|
||||||
}else{
|
|
||||||
//a folder of this name does not exist
|
|
||||||
None
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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