From 4c485e76e4f0c743ebf1e03405080ebf7e99957d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 14 Sep 2023 13:54:08 -0700 Subject: [PATCH] implement upload --- src/main.rs | 78 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index ef02c2a..eb588f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -use std::unimplemented; - use clap::{Args, Parser, Subcommand}; mod error; @@ -143,6 +141,38 @@ fn check_source_illegal_keywords(source:&String)->bool{ 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) -> BoxResult<()>{ let header=format!("Cookie: .ROBLOSECURITY={}",std::env::var("RBXCOOKIE")?); let shared_args=&[ @@ -315,16 +345,40 @@ fn replace() -> BoxResult<()>{ } fn upload() -> BoxResult<()>{ //interactive prompt per upload: - //Creator: [auto fill creator] - //DisplayName: [auto fill DisplayName] - //id: ["New" for blank because of my double enter key] - // std::process::Command::new("rbxcompiler") - // .arg("--compile=false") - // .arg("--group=6980477") - // .arg("--asset=5692139100") - // .arg("--input=map.rbxm") - // .spawn()?; - unimplemented!() + 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] + //DisplayName: [auto fill DisplayName] + //id: ["New" for blank because of my double enter key] + print!("Model name: {}\nCreator: {}\nDisplayName: {}\nAsset Id: ",modelname,creator,displayname); + std::io::Write::flush(&mut std::io::stdout())?; + let asset_id; + loop{ + let mut asset_id_string = String::new(); + std::io::stdin().read_line(&mut asset_id_string)?; + asset_id_string.pop();//drop newline + if let Ok(parsed_asset_id)=asset_id_string.parse::(){ + 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{