Browse Source

Apply suggestions (III)

pull/63/head
TechiePi 2 years ago
parent
commit
7fa7137b39
  1. 45
      ctru-rs/src/services/cfgu.rs

45
ctru-rs/src/services/cfgu.rs

@ -2,11 +2,11 @@
//! //!
//! This module contains basic methods to retrieve and change configuration from the console. //! This module contains basic methods to retrieve and change configuration from the console.
#[derive(Debug)] #[derive(Clone, Debug)]
#[repr(u32)] #[repr(u32)]
pub enum Region { pub enum Region {
Japan = ctru_sys::CFG_REGION_JPN, Japan = ctru_sys::CFG_REGION_JPN,
Usa = ctru_sys::CFG_REGION_USA, USA = ctru_sys::CFG_REGION_USA,
Europe = ctru_sys::CFG_REGION_EUR, Europe = ctru_sys::CFG_REGION_EUR,
Australia = ctru_sys::CFG_REGION_AUS, Australia = ctru_sys::CFG_REGION_AUS,
China = ctru_sys::CFG_REGION_CHN, China = ctru_sys::CFG_REGION_CHN,
@ -14,7 +14,7 @@ pub enum Region {
Taiwan = ctru_sys::CFG_REGION_TWN, Taiwan = ctru_sys::CFG_REGION_TWN,
} }
#[derive(Debug)] #[derive(Clone, Debug)]
#[repr(u32)] #[repr(u32)]
pub enum Language { pub enum Language {
Japan = ctru_sys::CFG_LANGUAGE_JP, Japan = ctru_sys::CFG_LANGUAGE_JP,
@ -23,15 +23,15 @@ pub enum Language {
German = ctru_sys::CFG_LANGUAGE_DE, German = ctru_sys::CFG_LANGUAGE_DE,
Italian = ctru_sys::CFG_LANGUAGE_IT, Italian = ctru_sys::CFG_LANGUAGE_IT,
Spanish = ctru_sys::CFG_LANGUAGE_ES, Spanish = ctru_sys::CFG_LANGUAGE_ES,
SimpChinese = ctru_sys::CFG_LANGUAGE_ZH, SimplifiedChinese = ctru_sys::CFG_LANGUAGE_ZH,
Korean = ctru_sys::CFG_LANGUAGE_KO, Korean = ctru_sys::CFG_LANGUAGE_KO,
Dutch = ctru_sys::CFG_LANGUAGE_NL, Dutch = ctru_sys::CFG_LANGUAGE_NL,
Portuguese = ctru_sys::CFG_LANGUAGE_PT, Portuguese = ctru_sys::CFG_LANGUAGE_PT,
Russian = ctru_sys::CFG_LANGUAGE_RU, Russian = ctru_sys::CFG_LANGUAGE_RU,
TradChinese = ctru_sys::CFG_LANGUAGE_TW, TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW,
} }
#[derive(Debug)] #[derive(Clone, Debug)]
#[repr(u32)] #[repr(u32)]
pub enum SystemModel { pub enum SystemModel {
Model3DS = ctru_sys::CFG_MODEL_3DS, Model3DS = ctru_sys::CFG_MODEL_3DS,
@ -73,10 +73,8 @@ impl Cfgu {
/// Gets system region from secure info /// Gets system region from secure info
pub fn get_region(&self) -> crate::Result<Region> { pub fn get_region(&self) -> crate::Result<Region> {
let mut region: u8 = 0; let mut region: u8 = 0;
let region_pointer: *mut u8 = &mut region;
unsafe { let r = unsafe { ctru_sys::CFGU_SecureInfoGetRegion(&mut region) };
let r = ctru_sys::CFGU_SecureInfoGetRegion(region_pointer);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -84,15 +82,12 @@ impl Cfgu {
Ok(Region::try_from(region).unwrap()) Ok(Region::try_from(region).unwrap())
} }
} }
}
/// Gets system's model /// Gets system's model
pub fn get_model(&self) -> crate::Result<SystemModel> { pub fn get_model(&self) -> crate::Result<SystemModel> {
let mut model: u8 = 0; let mut model: u8 = 0;
let model_pointer: *mut u8 = &mut model;
unsafe { let r = unsafe { ctru_sys::CFGU_GetSystemModel(&mut model) };
let r = ctru_sys::CFGU_GetSystemModel(model_pointer);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -100,15 +95,12 @@ impl Cfgu {
Ok(SystemModel::try_from(model).unwrap()) Ok(SystemModel::try_from(model).unwrap())
} }
} }
}
/// Gets system's language /// Gets system's language
pub fn get_language(&self) -> crate::Result<Language> { pub fn get_language(&self) -> crate::Result<Language> {
let mut language: u8 = 0; let mut language: u8 = 0;
let language_pointer: *mut u8 = &mut language;
unsafe { let r = unsafe { ctru_sys::CFGU_GetSystemLanguage(&mut language) };
let r = ctru_sys::CFGU_GetSystemLanguage(language_pointer);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -116,35 +108,28 @@ impl Cfgu {
Ok(Language::try_from(language).unwrap()) Ok(Language::try_from(language).unwrap())
} }
} }
}
/// Checks if NFC is supported by the console /// Checks if NFC is supported by the console
pub fn is_nfc_supported(&self) -> crate::Result<bool> { pub fn is_nfc_supported(&self) -> crate::Result<bool> {
let mut supported: bool = false; let mut supported: bool = false;
let supported_pointer: *mut bool = &mut supported;
unsafe { let r = unsafe { ctru_sys::CFGU_IsNFCSupported(&mut supported) };
let r = ctru_sys::CFGU_IsNFCSupported(supported_pointer);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
Ok(supported) Ok(supported)
} }
} }
}
/// Check if the console is from the 2DS family (2DS, New2DS, New2DSXL) /// Check if the console is from the 2DS family (2DS, New2DS, New2DSXL)
pub fn is_2ds_family(&self) -> crate::Result<bool> { pub fn is_2ds_family(&self) -> crate::Result<bool> {
let mut is_2ds_family: u8 = 0; let mut is_2ds_family: u8 = 0;
let is_2ds_family_pointer: *mut u8 = &mut is_2ds_family;
unsafe { let r = unsafe { ctru_sys::CFGU_GetModelNintendo2DS(&mut is_2ds_family) };
let r = ctru_sys::CFGU_GetModelNintendo2DS(is_2ds_family_pointer);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
Ok(is_2ds_family < 1) Ok(is_2ds_family == 0)
}
} }
} }
} }
@ -177,7 +162,7 @@ impl TryFrom<u8> for Region {
fn try_from(value: u8) -> Result<Self, Self::Error> { fn try_from(value: u8) -> Result<Self, Self::Error> {
match value as u32 { match value as u32 {
ctru_sys::CFG_REGION_JPN => Ok(Region::Japan), ctru_sys::CFG_REGION_JPN => Ok(Region::Japan),
ctru_sys::CFG_REGION_USA => Ok(Region::Usa), ctru_sys::CFG_REGION_USA => Ok(Region::USA),
ctru_sys::CFG_REGION_EUR => Ok(Region::Europe), ctru_sys::CFG_REGION_EUR => Ok(Region::Europe),
ctru_sys::CFG_REGION_AUS => Ok(Region::Australia), ctru_sys::CFG_REGION_AUS => Ok(Region::Australia),
ctru_sys::CFG_REGION_CHN => Ok(Region::China), ctru_sys::CFG_REGION_CHN => Ok(Region::China),
@ -199,12 +184,12 @@ impl TryFrom<u8> for Language {
ctru_sys::CFG_LANGUAGE_DE => Ok(Language::German), ctru_sys::CFG_LANGUAGE_DE => Ok(Language::German),
ctru_sys::CFG_LANGUAGE_IT => Ok(Language::Italian), ctru_sys::CFG_LANGUAGE_IT => Ok(Language::Italian),
ctru_sys::CFG_LANGUAGE_ES => Ok(Language::Spanish), ctru_sys::CFG_LANGUAGE_ES => Ok(Language::Spanish),
ctru_sys::CFG_LANGUAGE_ZH => Ok(Language::SimpChinese), ctru_sys::CFG_LANGUAGE_ZH => Ok(Language::SimplifiedChinese),
ctru_sys::CFG_LANGUAGE_KO => Ok(Language::Korean), ctru_sys::CFG_LANGUAGE_KO => Ok(Language::Korean),
ctru_sys::CFG_LANGUAGE_NL => Ok(Language::Dutch), ctru_sys::CFG_LANGUAGE_NL => Ok(Language::Dutch),
ctru_sys::CFG_LANGUAGE_PT => Ok(Language::Portuguese), ctru_sys::CFG_LANGUAGE_PT => Ok(Language::Portuguese),
ctru_sys::CFG_LANGUAGE_RU => Ok(Language::Russian), ctru_sys::CFG_LANGUAGE_RU => Ok(Language::Russian),
ctru_sys::CFG_LANGUAGE_TW => Ok(Language::TradChinese), ctru_sys::CFG_LANGUAGE_TW => Ok(Language::TraditionalChinese),
_ => Err(()) _ => Err(())
} }
} }

Loading…
Cancel
Save