From 158db91f7a4dfd93547abce3252deea045444d38 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 24 Jan 2021 15:45:30 +0100 Subject: [PATCH] Formatting and logging --- src/FileUtils.cpp | 23 +++++++++++++---------- src/RPXLoading.cpp | 16 ++++++++-------- src/RPXLoading.h | 2 +- src/main.cpp | 10 +++++----- src/utils/StringTools.cpp | 6 +++--- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 5823247..9b70590 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -87,29 +87,32 @@ int32_t readIntoBuffer(int32_t handle, void *buffer, size_t size, size_t count) //DEBUG_FUNCTION_LINE("Reading. missing %08X bytes\n", sizeToRead); } } - ////DEBUG_FUNCTION_LINE("Success: Read %08X bytes from handle %08X. result %08X \n", size * count, handle, totalSize); + //DEBUG_FUNCTION_LINE("Success: Read %08X bytes from handle %08X. result %08X \n", size * count, handle, totalSize); return totalSize; } int32_t CheckFile(const char * filepath) { - if(!filepath) + if (!filepath) { return 0; + } struct stat filestat{}; - char dirnoslash[strlen(filepath)+2]; + char dirnoslash[strlen(filepath) + 2]; snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); - while(dirnoslash[strlen(dirnoslash)-1] == '/') - dirnoslash[strlen(dirnoslash)-1] = '\0'; + while (dirnoslash[strlen(dirnoslash) - 1] == '/') { + dirnoslash[strlen(dirnoslash) - 1] = '\0'; + } - char * notRoot = strrchr(dirnoslash, '/'); - if(!notRoot) { + char *notRoot = strrchr(dirnoslash, '/'); + if (!notRoot) { strcat(dirnoslash, "/"); } - if (stat(dirnoslash, &filestat) == 0) + if (stat(dirnoslash, &filestat) == 0) { return 1; + } return 0; } @@ -140,8 +143,9 @@ int32_t CreateSubfolder(const char * fullpath) { //!Device root directory (must be with '/') strcat(parentpath, "/"); struct stat filestat{}; - if (stat(parentpath, &filestat) == 0) + if (stat(parentpath, &filestat) == 0){ return 1; + } return 0; } @@ -178,7 +182,6 @@ int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info) { bool found = false; int res = -3; while ((entry = readdir(dir)) != nullptr) { - DEBUG_FUNCTION_LINE("%s", entry->d_name); if (StringTools::EndsWith(entry->d_name, ".rpx")) { if (romfsGetFileInfoPerPath("rcc", (std::string("code/") + entry->d_name).c_str(), info) >= 0) { found = true; diff --git a/src/RPXLoading.cpp b/src/RPXLoading.cpp index 24c1d76..d4f8b10 100644 --- a/src/RPXLoading.cpp +++ b/src/RPXLoading.cpp @@ -24,9 +24,11 @@ char gIconCache[65580] __attribute__((section(".data"))); DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) { if (gReplacedRPX) { memset(&metaxml->longname_ja, 0, 0x338C - 0x38C); // clear all names - strncpy(metaxml->longname_en, gBundleInfo.longname, 64); - strncpy(metaxml->shortname_en, gBundleInfo.shortname, 64); - strncpy(metaxml->publisher_en, gBundleInfo.author, 64); + strncpy(metaxml->longname_en, gBundleInfo.longname, sizeof(gBundleInfo.longname)); + strncpy(metaxml->shortname_en, gBundleInfo.shortname, sizeof(gBundleInfo.longname)); + strncpy(metaxml->publisher_en, gBundleInfo.author, sizeof(gBundleInfo.longname)); + + // Disbale the emanual metaxml->e_manual = 0; return 0; @@ -83,7 +85,6 @@ uint32_t rpx_utils_function_replacements_size = sizeof(rpx_utils_function_replac static int parseINIhandler(void *user, const char *section, const char *name, const char *value) { - DEBUG_FUNCTION_LINE("%s %s %s", section, name, value); auto *fInfo = (BundleInformation *) user; #define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0 if (MATCH("menu", "longname")) { @@ -116,7 +117,6 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { int res = getRPXInfoForPath(completePath, &info); bool isBundle = false; if (res >= 0) { - DEBUG_FUNCTION_LINE("Is bundle :)"); isBundle = true; request.filesize = ((uint32_t *) &info.length)[1]; request.fileoffset = ((uint32_t *) &info.offset)[1]; @@ -153,8 +153,6 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { } romfsUnmount("rcc"); } - } else { - DEBUG_FUNCTION_LINE("not a bundle %s %d", completePath.c_str(), res); } if (!metaLoaded) { @@ -165,7 +163,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { strncpy(request.path, bundle_path, 255); - DEBUG_FUNCTION_LINE("Loading file %s size: %08X offset: %08X", request.path, request.filesize, request.fileoffset); + DEBUG_FUNCTION_LINE("Launch %s on next restart [size: %08X offset: %08X]", request.path, request.filesize, request.fileoffset); DCFlushRange(gIconCache, sizeof(gIconCache)); DCFlushRange(&request, sizeof(LOAD_REQUEST)); @@ -179,10 +177,12 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) { } if (isBundle) { + DEBUG_FUNCTION_LINE("Loaded file is a .wuhb bundle"); gTryToReplaceOnNextLaunch = true; memset(gLoadedBundlePath, 0, sizeof(gLoadedBundlePath)); strncpy(gLoadedBundlePath, completePath.c_str(), completePath.length()); } else { + DEBUG_FUNCTION_LINE("Loaded file is no bundle"); if (!gIsMounted) { gTryToReplaceOnNextLaunch = false; memset(gLoadedBundlePath, 0, sizeof(gLoadedBundlePath)); diff --git a/src/RPXLoading.h b/src/RPXLoading.h index d8db49e..ab196f9 100644 --- a/src/RPXLoading.h +++ b/src/RPXLoading.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/main.cpp b/src/main.cpp index 5073cce..bb223e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader"); -WUMS_INITIALIZE(args) { +WUMS_INITIALIZE() { WHBLogUdpInit(); DEBUG_FUNCTION_LINE("Patch functions"); // we only patch static functions, we don't need re-patch them and every launch @@ -32,8 +32,8 @@ WUMS_INITIALIZE(args) { WUMS_APPLICATION_ENDS() { - DEBUG_FUNCTION_LINE("bye bye from rpx loader"); if (gIsMounted) { + DEBUG_FUNCTION_LINE("Unmount /vol/content"); romfsUnmount("rom"); gIsMounted = false; DCFlushRange(&gIsMounted, sizeof(gIsMounted)); @@ -47,7 +47,7 @@ WUMS_APPLICATION_STARTS() { } WHBLogUdpInit(); if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { - DEBUG_FUNCTION_LINE("gTryToReplaceOnNextLaunch, gReplacedRPX and gIsMounted to FALSE"); + DEBUG_FUNCTION_LINE("Set gTryToReplaceOnNextLaunch, gReplacedRPX and gIsMounted to FALSE"); gReplacedRPX = false; gTryToReplaceOnNextLaunch = false; gIsMounted = false; @@ -74,10 +74,10 @@ WUMS_APPLICATION_STARTS() { CreateSubfolder(user.c_str()); DEBUG_FUNCTION_LINE("Created %s and %s", common.c_str(), user.c_str()); if (romfsMount("rom", gLoadedBundlePath, RomfsSource_FileDescriptor_CafeOS) == 0) { - DEBUG_FUNCTION_LINE("MOUNTED!"); + DEBUG_FUNCTION_LINE("Mounted %s to /vol/content", gLoadedBundlePath); gIsMounted = true; } else { - DEBUG_FUNCTION_LINE("MOUNTED FAILED %s", gLoadedBundlePath); + DEBUG_FUNCTION_LINE("Failed to mount %s", gLoadedBundlePath); gIsMounted = false; } gReplacedRPX = true; diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index 739de30..27264dc 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -254,17 +254,17 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) { // sanity checks and initialization if (!orig || !rep) - return NULL; + return nullptr; len_rep = strlen(rep); if (len_rep == 0) - return NULL; // empty rep causes infinite loop during count + return nullptr; // empty rep causes infinite loop during count if (!with) with = ""; len_with = strlen(with); // count the number of replacements needed ins = orig; - for (count = 0; tmp = strstr(ins, rep); ++count) { + for (count = 0; (tmp = strstr(ins, rep)); ++count) { ins = tmp + len_rep; }