mirror of
https://github.com/wiiu-env/AutobootModule.git
synced 2024-11-22 02:49:16 +01:00
Add option to (un)block updates from within the boot selector and update block warning
This commit is contained in:
parent
8f495d213f
commit
7c987b5b9d
@ -4,15 +4,18 @@
|
|||||||
#include "InputUtils.h"
|
#include "InputUtils.h"
|
||||||
#include "PairUtils.h"
|
#include "PairUtils.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "main.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
|
#include <coreinit/filesystem_fsa.h>
|
||||||
#include <coreinit/screen.h>
|
#include <coreinit/screen.h>
|
||||||
#include <coreinit/thread.h>
|
#include <coreinit/thread.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <gx2/state.h>
|
#include <gx2/state.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mocha/mocha.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sysapp/title.h>
|
#include <sysapp/title.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -55,7 +58,7 @@ void writeAutobootOption(std::string &configPath, int32_t autobootOption) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMenuScreen(const std::map<uint32_t, std::string> &menu, uint32_t selectedIndex, uint32_t autobootIndex) {
|
void drawMenuScreen(const std::map<uint32_t, std::string> &menu, uint32_t selectedIndex, uint32_t autobootIndex, bool updatesBlocked) {
|
||||||
DrawUtils::beginDraw();
|
DrawUtils::beginDraw();
|
||||||
DrawUtils::clear(COLOR_BACKGROUND);
|
DrawUtils::clear(COLOR_BACKGROUND);
|
||||||
|
|
||||||
@ -93,6 +96,14 @@ void drawMenuScreen(const std::map<uint32_t, std::string> &menu, uint32_t select
|
|||||||
const char *autobootHints = "\ue002/\ue046 Clear Autoboot / \ue003/\ue045 Select Autoboot";
|
const char *autobootHints = "\ue002/\ue046 Clear Autoboot / \ue003/\ue045 Select Autoboot";
|
||||||
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(autobootHints) / 2, SCREEN_HEIGHT - 8, autobootHints, true);
|
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(autobootHints) / 2, SCREEN_HEIGHT - 8, autobootHints, true);
|
||||||
|
|
||||||
|
if (updatesBlocked) {
|
||||||
|
DrawUtils::setFontSize(10);
|
||||||
|
DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 24 - 8 - 4 - 10, "Updates blocked! Hold \ue045 + \ue046 to restore Update folder", true);
|
||||||
|
} else {
|
||||||
|
DrawUtils::setFontSize(10);
|
||||||
|
DrawUtils::print(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 24 - 8 - 4 - 10, "Updates not blocked! Hold \ue045 + \ue046 to delete Update folder", true);
|
||||||
|
}
|
||||||
|
|
||||||
DrawUtils::endDraw();
|
DrawUtils::endDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,16 +144,18 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
PairMenu pairMenu;
|
PairMenu pairMenu;
|
||||||
|
|
||||||
|
int32_t holdUpdateBlockedForFrames = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (pairMenu.ProcessPairScreen()) {
|
if (pairMenu.ProcessPairScreen()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
InputUtils::InputData input = InputUtils::getControllerInput();
|
InputUtils::InputData input = InputUtils::getControllerInput();
|
||||||
|
|
||||||
if (input.trigger & VPAD_BUTTON_UP) {
|
if (input.trigger & VPAD_BUTTON_UP) {
|
||||||
selectedIndex--;
|
selectedIndex--;
|
||||||
|
|
||||||
@ -164,10 +177,20 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput, c
|
|||||||
autobootIndex = -1;
|
autobootIndex = -1;
|
||||||
} else if (input.trigger & (VPAD_BUTTON_Y | VPAD_BUTTON_PLUS)) {
|
} else if (input.trigger & (VPAD_BUTTON_Y | VPAD_BUTTON_PLUS)) {
|
||||||
autobootIndex = selectedIndex;
|
autobootIndex = selectedIndex;
|
||||||
|
} else if ((input.hold & (VPAD_BUTTON_PLUS | VPAD_BUTTON_MINUS)) == (VPAD_BUTTON_PLUS | VPAD_BUTTON_MINUS)) {
|
||||||
|
if (holdUpdateBlockedForFrames++ > 50) {
|
||||||
|
if (gUpdatesBlocked) {
|
||||||
|
gUpdatesBlocked = !RestoreMLCUpdateDirectory();
|
||||||
|
} else {
|
||||||
|
gUpdatesBlocked = DeleteMLCUpdateDirectory();
|
||||||
|
}
|
||||||
|
holdUpdateBlockedForFrames = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
holdUpdateBlockedForFrames = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawMenuScreen(menu, selectedIndex, autobootIndex, gUpdatesBlocked);
|
||||||
drawMenuScreen(menu, selectedIndex, autobootIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +358,7 @@ void drawUpdateWarningScreen() {
|
|||||||
DrawUtils::beginDraw();
|
DrawUtils::beginDraw();
|
||||||
DrawUtils::clear(COLOR_BACKGROUND_WARN);
|
DrawUtils::clear(COLOR_BACKGROUND_WARN);
|
||||||
|
|
||||||
DrawUtils::setFontColor(COLOR_TEXT);
|
DrawUtils::setFontColor(COLOR_WARNING);
|
||||||
|
|
||||||
// draw top bar
|
// draw top bar
|
||||||
DrawUtils::setFontSize(48);
|
DrawUtils::setFontSize(48);
|
||||||
@ -349,8 +372,12 @@ void drawUpdateWarningScreen() {
|
|||||||
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 - 48, message, true);
|
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 - 48, message, true);
|
||||||
message = "Your system might not be blocking updates properly!";
|
message = "Your system might not be blocking updates properly!";
|
||||||
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 - 24, message, true);
|
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 - 24, message, true);
|
||||||
|
|
||||||
|
message = "Press \ue002 to block the updates! This can be reverted in the Boot Selector.";
|
||||||
|
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 + 24, message, true);
|
||||||
|
|
||||||
message = "See https://wiiu.hacks.guide/#/block-updates for more information.";
|
message = "See https://wiiu.hacks.guide/#/block-updates for more information.";
|
||||||
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 + 0, message, true);
|
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 + 64 + 24, message, true);
|
||||||
|
|
||||||
DrawUtils::setFontSize(16);
|
DrawUtils::setFontSize(16);
|
||||||
|
|
||||||
@ -360,7 +387,7 @@ void drawUpdateWarningScreen() {
|
|||||||
// draw bottom bar
|
// draw bottom bar
|
||||||
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_WHITE);
|
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_WHITE);
|
||||||
DrawUtils::setFontSize(18);
|
DrawUtils::setFontSize(18);
|
||||||
const char *exitHints = "\ue000 Continue / \ue001 Don't show this again";
|
const char *exitHints = "\ue000 Continue without blocking / \ue001 Don't show this again";
|
||||||
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHints) / 2, SCREEN_HEIGHT - 8, exitHints, true);
|
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(exitHints) / 2, SCREEN_HEIGHT - 8, exitHints, true);
|
||||||
|
|
||||||
DrawUtils::endDraw();
|
DrawUtils::endDraw();
|
||||||
@ -400,6 +427,9 @@ void handleUpdateWarningScreen() {
|
|||||||
InputUtils::InputData input = InputUtils::getControllerInput();
|
InputUtils::InputData input = InputUtils::getControllerInput();
|
||||||
if (input.trigger & VPAD_BUTTON_A) {
|
if (input.trigger & VPAD_BUTTON_A) {
|
||||||
break;
|
break;
|
||||||
|
} else if (input.trigger & VPAD_BUTTON_X) {
|
||||||
|
gUpdatesBlocked = DeleteMLCUpdateDirectory();
|
||||||
|
break;
|
||||||
} else if (input.trigger & VPAD_BUTTON_B) {
|
} else if (input.trigger & VPAD_BUTTON_B) {
|
||||||
f = fopen(UPDATE_SKIP_PATH, "w");
|
f = fopen(UPDATE_SKIP_PATH, "w");
|
||||||
if (f) {
|
if (f) {
|
||||||
|
@ -13,8 +13,9 @@
|
|||||||
#define COLOR_WHITE Color(0xffffffff)
|
#define COLOR_WHITE Color(0xffffffff)
|
||||||
#define COLOR_BLACK Color(0, 0, 0, 255)
|
#define COLOR_BLACK Color(0, 0, 0, 255)
|
||||||
#define COLOR_BACKGROUND COLOR_BLACK
|
#define COLOR_BACKGROUND COLOR_BLACK
|
||||||
#define COLOR_BACKGROUND_WARN Color(255, 40, 0, 255)
|
#define COLOR_BACKGROUND_WARN Color(255, 251, 4, 255)
|
||||||
#define COLOR_TEXT COLOR_WHITE
|
#define COLOR_TEXT COLOR_WHITE
|
||||||
|
#define COLOR_WARNING COLOR_BLACK
|
||||||
#define COLOR_TEXT2 Color(0xB3ffffff)
|
#define COLOR_TEXT2 Color(0xB3ffffff)
|
||||||
#define COLOR_AUTOBOOT Color(0xaeea00ff)
|
#define COLOR_AUTOBOOT Color(0xaeea00ff)
|
||||||
#define COLOR_BORDER Color(204, 204, 204, 255)
|
#define COLOR_BORDER Color(204, 204, 204, 255)
|
||||||
|
@ -41,6 +41,7 @@ extern "C" {
|
|||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "## WARN## ", "", FMT, ##ARGS)
|
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "## WARN## ", "", FMT, ##ARGS)
|
||||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
|
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
|
||||||
|
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "## INFO## ", "", FMT, ##ARGS)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
|
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ extern "C" {
|
|||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "## WARN## ", "\n", FMT, ##ARGS)
|
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "## WARN## ", "\n", FMT, ##ARGS)
|
||||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
|
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
|
||||||
|
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "## INFO## ", "\n", FMT, ##ARGS)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);
|
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);
|
||||||
|
|
||||||
|
@ -31,6 +31,8 @@ void clearScreen() {
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gUpdatesBlocked = false;
|
||||||
|
|
||||||
int32_t main(int32_t argc, char **argv) {
|
int32_t main(int32_t argc, char **argv) {
|
||||||
initLogging();
|
initLogging();
|
||||||
DEBUG_FUNCTION_LINE("Hello from Autoboot Module");
|
DEBUG_FUNCTION_LINE("Hello from Autoboot Module");
|
||||||
@ -76,7 +78,16 @@ int32_t main(int32_t argc, char **argv) {
|
|||||||
FSADirectoryHandle dirHandle{};
|
FSADirectoryHandle dirHandle{};
|
||||||
if (FSAOpenDir(client, "/vol/storage_mlc01/sys/update", &dirHandle) >= 0) {
|
if (FSAOpenDir(client, "/vol/storage_mlc01/sys/update", &dirHandle) >= 0) {
|
||||||
FSACloseDir(client, dirHandle);
|
FSACloseDir(client, dirHandle);
|
||||||
|
gUpdatesBlocked = false;
|
||||||
handleUpdateWarningScreen();
|
handleUpdateWarningScreen();
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");
|
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");
|
||||||
|
@ -1 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
extern bool gUpdatesBlocked;
|
@ -1,5 +1,7 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include <coreinit/filesystem_fsa.h>
|
||||||
#include <coreinit/mcp.h>
|
#include <coreinit/mcp.h>
|
||||||
|
#include <mocha/mocha.h>
|
||||||
|
|
||||||
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent) {
|
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent) {
|
||||||
if (discPresent) {
|
if (discPresent) {
|
||||||
@ -30,4 +32,48 @@ bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DeleteMLCUpdateDirectory() {
|
||||||
|
bool result = false;
|
||||||
|
auto client = FSAAddClient(nullptr);
|
||||||
|
if (client > 0) {
|
||||||
|
if (Mocha_UnlockFSClientEx(client) == MOCHA_RESULT_SUCCESS) {
|
||||||
|
if (FSARemove(client, "/vol/storage_mlc01/sys/update") != FS_ERROR_OK) {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to remove update directory");
|
||||||
|
} else {
|
||||||
|
FSAFileHandle fd;
|
||||||
|
if (FSAOpenFileEx(client, "/vol/storage_mlc01/sys/update", "w", static_cast<FSMode>(0x666), FS_OPEN_FLAG_NONE, 0, &fd) != FS_ERROR_OK) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Failed to create update file");
|
||||||
|
}
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");
|
||||||
|
}
|
||||||
|
FSADelClient(client);
|
||||||
|
} else {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to create FSA Client");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RestoreMLCUpdateDirectory() {
|
||||||
|
bool result = false;
|
||||||
|
auto client = FSAAddClient(nullptr);
|
||||||
|
if (client > 0) {
|
||||||
|
if (Mocha_UnlockFSClientEx(client) == MOCHA_RESULT_SUCCESS) {
|
||||||
|
FSARemove(client, "/vol/storage_mlc01/sys/update"); // Remove any existing files
|
||||||
|
if (FSAMakeDir(client, "/vol/storage_mlc01/sys/update", static_cast<FSMode>(0x666)) != FS_ERROR_OK) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Failed to restore update directory");
|
||||||
|
}
|
||||||
|
result = true;
|
||||||
|
} else {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");
|
||||||
|
}
|
||||||
|
FSADelClient(client);
|
||||||
|
} else {
|
||||||
|
DEBUG_FUNCTION_LINE_ERR("Failed to create FSA Client");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
@ -28,4 +28,8 @@ std::string string_format(const std::string &format, Args... args) {
|
|||||||
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent);
|
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent);
|
||||||
|
|
||||||
|
bool DeleteMLCUpdateDirectory();
|
||||||
|
|
||||||
|
bool RestoreMLCUpdateDirectory();
|
Loading…
Reference in New Issue
Block a user