From aecc164dda18afe4d21c3175541b1663731cb804 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 23 Mar 2024 20:24:59 +0100 Subject: [PATCH] Refactor TcpReceiver::loadBinary --- src/globals.h | 2 +- src/utils/TcpReceiver.cpp | 25 +++++++++++++------------ src/utils/TcpReceiver.h | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/globals.h b/src/globals.h index a004dc4..db316e7 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,6 +1,6 @@ #include "utils/TcpReceiver.h" -#include #include +#include extern bool gLibRPXLoaderInitDone; extern std::unique_ptr gTcpReceiverThread; diff --git a/src/utils/TcpReceiver.cpp b/src/utils/TcpReceiver.cpp index f108a00..763d2df 100644 --- a/src/utils/TcpReceiver.cpp +++ b/src/utils/TcpReceiver.cpp @@ -227,22 +227,23 @@ TcpReceiver::eLoadResults TcpReceiver::loadBinary(void *data, uint32_t fileSize) std::string loadedPath; eLoadResults error; if ((error = tryLoadWUHB(data, fileSize, loadedPath)) != UNSUPPORTED_FORMAT || (error = tryLoadRPX((uint8_t *) data, fileSize, loadedPath)) != UNSUPPORTED_FORMAT) { - if (error == SUCCESS) { - RPXLoaderStatus launchRes; - 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; - } + if (error != SUCCESS) { + return error; + } + RPXLoaderStatus launchRes; + 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) { - if (error == SUCCESS) { - _SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr); + if (error != SUCCESS) { + return error; } - return error; + _SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), nullptr); + } else { + return UNSUPPORTED_FORMAT; } - return UNSUPPORTED_FORMAT; + return SUCCESS; } std::unique_ptr TcpReceiver::uncompressData(uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr &&inData, uint32_t &fileSizeOut, eLoadResults &err) { diff --git a/src/utils/TcpReceiver.h b/src/utils/TcpReceiver.h index df485fb..b8653b2 100644 --- a/src/utils/TcpReceiver.h +++ b/src/utils/TcpReceiver.h @@ -36,7 +36,7 @@ private: 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 loadBinary(void *data, uint32_t fileSize); - static std::unique_ptr receiveData(int32_t clientSocket, uint32_t fileSize, eLoadResults &err); + static std::unique_ptr receiveData(int32_t clientSocket, uint32_t fileSize, eLoadResults &err); static std::unique_ptr uncompressData(uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr &&in_out_data, uint32_t &fileSizeOut, eLoadResults &err); bool exitRequested;