Skip to content

Commit

Permalink
Rewrite logic, clean up and remove unused parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Apr 27, 2024
1 parent 9d44e51 commit d4984da
Show file tree
Hide file tree
Showing 22 changed files with 441 additions and 1,368 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cmake-build-debug/
.idea/
*.rpx
*.txt
*.zip
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ghcr.io/wiiu-env/devkitppc:20231112

COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20231221-ca17105 /artifacts $DEVKITPRO
COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20240302-3b5cc2f /artifacts $DEVKITPRO
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/libnotifications:20230621 /artifacts $DEVKITPRO
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ WUMS_ROOT := $(DEVKITPRO)/wums
TARGET := wiiload
BUILD := build
SOURCES := src \
src/fs \
src/utils
DATA := data
INCLUDES := src
Expand Down
71 changes: 71 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "config.h"
#include "globals.h"
#include "utils/TcpReceiver.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include <string>
#include <wups/config/WUPSConfigItemBoolean.h>
#include <wups/storage.h>

static void gServerEnabledChanged(ConfigItemBoolean *item, bool newValue) {
if (std::string_view(WIILOAD_ENABLED_STRING) != item->identifier) {
DEBUG_FUNCTION_LINE_WARN("Unexpected identifier in bool callback: %s", item->identifier);
return;
}
DEBUG_FUNCTION_LINE_VERBOSE("New value in gWiiloadServerEnabled: %d", newValue);
gWiiloadServerEnabled = newValue;

gTcpReceiverThread.reset();

if (gWiiloadServerEnabled) {
DEBUG_FUNCTION_LINE("Starting server!");
gTcpReceiverThread = make_unique_nothrow<TcpReceiver>(4299);
if (gTcpReceiverThread == nullptr) {
DEBUG_FUNCTION_LINE_ERR("Failed to create wiiload thread");
}
} else {
DEBUG_FUNCTION_LINE("Wiiload server has been stopped!");
}
// If the value has changed, we store it in the storage.
WUPSStorageError res;
if ((res = WUPSStorageAPI::Store(item->identifier, gWiiloadServerEnabled)) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to store gWiiloadServerEnabled: %s (%d)", WUPSStorageAPI_GetStatusStr(res), res);
}
}

static WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback(WUPSConfigCategoryHandle rootHandle) {
try {
WUPSConfigCategory root = WUPSConfigCategory(rootHandle);

root.add(WUPSConfigItemBoolean::Create(WIILOAD_ENABLED_STRING, "Enable Wiiload",
DEFAULT_WIILOAD_ENABLED_VALUE, gWiiloadServerEnabled,
&gServerEnabledChanged));

} catch (std::exception &e) {
OSReport("Exception: %s\n", e.what());
return WUPSCONFIG_API_CALLBACK_RESULT_ERROR;
}
return WUPSCONFIG_API_CALLBACK_RESULT_SUCCESS;
}

static void ConfigMenuClosedCallback() {
// Save all changes
if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to close storage");
}
}

void InitConfigAndStorage() {
WUPSConfigAPIOptionsV1 configOptions = {.name = "Wiiload Plugin"};
if (WUPSConfigAPI_Init(configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to init config api");
}

if (WUPSStorageAPI::GetOrStoreDefault(WIILOAD_ENABLED_STRING, gWiiloadServerEnabled, DEFAULT_WIILOAD_ENABLED_VALUE) != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to get or create item \"%s\"", WIILOAD_ENABLED_STRING);
}

if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) {
DEBUG_FUNCTION_LINE_ERR("Failed to save storage");
}
}
6 changes: 6 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#define WIILOAD_ENABLED_STRING "enabled"
#define DEFAULT_WIILOAD_ENABLED_VALUE true

void InitConfigAndStorage();
172 changes: 0 additions & 172 deletions src/fs/CFile.cpp

This file was deleted.

68 changes: 0 additions & 68 deletions src/fs/CFile.hpp

This file was deleted.

Loading

0 comments on commit d4984da

Please sign in to comment.