From 37360c787a1d24e1bb2697aa040c568e8774c250 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:24:09 +0000 Subject: [PATCH] Format Rust code using rustfmt --- src/common/button_config.rs | 3 +- src/common/menu.rs | 7 +- src/common/release.rs | 131 ++++++++++++++++++------------------ src/lib.rs | 21 ++++-- src/training/mod.rs | 2 +- 5 files changed, 87 insertions(+), 77 deletions(-) diff --git a/src/common/button_config.rs b/src/common/button_config.rs index 97be9b2..a76c91f 100644 --- a/src/common/button_config.rs +++ b/src/common/button_config.rs @@ -61,7 +61,8 @@ struct TopLevelBtnComboConfig { } pub fn validate_config(data: &str) -> bool { - let conf: TopLevelBtnComboConfig = toml::from_str(data).expect("Custom button config has invalid schema"); + let conf: TopLevelBtnComboConfig = + toml::from_str(data).expect("Custom button config has invalid schema"); let conf = conf.button_config; let configs = [conf.open_menu, conf.save_state, conf.load_state]; let bad_keys = configs diff --git a/src/common/menu.rs b/src/common/menu.rs index 5fc35e9..6763c26 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -1,7 +1,7 @@ use crate::common::*; use crate::events::{Event, EVENT_QUEUE}; -use crate::training::frame_counter; use crate::logging::*; +use crate::training::frame_counter; use ramhorns::Template; use skyline::info::get_program_id; @@ -347,10 +347,7 @@ static mut WEB_MENU_ACTIVE: bool = false; unsafe fn spawn_web_session(session: WebSession) { info!("Opening menu session..."); let loaded_msg = session.recv(); - info!( - "Received loaded message from web: {}", - &loaded_msg - ); + info!("Received loaded message from web: {}", &loaded_msg); let message_send = MenuJsonStruct { menu: MENU, defaults_menu: DEFAULTS_MENU, diff --git a/src/common/release.rs b/src/common/release.rs index 6929ee1..c35e765 100644 --- a/src/common/release.rs +++ b/src/common/release.rs @@ -1,64 +1,67 @@ -use skyline_web::DialogOk; -use std::fs; -use crate::logging::*; - -pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION"); -const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt"; - -enum VersionCheck { - Current, - NoFile, - Update, -} - -fn is_current_version(fpath: &str) -> VersionCheck { - // Create a blank version file if it doesn't exists - if fs::metadata(fpath).is_err() { - fs::File::create(fpath).expect("Could not create version file!"); - return VersionCheck::NoFile; - } - - if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION { - VersionCheck::Current - } else { - VersionCheck::Update - } -} - -fn record_current_version(fpath: &str) { - // Write the current version to the version file - fs::write(fpath, CURRENT_VERSION).expect("Could not record current version!") -} - -pub fn version_check() { - match is_current_version(VERSION_FILE_PATH) { - VersionCheck::Current => { - // Version is current, no need to take any action - } - VersionCheck::Update => { - // Display dialog box on launch if changing versions - DialogOk::ok( - format!( - "Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\ - Due to a breaking change in this version, your menu selections and defaults must be reset once.\n\n\ - Please refer to the Github page and the Discord server for a full list of recent features, bugfixes, and other changes." - ) - ); - // Remove old menu selections, silently ignoring errors (i.e. if the file doesn't exist) - fs::remove_file("sd:/TrainingModpack/training_modpack_menu.conf").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.conf")); - fs::remove_file("sd:/TrainingModpack/training_modpack_menu.json").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.json")); - fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu_defaults.conf")); - record_current_version(VERSION_FILE_PATH); - } - VersionCheck::NoFile => { - // Display dialog box on fresh installation - DialogOk::ok( - format!( - "Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\ - Please refer to the Github page and the Discord server for a full list of features and instructions on how to utilize the improved Training Mode." - ) - ); - record_current_version(VERSION_FILE_PATH); - } - } -} +use crate::logging::*; +use skyline_web::DialogOk; +use std::fs; + +pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION"); +const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt"; + +enum VersionCheck { + Current, + NoFile, + Update, +} + +fn is_current_version(fpath: &str) -> VersionCheck { + // Create a blank version file if it doesn't exists + if fs::metadata(fpath).is_err() { + fs::File::create(fpath).expect("Could not create version file!"); + return VersionCheck::NoFile; + } + + if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION { + VersionCheck::Current + } else { + VersionCheck::Update + } +} + +fn record_current_version(fpath: &str) { + // Write the current version to the version file + fs::write(fpath, CURRENT_VERSION).expect("Could not record current version!") +} + +pub fn version_check() { + match is_current_version(VERSION_FILE_PATH) { + VersionCheck::Current => { + // Version is current, no need to take any action + } + VersionCheck::Update => { + // Display dialog box on launch if changing versions + DialogOk::ok( + format!( + "Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\ + Due to a breaking change in this version, your menu selections and defaults must be reset once.\n\n\ + Please refer to the Github page and the Discord server for a full list of recent features, bugfixes, and other changes." + ) + ); + // Remove old menu selections, silently ignoring errors (i.e. if the file doesn't exist) + fs::remove_file("sd:/TrainingModpack/training_modpack_menu.conf") + .unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.conf")); + fs::remove_file("sd:/TrainingModpack/training_modpack_menu.json") + .unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.json")); + fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf") + .unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu_defaults.conf")); + record_current_version(VERSION_FILE_PATH); + } + VersionCheck::NoFile => { + // Display dialog box on fresh installation + DialogOk::ok( + format!( + "Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\ + Please refer to the Github page and the Discord server for a full list of features and instructions on how to utilize the improved Training Mode." + ) + ); + record_current_version(VERSION_FILE_PATH); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 6f18d48..4f4f79a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,9 +21,9 @@ mod hazard_manager; mod hitbox_visualizer; mod training; +mod logging; #[cfg(test)] mod test; -mod logging; use crate::common::*; use crate::events::{Event, EVENT_QUEUE}; @@ -32,11 +32,11 @@ use skyline::libc::mkdir; use skyline::nro::{self, NroInfo}; use std::fs; +use crate::logging::*; use crate::menu::quick_menu_loop; #[cfg(feature = "web_session_preload")] use crate::menu::web_session_loop; use training_mod_consts::{MenuJsonStruct, OnOff}; -use crate::logging::*; fn nro_main(nro: &NroInfo<'_>) { if nro.module.isLoaded { @@ -108,7 +108,8 @@ pub fn main() { let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.json"; info!("Checking for previous menu in training_modpack_menu.json..."); if fs::metadata(menu_conf_path).is_ok() { - let menu_conf = fs::read_to_string(menu_conf_path).expect(&format!("Could not remove {}", menu_conf_path)); + let menu_conf = fs::read_to_string(menu_conf_path) + .expect(&format!("Could not remove {}", menu_conf_path)); if let Ok(menu_conf_json) = serde_json::from_str::(&menu_conf) { unsafe { MENU = menu_conf_json.menu; @@ -117,7 +118,10 @@ pub fn main() { } } else { warn!("Previous menu found but is invalid. Deleting..."); - fs::remove_file(menu_conf_path).expect(&format!("{} has invalid schema but could not be deleted!", menu_conf_path)); + fs::remove_file(menu_conf_path).expect(&format!( + "{} has invalid schema but could not be deleted!", + menu_conf_path + )); } } else { info!("No previous menu file found."); @@ -127,7 +131,8 @@ pub fn main() { info!("Checking for previous button combo settings in training_modpack.toml..."); if fs::metadata(combo_path).is_ok() { info!("Previous button combo settings found. Loading..."); - let combo_conf = fs::read_to_string(combo_path).expect(&format!("Could not read {}", combo_path)); + let combo_conf = + fs::read_to_string(combo_path).expect(&format!("Could not read {}", combo_path)); if button_config::validate_config(&combo_conf) { button_config::save_all_btn_config_from_toml(&combo_conf); } else { @@ -159,7 +164,11 @@ pub fn main() { ); let url = format!("{host}{path}"); - minreq::post(url).with_json(&event).expect("Failed to send info to firebase").send().ok(); + minreq::post(url) + .with_json(&event) + .expect("Failed to send info to firebase") + .send() + .ok(); } } }); diff --git a/src/training/mod.rs b/src/training/mod.rs index 8dfac10..465dea9 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -2,8 +2,8 @@ use crate::common::{ is_training_mode, menu, FIGHTER_MANAGER_ADDR, ITEM_MANAGER_ADDR, STAGE_MANAGER_ADDR, }; use crate::hitbox_visualizer; -use crate::training::character_specific::items; use crate::logging::*; +use crate::training::character_specific::items; use skyline::hooks::{getRegionAddress, InlineCtx, Region}; use skyline::nn::hid::*; use skyline::nn::ro::LookupSymbol;