From a5c01ff9cf7674c7492a1b8a70dcce3f6baeab91 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 11 Jan 2024 16:06:24 -0800 Subject: [PATCH] DownloadAndDecompileHistoryIntoGit --- src/main.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index bbd776c..455d317 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,7 @@ enum Commands{ Compile, Decompile, DecompileHistoryIntoGit, + DownloadAndDecompileHistoryIntoGit, } #[derive(Args)] @@ -119,6 +120,15 @@ async fn main()->AResult<()>{ write_scripts:!cli.no_scripts.unwrap_or(false), }).await, Commands::DecompileHistoryIntoGit=>decompile_history_into_git(DecompileHistoryConfig{ + git_committer_name:cli.git_committer_name.unwrap(), + git_committer_email:cli.git_committer_email.unwrap(), + input_folder:cli.input.unwrap(), + output_folder:cli.output.unwrap(), + write_template:!cli.no_template.unwrap_or(false), + write_models:!cli.no_models.unwrap_or(false), + write_scripts:!cli.no_scripts.unwrap_or(false), + }).await, + Commands::DownloadAndDecompileHistoryIntoGit=>download_and_decompile_history_into_git(DownloadAndDecompileHistoryConfig{ git_committer_name:cli.git_committer_name.unwrap(), git_committer_email:cli.git_committer_email.unwrap(), cookie:cookie.unwrap(), @@ -766,6 +776,51 @@ async fn write_commit(config:WriteCommitConfig,b:ResultAResult<()>{ + //poll paged list of all asset versions + let mut versions_path=config.input_folder.clone(); + versions_path.push("versions.json"); + let asset_list:Vec=serde_json::from_reader(std::fs::File::open(versions_path)?)?; + + let repo=git2::Repository::init(config.output_folder.clone())?; + + //decompile all versions + futures::stream::iter(asset_list) + .map(|asset_version|{ + let mut file_path=config.input_folder.clone(); + tokio::task::spawn(async move{ + file_path.push(format!("{}_v{}.rbxl",asset_version.assetId,asset_version.assetVersionNumber)); + let contents=generate_decompiled_context(std::fs::File::open(file_path)?)?; + Ok::<_,anyhow::Error>((asset_version,contents)) + }) + }) + .buffered(CONCURRENT_REQUESTS) + .for_each(|join_handle_result|async{ + match write_commit(WriteCommitConfig{ + git_committer_name:config.git_committer_name.clone(), + git_committer_email:config.git_committer_email.clone(), + output_folder:config.output_folder.clone(), + write_template:config.write_template, + write_models:config.write_models, + write_scripts:config.write_scripts, + },join_handle_result,&repo).await{ + Ok(())=>(), + Err(e)=>println!("download/unzip/decompile/write/commit error: {}",e), + } + }).await; + Ok(()) +} + +struct DownloadAndDecompileHistoryConfig{ cookie:String, asset_id:AssetID, git_committer_name:String, @@ -776,7 +831,7 @@ struct DecompileHistoryConfig{ write_scripts:bool, } -async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{ +async fn download_and_decompile_history_into_git(config:DownloadAndDecompileHistoryConfig)->AResult<()>{ let client=reqwest::Client::new(); //poll paged list of all asset versions