Add the shortname to the save directory of a wuhb

This commit is contained in:
Maschell 2022-10-08 20:53:11 +02:00
parent ba1ea768e4
commit 7ffde9961b
3 changed files with 43 additions and 4 deletions

View File

@ -91,14 +91,19 @@ WUMS_APPLICATION_STARTS() {
if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) == OSGetTitleID() && if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) == OSGetTitleID() &&
strlen(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) > 0) { 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::Initialize();
nn::act::PersistentId persistentId = nn::act::GetPersistentId(); nn::act::PersistentId persistentId = nn::act::GetPersistentId();
nn::act::Finalize(); nn::act::Finalize();
std::string basePath = string_format("fs:/vol/external01/wiiu/apps/save/%08X", currentHash); 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); if (!shortNameSanitized.empty()) {
std::string user = string_format("fs:/vol/external01/wiiu/apps/save/%08X/%08X", currentHash, 0x80000000 | persistentId); 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(common.c_str());
CreateSubfolder(user.c_str()); CreateSubfolder(user.c_str());

View File

@ -1,9 +1,41 @@
#include "utils/logger.h" #include "utils/logger.h"
#include <string.h> #include <string.h>
#include <string>
#include <whb/log.h> #include <whb/log.h>
#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 // https://gist.github.com/ccbrown/9722406
void dumpHex(const void *data, size_t size) { void dumpHex(const void *data, size_t size) {
char ascii[17]; char ascii[17];

View File

@ -35,6 +35,8 @@ bool remove_locked_first_if(std::mutex &mutex, std::forward_list<T, Allocator> &
return false; return false;
} }
std::string sanitizeName(const std::string &input);
// those work only in powers of 2 // those work only in powers of 2
#define ROUNDDOWN(val, align) ((val) & ~(align - 1)) #define ROUNDDOWN(val, align) ((val) & ~(align - 1))
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align) #define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)