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