Refactor TcpReceiver::loadBinary

This commit is contained in:
Maschell 2024-03-23 20:24:59 +01:00
parent fb97f0353d
commit aecc164dda
3 changed files with 15 additions and 14 deletions

View File

@ -1,6 +1,6 @@
#include "utils/TcpReceiver.h" #include "utils/TcpReceiver.h"
#include <memory>
#include <cstdint> #include <cstdint>
#include <memory>
extern bool gLibRPXLoaderInitDone; extern bool gLibRPXLoaderInitDone;
extern std::unique_ptr<TcpReceiver> gTcpReceiverThread; extern std::unique_ptr<TcpReceiver> gTcpReceiverThread;

View File

@ -227,22 +227,23 @@ TcpReceiver::eLoadResults TcpReceiver::loadBinary(void *data, uint32_t fileSize)
std::string loadedPath; std::string loadedPath;
eLoadResults error; eLoadResults error;
if ((error = tryLoadWUHB(data, fileSize, loadedPath)) != UNSUPPORTED_FORMAT || (error = tryLoadRPX((uint8_t *) data, fileSize, loadedPath)) != UNSUPPORTED_FORMAT) { if ((error = tryLoadWUHB(data, fileSize, loadedPath)) != UNSUPPORTED_FORMAT || (error = tryLoadRPX((uint8_t *) data, fileSize, loadedPath)) != UNSUPPORTED_FORMAT) {
if (error == SUCCESS) { if (error != SUCCESS) {
RPXLoaderStatus launchRes; return error;
if ((launchRes = RPXLoader_LaunchHomebrew(loadedPath.c_str())) != RPX_LOADER_RESULT_SUCCESS) { }
DEBUG_FUNCTION_LINE_ERR("Failed to start %s %s", loadedPath.c_str(), RPXLoader_GetStatusStr(launchRes)); RPXLoaderStatus launchRes;
return LAUNCH_FAILED; if ((launchRes = RPXLoader_LaunchHomebrew(loadedPath.c_str())) != RPX_LOADER_RESULT_SUCCESS) {
} DEBUG_FUNCTION_LINE_ERR("Failed to start %s %s", loadedPath.c_str(), RPXLoader_GetStatusStr(launchRes));
return LAUNCH_FAILED;
} }
return error;
} else if ((error = tryLoadWPS((uint8_t *) data, fileSize)) != UNSUPPORTED_FORMAT) { } else if ((error = tryLoadWPS((uint8_t *) data, fileSize)) != UNSUPPORTED_FORMAT) {
if (error == SUCCESS) { if (error != SUCCESS) {
_SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr); return error;
} }
return error; _SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr);
} else {
return UNSUPPORTED_FORMAT;
} }
return UNSUPPORTED_FORMAT; return SUCCESS;
} }
std::unique_ptr<uint8_t[]> TcpReceiver::uncompressData(uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr<uint8_t[]> &&inData, uint32_t &fileSizeOut, eLoadResults &err) { std::unique_ptr<uint8_t[]> TcpReceiver::uncompressData(uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr<uint8_t[]> &&inData, uint32_t &fileSizeOut, eLoadResults &err) {

View File

@ -36,7 +36,7 @@ private:
static TcpReceiver::eLoadResults tryLoadRPX(uint8_t *data, uint32_t fileSize, std::string &loadedPathOut); static TcpReceiver::eLoadResults tryLoadRPX(uint8_t *data, uint32_t fileSize, std::string &loadedPathOut);
static TcpReceiver::eLoadResults tryLoadWPS(uint8_t *data, uint32_t fileSize); static TcpReceiver::eLoadResults tryLoadWPS(uint8_t *data, uint32_t fileSize);
static TcpReceiver::eLoadResults loadBinary(void *data, uint32_t fileSize); static TcpReceiver::eLoadResults loadBinary(void *data, uint32_t fileSize);
static std::unique_ptr<uint8_t[]> receiveData(int32_t clientSocket, uint32_t fileSize, eLoadResults &err); static std::unique_ptr<uint8_t[]> receiveData(int32_t clientSocket, uint32_t fileSize, eLoadResults &err);
static std::unique_ptr<uint8_t[]> uncompressData(uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr<uint8_t[]> &&in_out_data, uint32_t &fileSizeOut, eLoadResults &err); static std::unique_ptr<uint8_t[]> uncompressData(uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr<uint8_t[]> &&in_out_data, uint32_t &fileSizeOut, eLoadResults &err);
bool exitRequested; bool exitRequested;