winner
This commit is contained in:
parent
3ed2b71e07
commit
52b43cef2b
32
src/main.rs
32
src/main.rs
@ -1,4 +1,4 @@
|
||||
use std::io::{Read,Seek};
|
||||
use std::io::Read;
|
||||
use clap::{Args,Parser,Subcommand};
|
||||
use anyhow::Result as AResult;
|
||||
use futures::StreamExt;
|
||||
@ -49,6 +49,7 @@ enum Commands{
|
||||
Upload,
|
||||
Compile,
|
||||
Decompile,
|
||||
DecompileHistoryIntoGit,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@ -112,6 +113,14 @@ async fn main()->AResult<()>{
|
||||
write_models:!cli.no_models.unwrap_or(false),
|
||||
write_scripts:!cli.no_scripts.unwrap_or(false),
|
||||
}),
|
||||
Commands::DecompileHistoryIntoGit=>decompile_history_into_git(DecompileHistoryConfig{
|
||||
cookie:cookie.unwrap(),
|
||||
asset_id:cli.asset_id.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,
|
||||
}
|
||||
}
|
||||
|
||||
@ -666,7 +675,7 @@ struct WriteCommitConfig{
|
||||
write_scripts:bool,
|
||||
}
|
||||
|
||||
fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledContext)>,repo:&git2::Repository,last_commit:Option<&git2::Commit>)->AResult<git2::Oid>{
|
||||
fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledContext)>,repo:&git2::Repository)->AResult<()>{
|
||||
let (asset_version,context)=b?;
|
||||
|
||||
//clean output dir
|
||||
@ -676,12 +685,12 @@ fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledConte
|
||||
std::fs::remove_dir_all(src)?;
|
||||
let mut template=config.output_folder.clone();
|
||||
template.push("template.rbxlx");
|
||||
std::fs::remove_file(template);
|
||||
std::fs::remove_file(template)?;
|
||||
}
|
||||
|
||||
//write files
|
||||
write_files(WriteConfig{
|
||||
output_folder:config.output_folder,
|
||||
output_folder:config.output_folder.clone(),
|
||||
write_template:config.write_template,
|
||||
write_models:config.write_models,
|
||||
write_scripts:config.write_scripts,
|
||||
@ -696,14 +705,15 @@ fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledConte
|
||||
tree_index.write_tree()?
|
||||
};
|
||||
let tree=repo.find_tree(tree_id)?;
|
||||
let commit_id=match last_commit{
|
||||
Some(commit)=>repo.commit(
|
||||
|
||||
match repo.revwalk().unwrap().next(){
|
||||
Some(Ok(commit_id))=>repo.commit(
|
||||
Some("HEAD"),//update_ref
|
||||
&sig,//author
|
||||
&sig,//commiter
|
||||
&format!("v{}", asset_version.assetVersionNumber),//message
|
||||
&tree,//tree (basically files)
|
||||
&[commit],//parents
|
||||
&[&repo.find_commit(commit_id)?],//parents
|
||||
).expect("commit failed"),
|
||||
None=>repo.commit(
|
||||
Some("HEAD"),//update_ref
|
||||
@ -713,10 +723,11 @@ fn write_commit(config:WriteCommitConfig,b:AResult<(AssetVersion,DecompiledConte
|
||||
&tree,//tree (basically files)
|
||||
&[],//parents
|
||||
).expect("commit failed"),
|
||||
Some(Err(e))=>Err(e)?,
|
||||
};
|
||||
|
||||
//commit
|
||||
Ok(commit_id)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct DecompileHistoryConfig{
|
||||
@ -735,7 +746,6 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
|
||||
let asset_list=get_version_history(&client,&config.cookie.as_str(),config.asset_id).await?;
|
||||
|
||||
let repo=git2::Repository::init(config.output_folder.clone())?;
|
||||
let mut commits=Vec::new();
|
||||
|
||||
//download all versions
|
||||
let asset_id_string=config.asset_id.to_string();
|
||||
@ -761,8 +771,8 @@ async fn decompile_history_into_git(config:DecompileHistoryConfig)->AResult<()>{
|
||||
write_template:config.write_template,
|
||||
write_models:config.write_models,
|
||||
write_scripts:config.write_scripts,
|
||||
},b,&repo,commits.last()){
|
||||
Ok(commit_id)=>commits.push(repo.find_commit(commit_id).expect("Failed to find commit")),
|
||||
},b,&repo){
|
||||
Ok(())=>(),
|
||||
Err(e)=>println!("download/unzip/decompile/write error: {}",e),
|
||||
}
|
||||
}).await;
|
||||
|
Loading…
Reference in New Issue
Block a user