download-decompile

This commit is contained in:
Quaternions 2024-07-01 20:41:52 -07:00
parent d38152600e
commit c856301aa6

View File

@ -21,6 +21,7 @@ struct Cli{
enum Commands{ enum Commands{
DownloadHistory(DownloadHistorySubcommand), DownloadHistory(DownloadHistorySubcommand),
Download(DownloadSubcommand), Download(DownloadSubcommand),
DownloadDecompile(DownloadDecompileSubcommand),
DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand), DownloadGroupInventoryJson(DownloadGroupInventoryJsonSubcommand),
Create(CreateSubcommand), Create(CreateSubcommand),
Upload(UploadSubcommand), Upload(UploadSubcommand),
@ -148,6 +149,25 @@ struct DecompileSubcommand{
write_scripts:Option<bool>, write_scripts:Option<bool>,
} }
#[derive(Args)] #[derive(Args)]
struct DownloadDecompileSubcommand{
#[arg(long)]
cookie_type:CookieType,
#[arg(long)]
cookie:String,
#[arg(long)]
output_folder:Option<PathBuf>,
#[arg(long)]
asset_id:AssetID,
#[arg(long)]
style:Style,
#[arg(long)]
write_template:Option<bool>,
#[arg(long)]
write_models:Option<bool>,
#[arg(long)]
write_scripts:Option<bool>,
}
#[derive(Args)]
struct DecompileHistoryIntoGitSubcommand{ struct DecompileHistoryIntoGitSubcommand{
#[arg(long)] #[arg(long)]
input_folder:PathBuf, input_folder:PathBuf,
@ -236,6 +256,17 @@ async fn main()->AResult<()>{
}).collect() }).collect()
).await ).await
}, },
Commands::DownloadDecompile(subcommand)=>{
download_decompile(DownloadDecompileConfig{
cookie:Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
asset_id:subcommand.asset_id,
output_folder:subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap()),
style:subcommand.style,
write_template:subcommand.write_template.unwrap_or(false),
write_models:subcommand.write_models.unwrap_or(false),
write_scripts:subcommand.write_scripts.unwrap_or(true),
}).await
},
Commands::DownloadGroupInventoryJson(subcommand)=>download_group_inventory_json( Commands::DownloadGroupInventoryJson(subcommand)=>download_group_inventory_json(
Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0, Cookie::from_type(subcommand.cookie_type,subcommand.cookie).await?.0,
subcommand.group, subcommand.group,
@ -606,6 +637,34 @@ async fn decompile(config:DecompileConfig)->AResult<()>{
Ok(()) Ok(())
} }
struct DownloadDecompileConfig{
cookie:String,
asset_id:AssetID,
style:Style,
output_folder:PathBuf,
write_template:bool,
write_models:bool,
write_scripts:bool,
}
async fn download_decompile(config:DownloadDecompileConfig)->AResult<()>{
let context=RobloxContext::new(config.cookie);
let file=context.download(rbx_asset::context::DownloadRequest{asset_id:config.asset_id,version:None}).await?;
let dom=load_dom(std::io::Cursor::new(file))?;
let context=rox_compiler::DecompiledContext::from_dom(dom);
context.write_files(rox_compiler::WriteConfig{
style:config.style.rox(),
output_folder:config.output_folder,
write_template:config.write_template,
write_models:config.write_models,
write_scripts:config.write_scripts,
}).await?;
Ok(())
}
struct WriteCommitConfig{ struct WriteCommitConfig{
git_committer_name:String, git_committer_name:String,
git_committer_email:String, git_committer_email:String,