AutobootModule/source/main.cpp

167 lines
5.1 KiB
C++
Raw Permalink Normal View History

#include "BootUtils.h"
2022-02-02 19:57:14 +01:00
#include "DrawUtils.h"
2023-06-06 10:29:53 +02:00
#include "InputUtils.h"
#include "MenuUtils.h"
2022-02-02 19:57:14 +01:00
#include "QuickStartUtils.h"
#include "StorageUtils.h"
#include "logger.h"
#include <coreinit/debug.h>
2022-09-04 21:19:54 +02:00
#include <coreinit/filesystem_fsa.h>
2024-07-04 17:28:32 +02:00
#include <coreinit/thread.h>
2024-05-05 02:16:14 +02:00
#include <coreinit/title.h>
2022-08-25 19:49:00 +02:00
#include <mocha/mocha.h>
#include <rpxloader/rpxloader.h>
#include <sndcore2/core.h>
#include <string>
#include <sys/stat.h>
2024-05-05 02:16:14 +02:00
#include <sysapp/launch.h>
2021-12-28 20:17:21 +01:00
#include <vpad/input.h>
2022-01-01 12:09:31 +01:00
bool gUpdatesBlocked = false;
2021-12-29 17:02:08 +01:00
int32_t main(int32_t argc, char **argv) {
initLogging();
DEBUG_FUNCTION_LINE("Hello from Autoboot Module");
2023-06-06 10:29:53 +02:00
InputUtils::Init();
2021-12-28 20:17:21 +01:00
initExternalStorage();
// Use librpxloader.
RPXLoaderStatus error3;
if ((error3 = RPXLoader_InitLibrary()) != RPX_LOADER_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("AutobootModule: Failed to init RPXLoader. This can be ignored when not running Aroma. Error %s [%d]", RPXLoader_GetStatusStr(error3), error3);
}
2024-05-05 02:16:14 +02:00
// If we are in System Transfer context we need to restart the app to actually
if (OSGetTitleID() == 0x0005001010062000L || OSGetTitleID() == 0x0005001010062100L || OSGetTitleID() == 0x0005001010062200L) {
_SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr);
deinitLogging();
return 0;
}
if (launchQuickStartTitle()) {
deinitLogging();
2021-12-28 20:17:21 +01:00
return 0;
}
2022-08-25 19:49:00 +02:00
if (Mocha_InitLibrary() != MOCHA_RESULT_SUCCESS) {
OSFatal("AutobootModule: Mocha_InitLibrary failed");
}
InputUtils::InputData buttons = InputUtils::getControllerInput();
2024-07-04 17:28:32 +02:00
bool hadMenu = false;
2022-09-04 21:19:54 +02:00
FSAInit();
auto client = FSAAddClient(nullptr);
if (client > 0) {
if (Mocha_UnlockFSClientEx(client) == MOCHA_RESULT_SUCCESS) {
// test if the update folder exists
2023-06-06 10:29:53 +02:00
FSADirectoryHandle dirHandle{};
if (FSAOpenDir(client, "/vol/storage_mlc01/sys/update", &dirHandle) >= 0) {
FSACloseDir(client, dirHandle);
gUpdatesBlocked = false;
if (!AXIsInit()) {
AXInit();
}
2022-09-04 21:19:54 +02:00
handleUpdateWarningScreen();
2024-07-04 17:28:32 +02:00
hadMenu = true;
} else {
FSAStat st{};
if (FSAGetStat(client, "/vol/storage_mlc01/sys/update", &st) != FS_ERROR_OK) {
DEBUG_FUNCTION_LINE_INFO("Created \"/vol/storage_mlc01/sys/update\" as file");
FSAFileHandle fd;
FSAOpenFileEx(client, "/vol/storage_mlc01/sys/update", "w", static_cast<FSMode>(0x666), FS_OPEN_FLAG_NONE, 0, &fd);
}
gUpdatesBlocked = true;
2022-09-04 21:19:54 +02:00
}
2023-01-11 10:50:29 +01:00
} else {
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");
2022-09-04 21:19:54 +02:00
}
FSADelClient(client);
2023-01-11 10:50:29 +01:00
} else {
DEBUG_FUNCTION_LINE_ERR("Failed to create FSA Client");
2022-09-04 21:19:54 +02:00
}
bool showvHBL = getVWiiHBLTitleId() != 0;
bool showHBL = false;
2022-03-30 16:35:12 +02:00
std::string configPath = "fs:/vol/external01/wiiu/autoboot.cfg";
if (argc >= 1) {
configPath = std::string(argv[0]) + "/autoboot.cfg";
auto hblInstallerPath = std::string(argv[0]) + "/modules/setup/50_hbl_installer.rpx";
struct stat st {};
if (stat(hblInstallerPath.c_str(), &st) >= 0) {
showHBL = true;
}
}
int32_t bootSelection = readAutobootOption(configPath);
2021-12-28 23:16:34 +01:00
std::map<uint32_t, std::string> menu;
menu[BOOT_OPTION_WII_U_MENU] = "Wii U Menu";
if (showHBL) {
menu[BOOT_OPTION_HOMEBREW_LAUNCHER] = "Homebrew Launcher";
}
menu[BOOT_OPTION_VWII_SYSTEM_MENU] = "vWii System Menu";
if (showvHBL) {
menu[BOOT_OPTION_VWII_HOMEBREW_CHANNEL] = "vWii Homebrew Channel";
}
if ((bootSelection == -1) ||
(bootSelection == BOOT_OPTION_HOMEBREW_LAUNCHER && !showHBL) ||
(bootSelection == BOOT_OPTION_VWII_HOMEBREW_CHANNEL && !showvHBL) ||
2023-06-06 10:29:53 +02:00
(buttons.hold & VPAD_BUTTON_PLUS)) {
if (!AXIsInit()) {
AXInit();
}
bootSelection = handleMenuScreen(configPath, bootSelection, menu);
2024-07-04 17:28:32 +02:00
hadMenu = true;
2021-12-28 20:17:21 +01:00
}
2021-12-28 23:16:34 +01:00
if (bootSelection >= 0) {
switch (bootSelection) {
2021-12-29 17:02:08 +01:00
case BOOT_OPTION_WII_U_MENU:
bootWiiUMenu();
break;
case BOOT_OPTION_HOMEBREW_LAUNCHER:
if (!showHBL) {
bootWiiUMenu();
break;
}
2021-12-29 17:02:08 +01:00
bootHomebrewLauncher();
break;
case BOOT_OPTION_VWII_SYSTEM_MENU:
bootvWiiMenu();
break;
case BOOT_OPTION_VWII_HOMEBREW_CHANNEL:
if (!showvHBL) {
bootvWiiMenu();
break;
}
2021-12-29 17:02:08 +01:00
bootHomebrewChannel();
break;
default:
bootWiiUMenu();
break;
2021-12-28 23:16:34 +01:00
}
2021-12-29 17:02:08 +01:00
} else {
bootWiiUMenu();
2021-12-28 23:16:34 +01:00
}
2021-12-28 20:17:21 +01:00
2023-06-06 10:29:53 +02:00
InputUtils::DeInit();
2022-09-04 00:08:31 +02:00
Mocha_DeInitLibrary();
deinitLogging();
if (AXIsInit()) {
AXQuit();
}
2024-07-04 17:28:32 +02:00
if (!hadMenu) {
DrawUtils::ClearSavedFrameBuffers();
}
2021-12-28 20:17:21 +01:00
return 0;
}