implement upload

This commit is contained in:
Quaternions 2023-09-14 13:54:08 -07:00
parent 7bbb9ca24f
commit 4c485e76e4

View File

@ -1,5 +1,3 @@
use std::unimplemented;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
mod error; mod error;
@ -143,6 +141,38 @@ fn check_source_illegal_keywords(source:&String)->bool{
source.find("getfenv").is_some()||source.find("require").is_some() source.find("getfenv").is_some()||source.find("require").is_some()
} }
fn find_first_child_class<'a>(dom:&'a rbx_dom_weak::WeakDom,instance:&'a rbx_dom_weak::Instance,name:&'a str,class:&'a str) -> Option<&'a rbx_dom_weak::Instance> {
for &referent in instance.children() {
if let Some(c) = dom.get_by_ref(referent) {
if c.name==name&&class_is_a(c.class.as_str(),class) {
return Some(c);
}
}
}
None
}
fn get_mapinfo(dom:&rbx_dom_weak::WeakDom) -> BoxResult<(String,String,String)>{
let workspace_children=dom.root().children();
if workspace_children.len()!=1{
return Err(Error::new("there can only be one model"));
}
if let Some(model_instance) = dom.get_by_ref(workspace_children[0]) {
if let (Some(creator),Some(displayname))=(find_first_child_class(dom, model_instance, "Creator", "StringValue"),find_first_child_class(dom, model_instance, "DisplayName", "StringValue")){
if let (
Some(rbx_dom_weak::types::Variant::String(creator_string)),
Some(rbx_dom_weak::types::Variant::String(displayname_string))
)=(
creator.properties.get("Value"),
displayname.properties.get("Value")
){
return Ok((model_instance.name.clone(),creator_string.clone(),displayname_string.clone()));
}
}
}
return Err(Error::new("no stuff in map"));
}
fn download(map_list: Vec<u64>) -> BoxResult<()>{ fn download(map_list: Vec<u64>) -> BoxResult<()>{
let header=format!("Cookie: .ROBLOSECURITY={}",std::env::var("RBXCOOKIE")?); let header=format!("Cookie: .ROBLOSECURITY={}",std::env::var("RBXCOOKIE")?);
let shared_args=&[ let shared_args=&[
@ -315,16 +345,40 @@ fn replace() -> BoxResult<()>{
} }
fn upload() -> BoxResult<()>{ fn upload() -> BoxResult<()>{
//interactive prompt per upload: //interactive prompt per upload:
for entry in std::fs::read_dir("maps/passed")? {
let file_thing=entry?;
let input = std::io::BufReader::new(std::fs::File::open(file_thing.path())?);
let dom = rbx_binary::from_reader(input)?;
let (modelname,creator,displayname) = get_mapinfo(&dom)?;
//Creator: [auto fill creator] //Creator: [auto fill creator]
//DisplayName: [auto fill DisplayName] //DisplayName: [auto fill DisplayName]
//id: ["New" for blank because of my double enter key] //id: ["New" for blank because of my double enter key]
// std::process::Command::new("rbxcompiler") print!("Model name: {}\nCreator: {}\nDisplayName: {}\nAsset Id: ",modelname,creator,displayname);
// .arg("--compile=false") std::io::Write::flush(&mut std::io::stdout())?;
// .arg("--group=6980477") let asset_id;
// .arg("--asset=5692139100") loop{
// .arg("--input=map.rbxm") let mut asset_id_string = String::new();
// .spawn()?; std::io::stdin().read_line(&mut asset_id_string)?;
unimplemented!() asset_id_string.pop();//drop newline
if let Ok(parsed_asset_id)=asset_id_string.parse::<u64>(){
asset_id=parsed_asset_id;
break;
}else{
print!("Asset Id: ");
std::io::Write::flush(&mut std::io::stdout())?;
}
}
std::process::Command::new("../rbxcompiler-linux-amd64")
.arg("--compile=false")
.arg("--group=6980477")
.arg(format!("--asset={}",asset_id))
.arg(format!("--input={}",file_thing.path().into_os_string().into_string().unwrap()))
.spawn()?;
}
Ok(())
} }
enum Interactive{ enum Interactive{