DownloadAndDecompileHistoryIntoGit
This commit is contained in:
parent
c3ca545119
commit
a5c01ff9cf
57
src/main.rs
57
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:Result<AResult<(AssetVersion,De
|
||||
}
|
||||
|
||||
struct DecompileHistoryConfig{
|
||||
git_committer_name:String,
|
||||
git_committer_email:String,
|
||||
input_folder:std::path::PathBuf,
|
||||
output_folder:std::path::PathBuf,
|
||||
write_template:bool,
|
||||
write_models:bool,
|
||||
write_scripts:bool,
|
||||
}
|
||||
|
||||
async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
|
||||
//poll paged list of all asset versions
|
||||
let mut versions_path=config.input_folder.clone();
|
||||
versions_path.push("versions.json");
|
||||
let asset_list:Vec<AssetVersion>=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
|
||||
|
Loading…
Reference in New Issue
Block a user