custom file stem

This commit is contained in:
Quaternions 2024-01-24 16:25:00 -08:00
parent 994eb9c4be
commit d9531f1d4e

View File

@ -1356,14 +1356,17 @@ enum FileDiscernment{
async fn discern_file(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->AResult<CompileNode>{
let path=entry.path();
let file_discernment=match path.extension(){
Some(extension)=>match extension.to_str(){
Some("lua")
|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:?}")))?,
let (ext_len,file_discernment)=match path.extension(){
Some(extension)=>{
let ext=extension.to_str().unwrap_or("");
(ext.len(),match ext{
"lua"
|"module.lua"=>FileDiscernment::Script(ScriptHint::ModuleScript),
"client.lua"=>FileDiscernment::Script(ScriptHint::LocalScript),
"server.lua"=>FileDiscernment::Script(ScriptHint::Script),
"rbxmx"=>FileDiscernment::Model,
other=>Err(anyhow::Error::msg(format!("Weird file extension: {other:?}")))?,
})
},
None=>Err(anyhow::Error::msg("No file extension"))?,
};
@ -1373,13 +1376,16 @@ async fn discern_file(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->
|(Some(DecompileStyle::Rojo),FileDiscernment::Model)=>Err(anyhow::Error::msg("Invalid file extension for style"))?,
_=>(),
}
let search_name=path.to_str().unwrap();
let mut search_name=entry
.file_name()
.into_string()
.map_err(|e|anyhow::Error::msg(format!("insane file name {e:?}")))?;
search_name.truncate(search_name.len()-ext_len-1);//remove period
let file=tokio::fs::File::open(path.as_path()).await?;
Ok(match file_discernment{
FileDiscernment::Model=>model_node(search_name,file).await?,
FileDiscernment::Script(hint)=>script_node(search_name,file,hint).await?,
FileDiscernment::Model=>model_node(search_name.as_str(),file).await?,
FileDiscernment::Script(hint)=>script_node(search_name.as_str(),file,hint).await?,
})
}
#[derive(Debug)]