Code cleanup and formatting

This commit is contained in:
Maschell 2021-12-29 17:02:08 +01:00
parent af3a589a97
commit f7f38999cf

View File

@ -54,9 +54,8 @@ static const char* autoboot_config_strings[] = {
}; };
std::string configPath; std::string configPath;
int autobootOption = -1;
void readAutobootOption(){ int32_t readAutobootOption() {
FILE *f = fopen(configPath.c_str(), "r"); FILE *f = fopen(configPath.c_str(), "r");
if (f) { if (f) {
char buf[128]{}; char buf[128]{};
@ -65,20 +64,19 @@ void readAutobootOption(){
for (uint32_t i = 0; i < sizeof(autoboot_config_strings) / sizeof(char *); i++) { for (uint32_t i = 0; i < sizeof(autoboot_config_strings) / sizeof(char *); i++) {
if (strncmp(autoboot_config_strings[i], buf, strlen(autoboot_config_strings[i])) == 0) { if (strncmp(autoboot_config_strings[i], buf, strlen(autoboot_config_strings[i])) == 0) {
autobootOption = i; return i;
break;
} }
} }
} }
return -1;
} }
void writeAutobootOption(){ void writeAutobootOption(int32_t autobootOption) {
FILE *f = fopen(configPath.c_str(), "w"); FILE *f = fopen(configPath.c_str(), "w");
if (f) { if (f) {
if (autobootOption >= 0) { if (autobootOption >= 0) {
fputs(autoboot_config_strings[autobootOption], f); fputs(autoboot_config_strings[autobootOption], f);
} } else {
else {
fputs("none", f); fputs("none", f);
} }
@ -142,7 +140,7 @@ bool getQuickBoot() {
MCP_Close(handle); MCP_Close(handle);
if (err == 0) { if (err == 0) {
nn::act::Initialize(); nn::act::Initialize();
for (int i = 0; i < 13; i++) { for (int32_t i = 0; i < 13; i++) {
char uuid[16]; char uuid[16];
result = nn::act::GetUuidEx(uuid, i); result = nn::act::GetUuidEx(uuid, i);
if (result.IsSuccess()) { if (result.IsSuccess()) {
@ -167,14 +165,14 @@ bool getQuickBoot() {
return false; return false;
} }
static void initExternalStorage(void){ static void initExternalStorage() {
nn::spm::Initialize(); nn::spm::Initialize();
nn::spm::StorageListItem items[0x20]; nn::spm::StorageListItem items[0x20];
int32_t numItems = nn::spm::GetStorageList(items, 0x20); int32_t numItems = nn::spm::GetStorageList(items, 0x20);
bool found = false; bool found = false;
for (int i = 0; i < numItems; i++) { for (int32_t i = 0; i < numItems; i++) {
if (items[i].type == nn::spm::STORAGE_TYPE_WFS) { if (items[i].type == nn::spm::STORAGE_TYPE_WFS) {
nn::spm::StorageInfo info{}; nn::spm::StorageInfo info{};
if (nn::spm::GetStorageInfo(&info, &items[i].index) == 0) { if (nn::spm::GetStorageInfo(&info, &items[i].index) == 0) {
@ -202,7 +200,7 @@ static void initExternalStorage(void){
nn::spm::Finalize(); nn::spm::Finalize();
} }
void bootSystemMenu(void){ void bootWiiUMenu() {
nn::act::Initialize(); nn::act::Initialize();
nn::act::SlotNo slot = nn::act::GetSlotNo(); nn::act::SlotNo slot = nn::act::GetSlotNo();
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount(); nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
@ -215,7 +213,7 @@ void bootSystemMenu(void){
} }
} }
void bootHomebrewLauncher(void){ void bootHomebrewLauncher() {
uint64_t titleId = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_MII_MAKER); uint64_t titleId = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_MII_MAKER);
_SYSLaunchTitleWithStdArgsInNoSplash(titleId, nullptr); _SYSLaunchTitleWithStdArgsInNoSplash(titleId, nullptr);
} }
@ -240,23 +238,22 @@ static void launchvWiiTitle(uint32_t titleId_low, uint32_t titleId_high){
if (titleId_low == 0 && titleId_high == 0) { if (titleId_low == 0 && titleId_high == 0) {
CMPTLaunchMenu(dataBuffer, dataSize); CMPTLaunchMenu(dataBuffer, dataSize);
} } else {
else {
CMPTLaunchTitle(dataBuffer, dataSize, titleId_low, titleId_high); CMPTLaunchTitle(dataBuffer, dataSize, titleId_low, titleId_high);
} }
free(dataBuffer); free(dataBuffer);
} }
void bootvWiiMenu(void){ void bootvWiiMenu() {
launchvWiiTitle(0, 0); launchvWiiTitle(0, 0);
} }
void bootHomebrewChannel(void){ void bootHomebrewChannel() {
launchvWiiTitle(0x00010001, 0x4f484243); // 'OHBC' launchvWiiTitle(0x00010001, 0x4f484243); // 'OHBC'
} }
int handleMenuScreen(void){ int32_t handleMenuScreen(int32_t autobootOption) {
OSScreenInit(); OSScreenInit();
uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV);
@ -284,24 +281,20 @@ int handleMenuScreen(void){
selected--; selected--;
redraw = true; redraw = true;
} }
} } else if (vpad.trigger & VPAD_BUTTON_DOWN) {
else if (vpad.trigger & VPAD_BUTTON_DOWN) {
if (selected < sizeof(menu_options) / sizeof(char *) - 1) { if (selected < sizeof(menu_options) / sizeof(char *) - 1) {
selected++; selected++;
redraw = true; redraw = true;
} }
} } else if (vpad.trigger & VPAD_BUTTON_A) {
else if (vpad.trigger & VPAD_BUTTON_A) {
break; break;
} } else if (vpad.trigger & VPAD_BUTTON_X) {
else if (vpad.trigger & VPAD_BUTTON_X) {
autobootOption = -1; autobootOption = -1;
writeAutobootOption(); writeAutobootOption(autobootOption);
redraw = true; redraw = true;
} } else if (vpad.trigger & VPAD_BUTTON_Y) {
else if (vpad.trigger & VPAD_BUTTON_Y) {
autobootOption = selected; autobootOption = selected;
writeAutobootOption(); writeAutobootOption(autobootOption);
redraw = true; redraw = true;
} }
@ -353,7 +346,7 @@ int handleMenuScreen(void){
} }
int main(int argc, char **argv){ int32_t main(int32_t argc, char **argv) {
if (!WHBLogModuleInit()) { if (!WHBLogModuleInit()) {
WHBLogCafeInit(); WHBLogCafeInit();
WHBLogUdpInit(); WHBLogUdpInit();
@ -371,20 +364,19 @@ int main(int argc, char **argv){
configPath = std::string(argv[0]) + "/autoboot.cfg"; configPath = std::string(argv[0]) + "/autoboot.cfg";
} }
readAutobootOption(); int32_t bootSelection = readAutobootOption();
int bootSelection = autobootOption;
VPADStatus vpad{}; VPADStatus vpad{};
VPADRead(VPAD_CHAN_0, &vpad, 1, NULL); VPADRead(VPAD_CHAN_0, &vpad, 1, NULL);
if ((bootSelection == -1) || (vpad.hold & VPAD_BUTTON_PLUS)) { if ((bootSelection == -1) || (vpad.hold & VPAD_BUTTON_PLUS)) {
bootSelection = handleMenuScreen(); bootSelection = handleMenuScreen(bootSelection);
} }
if (bootSelection >= 0) { if (bootSelection >= 0) {
switch (bootSelection) { switch (bootSelection) {
case BOOT_OPTION_WII_U_MENU: case BOOT_OPTION_WII_U_MENU:
bootSystemMenu(); bootWiiUMenu();
break; break;
case BOOT_OPTION_HOMEBREW_LAUNCHER: case BOOT_OPTION_HOMEBREW_LAUNCHER:
bootHomebrewLauncher(); bootHomebrewLauncher();
@ -395,10 +387,12 @@ int main(int argc, char **argv){
case BOOT_OPTION_VWII_HOMEBREW_CHANNEL: case BOOT_OPTION_VWII_HOMEBREW_CHANNEL:
bootHomebrewChannel(); bootHomebrewChannel();
break; break;
default:
bootWiiUMenu();
break;
} }
} } else {
else { bootWiiUMenu();
bootSystemMenu();
} }
return 0; return 0;