From 070de964be66870d955b2bf1f7a68c1c6ac97e9d Mon Sep 17 00:00:00 2001 From: DeltaF1 Date: Mon, 8 May 2023 11:29:01 -0400 Subject: [PATCH 1/4] Add an error code for when Mii selection is cancelled --- ctru-rs/examples/mii-selector.rs | 26 +++++++++++++++----------- ctru-rs/src/applets/mii_selector.rs | 7 +++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index d489e07..363a034 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -1,4 +1,4 @@ -use ctru::applets::mii_selector::MiiSelector; +use ctru::applets::mii_selector::{LaunchError, MiiSelector}; use ctru::prelude::*; fn main() { @@ -14,16 +14,20 @@ fn main() { mii_selector.blacklist_user_mii(0.into()); mii_selector.set_title("Great Mii Selector!"); - let result = mii_selector.launch().unwrap(); - - println!("Is Mii selected?: {:?}", result.is_mii_selected); - println!("Mii type: {:?}", result.mii_type); - println!("Name: {:?}", result.mii_data.name); - println!("Author: {:?}", result.mii_data.author_name); - println!( - "Does the Mii have moles?: {:?}", - result.mii_data.mole_details.is_enabled - ); + match mii_selector.launch() { + Ok(result) => { + println!("Is Mii selected?: {:?}", result.is_mii_selected); + println!("Mii type: {:?}", result.mii_type); + println!("Name: {:?}", result.mii_data.name); + println!("Author: {:?}", result.mii_data.author_name); + println!( + "Does the Mii have moles?: {:?}", + result.mii_data.mole_details.is_enabled + ); + } + Err(LaunchError::InvalidChecksum) => println!("Corrupt Mii selected"), + Err(LaunchError::NoMiiSelected) => println!("No Mii selected"), + } // Main loop while apt.main_loop() { diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index a6acd61..4d89288 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -56,6 +56,8 @@ pub struct MiiSelector { #[derive(Clone, Debug)] pub struct SelectionResult { pub mii_data: MiiData, + + #[deprecated] pub is_mii_selected: bool, pub mii_type: MiiType, } @@ -64,6 +66,7 @@ pub struct SelectionResult { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum LaunchError { InvalidChecksum, + NoMiiSelected, } impl MiiSelector { @@ -147,6 +150,10 @@ impl MiiSelector { let mut return_val = Box::::default(); unsafe { ctru_sys::miiSelectorLaunch(self.config.as_mut(), return_val.as_mut()) } + if return_val.no_mii_selected != 0 { + return Err(LaunchError::NoMiiSelected); + } + if unsafe { ctru_sys::miiSelectorChecksumIsValid(return_val.as_mut()) } { Ok((*return_val).into()) } else { From 1e158191ff2d74e7f9440cd15d8488366b74a182 Mon Sep 17 00:00:00 2001 From: DeltaF1 Date: Mon, 8 May 2023 12:23:44 -0400 Subject: [PATCH 2/4] Add documentation to LaunchError. Update mii-selector example. --- ctru-rs/examples/mii-selector.rs | 2 +- ctru-rs/src/applets/mii_selector.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index 363a034..2fc3d4f 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -10,13 +10,13 @@ fn main() { let _console = Console::new(gfx.top_screen.borrow_mut()); let mut mii_selector = MiiSelector::new(); + mii_selector.set_options(Options::MII_SELECTOR_CANCEL); mii_selector.set_initial_index(3); mii_selector.blacklist_user_mii(0.into()); mii_selector.set_title("Great Mii Selector!"); match mii_selector.launch() { Ok(result) => { - println!("Is Mii selected?: {:?}", result.is_mii_selected); println!("Mii type: {:?}", result.mii_type); println!("Name: {:?}", result.mii_data.name); println!("Author: {:?}", result.mii_data.author_name); diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index 4d89288..ca6f597 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -65,7 +65,10 @@ pub struct SelectionResult { /// Error type for the Mii selector #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum LaunchError { + /// The selected Mii's data is corrupt in some way InvalidChecksum, + + /// Either the user cancelled the selection (see [Options::MII_SELECTOR_CANCEL]), or no valid Miis were available to select NoMiiSelected, } From 827f00314df88c1673c8dd1dfe1e06770d496168 Mon Sep 17 00:00:00 2001 From: DeltaF1 Date: Mon, 8 May 2023 12:50:33 -0400 Subject: [PATCH 3/4] Fix missing use --- ctru-rs/examples/mii-selector.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctru-rs/examples/mii-selector.rs b/ctru-rs/examples/mii-selector.rs index 2fc3d4f..4602e9b 100644 --- a/ctru-rs/examples/mii-selector.rs +++ b/ctru-rs/examples/mii-selector.rs @@ -1,4 +1,4 @@ -use ctru::applets::mii_selector::{LaunchError, MiiSelector}; +use ctru::applets::mii_selector::{LaunchError, MiiSelector, Options}; use ctru::prelude::*; fn main() { From b50bacff4c7e7ca33515e8876580ee93d9076034 Mon Sep 17 00:00:00 2001 From: DeltaF1 Date: Mon, 8 May 2023 15:16:27 -0400 Subject: [PATCH 4/4] Remove is_mii_selected entirely, formatting --- ctru-rs/src/applets/mii_selector.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ctru-rs/src/applets/mii_selector.rs b/ctru-rs/src/applets/mii_selector.rs index ca6f597..bd0eac2 100644 --- a/ctru-rs/src/applets/mii_selector.rs +++ b/ctru-rs/src/applets/mii_selector.rs @@ -56,9 +56,6 @@ pub struct MiiSelector { #[derive(Clone, Debug)] pub struct SelectionResult { pub mii_data: MiiData, - - #[deprecated] - pub is_mii_selected: bool, pub mii_type: MiiType, } @@ -67,7 +64,6 @@ pub struct SelectionResult { pub enum LaunchError { /// The selected Mii's data is corrupt in some way InvalidChecksum, - /// Either the user cancelled the selection (see [Options::MII_SELECTOR_CANCEL]), or no valid Miis were available to select NoMiiSelected, } @@ -178,7 +174,6 @@ impl From for SelectionResult { SelectionResult { mii_data: raw_mii_data.into(), - is_mii_selected: ret.no_mii_selected == 0, mii_type: if ret.guest_mii_index != 0xFFFFFFFF { MiiType::Guest { index: ret.guest_mii_index,