Browse Source

Apply suggestions (III)

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

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

@ -2,11 +2,11 @@ @@ -2,11 +2,11 @@
//!
//! This module contains basic methods to retrieve and change configuration from the console.
#[derive(Debug)]
#[derive(Clone, Debug)]
#[repr(u32)]
pub enum Region {
Japan = ctru_sys::CFG_REGION_JPN,
Usa = ctru_sys::CFG_REGION_USA,
USA = ctru_sys::CFG_REGION_USA,
Europe = ctru_sys::CFG_REGION_EUR,
Australia = ctru_sys::CFG_REGION_AUS,
China = ctru_sys::CFG_REGION_CHN,
@ -14,24 +14,24 @@ pub enum Region { @@ -14,24 +14,24 @@ pub enum Region {
Taiwan = ctru_sys::CFG_REGION_TWN,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
#[repr(u32)]
pub enum Language {
Japan = ctru_sys::CFG_LANGUAGE_JP,
English = ctru_sys::CFG_LANGUAGE_EN,
French = ctru_sys::CFG_LANGUAGE_FR,
German = ctru_sys::CFG_LANGUAGE_DE,
Italian = ctru_sys::CFG_LANGUAGE_IT,
Spanish = ctru_sys::CFG_LANGUAGE_ES,
SimpChinese = ctru_sys::CFG_LANGUAGE_ZH,
Korean = ctru_sys::CFG_LANGUAGE_KO,
Dutch = ctru_sys::CFG_LANGUAGE_NL,
Portuguese = ctru_sys::CFG_LANGUAGE_PT,
Russian = ctru_sys::CFG_LANGUAGE_RU,
TradChinese = ctru_sys::CFG_LANGUAGE_TW,
Japan = ctru_sys::CFG_LANGUAGE_JP,
English = ctru_sys::CFG_LANGUAGE_EN,
French = ctru_sys::CFG_LANGUAGE_FR,
German = ctru_sys::CFG_LANGUAGE_DE,
Italian = ctru_sys::CFG_LANGUAGE_IT,
Spanish = ctru_sys::CFG_LANGUAGE_ES,
SimplifiedChinese = ctru_sys::CFG_LANGUAGE_ZH,
Korean = ctru_sys::CFG_LANGUAGE_KO,
Dutch = ctru_sys::CFG_LANGUAGE_NL,
Portuguese = ctru_sys::CFG_LANGUAGE_PT,
Russian = ctru_sys::CFG_LANGUAGE_RU,
TraditionalChinese = ctru_sys::CFG_LANGUAGE_TW,
}
#[derive(Debug)]
#[derive(Clone, Debug)]
#[repr(u32)]
pub enum SystemModel {
Model3DS = ctru_sys::CFG_MODEL_3DS,
@ -73,78 +73,63 @@ impl Cfgu { @@ -73,78 +73,63 @@ impl Cfgu {
/// Gets system region from secure info
pub fn get_region(&self) -> crate::Result<Region> {
let mut region: u8 = 0;
let region_pointer: *mut u8 = &mut region;
unsafe {
let r = ctru_sys::CFGU_SecureInfoGetRegion(region_pointer);
if r < 0 {
Err(r.into())
} else {
// The system shouldn't give an invalid value
Ok(Region::try_from(region).unwrap())
}
let r = unsafe { ctru_sys::CFGU_SecureInfoGetRegion(&mut region) };
if r < 0 {
Err(r.into())
} else {
// The system shouldn't give an invalid value
Ok(Region::try_from(region).unwrap())
}
}
/// Gets system's model
pub fn get_model(&self) -> crate::Result<SystemModel> {
let mut model: u8 = 0;
let model_pointer: *mut u8 = &mut model;
unsafe {
let r = ctru_sys::CFGU_GetSystemModel(model_pointer);
if r < 0 {
Err(r.into())
} else {
// The system shouldn't give an invalid value
Ok(SystemModel::try_from(model).unwrap())
}
let r = unsafe { ctru_sys::CFGU_GetSystemModel(&mut model) };
if r < 0 {
Err(r.into())
} else {
// The system shouldn't give an invalid value
Ok(SystemModel::try_from(model).unwrap())
}
}
/// Gets system's language
pub fn get_language(&self) -> crate::Result<Language> {
let mut language: u8 = 0;
let language_pointer: *mut u8 = &mut language;
unsafe {
let r = ctru_sys::CFGU_GetSystemLanguage(language_pointer);
if r < 0 {
Err(r.into())
} else {
// The system shouldn't give an invalid value
Ok(Language::try_from(language).unwrap())
}
let r = unsafe { ctru_sys::CFGU_GetSystemLanguage(&mut language) };
if r < 0 {
Err(r.into())
} else {
// The system shouldn't give an invalid value
Ok(Language::try_from(language).unwrap())
}
}
/// Checks if NFC is supported by the console
pub fn is_nfc_supported(&self) -> crate::Result<bool> {
let mut supported: bool = false;
let supported_pointer: *mut bool = &mut supported;
unsafe {
let r = ctru_sys::CFGU_IsNFCSupported(supported_pointer);
if r < 0 {
Err(r.into())
} else {
Ok(supported)
}
let r = unsafe { ctru_sys::CFGU_IsNFCSupported(&mut supported) };
if r < 0 {
Err(r.into())
} else {
Ok(supported)
}
}
/// Check if the console is from the 2DS family (2DS, New2DS, New2DSXL)
pub fn is_2ds_family(&self) -> crate::Result<bool> {
let mut is_2ds_family: u8 = 0;
let is_2ds_family_pointer: *mut u8 = &mut is_2ds_family;
unsafe {
let r = ctru_sys::CFGU_GetModelNintendo2DS(is_2ds_family_pointer);
if r < 0 {
Err(r.into())
} else {
Ok(is_2ds_family < 1)
}
let r = unsafe { ctru_sys::CFGU_GetModelNintendo2DS(&mut is_2ds_family) };
if r < 0 {
Err(r.into())
} else {
Ok(is_2ds_family == 0)
}
}
}
@ -177,7 +162,7 @@ impl TryFrom<u8> for Region { @@ -177,7 +162,7 @@ impl TryFrom<u8> for Region {
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value as u32 {
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_AUS => Ok(Region::Australia),
ctru_sys::CFG_REGION_CHN => Ok(Region::China),
@ -199,12 +184,12 @@ impl TryFrom<u8> for Language { @@ -199,12 +184,12 @@ impl TryFrom<u8> for Language {
ctru_sys::CFG_LANGUAGE_DE => Ok(Language::German),
ctru_sys::CFG_LANGUAGE_IT => Ok(Language::Italian),
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_NL => Ok(Language::Dutch),
ctru_sys::CFG_LANGUAGE_PT => Ok(Language::Portuguese),
ctru_sys::CFG_LANGUAGE_RU => Ok(Language::Russian),
ctru_sys::CFG_LANGUAGE_TW => Ok(Language::TradChinese),
ctru_sys::CFG_LANGUAGE_RU => Ok(Language::Russian),
ctru_sys::CFG_LANGUAGE_TW => Ok(Language::TraditionalChinese),
_ => Err(())
}
}
@ -215,10 +200,10 @@ impl TryFrom<u8> for SystemModel { @@ -215,10 +200,10 @@ impl TryFrom<u8> for SystemModel {
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value as u32 {
ctru_sys::CFG_MODEL_3DS => Ok(SystemModel::Model3DS),
ctru_sys::CFG_MODEL_3DSXL => Ok(SystemModel::Model3DSXL),
ctru_sys::CFG_MODEL_N3DS => Ok(SystemModel::ModelNew3DS),
ctru_sys::CFG_MODEL_2DS => Ok(SystemModel::Model2DS),
ctru_sys::CFG_MODEL_3DS => Ok(SystemModel::Model3DS),
ctru_sys::CFG_MODEL_3DSXL => Ok(SystemModel::Model3DSXL),
ctru_sys::CFG_MODEL_N3DS => Ok(SystemModel::ModelNew3DS),
ctru_sys::CFG_MODEL_2DS => Ok(SystemModel::Model2DS),
ctru_sys::CFG_MODEL_N3DSXL => Ok(SystemModel::ModelNew3DSXL),
ctru_sys::CFG_MODEL_N2DSXL => Ok(SystemModel::ModelNew2DSXL),
_ => Err(())

Loading…
Cancel
Save