first commit

This commit is contained in:
Maschell 2022-04-14 22:32:09 +02:00
commit 9605015096
10 changed files with 630 additions and 0 deletions

67
.clang-format Normal file
View File

@ -0,0 +1,67 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

25
.github/workflows/pr.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: CI-PR
on: [pull_request]
jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source ./include
build-lib:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build lib
run: |
docker build . -f Dockerfile.buildlocal -t builder
docker run --rm -v ${PWD}:/project builder make
- uses: actions/upload-artifact@master
with:
name: lib
path: "lib/*.a"

33
.github/workflows/push_image.yml vendored Normal file
View File

@ -0,0 +1,33 @@
name: Publish Docker Image
on:
push:
branches:
- main
jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source ./include
build:
runs-on: ubuntu-latest
needs: clang-format
steps:
- uses: actions/checkout@master
- name: Get release version
id: get_release_tag
run: |
echo RELEASE_VERSION=$(echo $(date '+%Y%m%d')) >> $GITHUB_ENV
echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//" | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
echo REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $1}' | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: ${{ env.REPOSITORY_OWNER }}/${{ env.REPOSITORY_NAME }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
snapshot: true
cache: true
tags: "latest, ${{ env.RELEASE_VERSION }}"

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
/*.a
/build
*.bz2
release/
lib/
CMakeLists.txt
.idea/
cmake-build-debug/
share/

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM wiiuenv/devkitppc:20220303
WORKDIR tmp_build
COPY . .
RUN make clean && make && mkdir -p /artifacts/wums && cp -r lib /artifacts/wums && cp -r include /artifacts/wums
WORKDIR /artifacts
FROM scratch
COPY --from=0 /artifacts /artifacts

3
Dockerfile.buildlocal Normal file
View File

@ -0,0 +1,3 @@
FROM wiiuenv/devkitppc:20220303
WORKDIR project

157
Makefile Normal file
View File

@ -0,0 +1,157 @@
#-------------------------------------------------------------------------------
.SUFFIXES:
#-------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/wut/share/wut_rules
export VER_MAJOR := 1
export VER_MINOR := 0
export VER_PATCH := 0
VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH)
#-------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#-------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := source \
include \
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -Wall -Werror -save-temps \
-ffunction-sections -fdata-sections \
$(MACHDEP) \
$(BUILD_CFLAGS)
CFLAGS += $(INCLUDE) -D__WIIU__
CXXFLAGS := $(CFLAGS) -std=gnu++17
ASFLAGS := $(MACHDEP)
LDFLAGS = $(ARCH) -Wl,--gc-sections
LIBS :=
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(WUT_ROOT)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
DEFFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.def)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(DEFFILES:.def=.o) $(SFILES:.s=.o) $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I.
.PHONY: all dist-bin dist-src dist install clean
#---------------------------------------------------------------------------------
all: lib/libcontentredirection.a
dist-bin: all
@tar --exclude=*~ -cjf libcontentredirection-$(VERSION).tar.bz2 include lib
dist-src:
@tar --exclude=*~ -cjf libcontentredirection-src-$(VERSION).tar.bz2 include source Makefile
dist: dist-src dist-bin
install: dist-bin
mkdir -p $(DESTDIR)$(DEVKITPRO)/wums
bzip2 -cd libcontentredirection-$(VERSION).tar.bz2 | tar -xf - -C $(DESTDIR)$(DEVKITPRO)/wums
lib:
@[ -d $@ ] || mkdir -p $@
release:
@[ -d $@ ] || mkdir -p $@
lib/libcontentredirection.a :$(SOURCES) $(INCLUDES) | lib release
@$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \
BUILD_CFLAGS="-DNDEBUG=1 -O2 -s" \
DEPSDIR=$(CURDIR)/release \
--no-print-directory -C release \
-f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -rf release lib
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
$(OFILES_SRC) : $(HFILES)
#---------------------------------------------------------------------------------
%_bin.h %.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

29
README.md Normal file
View File

@ -0,0 +1,29 @@
[![Publish Docker Image](https://github.com/wiiu-env/libcontentredirection/actions/workflows/push_image.yml/badge.svg)](https://github.com/wiiu-env/libcontentredirection/actions/workflows/push_image.yml)
# libcontentredirection
Requires the [ContentRedirectionModule](https://github.com/wiiu-env/ContentRedirectionModule) to be running via [WUMSLoader](https://github.com/wiiu-env/WUMSLoader).
Requires [wut](https://github.com/devkitPro/wut) for building.
Install via `make install`.
## Usage
Make sure to define
```
WUMS_ROOT := $(DEVKITPRO)/wums
```
and add `-lcontentredirection` to `LIBS` and `$(WUMS_ROOT)` to `LIBDIRS`.
After that you can simply include `<content_redirection/redirection.h>`, call `ContentRedirection_Init();` to get access to the content redirection functions if it returns `CONTENT_REDIRECTION_RESULT_SUCCESS`.
## Use this lib in Dockerfiles.
A prebuilt version of this lib can found on dockerhub. To use it for your projects, add this to your Dockerfile.
```
[...]
COPY --from=wiiuenv/libcontentredirection:[tag] /artifacts $DEVKITPRO
[...]
```
Replace [tag] with a tag you want to use, a list of tags can be found [here](https://hub.docker.com/r/wiiuenv/libcontentredirection/tags).
It's highly recommended to pin the version to the **latest date** instead of using `latest`.
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source ./include -i`

View File

@ -0,0 +1,153 @@
#pragma once
#include <stdint.h>
#include <sys/iosupport.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <cstdint>
enum FSLayerType {
/* Redirects the /vol/content to a given path.
* Existing files in /vol/content will be ignored, only files of the layer (provided via the replacementDir) will be used.
*/
FS_LAYER_TYPE_CONTENT_REPLACE,
/* Redirects the /vol/content to a given path.
* Merges the files of the layer (provided via the replacementDir) into the existing /vol/content (which is used as fallback).
* All files which start with ".deleted_" will be ignored.
*
* If a file exists in both the layer and /vol/content, the layer has priority and will be used.
* If a file doesn't exist in the layer but in /vol/content, the file from /vol/content will be used.
* If a file only exists in the layer and not in /vol/content, the file from the layer will be used.
*
* To "hide" a file which exists in /vol/content you need to create an empty dummy file with the prefix ".deleted_" in the same directory for the layer..
* e.g. When the OS requests "/vol/content/music/track1.wav" (which exists) and the layer has a file "[replacementDir]/music/.deleted_track1.wav", FS_STATUS_NOT_FOUND will be returned.
*
* If multiple layers are used, the "parent layer" will act like /vol/content and is used as a fallback.
*/
FS_LAYER_TYPE_CONTENT_MERGE,
/* Redirects the /vol/save to a given path.
* Existing files in /vol/save will be ignored, only files in the layer (provided via the replacementDir) will be used.
*/
FS_LAYER_TYPE_SAVE_REPLACE,
};
enum ContentRedirectionStatus {
CONTENT_REDIRECTION_RESULT_SUCCESS = 0,
CONTENT_REDIRECTION_RESULT_MODULE_NOT_FOUND = -1,
CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT = -2,
CONTENT_REDIRECTION_RESULT_UNSUPPORTED_VERSION = -3,
CONTENT_REDIRECTION_RESULT_INVALID_ARG = -10,
CONTENT_REDIRECTION_RESULT_NO_MEMORY = -11,
CONTENT_REDIRECTION_RESULT_UNKNOWN_FS_LAYER_TYPE = -12,
CONTENT_REDIRECTION_RESULT_LAYER_NOT_FOUND = -13,
CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED = -20,
CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR = -1000,
};
typedef uint32_t CRLayerHandle;
typedef uint32_t ContentRedirectionVersion;
#define CONTENT_REDIRECT_MODULE_VERSION 0x00000001
typedef enum ContentRedirectionApiErrorType {
CONTENT_REDIRECTION_API_ERROR_NONE = 0,
CONTENT_REDIRECTION_API_ERROR_INVALID_ARG = -1,
CONTENT_REDIRECTION_API_ERROR_NO_MEMORY = -2,
CONTENT_REDIRECTION_API_ERROR_UNKNOWN_FS_LAYER_TYPE = -3,
CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND = -4,
} ContentRedirectionApiErrorType;
/**
* This function has to be called before any other function of this lib (except ContentRedirection_GetVersion) can be used.
*
* @return CONTENT_REDIRECTION_RESULT_SUCCESS: The library has been initialized successfully. Other functions can now be used.
* CONTENT_REDIRECTION_RESULT_MODULE_NOT_FOUND: The module could not be found. Make sure the module is loaded.
* CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT: The module is missing an expected export.
* CONTENT_REDIRECTION_RESULT_UNSUPPORTED_VERSION: The version of the loaded module is not compatible with this version of the lib.
*/
ContentRedirectionStatus ContentRedirection_Init();
/**
* Returns the API Version of the Content Redirection Module.
* @return The ContentRedirectionVersion of the Module
*/
ContentRedirectionVersion ContentRedirection_GetVersion();
/**
* Adds a a FSLayers that redirects the /vol/content or /vol/save fs calles for the Game/Wii U Menu process.
* Make sure to remove all added the layers before the application ends.
* The replacement dir has be to valid in the ContentRedirection Module, use "ContentRedirection_AddDevice" to add a Device for the ContentRedirection Module.
* Multiple layers can be added. Each layer is valid system wide for the Game/Wii U Menu process.
* The layers will be processed in reverse adding order. e.g. when you add Layer1, Layer2 and then Layer3; Layer3, Layer2 and finally Layer1 will be processed.
* An added layer is active by default.
*
* @param handlePtr The handle of the layer is written to this pointer.
* @param layerName Name of the layer, used for debugging.
* @param replacementDir Path to the directory that will replace / merge into the original one.
* @param layerType Type of the layer, see FSLayerType for more information.
*
* If set to to false, errors of this layer will be returned to the OS.
* @return CONTENT_REDIRECTION_RESULT_SUCCESS: The layer had been added successfully.
* The layer has to be removed before the currently running application ends.
* CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED: "ContentRedirection_Init()" was not called.
* CONTENT_REDIRECTION_API_ERROR_INVALID_ARG: "handlePtr", "layerName" or "replacementDir" is NULL
* CONTENT_REDIRECTION_API_ERROR_NO_MEMORY: Not enough memory to create this layer.
* CONTENT_REDIRECTION_API_ERROR_UNKNOWN_LAYER_TYPE: Unknown/invalid LayerType. See FSLayerType for all supported layers.
* CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR: Unknown error.
*/
ContentRedirectionStatus ContentRedirection_AddFSLayer(CRLayerHandle *handlePtr, const char *layerName, const char *replacementDir, FSLayerType layerType);
/**
* Removes a previously added FS Layer.
* @param handle handle of the layer that will be removed
* @return
*/
ContentRedirectionStatus ContentRedirection_RemoveFSLayer(CRLayerHandle handle);
/**
* Set the "active" flag for a given FSLayer.
*
* @param handle Handle of the FSLayer.
* @param active New "active"-state of the layer
* @return CONTENT_REDIRECTION_RESULT_SUCCESS: The active state has been set successfully.
* CONTENT_REDIRECTION_RESULT_LAYER_NOT_FOUND: Invalid FSLayer handle.
* CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED: "ContentRedirection_Init()" was not called.
* CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR: Unknown error.
*/
ContentRedirectionStatus ContentRedirection_SetActive(CRLayerHandle handle, bool active);
/**
* Calls "AddDevice" for the ContentRedirection Module.
* When a device is added for the ContentRedirection Module, it can be used in FSLayers.
*
* @param device Device that will be added
* @param resultOut Will hold the result of the "AddDevice" call.
* @return CONTENT_REDIRECTION_RESULT_SUCCESS: AddDevice has been called, result is written to resultOut.
* See documentation of AddDevice for more information
* CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED: "ContentRedirection_Init()" was not called.
* CONTENT_REDIRECTION_RESULT_INVALID_ARG: resultOut is NULL.
* CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR: Unknown error.
*/
ContentRedirectionStatus ContentRedirection_AddDevice(const devoptab_t *device, int *resultOut);
/**
* Calls "RemoveDevice" for the ContentRedirection Module.
*
* @param name name of the device that will be added. e.g. "romfs:"
* @param resultOut Will hold the result of the "AddDevice" call.
* @return CONTENT_REDIRECTION_RESULT_SUCCESS: RemoveDevice has been called, result is written to resultOut.
* See documentation of RemoveDevice for more information
* CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED: "ContentRedirection_Init()" was not called.
* CONTENT_REDIRECTION_RESULT_INVALID_ARG: resultOut is NULL.
* CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR: Unknown error.
*/
ContentRedirectionStatus ContentRedirection_RemoveDevice(const char *name, int *resultOut);
#ifdef __cplusplus
} // extern "C"
#endif

145
source/utils.cpp Normal file
View File

@ -0,0 +1,145 @@
#include "content_redirection/redirection.h"
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <sys/iosupport.h>
static OSDynLoad_Module sModuleHandle = nullptr;
static ContentRedirectionStatus (*sCRAddFSLayer)(CRLayerHandle *, const char *, const char *, FSLayerType) = nullptr;
static ContentRedirectionStatus (*sCRRemoveFSLayer)(CRLayerHandle) = nullptr;
static ContentRedirectionStatus (*sCRSetActive)(CRLayerHandle) = nullptr;
static ContentRedirectionVersion (*sCRGetVersion)() = nullptr;
static ContentRedirectionStatus (*sCRAddDevice)(const devoptab_t *, int *) = nullptr;
static ContentRedirectionStatus (*sCRRemoveDevice)(const char *) = nullptr;
ContentRedirectionStatus ContentRedirection_Init() {
if (OSDynLoad_Acquire("homebrew_content_redirection", &sModuleHandle) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: OSDynLoad_Acquire failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_NOT_FOUND;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "CRGetVersion", (void **) &sCRGetVersion) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: CRGetVersion failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT;
}
auto res = ContentRedirection_GetVersion();
if (res != CONTENT_REDIRECT_MODULE_VERSION) {
return CONTENT_REDIRECTION_RESULT_UNSUPPORTED_VERSION;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "CRAddFSLayer", (void **) &sCRAddFSLayer) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: CRAddFSLayer failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "CRRemoveFSLayer", (void **) &sCRRemoveFSLayer) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: CRRemoveFSLayer failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "CRSetActive", (void **) &sCRSetActive) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: CRSetActive failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "CRAddDevice", (void **) &sCRAddDevice) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: CRAddDevice failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT;
}
if (OSDynLoad_FindExport(sModuleHandle, FALSE, "CRRemoveDevice", (void **) &sCRRemoveDevice) != OS_DYNLOAD_OK) {
OSReport("ContentRedirection_Init: CRRemoveDevice failed.\n");
return CONTENT_REDIRECTION_RESULT_MODULE_MISSING_EXPORT;
}
return CONTENT_REDIRECTION_RESULT_SUCCESS;
}
ContentRedirectionVersion GetVersion();
ContentRedirectionVersion ContentRedirection_GetVersion() {
if (sCRGetVersion == nullptr) {
return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED;
}
return reinterpret_cast<decltype(&GetVersion)>(sCRGetVersion)();
}
ContentRedirectionApiErrorType AddFSLayer(CRLayerHandle *, const char *, const char *, FSLayerType);
ContentRedirectionStatus ContentRedirection_AddFSLayer(CRLayerHandle *handlePtr, const char *layerName, const char *replacementDir, FSLayerType layerType) {
if (sCRAddFSLayer == nullptr) {
return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED;
}
auto res = reinterpret_cast<decltype(&AddFSLayer)>(sCRAddFSLayer)(handlePtr, layerName, replacementDir, layerType);
if (res == CONTENT_REDIRECTION_API_ERROR_NONE) {
return CONTENT_REDIRECTION_RESULT_SUCCESS;
}
switch (res) {
case CONTENT_REDIRECTION_API_ERROR_INVALID_ARG:
return CONTENT_REDIRECTION_RESULT_INVALID_ARG;
case CONTENT_REDIRECTION_API_ERROR_NO_MEMORY:
return CONTENT_REDIRECTION_RESULT_NO_MEMORY;
case CONTENT_REDIRECTION_API_ERROR_UNKNOWN_FS_LAYER_TYPE:
return CONTENT_REDIRECTION_RESULT_UNKNOWN_FS_LAYER_TYPE;
default:
return CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR;
}
}
ContentRedirectionApiErrorType RemoveFSLayer(CRLayerHandle);
ContentRedirectionStatus ContentRedirection_RemoveFSLayer(CRLayerHandle handlePtr) {
if (sCRAddFSLayer == nullptr) {
return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED;
}
auto res = reinterpret_cast<decltype(&RemoveFSLayer)>(sCRRemoveFSLayer)(handlePtr);
if (res == CONTENT_REDIRECTION_API_ERROR_NONE) {
return CONTENT_REDIRECTION_RESULT_SUCCESS;
}
if (res == CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND) {
return CONTENT_REDIRECTION_RESULT_LAYER_NOT_FOUND;
}
return CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR;
}
ContentRedirectionApiErrorType SetActive(CRLayerHandle, bool);
ContentRedirectionStatus ContentRedirection_SetActive(CRLayerHandle handle, bool active) {
if (sCRAddFSLayer == nullptr) {
return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED;
}
auto res = reinterpret_cast<decltype(&SetActive)>(sCRSetActive)(handle, active);
if (res == CONTENT_REDIRECTION_API_ERROR_NONE) {
return CONTENT_REDIRECTION_RESULT_SUCCESS;
}
if (res == CONTENT_REDIRECTION_API_ERROR_LAYER_NOT_FOUND) {
return CONTENT_REDIRECTION_RESULT_LAYER_NOT_FOUND;
}
return CONTENT_REDIRECTION_RESULT_UNKNOWN_ERROR;
}
ContentRedirectionStatus ContentRedirection_AddDevice(const devoptab_t *device, int *resultOut) {
if (sCRAddFSLayer == nullptr) {
return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED;
}
if (resultOut == nullptr) {
return CONTENT_REDIRECTION_RESULT_INVALID_ARG;
}
*resultOut = reinterpret_cast<decltype(&AddDevice)>(sCRAddDevice)(device);
return CONTENT_REDIRECTION_RESULT_SUCCESS;
}
ContentRedirectionStatus ContentRedirection_RemoveDevice(const char *name, int *resultOut) {
if (sCRAddFSLayer == nullptr) {
return CONTENT_REDIRECTION_RESULT_LIB_UNINITIALIZED;
}
if (resultOut == nullptr) {
return CONTENT_REDIRECTION_RESULT_INVALID_ARG;
}
*resultOut = reinterpret_cast<decltype(&RemoveDevice)>(sCRRemoveDevice)(name);
return CONTENT_REDIRECTION_RESULT_SUCCESS;
}