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>{ async fn discern_file(entry:&tokio::fs::DirEntry,style:Option<DecompileStyle>)->AResult<CompileNode>{
let path=entry.path(); let path=entry.path();
let file_discernment=match path.extension(){ let (ext_len,file_discernment)=match path.extension(){
Some(extension)=>match extension.to_str(){ Some(extension)=>{
Some("lua") let ext=extension.to_str().unwrap_or("");
|Some("module.lua")=>FileDiscernment::Script(ScriptHint::ModuleScript), (ext.len(),match ext{
Some("client.lua")=>FileDiscernment::Script(ScriptHint::LocalScript), "lua"
Some("server.lua")=>FileDiscernment::Script(ScriptHint::Script), |"module.lua"=>FileDiscernment::Script(ScriptHint::ModuleScript),
Some("rbxmx")=>FileDiscernment::Model, "client.lua"=>FileDiscernment::Script(ScriptHint::LocalScript),
other=>Err(anyhow::Error::msg(format!("Weird file extension: {other:?}")))?, "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"))?, 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"))?, |(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?; let file=tokio::fs::File::open(path.as_path()).await?;
Ok(match file_discernment{ Ok(match file_discernment{
FileDiscernment::Model=>model_node(search_name,file).await?, FileDiscernment::Model=>model_node(search_name.as_str(),file).await?,
FileDiscernment::Script(hint)=>script_node(search_name,file,hint).await?, FileDiscernment::Script(hint)=>script_node(search_name.as_str(),file,hint).await?,
}) })
} }
#[derive(Debug)] #[derive(Debug)]