Skip to content

Commit

Permalink
Add option to (un)block updates from within the boot selector and upd…
Browse files Browse the repository at this point in the history
…ate block warning
  • Loading branch information
Maschell committed May 6, 2024
1 parent 8f495d2 commit 7c987b5
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 9 deletions.
44 changes: 37 additions & 7 deletions source/MenuUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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--;

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion source/MenuUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions source/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions source/main.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#pragma once

extern bool gUpdatesBlocked;
46 changes: 46 additions & 0 deletions source/utils.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -30,4 +32,48 @@ 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;
}
6 changes: 5 additions & 1 deletion source/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent);
bool GetTitleIdOfDisc(uint64_t *titleId, bool *discPresent);

bool DeleteMLCUpdateDirectory();

bool RestoreMLCUpdateDirectory();

0 comments on commit 7c987b5

Please sign in to comment.