diff --git a/Cargo.toml b/Cargo.toml index d23c1e1..058c46f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "shticker_book_unwritten" -version = "0.4.2" +version = "0.5.0" authors = ["Dr. Jonathan Helianthicus Doe, IV "] edition = "2018" description = "Minimal CLI launcher for the Toontown Rewritten MMORPG" diff --git a/README.md b/README.md index 705a863..18ee0b1 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,12 @@ for the [Toontown Rewritten](https://www.toontownrewritten.com/) Inspired by [Shticker Book Rewritten](https://github.com/madsciencecoder/Shticker-Book-Rewritten). -Currently **only** built to support GNU/Linux, because I don’t know much -about Windows NT nor about macOS. If you know something about either of those -platforms and want to help out, feel very free to submit a PR or to file an -issue with a description of what can be done to support the platform(s). +Currently **only** built to support GNU/Linux and Windows NT (using the MSVC +toolchain), because I don’t know much about ~~Windows NT nor about~~ +macOS. If you know something about macOS and want to help out, feel very free +to submit a PR or to file an issue with a description of what can be done to +support the platform. Mostly I just don’t have a macOS machine that I +can test on. ## Installing diff --git a/src/config.rs b/src/config.rs index 05115b0..45f8bb6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -71,30 +71,56 @@ pub fn get_config( let config_path = if let Some(s) = config_path { PathBuf::from(s) } else { - let mut xdg_config_home = String::new(); - let mut home = String::new(); - - for (key, value) in env::vars() { - match key.as_str() { - "XDG_CONFIG_HOME" => xdg_config_home = value, - "HOME" => home = value, - _ => - if !(home.is_empty() || xdg_config_home.is_empty()) { - break; - }, + #[cfg(unix)] + { + let mut xdg_config_home = String::new(); + let mut home = String::new(); + + for (key, value) in env::vars() { + match key.as_str() { + "XDG_CONFIG_HOME" => xdg_config_home = value, + "HOME" => home = value, + _ => + if !(home.is_empty() || xdg_config_home.is_empty()) + { + break; + }, + } + } + + if !xdg_config_home.is_empty() { + [xdg_config_home.as_str(), crate_name!(), "config.json"] + .iter() + .collect() + } else if !home.is_empty() { + [home.as_str(), ".config", crate_name!(), "config.json"] + .iter() + .collect() + } else { + return Err(Error::NoPossibleConfigPath); } } + #[cfg(windows)] + { + let mut appdata = String::new(); - if !xdg_config_home.is_empty() { - [xdg_config_home.as_str(), crate_name!(), "config.json"] - .iter() - .collect() - } else if !home.is_empty() { - [home.as_str(), ".config", crate_name!(), "config.json"] - .iter() - .collect() - } else { - return Err(Error::NoPossibleConfigPath); + for (key, value) in env::vars() { + match key.as_str() { + "APPDATA" => appdata = value, + _ => + if !appdata.is_empty() { + break; + }, + } + } + + if !appdata.is_empty() { + [appdata.as_str(), crate_name!(), "config.json"] + .iter() + .collect() + } else { + return Err(Error::NoPossibleConfigPath); + } } }; diff --git a/src/error.rs b/src/error.rs index 09ddafb..6b2bd40 100644 --- a/src/error.rs +++ b/src/error.rs @@ -29,7 +29,9 @@ pub enum Error { FileRenameError(io::Error), NotDir(PathBuf), RemoveFileError(io::Error), + #[allow(dead_code)] MissingFile(&'static str), + #[allow(dead_code)] PermissionsSetError(io::Error), MissingCommandLineArg(&'static str), PasswordReadError(io::Error), @@ -45,10 +47,18 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Self::NoPossibleConfigPath => f.write_str( - "No config path was given, and the $XDG_CONFIG_HOME and \ - $HOME environment variables are both unset or empty", - ), + Self::NoPossibleConfigPath => { + #[cfg(unix)] + const MSG: &str = "No config path was given, and the \ + $XDG_CONFIG_HOME and $HOME environment \ + variables are both unset or empty"; + #[cfg(windows)] + const MSG: &str = "No config path was given, and the \ + %APPDATA% environment variable is unset \ + or empty"; + + f.write_str(MSG) + }, Self::BadConfigPath(bcp) => write!(f, "Bad config file path specified: {}", bcp.display()), Self::MkdirError(ioe) => diff --git a/src/login.rs b/src/login.rs index 2768369..de0efa2 100644 --- a/src/login.rs +++ b/src/login.rs @@ -358,7 +358,20 @@ fn launch, T: AsRef>( println!("Launching the game..."); } - process::Command::new("./TTREngine") + #[cfg(unix)] + let command_text = "./TTREngine"; + #[cfg(windows)] + let command_text = { + // `.current_dir(&config.install_dir)` doesn't seem to work like it + // does on Linux, so this is just a (naive) way of making real sure + // that we are pointing at the right executable. + let mut command_buf = config.install_dir.clone(); + command_buf.push("TTREngine.exe"); + + command_buf + }; + + process::Command::new(&command_text) .current_dir(&config.install_dir) .env("TTR_PLAYCOOKIE", play_cookie) .env("TTR_GAMESERVER", game_server) diff --git a/src/main.rs b/src/main.rs index 0776214..91fc47b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,21 @@ fn main() { } fn run() -> Result<(), Error> { + #[cfg(unix)] + const CONFIG_LONG_HELP: &str = concat!( + "Configuration JSON file to use. Defaults to \"$XDG_CONFIG_HOME\"/", + crate_name!(), + "/config.json and then to \"$HOME\"/.config/", + crate_name!(), + "/config.json", + ); + #[cfg(windows)] + const CONFIG_LONG_HELP: &str = concat!( + r"Configuration JSON file to use. Defaults to %APPDATA%\", + crate_name!(), + r"\config.json", + ); + let arg_matches = App::new(crate_name!()) .version(crate_version!()) .author(crate_authors!()) @@ -40,14 +55,7 @@ fn run() -> Result<(), Error> { .aliases(&["conf", "configuration"]) .value_name("CONFIG_FILE") .help("Configuration JSON file to use.") - .long_help(concat!( - "Configuration JSON file to use. Defaults to \ - \"$XDG_CONFIG_HOME\"/", - crate_name!(), - "/config.json and then to \"$HOME\"/.config/", - crate_name!(), - "/config.json", - )) + .long_help(CONFIG_LONG_HELP) .takes_value(true) .conflicts_with("no-config"), ) diff --git a/src/update.rs b/src/update.rs index 483aeba..c4fd452 100644 --- a/src/update.rs +++ b/src/update.rs @@ -6,7 +6,6 @@ use sha1::{Digest, Sha1}; use std::{ fs::{self, File}, io::{self, prelude::*}, - os::unix::fs::PermissionsExt, path::{Path, PathBuf}, }; @@ -190,6 +189,8 @@ pub fn update( #[cfg(unix)] { + use std::os::unix::fs::PermissionsExt; + if !quiet { println!("Making sure TTREngine is executable..."); }