diff --git a/src/main.cpp b/src/main.cpp index 3a50838..6eff875 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -90,15 +90,20 @@ WUMS_APPLICATION_STARTS() { if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) == OSGetTitleID() && strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) > 0) { - uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath); + uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath); + std::string shortNameSanitized = sanitizeName(gReplacementInfo.rpxReplacementInfo.metaInformation.shortname); nn::act::Initialize(); nn::act::PersistentId persistentId = nn::act::GetPersistentId(); nn::act::Finalize(); std::string basePath = string_format("fs:/vol/external01/wiiu/apps/save/%08X", currentHash); - std::string common = string_format("fs:/vol/external01/wiiu/apps/save/%08X/common", currentHash); - std::string user = string_format("fs:/vol/external01/wiiu/apps/save/%08X/%08X", currentHash, 0x80000000 | persistentId); + if (!shortNameSanitized.empty()) { + basePath += string_format(" (%s)", shortNameSanitized.c_str()); + } + + std::string common = basePath + "/common"; + std::string user = basePath + string_format("/%08X", 0x80000000 | persistentId); CreateSubfolder(common.c_str()); CreateSubfolder(user.c_str()); diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index bbe9a07..8811ff0 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -1,9 +1,41 @@ #include "utils/logger.h" #include +#include #include -#define PRINTF_BUFFER_LENGTH 2048 +std::string sanitizeName(const std::string &input) { + if (input.empty() || input.starts_with(' ')) { + return ""; + } + std::string result = input; + std::string illegalChars = "\\/:?\"<>|@=;`_^]["; + for (auto it = result.begin(); it < result.end(); ++it) { + if (*it < '0' || *it > 'z') { + *it = ' '; + } + } + for (auto it = result.begin(); it < result.end(); ++it) { + bool found = illegalChars.find(*it) != std::string::npos; + if (found) { + *it = ' '; + } + } + uint32_t length = result.length(); + for (uint32_t i = 1; i < length; ++i) { + if (result[i - 1] == ' ' && result[i] == ' ') { + result.erase(i, 1); + i--; + length--; + } + } + if (result.size() == 1 && result[0] == ' ') { + result.clear(); + } + return result; +} + +#define PRINTF_BUFFER_LENGTH 2048 // https://gist.github.com/ccbrown/9722406 void dumpHex(const void *data, size_t size) { char ascii[17]; diff --git a/src/utils/utils.h b/src/utils/utils.h index 1158ec1..f879c30 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -35,6 +35,8 @@ bool remove_locked_first_if(std::mutex &mutex, std::forward_list & return false; } +std::string sanitizeName(const std::string &input); + // those work only in powers of 2 #define ROUNDDOWN(val, align) ((val) & ~(align - 1)) #define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align) \ No newline at end of file