Skip to content

Commit

Permalink
Add error notifications if wiiloading a rpx/wuhb fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Nov 27, 2023
1 parent 458e3ba commit cee5d8e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM ghcr.io/wiiu-env/devkitppc:20230621
FROM ghcr.io/wiiu-env/devkitppc:20231112

COPY --from=ghcr.io/wiiu-env/libwupsbackend:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/librpxloader:20230621 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/libnotifications:20230621 /artifacts $DEVKITPRO

WORKDIR project
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
endif

LIBS := -lwups -lwut -lwupsbackend -lz -lrpxloader
LIBS := -lwups -lwut -lwupsbackend -lz -lrpxloader -lnotifications

#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
1. Copy the file `wiiload.wps` into `sd:/wiiu/environments/[ENVIRONMENT]/plugins`.
2. Requires the [WiiUPluginLoaderBackend](https://github.com/wiiu-env/WiiUPluginLoaderBackend) in `sd:/wiiu/environments/[ENVIRONMENT]/modules`.
3. Requires the [RPXLoadingModule](https://github.com/wiiu-env/RPXLoadingModule) in `sd:/wiiu/environments/[ENVIRONMENT]/modules`.
4. Requires the [NotificationModule](https://github.com/wiiu-env/NotificationModule) in `sd:/wiiu/environments/[ENVIRONMENT]/modules`.

## Buildflags

Expand Down
5 changes: 3 additions & 2 deletions src/globals.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "globals.h"

bool gLibRPXLoaderInitDone __attribute__((section(".data"))) = false;
bool gWiiloadServerEnabled __attribute__((section(".data"))) = true;
bool gLibRPXLoaderInitDone __attribute__((section(".data"))) = false;
bool gWiiloadServerEnabled __attribute__((section(".data"))) = true;
bool gNotificationModuleLoaded __attribute__((section(".data"))) = true;
3 changes: 2 additions & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdint.h>

extern bool gLibRPXLoaderInitDone;
extern bool gWiiloadServerEnabled;
extern bool gWiiloadServerEnabled;
extern bool gNotificationModuleLoaded;
10 changes: 10 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "utils/TcpReceiver.h"
#include "utils/logger.h"
#include <coreinit/debug.h>
#include <notifications/notifications.h>
#include <rpxloader/rpxloader.h>
#include <wups.h>
#include <wups/config/WUPSConfigItemBoolean.h>
Expand All @@ -28,6 +29,15 @@ INITIALIZE_PLUGIN() {
gLibRPXLoaderInitDone = true;
}

NotificationModuleStatus res;
if ((res = NotificationModule_InitLibrary()) != NOTIFICATION_MODULE_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init NotificationModule");
gNotificationModuleLoaded = false;
} else {
NotificationModule_SetDefaultValue(NOTIFICATION_MODULE_NOTIFICATION_TYPE_ERROR, NOTIFICATION_MODULE_DEFAULT_OPTION_DURATION_BEFORE_FADE_OUT, 10.0f);
gNotificationModuleLoaded = true;
}

// Open storage to read values
WUPSStorageError storageRes = WUPS_OpenStorage();
if (storageRes != WUPS_STORAGE_ERROR_SUCCESS) {
Expand Down
23 changes: 19 additions & 4 deletions src/utils/TcpReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <coreinit/dynload.h>
#include <coreinit/title.h>
#include <cstring>
#include <notifications/notifications.h>
#include <rpxloader/rpxloader.h>
#include <sysapp/launch.h>
#include <vector>
Expand Down Expand Up @@ -244,13 +245,21 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
file_path = WUHB_TEMP_FILE_2_EX;
}

if (!res) {
NotificationModule_AddErrorNotification("Wiiload plugin: Failed to save .wuhb file to the sd card. Launching will be aborted.");
}

loadedRPX = true;
} else if (inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] != 0x50 && inflatedData[0xA] != 0x4C) {
DEBUG_FUNCTION_LINE("Try to load a .rpx");
FSUtils::CreateSubfolder(RPX_TEMP_PATH);
res = FSUtils::saveBufferToFile(RPX_TEMP_FILE, inflatedData, fileSize);
file_path = RPX_TEMP_FILE_EX;
loadedRPX = true;

if (!res) {
NotificationModule_AddErrorNotification("Wiiload plugin: Failed to save .rpx file to the sd card. Launching will be aborted.");
}
} else if (inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] == 0x50 && inflatedData[0xA] == 0x4C) {
auto newContainer = WUPSBackend::PluginUtils::getPluginForBuffer((char *) inflatedData, fileSize);
if (newContainer) {
Expand All @@ -259,15 +268,14 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
auto &metaInformation = newContainer.value()->getMetaInformation();

// remove plugins with the same name and author as our new plugin

plugins.erase(std::remove_if(plugins.begin(), plugins.end(),
[metaInformation](auto &plugin) {
return plugin->getMetaInformation()->getName() == metaInformation->getName() &&
plugin->getMetaInformation()->getAuthor() == metaInformation->getAuthor();
}),
plugins.end());

// at the new plugin
// add the new plugin
plugins.push_back(std::move(newContainer.value()));

#ifdef VERBOSE_DEBUG
Expand All @@ -280,7 +288,8 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
#endif

if (WUPSBackend::PluginUtils::LoadAndLinkOnRestart(plugins) != 0) {
DEBUG_FUNCTION_LINE_ERR("Failed to load & link");
DEBUG_FUNCTION_LINE_ERR("WUPSBackend::PluginUtils::LoadAndLinkOnRestart failed");
NotificationModule_AddErrorNotification("Wiiload plugin: Failed to load plugin. Launching will be aborted.");
}

free(loadAddress);
Expand All @@ -289,6 +298,9 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
_SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr);
return fileSize;
} else {
if (NotificationModule_AddErrorNotification("Wiiload plugin: Failed to load or parse the plugin. Launching will be aborted.") != NOTIFICATION_MODULE_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to display error notification");
}
DEBUG_FUNCTION_LINE_ERR("Failed to parse plugin");
}
}
Expand All @@ -309,12 +321,15 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
} else if (loadAddress[0x7] == 0xCA && loadAddress[0x8] == 0xFE && loadAddress[0x9] == 0x50) {
OSFatal("Not implemented yet");
}
if (NotificationModule_AddErrorNotification("Failed to write file to the sd card.") != NOTIFICATION_MODULE_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to display error notification");
}
}

free(loadAddress);

if (!res) {
DEBUG_FUNCTION_LINE_ERR("Failed to launch save a homebrew to the sd card");
DEBUG_FUNCTION_LINE_ERR("Failed to launch/save a homebrew to the sd card");
return NOT_ENOUGH_MEMORY;
}

Expand Down

0 comments on commit cee5d8e

Please sign in to comment.