2022-04-14 22:41:41 +02:00
|
|
|
#include "FSWrapper.h"
|
|
|
|
#include "FSWrapperMergeDirsWithParent.h"
|
|
|
|
#include "FileUtils.h"
|
|
|
|
#include "IFSWrapper.h"
|
|
|
|
#include "utils/logger.h"
|
2022-04-29 13:34:04 +02:00
|
|
|
#include "utils/utils.h"
|
2022-04-14 22:41:41 +02:00
|
|
|
#include <content_redirection/redirection.h>
|
|
|
|
#include <coreinit/debug.h>
|
|
|
|
#include <mutex>
|
|
|
|
#include <wums/exports.h>
|
|
|
|
|
|
|
|
ContentRedirectionApiErrorType CRAddFSLayer(CRLayerHandle *handle, const char *layerName, const char *replacementDir, FSLayerType layerType) {
|
|
|
|
if (!handle || layerName == nullptr || replacementDir == nullptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("CONTENT_REDIRECTION_API_ERROR_INVALID_ARG");
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_INVALID_ARG;
|
|
|
|
}
|
2022-04-29 13:34:04 +02:00
|
|
|
std::unique_ptr<IFSWrapper> ptr;
|
2022-04-14 22:41:41 +02:00
|
|
|
if (layerType == FS_LAYER_TYPE_CONTENT_REPLACE) {
|
2022-04-29 13:34:04 +02:00
|
|
|
ptr = make_unique_nothrow<FSWrapper>(layerName, "/vol/content", replacementDir, false, false);
|
2022-04-14 22:41:41 +02:00
|
|
|
} else if (layerType == FS_LAYER_TYPE_CONTENT_MERGE) {
|
2022-04-29 13:34:04 +02:00
|
|
|
ptr = make_unique_nothrow<FSWrapperMergeDirsWithParent>(layerName, "/vol/content", replacementDir, true);
|
2022-04-14 22:41:41 +02:00
|
|
|
} else if (layerType == FS_LAYER_TYPE_SAVE_REPLACE) {
|
2022-04-29 13:34:04 +02:00
|
|
|
ptr = make_unique_nothrow<FSWrapper>(layerName, "/vol/save", replacementDir, false, true);
|
2022-04-14 22:41:41 +02:00
|
|
|
} else {
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("CONTENT_REDIRECTION_API_ERROR_UNKNOWN_LAYER_DIR_TYPE: %s %s %d", layerName, replacementDir, layerType);
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_UNKNOWN_FS_LAYER_TYPE;
|
|
|
|
}
|
|
|
|
if (ptr) {
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Added new layer (%s). Replacement dir: %s Type:%d", layerName, replacementDir, layerType);
|
|
|
|
std::lock_guard<std::mutex> lock(fsLayerMutex);
|
2022-04-29 13:34:04 +02:00
|
|
|
*handle = (CRLayerHandle) ptr->getHandle();
|
|
|
|
fsLayers.push_back(std::move(ptr));
|
2022-04-14 22:41:41 +02:00
|
|
|
return CONTENT_REDIRECTION_API_ERROR_NONE;
|
|
|
|
}
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to allocate memory");
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentRedirectionApiErrorType CRRemoveFSLayer(CRLayerHandle handle) {
|
2022-04-29 13:34:04 +02:00
|
|
|
if (remove_locked_first_if(fsLayerMutex, fsLayers, [handle](auto &cur) { return (CRLayerHandle) cur->getHandle() == handle; })) {
|
2022-04-14 22:41:41 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND for handle %08X", handle);
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND;
|
|
|
|
}
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentRedirectionApiErrorType CRSetActive(CRLayerHandle handle, bool active) {
|
|
|
|
std::lock_guard<std::mutex> lock(fsLayerMutex);
|
|
|
|
for (auto &cur : fsLayers) {
|
2022-04-29 13:34:04 +02:00
|
|
|
if ((CRLayerHandle) cur->getHandle() == handle) {
|
|
|
|
cur->setActive(active);
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_NONE;
|
2022-04-14 22:41:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-29 13:34:04 +02:00
|
|
|
|
|
|
|
DEBUG_FUNCTION_LINE_ERR("CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND for handle %08X", handle);
|
|
|
|
return CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND;
|
2022-04-14 22:41:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CRGetVersion() {
|
|
|
|
return CONTENT_REDIRECT_MODULE_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CRAddDevice(const devoptab_t *device) {
|
|
|
|
return AddDevice(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CRRemoveDevice(const char *name) {
|
|
|
|
return RemoveDevice(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
WUMS_EXPORT_FUNCTION(CRGetVersion);
|
|
|
|
WUMS_EXPORT_FUNCTION(CRAddFSLayer);
|
|
|
|
WUMS_EXPORT_FUNCTION(CRRemoveFSLayer);
|
|
|
|
WUMS_EXPORT_FUNCTION(CRSetActive);
|
|
|
|
WUMS_EXPORT_FUNCTION(CRAddDevice);
|
|
|
|
WUMS_EXPORT_FUNCTION(CRRemoveDevice);
|