mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 05:06:29 +00:00
Let Rojo pull auth cookie from registry on Windows
This commit is contained in:
30
src/auth_cookie.rs
Normal file
30
src/auth_cookie.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
//! Implementation of automatically fetching authentication cookie from a Roblox
|
||||
//! Studio installation.
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn get_auth_cookie() -> Option<String> {
|
||||
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
|
||||
|
||||
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
||||
let cookies = hkcu
|
||||
.open_subkey("Software\\Roblox\\RobloxStudioBrowser\\roblox.com")
|
||||
.ok()?;
|
||||
|
||||
let entry: String = cookies.get_value(".ROBLOSECURITY").ok()?;
|
||||
let mut cookie = None;
|
||||
|
||||
for kv_pair in entry.split(",") {
|
||||
let mut pieces = kv_pair.split("::");
|
||||
|
||||
if let Some("COOK") = pieces.next() {
|
||||
cookie = pieces.next();
|
||||
}
|
||||
}
|
||||
|
||||
cookie.map(Into::into)
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub fn get_auth_cookie() -> Option<String> {
|
||||
None
|
||||
}
|
||||
@@ -54,7 +54,7 @@ fn main() {
|
||||
(about: "Generates a place or model file out of the project and uploads it to Roblox.")
|
||||
(@arg PROJECT: "Path to the project to upload. Defaults to the current directory.")
|
||||
(@arg kind: --kind +takes_value "The kind of asset to generate, 'place', or 'model'. Defaults to place.")
|
||||
(@arg cookie: --cookie +takes_value "Security cookie to authenticate with. If not specified, Rojo will attempt to find one from the system automatically.")
|
||||
(@arg cookie: --cookie +takes_value "Authenication cookie to authenticate with. If not specified, Rojo will attempt to find one from the system automatically.")
|
||||
(@arg asset_id: --asset_id +takes_value +required "Asset ID to upload to.")
|
||||
)
|
||||
);
|
||||
@@ -172,7 +172,7 @@ fn start_upload(sub_matches: &ArgMatches) {
|
||||
};
|
||||
|
||||
let kind = sub_matches.value_of("kind");
|
||||
let security_cookie = sub_matches.value_of("cookie").map(Into::into);
|
||||
let auth_cookie = sub_matches.value_of("cookie").map(Into::into);
|
||||
|
||||
let asset_id: u64 = {
|
||||
let arg = sub_matches.value_of("asset_id").unwrap();
|
||||
@@ -188,12 +188,12 @@ fn start_upload(sub_matches: &ArgMatches) {
|
||||
|
||||
let options = commands::UploadOptions {
|
||||
fuzzy_project_path,
|
||||
security_cookie: security_cookie,
|
||||
auth_cookie,
|
||||
asset_id,
|
||||
kind,
|
||||
};
|
||||
|
||||
match commands::upload(&options) {
|
||||
match commands::upload(options) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
error!("{}", e);
|
||||
|
||||
@@ -2,20 +2,27 @@ use std::path::PathBuf;
|
||||
|
||||
use failure::Fail;
|
||||
|
||||
use crate::auth_cookie::get_auth_cookie;
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum UploadError {
|
||||
#[fail(display = "This error cannot happen")]
|
||||
StubError,
|
||||
#[fail(display = "Rojo could not find your Roblox auth cookie. Please pass one via --cookie.")]
|
||||
NeedAuthCookie,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UploadOptions<'a> {
|
||||
pub fuzzy_project_path: PathBuf,
|
||||
pub security_cookie: Option<String>,
|
||||
pub auth_cookie: Option<String>,
|
||||
pub asset_id: u64,
|
||||
pub kind: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub fn upload(_options: &UploadOptions) -> Result<(), UploadError> {
|
||||
pub fn upload(options: UploadOptions) -> Result<(), UploadError> {
|
||||
let cookie = options
|
||||
.auth_cookie
|
||||
.or_else(get_auth_cookie)
|
||||
.ok_or(UploadError::NeedAuthCookie)?;
|
||||
|
||||
unimplemented!("TODO: Reimplement upload command");
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ pub mod commands;
|
||||
#[doc(hidden)]
|
||||
pub mod project;
|
||||
|
||||
mod auth_cookie;
|
||||
mod imfs;
|
||||
mod message_queue;
|
||||
mod path_map;
|
||||
|
||||
Reference in New Issue
Block a user