Add support for redirecting the /vol/content folder

This commit is contained in:
Maschell 2021-04-05 21:32:40 +02:00
parent 2e25fbd8c1
commit 702524251e
2 changed files with 21 additions and 3 deletions

View File

@ -36,6 +36,9 @@ inline void getFullPath(char *pathForCheck, int pathSize, char *path) {
} }
inline bool checkForSave(char *pathForCheck, int pathSize, char *path) { inline bool checkForSave(char *pathForCheck, int pathSize, char *path) {
if (!gReplacementInfo.contentReplacementInfo.replaceSave) {
return false;
}
if (strncmp(path, "/vol/save", 9) == 0) { if (strncmp(path, "/vol/save", 9) == 0) {
int copyLen = strlen(path); int copyLen = strlen(path);
char copy[copyLen + 1]; char copy[copyLen + 1];
@ -468,8 +471,7 @@ FSStatus FSGetStatWrapper(char *path, FSStat *stats, FSErrorFlag errorMask,
getFullPath(pathForCheck, sizeof(pathForCheck), path); getFullPath(pathForCheck, sizeof(pathForCheck), path);
if (gReplacementInfo.contentReplacementInfo.replaceSave && if (checkForSave(pathForCheck, sizeof(pathForCheck), pathForCheck)) {
checkForSave(pathForCheck, sizeof(pathForCheck), pathForCheck)) {
DEBUG_FUNCTION_LINE("Redirect save to %s", pathForCheck); DEBUG_FUNCTION_LINE("Redirect save to %s", pathForCheck);
return fallback_function(pathForCheck); return fallback_function(pathForCheck);
} }

View File

@ -280,6 +280,21 @@ bool RL_FileExists(const char *name) {
return CheckFile(name) || CheckFile(checkgz.c_str()); return CheckFile(name) || CheckFile(checkgz.c_str());
} }
bool RL_RedirectContentWithFallback(const char * newContentPath) {
auto dirHandle = opendir(newContentPath);
if (dirHandle == nullptr) {
return false;
}
closedir(dirHandle);
gReplacementInfo.contentReplacementInfo.replacementPath[0] = '\0';
strncat(gReplacementInfo.contentReplacementInfo.replacementPath, newContentPath, sizeof(gReplacementInfo.contentReplacementInfo.replacementPath) - 1);
gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_FROM_PATH;
gReplacementInfo.contentReplacementInfo.fallbackOnError = true;
gReplacementInfo.contentReplacementInfo.replaceSave = false;
return true;
}
WUMS_EXPORT_FUNCTION(RL_LoadFromSDOnNextLaunch); WUMS_EXPORT_FUNCTION(RL_LoadFromSDOnNextLaunch);
WUMS_EXPORT_FUNCTION(RL_MountBundle); WUMS_EXPORT_FUNCTION(RL_MountBundle);
WUMS_EXPORT_FUNCTION(RL_UnmountBundle); WUMS_EXPORT_FUNCTION(RL_UnmountBundle);
@ -287,3 +302,4 @@ WUMS_EXPORT_FUNCTION(RL_FileOpen);
WUMS_EXPORT_FUNCTION(RL_FileRead); WUMS_EXPORT_FUNCTION(RL_FileRead);
WUMS_EXPORT_FUNCTION(RL_FileClose); WUMS_EXPORT_FUNCTION(RL_FileClose);
WUMS_EXPORT_FUNCTION(RL_FileExists); WUMS_EXPORT_FUNCTION(RL_FileExists);
WUMS_EXPORT_FUNCTION(RL_RedirectContentWithFallback);