Add option to (un)block updates from within the boot selector and update block warning

This commit is contained in:
Maschell 2024-05-06 13:25:44 +02:00
parent 8f495d213f
commit 7c987b5b9d
7 changed files with 105 additions and 9 deletions

View File

@ -4,15 +4,18 @@
#include "InputUtils.h"
#include "PairUtils.h"
#include "logger.h"
#include "main.h"
#include "utils.h"
#include "version.h"
#include <coreinit/debug.h>
#include <coreinit/filesystem_fsa.h>
#include <coreinit/screen.h>
#include <coreinit/thread.h>
#include <cstring>
#include <gx2/state.h>
#include <malloc.h>
#include <memory>
#include <mocha/mocha.h>
#include <string>
#include <sysapp/title.h>
#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::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";
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();
}
@ -133,16 +144,18 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput, c
}
}
{
PairMenu pairMenu;
int32_t holdUpdateBlockedForFrames = 0;
while (true) {
if (pairMenu.ProcessPairScreen()) {
continue;
}
InputUtils::InputData input = InputUtils::getControllerInput();
if (input.trigger & VPAD_BUTTON_UP) {
selectedIndex--;
@ -164,10 +177,20 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput, c
autobootIndex = -1;
} else if (input.trigger & (VPAD_BUTTON_Y | VPAD_BUTTON_PLUS)) {
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);
drawMenuScreen(menu, selectedIndex, autobootIndex, gUpdatesBlocked);
}
}
@ -335,7 +358,7 @@ void drawUpdateWarningScreen() {
DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BACKGROUND_WARN);
DrawUtils::setFontColor(COLOR_TEXT);
DrawUtils::setFontColor(COLOR_WARNING);
// draw top bar
DrawUtils::setFontSize(48);
@ -349,8 +372,12 @@ void drawUpdateWarningScreen() {
DrawUtils::print(SCREEN_WIDTH / 2 + DrawUtils::getTextWidth(message) / 2, SCREEN_HEIGHT / 2 - 48, message, true);
message = "Your system might not be blocking updates properly!";
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.";
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);
@ -360,7 +387,7 @@ void drawUpdateWarningScreen() {
// draw bottom bar
DrawUtils::drawRectFilled(8, SCREEN_HEIGHT - 24 - 8 - 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_WHITE);
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::endDraw();
@ -400,6 +427,9 @@ void handleUpdateWarningScreen() {
InputUtils::InputData input = InputUtils::getControllerInput();
if (input.trigger & VPAD_BUTTON_A) {
break;
} else if (input.trigger & VPAD_BUTTON_X) {
gUpdatesBlocked = DeleteMLCUpdateDirectory();
break;
} else if (input.trigger & VPAD_BUTTON_B) {
f = fopen(UPDATE_SKIP_PATH, "w");
if (f) {

View File

@ -13,8 +13,9 @@
#define COLOR_WHITE Color(0xffffffff)
#define COLOR_BLACK Color(0, 0, 0, 255)
#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_WARNING COLOR_BLACK
#define COLOR_TEXT2 Color(0xB3ffffff)
#define COLOR_AUTOBOOT Color(0xaeea00ff)
#define COLOR_BORDER Color(204, 204, 204, 255)

View File

@ -41,6 +41,7 @@ extern "C" {
#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_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);
@ -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_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);

View File

@ -31,6 +31,8 @@ void clearScreen() {
free(buffer);
}
bool gUpdatesBlocked = false;
int32_t main(int32_t argc, char **argv) {
initLogging();
DEBUG_FUNCTION_LINE("Hello from Autoboot Module");
@ -76,7 +78,16 @@ int32_t main(int32_t argc, char **argv) {
FSADirectoryHandle dirHandle{};
if (FSAOpenDir(client, "/vol/storage_mlc01/sys/update", &dirHandle) >= 0) {
FSACloseDir(client, dirHandle);
gUpdatesBlocked = false;
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 {
DEBUG_FUNCTION_LINE_ERR("Failed to unlock FSA Client");

View File

@ -1 +1,3 @@
#pragma once
extern bool gUpdatesBlocked;

View File

@ -1,5 +1,7 @@
#include "logger.h"
#include <coreinit/filesystem_fsa.h>
#include <coreinit/mcp.h>
#include <mocha/mocha.h>
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent) {
if (discPresent) {
@ -31,3 +33,47 @@ bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent) {
}
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;
}

View File

@ -29,3 +29,7 @@ std::string string_format(const std::string &format, Args... args) {
}
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent);
bool DeleteMLCUpdateDirectory();
bool RestoreMLCUpdateDirectory();