Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 16:35:35 +01:00
parent 91f77ed210
commit 142aa827d2
29 changed files with 512 additions and 366 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

View File

@ -6,8 +6,16 @@ on:
- main - main
jobs: 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 ./src
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request] on: [pull_request]
jobs: 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 ./src
build-binary: build-binary:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
needs: clang-format
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: build binary - name: build binary

View File

@ -1,3 +1,5 @@
[![CI-Release](https://github.com/wiiu-env/RPXLoadingModule/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/RPXLoadingModule/actions/workflows/ci.yml)
## Usage ## Usage
(`[ENVIRONMENT]` is a placeholder for the actual environment name.) (`[ENVIRONMENT]` is a placeholder for the actual environment name.)
@ -18,3 +20,7 @@ docker run -it --rm -v ${PWD}:/project rpxloadingmodule-builder make
# make clean # make clean
docker run -it --rm -v ${PWD}:/project rpxloadingmodule-builder make clean docker run -it --rm -v ${PWD}:/project rpxloadingmodule-builder make clean
``` ```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i`

View File

@ -1,28 +1,28 @@
#include "FSDirReplacements.h" #include "FSDirReplacements.h"
#include <coreinit/filesystem.h>
#include <coreinit/cache.h>
#include "utils/logger.h"
#include "globals.h"
#include "FSWrapper.h" #include "FSWrapper.h"
#include "FileUtils.h" #include "FileUtils.h"
#include "globals.h"
#include "utils/logger.h"
#include <coreinit/cache.h>
#include <coreinit/filesystem.h>
#define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \ #define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \
return res; \ return res; \
} }
#define ASYNC_RESULT_HANDLER [client, block, asyncData](FSStatus res) -> FSStatus { \ #define ASYNC_RESULT_HANDLER [client, block, asyncData](FSStatus res) -> FSStatus { \
DEBUG_FUNCTION_LINE_VERBOSE("Result was %d", res); \ DEBUG_FUNCTION_LINE_VERBOSE("Result was %d", res); \
return send_result_async(client, block, asyncData, res); \ return send_result_async(client, block, asyncData, res); \
} }
DECL_FUNCTION(FSStatus, FSOpenDir, FSClient *client, FSCmdBlock *block, char *path, FSDirectoryHandle *handle, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSOpenDir, FSClient *client, FSCmdBlock *block, char *path, FSDirectoryHandle *handle, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSOpenDirWrapper(path, handle, errorMask, FSStatus result = FSOpenDirWrapper(
[client, block, handle, errorMask] path, handle, errorMask,
(char *_path) -> FSStatus { [client, block, handle, errorMask](char *_path) -> FSStatus {
return real_FSOpenDir(client, block, _path, handle, errorMask); return real_FSOpenDir(client, block, _path, handle, errorMask);
}, },
SYNC_RESULT_HANDLER); SYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
DEBUG_FUNCTION_LINE_VERBOSE("Result was %d", result); DEBUG_FUNCTION_LINE_VERBOSE("Result was %d", result);
return result; return result;
@ -37,12 +37,12 @@ DECL_FUNCTION(FSStatus, FSOpenDirAsync, FSClient *client, FSCmdBlock *block, cha
// Even real_FSOpenDir is still calling our FSOpenDirAsync hook. To bypass our code we use "FORCE_REAL_FUNC_WITH_FULL_ERRORS" as an errorMask. // Even real_FSOpenDir is still calling our FSOpenDirAsync hook. To bypass our code we use "FORCE_REAL_FUNC_WITH_FULL_ERRORS" as an errorMask.
if ((errorMask & ERROR_FLAG_MASK) != FORCE_REAL_FUNC_MAGIC) { if ((errorMask & ERROR_FLAG_MASK) != FORCE_REAL_FUNC_MAGIC) {
FSStatus result = FSOpenDirWrapper(path, handle, errorMask, FSStatus result = FSOpenDirWrapper(
[client, block, handle, errorMask, asyncData] path, handle, errorMask,
(char *_path) -> FSStatus { [client, block, handle, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSOpenDirAsync(client, block, _path, handle, errorMask, asyncData); return real_FSOpenDirAsync(client, block, _path, handle, errorMask, asyncData);
}, },
ASYNC_RESULT_HANDLER); ASYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -133,12 +133,12 @@ DECL_FUNCTION(FSStatus, FSRewindDirAsync, FSClient *client, FSCmdBlock *block, F
DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSMakeDirWrapper(path, errorMask, FSStatus result = FSMakeDirWrapper(
[client, block, errorMask] path, errorMask,
(char *_path) -> FSStatus { [client, block, errorMask](char *_path) -> FSStatus {
return real_FSMakeDir(client, block, _path, errorMask); return real_FSMakeDir(client, block, _path, errorMask);
}, },
SYNC_RESULT_HANDLER); SYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -148,12 +148,12 @@ DECL_FUNCTION(FSStatus, FSMakeDir, FSClient *client, FSCmdBlock *block, char *pa
DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSMakeDirWrapper(path, errorMask, FSStatus result = FSMakeDirWrapper(
[client, block, errorMask, asyncData] path, errorMask,
(char *_path) -> FSStatus { [client, block, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSMakeDirAsync(client, block, _path, errorMask, asyncData); return real_FSMakeDirAsync(client, block, _path, errorMask, asyncData);
}, },
ASYNC_RESULT_HANDLER); ASYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -163,10 +163,10 @@ DECL_FUNCTION(FSStatus, FSMakeDirAsync, FSClient *client, FSCmdBlock *block, cha
DECL_FUNCTION(FSStatus, FSChangeDirAsync, FSClient *client, FSCmdBlock *block, const char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSChangeDirAsync, FSClient *client, FSCmdBlock *block, const char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("FSChangeDirAsync %s", path); DEBUG_FUNCTION_LINE_VERBOSE("FSChangeDirAsync %s", path);
snprintf(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir), "%s", path); snprintf(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir), "%s", path);
int len = strlen(gReplacementInfo.contentReplacementInfo.workingDir); auto len = strlen(gReplacementInfo.contentReplacementInfo.workingDir);
if (len > 0 && gReplacementInfo.contentReplacementInfo.workingDir[len - 1] != '/') { if (len > 0 && gReplacementInfo.contentReplacementInfo.workingDir[len - 1] != '/') {
gReplacementInfo.contentReplacementInfo.workingDir[len - 1] = '/'; gReplacementInfo.contentReplacementInfo.workingDir[len - 1] = '/';
gReplacementInfo.contentReplacementInfo.workingDir[len] = 0; gReplacementInfo.contentReplacementInfo.workingDir[len] = 0;
} }
DCFlushRange(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir)); DCFlushRange(gReplacementInfo.contentReplacementInfo.workingDir, sizeof(gReplacementInfo.contentReplacementInfo.workingDir));
return real_FSChangeDirAsync(client, block, path, errorMask, asyncData); return real_FSChangeDirAsync(client, block, path, errorMask, asyncData);

View File

@ -13,4 +13,3 @@ extern uint32_t fs_dir_function_replacements_size;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -4,26 +4,26 @@
#include <coreinit/dynload.h> #include <coreinit/dynload.h>
#include <cstring> #include <cstring>
#include "utils/logger.h"
#include "FileUtils.h"
#include "FSWrapper.h" #include "FSWrapper.h"
#include "FileUtils.h"
#include "utils/logger.h"
#define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \ #define SYNC_RESULT_HANDLER [](FSStatus res) -> FSStatus { \
return res; \ return res; \
} }
#define ASYNC_RESULT_HANDLER [client, block, asyncData](FSStatus res) -> FSStatus { \ #define ASYNC_RESULT_HANDLER [client, block, asyncData](FSStatus res) -> FSStatus { \
return send_result_async(client, block, asyncData, res);\ return send_result_async(client, block, asyncData, res); \
} }
DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSOpenFileWrapper(path, mode, handle, errorMask, FSStatus result = FSOpenFileWrapper(
[client, block, mode, handle, errorMask] path, mode, handle, errorMask,
(char *_path) -> FSStatus { [client, block, mode, handle, errorMask](char *_path) -> FSStatus {
return real_FSOpenFile(client, block, _path, mode, handle, errorMask); return real_FSOpenFile(client, block, _path, mode, handle, errorMask);
}, },
SYNC_RESULT_HANDLER); SYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -34,12 +34,12 @@ DECL_FUNCTION(FSStatus, FSOpenFile, FSClient *client, FSCmdBlock *block, char *p
DECL_FUNCTION(FSStatus, FSOpenFileAsync, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSOpenFileAsync, FSClient *client, FSCmdBlock *block, char *path, const char *mode, FSFileHandle *handle, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSOpenFileWrapper(path, mode, handle, errorMask, FSStatus result = FSOpenFileWrapper(
[client, block, mode, handle, errorMask, asyncData] path, mode, handle, errorMask,
(char *_path) -> FSStatus { [client, block, mode, handle, errorMask, asyncData](char *_path) -> FSStatus {
return real_FSOpenFileAsync(client, block, _path, mode, handle, errorMask, asyncData); return real_FSOpenFileAsync(client, block, _path, mode, handle, errorMask, asyncData);
}, },
ASYNC_RESULT_HANDLER); ASYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -70,11 +70,12 @@ DECL_FUNCTION(FSStatus, FSCloseFileAsync, FSClient *client, FSCmdBlock *block, F
DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSGetStatWrapper(path, stats, errorMask, FSStatus result = FSGetStatWrapper(
[client, block, stats, errorMask](char *_path) -> FSStatus { path, stats, errorMask,
return real_FSGetStat(client, block, _path, stats, errorMask); [client, block, stats, errorMask](char *_path) -> FSStatus {
}, return real_FSGetStat(client, block, _path, stats, errorMask);
SYNC_RESULT_HANDLER); },
SYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -83,11 +84,12 @@ DECL_FUNCTION(FSStatus, FSGetStat, FSClient *client, FSCmdBlock *block, char *pa
DECL_FUNCTION(FSStatus, FSGetStatAsync, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSGetStatAsync, FSClient *client, FSCmdBlock *block, char *path, FSStat *stats, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSGetStatWrapper(path, stats, errorMask, FSStatus result = FSGetStatWrapper(
[client, block, stats, errorMask, asyncData](char *_path) -> FSStatus { path, stats, errorMask,
return real_FSGetStatAsync(client, block, _path, stats, errorMask, asyncData); [client, block, stats, errorMask, asyncData](char *_path) -> FSStatus {
}, return real_FSGetStatAsync(client, block, _path, stats, errorMask, asyncData);
ASYNC_RESULT_HANDLER); },
ASYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -257,11 +259,12 @@ DECL_FUNCTION(FSStatus, FSTruncateFileAsync, FSClient *client, FSCmdBlock *block
DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSRemoveWrapper(path, errorMask, FSStatus result = FSRemoveWrapper(
[client, block, errorMask](char *_path) -> FSStatus { path, errorMask,
return real_FSRemove(client, block, _path, errorMask); [client, block, errorMask](char *_path) -> FSStatus {
}, return real_FSRemove(client, block, _path, errorMask);
SYNC_RESULT_HANDLER); },
SYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -271,11 +274,12 @@ DECL_FUNCTION(FSStatus, FSRemove, FSClient *client, FSCmdBlock *block, char *pat
DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, char *path, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s", path); DEBUG_FUNCTION_LINE_VERBOSE("%s", path);
FSStatus result = FSRemoveWrapper(path, errorMask, FSStatus result = FSRemoveWrapper(
[client, block, errorMask, asyncData](char *_path) -> FSStatus { path, errorMask,
return real_FSRemoveAsync(client, block, _path, errorMask, asyncData); [client, block, errorMask, asyncData](char *_path) -> FSStatus {
}, return real_FSRemoveAsync(client, block, _path, errorMask, asyncData);
ASYNC_RESULT_HANDLER); },
ASYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -285,11 +289,12 @@ DECL_FUNCTION(FSStatus, FSRemoveAsync, FSClient *client, FSCmdBlock *block, char
DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask) { DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask) {
DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath); DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath);
FSStatus result = FSRenameWrapper(oldPath, newPath, errorMask, FSStatus result = FSRenameWrapper(
[client, block, errorMask](char *_oldOath, char *_newPath) -> FSStatus { oldPath, newPath, errorMask,
return real_FSRename(client, block, _oldOath, _newPath, errorMask); [client, block, errorMask](char *_oldOath, char *_newPath) -> FSStatus {
}, return real_FSRename(client, block, _oldOath, _newPath, errorMask);
SYNC_RESULT_HANDLER); },
SYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }
@ -299,11 +304,12 @@ DECL_FUNCTION(FSStatus, FSRename, FSClient *client, FSCmdBlock *block, char *old
DECL_FUNCTION(FSStatus, FSRenameAsync, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask, FSAsyncData *asyncData) { DECL_FUNCTION(FSStatus, FSRenameAsync, FSClient *client, FSCmdBlock *block, char *oldPath, char *newPath, FSErrorFlag errorMask, FSAsyncData *asyncData) {
DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath); DEBUG_FUNCTION_LINE_VERBOSE("%s %s", oldPath, newPath);
FSStatus result = FSRenameWrapper(oldPath, newPath, errorMask, FSStatus result = FSRenameWrapper(
[client, block, errorMask, asyncData](char *_oldOath, char *_newPath) -> FSStatus { oldPath, newPath, errorMask,
return real_FSRenameAsync(client, block, _oldOath, _newPath, errorMask, asyncData); [client, block, errorMask, asyncData](char *_oldOath, char *_newPath) -> FSStatus {
}, return real_FSRenameAsync(client, block, _oldOath, _newPath, errorMask, asyncData);
ASYNC_RESULT_HANDLER); },
ASYNC_RESULT_HANDLER);
if (result != FS_STATUS_USE_REAL_OS) { if (result != FS_STATUS_USE_REAL_OS) {
return result; return result;
} }

View File

@ -13,4 +13,3 @@ extern uint32_t fs_file_function_replacements_size;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,15 +1,15 @@
#include "FSWrapper.h" #include "FSWrapper.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <cstring>
#include <mutex>
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include "utils/logger.h"
#include "FileUtils.h" #include "FileUtils.h"
#include "globals.h" #include "globals.h"
#include "utils/logger.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <cstring>
#include <fcntl.h>
#include <mutex>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
dirMagic_t dir_handles[DIR_HANDLES_LENGTH]; dirMagic_t dir_handles[DIR_HANDLES_LENGTH];
fileMagic_t file_handles[FILE_HANDLES_LENGTH]; fileMagic_t file_handles[FILE_HANDLES_LENGTH];
@ -59,10 +59,10 @@ int getNewFileHandleIndex() {
handle_id = i; handle_id = i;
if (!file_handles[i].mutex) { if (!file_handles[i].mutex) {
file_handles[i].mutex = (OSMutex *) malloc(sizeof(OSMutex)); file_handles[i].mutex = (OSMutex *) malloc(sizeof(OSMutex));
OSInitMutex(file_handles[i].mutex);
if (!file_handles[i].mutex) { if (!file_handles[i].mutex) {
OSFatal("Failed to alloc memory for mutex"); OSFatal("Failed to alloc memory for mutex");
} }
OSInitMutex(file_handles[i].mutex);
DCFlushRange(file_handles[i].mutex, sizeof(OSMutex)); DCFlushRange(file_handles[i].mutex, sizeof(OSMutex));
DCFlushRange(&file_handles[i], sizeof(fileMagic_t)); DCFlushRange(&file_handles[i], sizeof(fileMagic_t));
} }
@ -172,8 +172,8 @@ FSStatus FSOpenDirWrapper(char *path,
if ((dir = opendir(pathForCheck))) { if ((dir = opendir(pathForCheck))) {
OSLockMutex(dir_handles[handle_index].mutex); OSLockMutex(dir_handles[handle_index].mutex);
dir_handles[handle_index].handle = DIR_HANDLE_MAGIC | handle_index; dir_handles[handle_index].handle = DIR_HANDLE_MAGIC | handle_index;
*handle = dir_handles[handle_index].handle; *handle = dir_handles[handle_index].handle;
dir_handles[handle_index].dir = dir; dir_handles[handle_index].dir = dir;
dir_handles[handle_index].in_use = true; dir_handles[handle_index].in_use = true;
dir_handles[handle_index].path[0] = '\0'; dir_handles[handle_index].path[0] = '\0';
@ -182,8 +182,8 @@ FSStatus FSOpenDirWrapper(char *path,
if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) { if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) {
auto dir_info = &dir_handles[handle_index]; auto dir_info = &dir_handles[handle_index];
dir_info->readResult = nullptr; dir_info->readResult = nullptr;
dir_info->readResultCapacity = 0; dir_info->readResultCapacity = 0;
dir_info->readResultNumberOfEntries = 0; dir_info->readResultNumberOfEntries = 0;
dir_info->realDirHandle = 0; dir_info->realDirHandle = 0;
@ -256,25 +256,25 @@ FSStatus FSReadDirWrapper(FSDirectoryHandle handle,
} }
struct dirent *entry_ = readdir(dir); struct dirent *entry_ = readdir(dir);
FSStatus result = FS_STATUS_END; FSStatus result = FS_STATUS_END;
if (entry_) { if (entry_) {
entry->name[0] = '\0'; entry->name[0] = '\0';
strncat(entry->name, entry_->d_name, sizeof(entry->name) - 1); strncat(entry->name, entry_->d_name, sizeof(entry->name) - 1);
entry->info.mode = (FSMode) FS_MODE_READ_OWNER; entry->info.mode = (FSMode) FS_MODE_READ_OWNER;
if (entry_->d_type == DT_DIR) { if (entry_->d_type == DT_DIR) {
entry->info.flags = (FSStatFlags) ((uint32_t) FS_STAT_DIRECTORY); entry->info.flags = (FSStatFlags) ((uint32_t) FS_STAT_DIRECTORY);
entry->info.size = 0; entry->info.size = 0;
} else { } else {
entry->info.flags = (FSStatFlags) 0; entry->info.flags = (FSStatFlags) 0;
if (strcmp(entry_->d_name, ".") == 0 || strcmp(entry_->d_name, "..") == 0) { if (strcmp(entry_->d_name, ".") == 0 || strcmp(entry_->d_name, "..") == 0) {
entry->info.size = 0; entry->info.size = 0;
} else { } else {
struct stat sb{}; struct stat sb {};
int strLen = strlen(dir_handles[handle_index].path) + 1 + strlen(entry_->d_name) + 1; int strLen = strlen(dir_handles[handle_index].path) + 1 + strlen(entry_->d_name) + 1;
char path[strLen]; char path[strLen];
snprintf(path, sizeof(path), "%s/%s", dir_handles[handle_index].path, entry_->d_name); snprintf(path, sizeof(path), "%s/%s", dir_handles[handle_index].path, entry_->d_name);
if (stat(path, &sb) >= 0) { if (stat(path, &sb) >= 0) {
entry->info.size = sb.st_size; entry->info.size = sb.st_size;
entry->info.flags = (FSStatFlags) 0; entry->info.flags = (FSStatFlags) 0;
entry->info.owner = sb.st_uid; entry->info.owner = sb.st_uid;
entry->info.group = sb.st_gid; entry->info.group = sb.st_gid;
@ -285,8 +285,8 @@ FSStatus FSReadDirWrapper(FSDirectoryHandle handle,
if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) { if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) {
auto dir_info = &dir_handles[handle_index]; auto dir_info = &dir_handles[handle_index];
if (dir_info->readResultNumberOfEntries >= dir_info->readResultCapacity) { if (dir_info->readResultNumberOfEntries >= dir_info->readResultCapacity) {
auto newCapacity = dir_info->readResultCapacity * 2; auto newCapacity = dir_info->readResultCapacity * 2;
dir_info->readResult = (FSDirectoryEntry *) realloc(dir_info->readResult, newCapacity * sizeof(FSDirectoryEntry)); dir_info->readResult = (FSDirectoryEntry *) realloc(dir_info->readResult, newCapacity * sizeof(FSDirectoryEntry));
dir_info->readResultCapacity = newCapacity; dir_info->readResultCapacity = newCapacity;
if (dir_info->readResult == nullptr) { if (dir_info->readResult == nullptr) {
OSFatal("Failed to alloc memory for dir entry list"); OSFatal("Failed to alloc memory for dir entry list");
@ -308,7 +308,7 @@ FSStatus FSReadDirWrapper(FSDirectoryHandle handle,
if (gFSClient && gFSCmd) { if (gFSClient && gFSCmd) {
FSDirectoryEntry realDirEntry; FSDirectoryEntry realDirEntry;
FSStatus readDirResult = FS_STATUS_OK; FSStatus readDirResult = FS_STATUS_OK;
result = FS_STATUS_END; result = FS_STATUS_END;
while (readDirResult == FS_STATUS_OK) { while (readDirResult == FS_STATUS_OK) {
readDirResult = real_FSReadDir(gFSClient, gFSCmd, dir_info->realDirHandle, &realDirEntry, (FSErrorFlag) FORCE_REAL_FUNC_WITH_FULL_ERRORS); readDirResult = real_FSReadDir(gFSClient, gFSCmd, dir_info->realDirHandle, &realDirEntry, (FSErrorFlag) FORCE_REAL_FUNC_WITH_FULL_ERRORS);
if (readDirResult == FS_STATUS_OK) { if (readDirResult == FS_STATUS_OK) {
@ -389,8 +389,8 @@ FSStatus FSCloseDirWrapper(FSDirectoryHandle handle,
if (dir_info->readResult != nullptr) { if (dir_info->readResult != nullptr) {
free(dir_info->readResult); free(dir_info->readResult);
dir_info->readResult = nullptr; dir_info->readResult = nullptr;
dir_info->readResultCapacity = 0; dir_info->readResultCapacity = 0;
dir_info->readResultNumberOfEntries = 0; dir_info->readResultNumberOfEntries = 0;
} }
DCFlushRange(dir_info, sizeof(dirMagic_t)); DCFlushRange(dir_info, sizeof(dirMagic_t));
@ -511,7 +511,7 @@ FSStatus FSOpenFileWrapper(char *path,
DEBUG_FUNCTION_LINE_VERBOSE("%s -> %s", path, pathForCheck); DEBUG_FUNCTION_LINE_VERBOSE("%s -> %s", path, pathForCheck);
int handle_index = getNewFileHandleIndex(); int handle_index = getNewFileHandleIndex();
FSStatus result = FS_STATUS_OK; FSStatus result = FS_STATUS_OK;
if (handle_index >= 0) { if (handle_index >= 0) {
OSLockMutex(file_handles[handle_index].mutex); OSLockMutex(file_handles[handle_index].mutex);
int _mode = 0; int _mode = 0;
@ -541,8 +541,8 @@ FSStatus FSOpenFileWrapper(char *path,
file_handles[handle_index].handle = FILE_HANDLE_MAGIC + handle_index; file_handles[handle_index].handle = FILE_HANDLE_MAGIC + handle_index;
//DEBUG_FUNCTION_LINE("handle %08X", file_handles[handle_index].handle); //DEBUG_FUNCTION_LINE("handle %08X", file_handles[handle_index].handle);
*handle = file_handles[handle_index].handle; *handle = file_handles[handle_index].handle;
file_handles[handle_index].fd = fd; file_handles[handle_index].fd = fd;
file_handles[handle_index].in_use = true; file_handles[handle_index].in_use = true;
DCFlushRange(&file_handles[handle_index], sizeof(fileMagic_t)); DCFlushRange(&file_handles[handle_index], sizeof(fileMagic_t));
} else { } else {
@ -587,7 +587,7 @@ FSStatus FSCloseFileWrapper(FSFileHandle handle,
OSLockMutex(file_handles[handle_index].mutex); OSLockMutex(file_handles[handle_index].mutex);
int real_fd = file_handles[handle_index].fd; int real_fd = file_handles[handle_index].fd;
file_handles[handle_index].in_use = false; file_handles[handle_index].in_use = false;
DEBUG_FUNCTION_LINE_VERBOSE("closing %d", real_fd); DEBUG_FUNCTION_LINE_VERBOSE("closing %d", real_fd);
@ -634,7 +634,7 @@ FSStatus FSGetStatWrapper(char *path, FSStat *stats, FSErrorFlag errorMask,
DEBUG_FUNCTION_LINE("Invalid args"); DEBUG_FUNCTION_LINE("Invalid args");
return FS_STATUS_FATAL_ERROR; return FS_STATUS_FATAL_ERROR;
} else { } else {
struct stat path_stat{}; struct stat path_stat {};
memset(&path_stat, 0, sizeof(path_stat)); memset(&path_stat, 0, sizeof(path_stat));
if (stat(pathForCheck, &path_stat) < 0) { if (stat(pathForCheck, &path_stat) < 0) {
if (gReplacementInfo.contentReplacementInfo.fallbackOnError) { if (gReplacementInfo.contentReplacementInfo.fallbackOnError) {
@ -648,8 +648,8 @@ FSStatus FSGetStatWrapper(char *path, FSStat *stats, FSErrorFlag errorMask,
if (S_ISDIR(path_stat.st_mode)) { if (S_ISDIR(path_stat.st_mode)) {
stats->flags = (FSStatFlags) ((uint32_t) FS_STAT_DIRECTORY); stats->flags = (FSStatFlags) ((uint32_t) FS_STAT_DIRECTORY);
} else { } else {
stats->size = path_stat.st_size; stats->size = path_stat.st_size;
stats->mode = (FSMode) FS_MODE_READ_OWNER; stats->mode = (FSMode) FS_MODE_READ_OWNER;
stats->flags = (FSStatFlags) 0; stats->flags = (FSStatFlags) 0;
stats->owner = path_stat.st_uid; stats->owner = path_stat.st_uid;
stats->group = path_stat.st_gid; stats->group = path_stat.st_gid;
@ -698,7 +698,7 @@ FSStatus FSGetStatFileWrapper(FSFileHandle handle,
int real_fd = file_handles[handle_index].fd; int real_fd = file_handles[handle_index].fd;
//DEBUG_FUNCTION_LINE("FSGetStatFileAsync real_fd %d", real_fd); //DEBUG_FUNCTION_LINE("FSGetStatFileAsync real_fd %d", real_fd);
struct stat path_stat{}; struct stat path_stat {};
FSStatus result = FS_STATUS_OK; FSStatus result = FS_STATUS_OK;
if (fstat(real_fd, &path_stat) < 0) { if (fstat(real_fd, &path_stat) < 0) {
@ -706,8 +706,8 @@ FSStatus FSGetStatFileWrapper(FSFileHandle handle,
} else { } else {
memset(&(stats->flags), 0, sizeof(stats->flags)); memset(&(stats->flags), 0, sizeof(stats->flags));
stats->size = path_stat.st_size; stats->size = path_stat.st_size;
stats->mode = (FSMode) FS_MODE_READ_OWNER; stats->mode = (FSMode) FS_MODE_READ_OWNER;
stats->flags = (FSStatFlags) 0; stats->flags = (FSStatFlags) 0;
stats->owner = path_stat.st_uid; stats->owner = path_stat.st_uid;
stats->group = path_stat.st_gid; stats->group = path_stat.st_gid;
@ -779,14 +779,12 @@ FSStatus FSReadFileWithPosWrapper(void *buffer,
FSStatus result; FSStatus result;
if ((result = FSSetPosFileWrapper(handle, pos, errorMask, if ((result = FSSetPosFileWrapper(handle, pos, errorMask,
[](FSStatus res) -> FSStatus { return res; }) [](FSStatus res) -> FSStatus { return res; })) != FS_STATUS_OK) {
) != FS_STATUS_OK) {
return result; return result;
} }
result = FSReadFileWrapper(buffer, size, count, handle, unk1, errorMask, result = FSReadFileWrapper(buffer, size, count, handle, unk1, errorMask,
[](FSStatus res) -> FSStatus { return res; } [](FSStatus res) -> FSStatus { return res; });
);
if (result != FS_STATUS_USE_REAL_OS && result != FS_STATUS_FATAL_ERROR) { if (result != FS_STATUS_USE_REAL_OS && result != FS_STATUS_FATAL_ERROR) {
return result_handler(result); return result_handler(result);
@ -881,7 +879,7 @@ FSStatus FSIsEofWrapper(FSFileHandle handle,
int real_fd = file_handles[handle_index].fd; int real_fd = file_handles[handle_index].fd;
off_t currentPos = lseek(real_fd, (off_t) 0, SEEK_CUR); off_t currentPos = lseek(real_fd, (off_t) 0, SEEK_CUR);
off_t endPos = lseek(real_fd, (off_t) 0, SEEK_END); off_t endPos = lseek(real_fd, (off_t) 0, SEEK_END);
if (currentPos == endPos) { if (currentPos == endPos) {
DEBUG_FUNCTION_LINE_VERBOSE("FSIsEof END for %d\n", real_fd); DEBUG_FUNCTION_LINE_VERBOSE("FSIsEof END for %d\n", real_fd);

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
#include <cstdint> #include <cstdint>
#include <dirent.h> #include <dirent.h>
#include <functional> #include <functional>
#include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
typedef struct dirMagic { typedef struct dirMagic {
uint32_t handle{}; uint32_t handle{};
@ -14,8 +14,8 @@ typedef struct dirMagic {
OSMutex *mutex{}; OSMutex *mutex{};
FSDirectoryEntry *readResult = nullptr; FSDirectoryEntry *readResult = nullptr;
int readResultCapacity = 0; int readResultCapacity = 0;
int readResultNumberOfEntries = 0; int readResultNumberOfEntries = 0;
FSDirectoryHandle realDirHandle = 0; FSDirectoryHandle realDirHandle = 0;
@ -29,20 +29,20 @@ typedef struct fileMagic {
} fileMagic_t; } fileMagic_t;
#define ERROR_FLAG_MASK (0xFFFF0000) #define ERROR_FLAG_MASK (0xFFFF0000)
#define FORCE_REAL_FUNC_MAGIC (0x42420000) #define FORCE_REAL_FUNC_MAGIC (0x42420000)
#define FORCE_REAL_FUNC_WITH_FULL_ERRORS (FORCE_REAL_FUNC_MAGIC | 0x0000FFFF) #define FORCE_REAL_FUNC_WITH_FULL_ERRORS (FORCE_REAL_FUNC_MAGIC | 0x0000FFFF)
#define HANDLE_INDICATOR_MASK 0xFFFFFF00 #define HANDLE_INDICATOR_MASK 0xFFFFFF00
#define HANDLE_INDICATOR_MASK 0xFFFFFF00 #define HANDLE_INDICATOR_MASK 0xFFFFFF00
#define HANDLE_MASK (0x000000FF) #define HANDLE_MASK (0x000000FF)
#define DIR_HANDLE_MAGIC 0x30000000 #define DIR_HANDLE_MAGIC 0x30000000
#define FILE_HANDLE_MAGIC 0x30000100 #define FILE_HANDLE_MAGIC 0x30000100
#define FILE_HANDLES_LENGTH 64 #define FILE_HANDLES_LENGTH 64
#define DIR_HANDLES_LENGTH 64 #define DIR_HANDLES_LENGTH 64
#define FS_STATUS_USE_REAL_OS (FSStatus) 0xFFFF0000 #define FS_STATUS_USE_REAL_OS (FSStatus) 0xFFFF0000
extern dirMagic_t dir_handles[DIR_HANDLES_LENGTH]; extern dirMagic_t dir_handles[DIR_HANDLES_LENGTH];
extern fileMagic_t file_handles[FILE_HANDLES_LENGTH]; extern fileMagic_t file_handles[FILE_HANDLES_LENGTH];

View File

@ -1,18 +1,18 @@
#include "FileUtils.h" #include "FileUtils.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <mutex> #include <mutex>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "utils/StringTools.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <map>
#include <coreinit/thread.h> #include <coreinit/thread.h>
#include <dirent.h> #include <dirent.h>
#include <coreinit/cache.h> #include <map>
#include "utils/StringTools.h"
#include "utils/utils.h"
#include "utils/logger.h"
extern "C" OSMessageQueue *OSGetDefaultAppIOQueue(); extern "C" OSMessageQueue *OSGetDefaultAppIOQueue();
@ -42,17 +42,17 @@ FSStatus send_result_async(FSClient *client, FSCmdBlock *block, FSAsyncData *asy
#pragma GCC diagnostic ignored "-Waddress-of-packed-member" #pragma GCC diagnostic ignored "-Waddress-of-packed-member"
FSAsyncResult *result = &(fsCmdBlockGetBody(block)->asyncResult); FSAsyncResult *result = &(fsCmdBlockGetBody(block)->asyncResult);
//DEBUG_FUNCTION_LINE("Send result %d to ioMsgQueue (%08X)", status, asyncData->ioMsgQueue); //DEBUG_FUNCTION_LINE("Send result %d to ioMsgQueue (%08X)", status, asyncData->ioMsgQueue);
result->asyncData.callback = asyncData->callback; result->asyncData.callback = asyncData->callback;
result->asyncData.param = asyncData->param; result->asyncData.param = asyncData->param;
result->asyncData.ioMsgQueue = asyncData->ioMsgQueue; result->asyncData.ioMsgQueue = asyncData->ioMsgQueue;
memset(&result->ioMsg, 0, sizeof(result->ioMsg)); memset(&result->ioMsg, 0, sizeof(result->ioMsg));
result->ioMsg.data = result; result->ioMsg.data = result;
result->ioMsg.type = OS_FUNCTION_TYPE_FS_CMD_ASYNC; result->ioMsg.type = OS_FUNCTION_TYPE_FS_CMD_ASYNC;
result->client = client; result->client = client;
result->block = block; result->block = block;
result->status = status; result->status = status;
while (!OSSendMessage(asyncData->ioMsgQueue, (OSMessage * ) & (result->ioMsg), OS_MESSAGE_FLAGS_NONE)) { while (!OSSendMessage(asyncData->ioMsgQueue, (OSMessage *) &(result->ioMsg), OS_MESSAGE_FLAGS_NONE)) {
DEBUG_FUNCTION_LINE("Failed to send message"); DEBUG_FUNCTION_LINE("Failed to send message");
} }
} }
@ -66,7 +66,7 @@ int32_t readIntoBuffer(int32_t handle, void *buffer, size_t size, size_t count)
if (sizeToRead > 0x100000) { if (sizeToRead > 0x100000) {
sizeToRead = 0x100000; sizeToRead = 0x100000;
}*/ }*/
void *newBuffer = buffer; void *newBuffer = buffer;
int32_t curResult = -1; int32_t curResult = -1;
int32_t totalSize = 0; int32_t totalSize = 0;
// int32_t toRead = 0; // int32_t toRead = 0;
@ -96,7 +96,7 @@ int32_t CheckFile(const char *filepath) {
return 0; return 0;
} }
struct stat filestat{}; struct stat filestat {};
char dirnoslash[strlen(filepath) + 2]; char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
@ -142,7 +142,7 @@ int32_t CreateSubfolder(const char *fullpath) {
if (!ptr) { if (!ptr) {
//!Device root directory (must be with '/') //!Device root directory (must be with '/')
strcat(parentpath, "/"); strcat(parentpath, "/");
struct stat filestat{}; struct stat filestat {};
if (stat(parentpath, &filestat) == 0) { if (stat(parentpath, &filestat) == 0) {
return 1; return 1;
} }
@ -180,12 +180,12 @@ int32_t getRPXInfoForPath(const std::string &path, romfs_fileInfo *info) {
return -2; return -2;
} }
bool found = false; bool found = false;
int res = -3; int res = -3;
while ((entry = readdir(dir)) != nullptr) { while ((entry = readdir(dir)) != nullptr) {
if (StringTools::EndsWith(entry->d_name, ".rpx")) { if (StringTools::EndsWith(entry->d_name, ".rpx")) {
if (romfsGetFileInfoPerPath("rcc", (std::string("code/") + entry->d_name).c_str(), info) >= 0) { if (romfsGetFileInfoPerPath("rcc", (std::string("code/") + entry->d_name).c_str(), info) >= 0) {
found = true; found = true;
res = 0; res = 0;
} else { } else {
DEBUG_FUNCTION_LINE("Failed to get info for %s", entry->d_name); DEBUG_FUNCTION_LINE("Failed to get info for %s", entry->d_name);
} }

View File

@ -1,14 +1,13 @@
#pragma once #pragma once
#include <string>
#include <coreinit/filesystem.h> #include <coreinit/filesystem.h>
#include <romfs_dev.h> #include <romfs_dev.h>
#include <string>
struct WUT_PACKED FSCmdBlockBody {//! FSAsyncResult object used for this command. struct WUT_PACKED FSCmdBlockBody { //! FSAsyncResult object used for this command.
WUT_UNKNOWN_BYTES(0x96C); WUT_UNKNOWN_BYTES(0x96C);
FSAsyncResult asyncResult; FSAsyncResult asyncResult;
}; };
WUT_CHECK_OFFSET(FSCmdBlockBody, 0x96C, asyncResult); WUT_CHECK_OFFSET(FSCmdBlockBody, 0x96C, asyncResult);
WUT_CHECK_SIZE(FSCmdBlockBody, 0x96C + 0x28); WUT_CHECK_SIZE(FSCmdBlockBody, 0x96C + 0x28);

View File

@ -1,21 +1,21 @@
#include <string>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <romfs_dev.h>
#include "utils/logger.h"
#include "RPXLoading.h" #include "RPXLoading.h"
#include "globals.h"
#include "FileUtils.h" #include "FileUtils.h"
#include <nn/acp/title.h> #include "globals.h"
#include <memory>
#include <algorithm>
#include "utils/FileReader.h" #include "utils/FileReader.h"
#include "utils/FileReaderCompressed.h" #include "utils/FileReaderCompressed.h"
#include "utils/StringTools.h" #include "utils/StringTools.h"
#include "utils/ini.h" #include "utils/ini.h"
#include "utils/logger.h"
#include <algorithm>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <cstring> #include <cstring>
#include <rpxloader.h>
#include <dirent.h> #include <dirent.h>
#include <memory>
#include <nn/acp/title.h>
#include <romfs_dev.h>
#include <rpxloader.h>
#include <string>
/* /*
* Patch the meta xml for the home menu * Patch the meta xml for the home menu
@ -43,7 +43,7 @@ DECL_FUNCTION(int, RPX_FSOpenFile, FSClient *client, FSCmdBlock *block, char *pa
if (gReplacementInfo.rpxReplacementInfo.isRPXReplaced) { if (gReplacementInfo.rpxReplacementInfo.isRPXReplaced) {
if (StringTools::EndsWith(path, iconTex)) { if (StringTools::EndsWith(path, iconTex)) {
auto *reader = new FileReader(reinterpret_cast<uint8_t *>(gReplacementInfo.rpxReplacementInfo.iconCache), sizeof(gReplacementInfo.rpxReplacementInfo.iconCache)); auto *reader = new FileReader(reinterpret_cast<uint8_t *>(gReplacementInfo.rpxReplacementInfo.iconCache), sizeof(gReplacementInfo.rpxReplacementInfo.iconCache));
*handle = (uint32_t) reader; *handle = (uint32_t) reader;
return FS_STATUS_OK; return FS_STATUS_OK;
} }
} }
@ -57,7 +57,6 @@ DECL_FUNCTION(FSStatus, RPX_FSReadFile, FSClient *client, FSCmdBlock *block, uin
if ((handle & 0xF0000000) == 0x80000000) { if ((handle & 0xF0000000) == 0x80000000) {
auto reader = (FileReader *) handle; auto reader = (FileReader *) handle;
return (FSStatus) reader->read(buffer, size * count); return (FSStatus) reader->read(buffer, size * count);
} }
FSStatus result = real_RPX_FSReadFile(client, block, buffer, size, count, handle, unk1, flags); FSStatus result = real_RPX_FSReadFile(client, block, buffer, size, count, handle, unk1, flags);
return result; return result;
@ -101,7 +100,7 @@ static int parseINIhandler(void *user, const char *section, const char *name,
fInfo->author[0] = '\0'; fInfo->author[0] = '\0';
strncat(fInfo->author, value, sizeof(fInfo->author) - 1); strncat(fInfo->author, value, sizeof(fInfo->author) - 1);
} else { } else {
return 0; /* unknown section/name, error */ return 0; /* unknown section/name, error */
} }
return 1; return 1;
@ -111,21 +110,21 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
LOAD_REQUEST request; LOAD_REQUEST request;
memset(&request, 0, sizeof(request)); memset(&request, 0, sizeof(request));
request.command = 0xFC; // IPC_CUSTOM_LOAD_CUSTOM_RPX; request.command = 0xFC; // IPC_CUSTOM_LOAD_CUSTOM_RPX;
request.target = 0; // LOAD_FILE_TARGET_SD_CARD request.target = 0; // LOAD_FILE_TARGET_SD_CARD
request.filesize = 0; // unknown filesize request.filesize = 0; // unknown filesize
request.fileoffset = 0; // request.fileoffset = 0; //
romfs_fileInfo info; romfs_fileInfo info;
bool metaLoaded = false; bool metaLoaded = false;
std::string completePath = std::string("/vol/external01/") + bundle_path; std::string completePath = std::string("/vol/external01/") + bundle_path;
int res = getRPXInfoForPath(completePath, &info); int res = getRPXInfoForPath(completePath, &info);
bool isBundle = false; bool isBundle = false;
if (res >= 0) { if (res >= 0) {
isBundle = true; isBundle = true;
request.filesize = ((uint32_t *) &info.length)[1]; request.filesize = ((uint32_t *) &info.length)[1];
request.fileoffset = ((uint32_t *) &info.offset)[1]; request.fileoffset = ((uint32_t *) &info.offset)[1];
if (romfsMount("rcc", completePath.c_str(), RomfsSource_FileDescriptor_CafeOS) == 0) { if (romfsMount("rcc", completePath.c_str(), RomfsSource_FileDescriptor_CafeOS) == 0) {
@ -138,14 +137,14 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
if (CheckFile("rcc:/meta/iconTex.tga")) { if (CheckFile("rcc:/meta/iconTex.tga")) {
std::string path = "rcc:/meta/iconTex.tga"; std::string path = "rcc:/meta/iconTex.tga";
reader = new FileReader(path); reader = new FileReader(path);
} else if (CheckFile("rcc:/meta/iconTex.tga.gz")) { } else if (CheckFile("rcc:/meta/iconTex.tga.gz")) {
std::string path = "rcc:/meta/iconTex.tga.gz"; std::string path = "rcc:/meta/iconTex.tga.gz";
reader = new FileReaderCompressed(path); reader = new FileReaderCompressed(path);
} }
if (reader) { if (reader) {
uint32_t alreadyRead = 0; uint32_t alreadyRead = 0;
uint32_t toRead = sizeof(gReplacementInfo.rpxReplacementInfo.iconCache); uint32_t toRead = sizeof(gReplacementInfo.rpxReplacementInfo.iconCache);
do { do {
int read = reader->read(reinterpret_cast<uint8_t *>(&gReplacementInfo.rpxReplacementInfo.iconCache[alreadyRead]), toRead); int read = reader->read(reinterpret_cast<uint8_t *>(&gReplacementInfo.rpxReplacementInfo.iconCache[alreadyRead]), toRead);
if (read <= 0) { if (read <= 0) {
@ -168,9 +167,9 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
} }
if (!metaLoaded) { if (!metaLoaded) {
gReplacementInfo.rpxReplacementInfo.metaInformation.author[0] = '\0'; gReplacementInfo.rpxReplacementInfo.metaInformation.author[0] = '\0';
gReplacementInfo.rpxReplacementInfo.metaInformation.shortname[0] = '\0'; gReplacementInfo.rpxReplacementInfo.metaInformation.shortname[0] = '\0';
gReplacementInfo.rpxReplacementInfo.metaInformation.longname[0] = '\0'; gReplacementInfo.rpxReplacementInfo.metaInformation.longname[0] = '\0';
strncat(gReplacementInfo.rpxReplacementInfo.metaInformation.author, bundle_path, sizeof(gReplacementInfo.rpxReplacementInfo.metaInformation.author) - 1); strncat(gReplacementInfo.rpxReplacementInfo.metaInformation.author, bundle_path, sizeof(gReplacementInfo.rpxReplacementInfo.metaInformation.author) - 1);
strncat(gReplacementInfo.rpxReplacementInfo.metaInformation.shortname, bundle_path, sizeof(gReplacementInfo.rpxReplacementInfo.metaInformation.shortname) - 1); strncat(gReplacementInfo.rpxReplacementInfo.metaInformation.shortname, bundle_path, sizeof(gReplacementInfo.rpxReplacementInfo.metaInformation.shortname) - 1);
@ -180,10 +179,10 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
request.path[0] = '\0'; request.path[0] = '\0';
strncat(request.path, bundle_path, sizeof(request.path) - 1); strncat(request.path, bundle_path, sizeof(request.path) - 1);
DCFlushRange(&request, sizeof(LOAD_REQUEST)); DCFlushRange(&request, sizeof(request));
int success = false; int success = false;
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0); int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0);
if (mcpFd >= 0) { if (mcpFd >= 0) {
int out = 0; int out = 0;
IOS_Ioctl(mcpFd, 100, &request, sizeof(request), &out, sizeof(out)); IOS_Ioctl(mcpFd, 100, &request, sizeof(request), &out, sizeof(out));
@ -212,7 +211,7 @@ bool RL_LoadFromSDOnNextLaunch(const char *bundle_path) {
strncat(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath, strncat(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath,
completePath.c_str(), completePath.c_str(),
sizeof(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) - 1); sizeof(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath) - 1);
gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_FROM_WUHB_BUNDLE; gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_FROM_WUHB_BUNDLE;
gReplacementInfo.contentReplacementInfo.replaceSave = true; gReplacementInfo.contentReplacementInfo.replaceSave = true;
} else { } else {
DEBUG_FUNCTION_LINE("Loaded file is no bundle"); DEBUG_FUNCTION_LINE("Loaded file is no bundle");
@ -265,7 +264,7 @@ int32_t RL_FileOpen(const char *name, uint32_t *handle) {
} }
FileReader *reader; FileReader *reader;
std::string path = std::string(name); std::string path = std::string(name);
std::string pathGZ = path + ".gz"; std::string pathGZ = path + ".gz";
if (CheckFile(path.c_str())) { if (CheckFile(path.c_str())) {
@ -307,9 +306,9 @@ bool RL_RedirectContentWithFallback(const char *newContentPath) {
gReplacementInfo.contentReplacementInfo.replacementPath[0] = '\0'; gReplacementInfo.contentReplacementInfo.replacementPath[0] = '\0';
strncat(gReplacementInfo.contentReplacementInfo.replacementPath, newContentPath, sizeof(gReplacementInfo.contentReplacementInfo.replacementPath) - 1); strncat(gReplacementInfo.contentReplacementInfo.replacementPath, newContentPath, sizeof(gReplacementInfo.contentReplacementInfo.replacementPath) - 1);
gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_FROM_PATH; gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_FROM_PATH;
gReplacementInfo.contentReplacementInfo.fallbackOnError = true; gReplacementInfo.contentReplacementInfo.fallbackOnError = true;
gReplacementInfo.contentReplacementInfo.replaceSave = false; gReplacementInfo.contentReplacementInfo.replaceSave = false;
return true; return true;
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <function_patcher/function_patching.h>
#include <cstdint> #include <cstdint>
#include <function_patcher/function_patching.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -21,5 +21,3 @@ extern uint32_t rpx_utils_function_replacements_size;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,7 +1,7 @@
#include <coreinit/filesystem.h>
#include "globals.h" #include "globals.h"
#include <coreinit/filesystem.h>
RPXLoader_ReplacementInformation gReplacementInfo __attribute__((section(".data"))); RPXLoader_ReplacementInformation gReplacementInfo __attribute__((section(".data")));
FSClient *gFSClient __attribute__((section(".data"))) = nullptr; FSClient *gFSClient __attribute__((section(".data"))) = nullptr;
FSCmdBlock *gFSCmd __attribute__((section(".data"))) = nullptr; FSCmdBlock *gFSCmd __attribute__((section(".data"))) = nullptr;

View File

@ -1,6 +1,6 @@
#include <wums.h>
#include <coreinit/mutex.h>
#include <coreinit/filesystem.h> #include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
#include <wums.h>
typedef struct MetaInformation_t { typedef struct MetaInformation_t {
char shortname[64]; char shortname[64];

View File

@ -1,22 +1,22 @@
#include <wums.h>
#include <cstring> #include <cstring>
#include <malloc.h> #include <malloc.h>
#include <wums.h>
#include "FSDirReplacements.h"
#include "FSFileReplacements.h"
#include "FileUtils.h"
#include "RPXLoading.h"
#include "globals.h"
#include "utils/StringTools.h"
#include "utils/logger.h"
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/title.h> #include <coreinit/title.h>
#include <sysapp/title.h>
#include <string> #include <string>
#include "utils/logger.h" #include <sysapp/title.h>
#include "utils/StringTools.h"
#include "FSFileReplacements.h"
#include "globals.h"
#include "FileUtils.h"
#include "FSDirReplacements.h"
#include "RPXLoading.h"
#include <romfs_dev.h>
#include <coreinit/cache.h> #include <coreinit/cache.h>
#include <nn/act.h> #include <nn/act.h>
#include <romfs_dev.h>
WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader"); WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader");
WUMS_USE_WUT_DEVOPTAB(); WUMS_USE_WUT_DEVOPTAB();
@ -66,12 +66,12 @@ WUMS_APPLICATION_STARTS() {
initLogging(); initLogging();
if (gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced) { if (gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced) {
gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced = false; gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced = false;
gReplacementInfo.rpxReplacementInfo.isRPXReplaced = true; gReplacementInfo.rpxReplacementInfo.isRPXReplaced = true;
} }
if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) { if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) {
auto fsClient = (FSClient *) memalign(0x20, sizeof(FSClient)); auto fsClient = (FSClient *) memalign(0x20, sizeof(FSClient));
auto fsCmd = (FSCmdBlock *) memalign(0x20, sizeof(FSCmdBlock)); auto fsCmd = (FSCmdBlock *) memalign(0x20, sizeof(FSCmdBlock));
if (fsClient == nullptr || fsCmd == nullptr) { if (fsClient == nullptr || fsCmd == nullptr) {
DEBUG_FUNCTION_LINE("Failed to alloc memory for fsclient or fsCmd"); DEBUG_FUNCTION_LINE("Failed to alloc memory for fsclient or fsCmd");
@ -84,7 +84,7 @@ WUMS_APPLICATION_STARTS() {
} else { } else {
FSInitCmdBlock(fsCmd); FSInitCmdBlock(fsCmd);
gFSClient = fsClient; gFSClient = fsClient;
gFSCmd = fsCmd; gFSCmd = fsCmd;
} }
} }
return; return;
@ -92,7 +92,7 @@ WUMS_APPLICATION_STARTS() {
if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) {
DEBUG_FUNCTION_LINE("Set mode to CONTENTREDIRECT_NONE and replaceSave to false"); DEBUG_FUNCTION_LINE("Set mode to CONTENTREDIRECT_NONE and replaceSave to false");
gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_NONE; gReplacementInfo.contentReplacementInfo.mode = CONTENTREDIRECT_NONE;
gReplacementInfo.contentReplacementInfo.replaceSave = false; gReplacementInfo.contentReplacementInfo.replaceSave = false;
DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo));
} else { } else {
@ -100,12 +100,12 @@ WUMS_APPLICATION_STARTS() {
uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath); uint32_t currentHash = StringTools::hash(gReplacementInfo.contentReplacementInfo.bundleMountInformation.toMountPath);
nn::act::Initialize(); nn::act::Initialize();
nn::act::PersistentId slot = nn::act::GetPersistentId(); nn::act::PersistentId persistentId = nn::act::GetPersistentId();
nn::act::Finalize(); nn::act::Finalize();
std::string basePath = StringTools::strfmt("/vol/external01/wiiu/apps/save/%08X", currentHash); std::string basePath = StringTools::strfmt("/vol/external01/wiiu/apps/save/%08X", currentHash);
std::string common = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/common", currentHash); std::string common = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/common", currentHash);
std::string user = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/%08X", currentHash, 0x80000000 | slot); std::string user = StringTools::strfmt("fs:/vol/external01/wiiu/apps/save/%08X/%08X", currentHash, 0x80000000 | persistentId);
gReplacementInfo.contentReplacementInfo.savePath[0] = '\0'; gReplacementInfo.contentReplacementInfo.savePath[0] = '\0';
strncat(gReplacementInfo.contentReplacementInfo.savePath, strncat(gReplacementInfo.contentReplacementInfo.savePath,
@ -140,4 +140,3 @@ WUMS_APPLICATION_STARTS() {
DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo)); DCFlushRange(&gReplacementInfo, sizeof(gReplacementInfo));
} }
} }

View File

@ -14,7 +14,7 @@ int FileReader::read(uint8_t *buffer, uint32_t size) {
if (toRead == 0) { if (toRead == 0) {
return 0; return 0;
} }
memcpy(buffer, input_buffer + input_pos, toRead); memcpy(buffer, &input_buffer[input_pos], toRead);
input_pos += toRead; input_pos += toRead;
return toRead; return toRead;
} else if (isReadFromFile) { } else if (isReadFromFile) {
@ -27,9 +27,9 @@ int FileReader::read(uint8_t *buffer, uint32_t size) {
FileReader::FileReader(std::string &path) { FileReader::FileReader(std::string &path) {
int fd; int fd;
if ((fd = open(path.c_str(), O_RDONLY)) >= 0) { if ((fd = open(path.c_str(), O_RDONLY)) >= 0) {
this->isReadFromFile = true; this->isReadFromFile = true;
this->isReadFromBuffer = false; this->isReadFromBuffer = false;
this->file_fd = fd; this->file_fd = fd;
} else { } else {
DEBUG_FUNCTION_LINE("Failed to open file %s", path.c_str()); DEBUG_FUNCTION_LINE("Failed to open file %s", path.c_str());
} }
@ -42,9 +42,9 @@ FileReader::~FileReader() {
} }
FileReader::FileReader(uint8_t *buffer, uint32_t size) { FileReader::FileReader(uint8_t *buffer, uint32_t size) {
this->input_buffer = buffer; this->input_buffer = buffer;
this->input_size = size; this->input_size = size;
this->input_pos = 0; this->input_pos = 0;
this->isReadFromBuffer = true; this->isReadFromBuffer = true;
this->isReadFromFile = false; this->isReadFromFile = false;
} }

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
class FileReader { class FileReader {
@ -20,9 +20,9 @@ public:
private: private:
bool isReadFromBuffer = false; bool isReadFromBuffer = false;
uint8_t *input_buffer = nullptr; uint8_t *input_buffer = nullptr;
uint32_t input_size = 0; uint32_t input_size = 0;
uint32_t input_pos = 0; uint32_t input_pos = 0;
bool isReadFromFile = false; bool isReadFromFile = false;
int file_fd = 0; int file_fd = 0;
}; };

View File

@ -4,9 +4,9 @@ int FileReaderCompressed::read(uint8_t *buffer, uint32_t size) {
if (!initDone) { if (!initDone) {
return -11; return -11;
} }
int startValue = this->strm.total_out; int startValue = this->strm.total_out;
uint32_t newSize = 0; uint32_t newSize = 0;
int ret = 0; int ret = 0;
do { do {
uint32_t nextOut = BUFFER_SIZE; uint32_t nextOut = BUFFER_SIZE;
if (nextOut > size) { if (nextOut > size) {
@ -18,7 +18,7 @@ int FileReaderCompressed::read(uint8_t *buffer, uint32_t size) {
break; break;
} }
this->strm.avail_in = read_res; this->strm.avail_in = read_res;
this->strm.next_in = this->zlib_in_buf; this->strm.next_in = this->zlib_in_buf;
} }
/* run inflate() on input until output buffer not full */ /* run inflate() on input until output buffer not full */
do { do {
@ -27,8 +27,8 @@ int FileReaderCompressed::read(uint8_t *buffer, uint32_t size) {
} }
this->strm.avail_out = nextOut; this->strm.avail_out = nextOut;
this->strm.next_out = buffer + newSize; this->strm.next_out = buffer + newSize;
ret = inflate(&this->strm, Z_NO_FLUSH); ret = inflate(&this->strm, Z_NO_FLUSH);
if (ret == Z_STREAM_ERROR) { if (ret == Z_STREAM_ERROR) {
DEBUG_FUNCTION_LINE("Z_STREAM_ERROR"); DEBUG_FUNCTION_LINE("Z_STREAM_ERROR");
@ -39,7 +39,7 @@ int FileReaderCompressed::read(uint8_t *buffer, uint32_t size) {
case Z_NEED_DICT: case Z_NEED_DICT:
DEBUG_FUNCTION_LINE("Z_NEED_DICT"); DEBUG_FUNCTION_LINE("Z_NEED_DICT");
ret = Z_DATA_ERROR; ret = Z_DATA_ERROR;
[[fallthrough]]; /* and fall through */ [[fallthrough]]; /* and fall through */
case Z_DATA_ERROR: case Z_DATA_ERROR:
case Z_MEM_ERROR: case Z_MEM_ERROR:
DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR"); DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR");
@ -55,7 +55,7 @@ int FileReaderCompressed::read(uint8_t *buffer, uint32_t size) {
} }
nextOut = BUFFER_SIZE; nextOut = BUFFER_SIZE;
if (newSize + nextOut >= (size)) { if (newSize + nextOut >= (size)) {
nextOut = (size) - newSize; nextOut = (size) -newSize;
} }
} while (this->strm.avail_out == 0 && newSize < (size)); } while (this->strm.avail_out == 0 && newSize < (size));
@ -71,12 +71,12 @@ FileReaderCompressed::FileReaderCompressed(std::string &file) : FileReader(file)
void FileReaderCompressed::initCompressedData() { void FileReaderCompressed::initCompressedData() {
/* allocate inflate state */ /* allocate inflate state */
this->strm.zalloc = Z_NULL; this->strm.zalloc = Z_NULL;
this->strm.zfree = Z_NULL; this->strm.zfree = Z_NULL;
this->strm.opaque = Z_NULL; this->strm.opaque = Z_NULL;
this->strm.avail_in = 0; this->strm.avail_in = 0;
this->strm.next_in = Z_NULL; this->strm.next_in = Z_NULL;
int ret = inflateInit2(&this->strm, MAX_WBITS | 16); //gzip int ret = inflateInit2(&this->strm, MAX_WBITS | 16); //gzip
if (ret != Z_OK) { if (ret != Z_OK) {
DEBUG_FUNCTION_LINE("inflateInit2 failed"); DEBUG_FUNCTION_LINE("inflateInit2 failed");
return; return;

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include <zlib.h>
#include "FileReader.h" #include "FileReader.h"
#include "logger.h" #include "logger.h"
#include <zlib.h>
#define BUFFER_SIZE 0x20000 #define BUFFER_SIZE 0x20000
@ -12,8 +12,7 @@ public:
explicit FileReaderCompressed(std::string &file); explicit FileReaderCompressed(std::string &file);
~FileReaderCompressed() override { ~FileReaderCompressed() override = default;
}
int read(uint8_t *buffer, uint32_t size) override; int read(uint8_t *buffer, uint32_t size) override;

View File

@ -23,22 +23,22 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <string.h>
#include <wchar.h> #include <string>
#include <strings.h> #include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include <utils/StringTools.h> #include <utils/StringTools.h>
#include <vector>
#include <wchar.h>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
if (b.size() > a.size()) if (b.size() > a.size()) {
return false; return false;
}
return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin());
} }
@ -85,7 +85,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
static char tmp[512]; static char tmp[512];
static wchar_t strWChar[512]; static wchar_t strWChar[512];
strWChar[0] = 0; strWChar[0] = 0;
tmp[0] = 0; tmp[0] = 0;
if (!format) if (!format)
return (const wchar_t *) strWChar; return (const wchar_t *) strWChar;
@ -98,7 +98,7 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
if ((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
int bt; int bt;
int32_t strlength = strlen(tmp); int32_t strlength = strlen(tmp);
bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512); bt = mbstowcs(strWChar, tmp, (strlength < 512) ? strlength : 512);
if (bt > 0) { if (bt > 0) {
strWChar[bt] = 0; strWChar[bt] = 0;
@ -112,13 +112,13 @@ const wchar_t *StringTools::wfmt(const char *format, ...) {
int32_t StringTools::strprintf(std::string &str, const char *format, ...) { int32_t StringTools::strprintf(std::string &str, const char *format, ...) {
static char tmp[512]; static char tmp[512];
tmp[0] = 0; tmp[0] = 0;
int32_t result = 0; int32_t result = 0;
va_list va; va_list va;
va_start(va, format); va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) { if ((vsprintf(tmp, format, va) >= 0)) {
str = tmp; str = tmp;
result = str.size(); result = str.size();
} }
va_end(va); va_end(va);
@ -215,7 +215,7 @@ const char *StringTools::FullpathToFilename(const char *path) {
if (!path) if (!path)
return path; return path;
const char *ptr = path; const char *ptr = path;
const char *Filename = ptr; const char *Filename = ptr;
while (*ptr != '\0') { while (*ptr != '\0') {
@ -244,13 +244,13 @@ void StringTools::RemoveDoubleSlashs(std::string &str) {
// You must free the result if result is non-NULL. // You must free the result if result is non-NULL.
char *StringTools::str_replace(char *orig, char *rep, char *with) { char *StringTools::str_replace(char *orig, char *rep, char *with) {
char *result; // the return string char *result; // the return string
char *ins; // the next insert point char *ins; // the next insert point
char *tmp; // varies char *tmp; // varies
int len_rep; // length of rep (the string to remove) int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with) int len_with; // length of with (the string to replace rep with)
int len_front; // distance between rep and end of last rep int len_front; // distance between rep and end of last rep
int count; // number of replacements int count; // number of replacements
// sanity checks and initialization // sanity checks and initialization
if (!orig || !rep) if (!orig || !rep)
@ -279,10 +279,10 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
// ins points to the next occurrence of rep in orig // ins points to the next occurrence of rep in orig
// orig points to the remainder of orig after "end of rep" // orig points to the remainder of orig after "end of rep"
while (count--) { while (count--) {
ins = strstr(orig, rep); ins = strstr(orig, rep);
len_front = ins - orig; len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front; tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with; tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep" orig += len_front + len_rep; // move to next "end of rep"
} }
strcpy(tmp, orig); strcpy(tmp, orig);
@ -301,4 +301,3 @@ uint32_t StringTools::hash(char *str) {
} }
return h; // or, h % ARRAY_SIZE; return h; // or, h % ARRAY_SIZE;
} }

View File

@ -26,8 +26,8 @@
#ifndef __STRING_TOOLS_H #ifndef __STRING_TOOLS_H
#define __STRING_TOOLS_H #define __STRING_TOOLS_H
#include <vector>
#include <string> #include <string>
#include <vector>
#include <wut_types.h> #include <wut_types.h>
class StringTools { class StringTools {
@ -64,4 +64,3 @@ public:
}; };
#endif /* __STRING_TOOLS_H */ #endif /* __STRING_TOOLS_H */

View File

@ -1,12 +1,16 @@
/* inih -- simple .INI file parser /* inih -- simple .INI file parser
SPDX-License-Identifier: BSD-3-Clause
Copyright (C) 2009-2020, Ben Hoyt
inih is released under the New BSD license (see LICENSE.txt). Go to the project inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info: home page for more info:
https://github.com/benhoyt/inih https://github.com/benhoyt/inih
*/ */
// clang-format off
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
@ -18,9 +22,17 @@ https://github.com/benhoyt/inih
#include "ini.h" #include "ini.h"
#if !INI_USE_STACK #if !INI_USE_STACK
#if INI_CUSTOM_ALLOCATOR
#include <stddef.h>
void* ini_malloc(size_t size);
void ini_free(void* ptr);
void* ini_realloc(void* ptr, size_t size);
#else
#include <stdlib.h> #include <stdlib.h>
#define ini_malloc malloc
#define ini_free free
#define ini_realloc realloc
#endif
#endif #endif
#define MAX_SECTION 50 #define MAX_SECTION 50
@ -28,34 +40,37 @@ https://github.com/benhoyt/inih
/* Used by ini_parse_string() to keep track of string parsing state. */ /* Used by ini_parse_string() to keep track of string parsing state. */
typedef struct { typedef struct {
const char *ptr; const char* ptr;
size_t num_left; size_t num_left;
} ini_parse_string_ctx; } ini_parse_string_ctx;
/* Strip whitespace chars off end of given string, in place. Return s. */ /* Strip whitespace chars off end of given string, in place. Return s. */
static char *rstrip(char *s) { static char* rstrip(char* s)
char *p = s + strlen(s); {
while (p > s && isspace((unsigned char) (*--p))) char* p = s + strlen(s);
while (p > s && isspace((unsigned char)(*--p)))
*p = '\0'; *p = '\0';
return s; return s;
} }
/* Return pointer to first non-whitespace char in given string. */ /* Return pointer to first non-whitespace char in given string. */
static char *lskip(const char *s) { static char* lskip(const char* s)
while (*s && isspace((unsigned char) (*s))) {
while (*s && isspace((unsigned char)(*s)))
s++; s++;
return (char *) s; return (char*)s;
} }
/* Return pointer to first char (of chars) or inline comment in given string, /* Return pointer to first char (of chars) or inline comment in given string,
or pointer to null at end of string if neither found. Inline comment must or pointer to NUL at end of string if neither found. Inline comment must
be prefixed by a whitespace character to register as a comment. */ be prefixed by a whitespace character to register as a comment. */
static char *find_chars_or_comment(const char *s, const char *chars) { static char* find_chars_or_comment(const char* s, const char* chars)
{
#if INI_ALLOW_INLINE_COMMENTS #if INI_ALLOW_INLINE_COMMENTS
int was_space = 0; int was_space = 0;
while (*s && (!chars || !strchr(chars, *s)) && while (*s && (!chars || !strchr(chars, *s)) &&
!(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
was_space = isspace((unsigned char) (*s)); was_space = isspace((unsigned char)(*s));
s++; s++;
} }
#else #else
@ -63,46 +78,49 @@ static char *find_chars_or_comment(const char *s, const char *chars) {
s++; s++;
} }
#endif #endif
return (char *) s; return (char*)s;
} }
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */ /* Similar to strncpy, but ensures dest (size bytes) is
static char *strncpy0(char *dest, const char *src, size_t size) { NUL-terminated, and doesn't pad with NULs. */
#pragma GCC diagnostic push static char* strncpy0(char* dest, const char* src, size_t size)
#pragma GCC diagnostic ignored "-Wstringop-truncation" {
strncpy(dest, src, size - 1); /* Could use strncpy internally, but it causes gcc warnings (see issue #91) */
#pragma GCC diagnostic pop size_t i;
dest[size - 1] = '\0'; for (i = 0; i < size - 1 && src[i]; i++)
dest[i] = src[i];
dest[i] = '\0';
return dest; return dest;
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void *user) { void* user)
{
/* Uses a fair bit of stack (use heap instead if you need to) */ /* Uses a fair bit of stack (use heap instead if you need to) */
#if INI_USE_STACK #if INI_USE_STACK
char line[INI_MAX_LINE]; char line[INI_MAX_LINE];
int max_line = INI_MAX_LINE; int max_line = INI_MAX_LINE;
#else #else
char *line; char* line;
int max_line = INI_INITIAL_ALLOC; size_t max_line = INI_INITIAL_ALLOC;
#endif #endif
#if INI_ALLOW_REALLOC #if INI_ALLOW_REALLOC && !INI_USE_STACK
char *new_line; char* new_line;
int offset; size_t offset;
#endif #endif
char section[MAX_SECTION] = ""; char section[MAX_SECTION] = "";
char prev_name[MAX_NAME] = ""; char prev_name[MAX_NAME] = "";
char *start; char* start;
char *end; char* end;
char *name; char* name;
char *value; char* value;
int lineno = 0; int lineno = 0;
int error = 0; int error = 0;
#if !INI_USE_STACK #if !INI_USE_STACK
line = (char *) malloc(INI_INITIAL_ALLOC); line = (char*)ini_malloc(INI_INITIAL_ALLOC);
if (!line) { if (!line) {
return -2; return -2;
} }
@ -115,20 +133,20 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
#endif #endif
/* Scan through stream line by line */ /* Scan through stream line by line */
while (reader(line, max_line, stream) != NULL) { while (reader(line, (int)max_line, stream) != NULL) {
#if INI_ALLOW_REALLOC #if INI_ALLOW_REALLOC && !INI_USE_STACK
offset = strlen(line); offset = strlen(line);
while (offset == max_line - 1 && line[offset - 1] != '\n') { while (offset == max_line - 1 && line[offset - 1] != '\n') {
max_line *= 2; max_line *= 2;
if (max_line > INI_MAX_LINE) if (max_line > INI_MAX_LINE)
max_line = INI_MAX_LINE; max_line = INI_MAX_LINE;
new_line = realloc(line, max_line); new_line = ini_realloc(line, max_line);
if (!new_line) { if (!new_line) {
free(line); ini_free(line);
return -2; return -2;
} }
line = new_line; line = new_line;
if (reader(line + offset, max_line - offset, stream) == NULL) if (reader(line + offset, (int)(max_line - offset), stream) == NULL)
break; break;
if (max_line >= INI_MAX_LINE) if (max_line >= INI_MAX_LINE)
break; break;
@ -140,9 +158,9 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
start = line; start = line;
#if INI_ALLOW_BOM #if INI_ALLOW_BOM
if (lineno == 1 && (unsigned char) start[0] == 0xEF && if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
(unsigned char) start[1] == 0xBB && (unsigned char)start[1] == 0xBB &&
(unsigned char) start[2] == 0xBF) { (unsigned char)start[2] == 0xBF) {
start += 3; start += 3;
} }
#endif #endif
@ -166,11 +184,17 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
*end = '\0'; *end = '\0';
strncpy0(section, start + 1, sizeof(section)); strncpy0(section, start + 1, sizeof(section));
*prev_name = '\0'; *prev_name = '\0';
} else if (!error) { #if INI_CALL_HANDLER_ON_NEW_SECTION
if (!HANDLER(user, section, NULL, NULL) && !error)
error = lineno;
#endif
}
else if (!error) {
/* No ']' found on section line */ /* No ']' found on section line */
error = lineno; error = lineno;
} }
} else if (*start) { }
else if (*start) {
/* Not a comment, must be a name[=:]value pair */ /* Not a comment, must be a name[=:]value pair */
end = find_chars_or_comment(start, "=:"); end = find_chars_or_comment(start, "=:");
if (*end == '=' || *end == ':') { if (*end == '=' || *end == ':') {
@ -189,9 +213,17 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
strncpy0(prev_name, name, sizeof(prev_name)); strncpy0(prev_name, name, sizeof(prev_name));
if (!HANDLER(user, section, name, value) && !error) if (!HANDLER(user, section, name, value) && !error)
error = lineno; error = lineno;
} else if (!error) { }
else if (!error) {
/* No '=' or ':' found on name[=:]value line */ /* No '=' or ':' found on name[=:]value line */
#if INI_ALLOW_NO_VALUE
*end = '\0';
name = rstrip(start);
if (!HANDLER(user, section, name, NULL) && !error)
error = lineno;
#else
error = lineno; error = lineno;
#endif
} }
} }
@ -202,20 +234,22 @@ int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler,
} }
#if !INI_USE_STACK #if !INI_USE_STACK
free(line); ini_free(line);
#endif #endif
return error; return error;
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_file(FILE *file, ini_handler handler, void *user) { int ini_parse_file(FILE* file, ini_handler handler, void* user)
return ini_parse_stream((ini_reader) fgets, file, handler, user); {
return ini_parse_stream((ini_reader)fgets, file, handler, user);
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse(const char *filename, ini_handler handler, void *user) { int ini_parse(const char* filename, ini_handler handler, void* user)
FILE *file; {
FILE* file;
int error; int error;
file = fopen(filename, "r"); file = fopen(filename, "r");
@ -228,11 +262,11 @@ int ini_parse(const char *filename, ini_handler handler, void *user) {
/* An ini_reader function to read the next line from a string buffer. This /* An ini_reader function to read the next line from a string buffer. This
is the fgets() equivalent used by ini_parse_string(). */ is the fgets() equivalent used by ini_parse_string(). */
static char *ini_reader_string(char *str, int num, void *stream) { static char* ini_reader_string(char* str, int num, void* stream) {
ini_parse_string_ctx *ctx = (ini_parse_string_ctx *) stream; ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream;
const char *ctx_ptr = ctx->ptr; const char* ctx_ptr = ctx->ptr;
size_t ctx_num_left = ctx->num_left; size_t ctx_num_left = ctx->num_left;
char *strp = str; char* strp = str;
char c; char c;
if (ctx_num_left == 0 || num < 2) if (ctx_num_left == 0 || num < 2)
@ -254,11 +288,11 @@ static char *ini_reader_string(char *str, int num, void *stream) {
} }
/* See documentation in header file. */ /* See documentation in header file. */
int ini_parse_string(const char *string, ini_handler handler, void *user) { int ini_parse_string(const char* string, ini_handler handler, void* user) {
ini_parse_string_ctx ctx; ini_parse_string_ctx ctx;
ctx.ptr = string; ctx.ptr = string;
ctx.num_left = strlen(string); ctx.num_left = strlen(string);
return ini_parse_stream((ini_reader) ini_reader_string, &ctx, handler, return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler,
user); user);
} }

View File

@ -1,14 +1,18 @@
/* inih -- simple .INI file parser /* inih -- simple .INI file parser
SPDX-License-Identifier: BSD-3-Clause
Copyright (C) 2009-2020, Ben Hoyt
inih is released under the New BSD license (see LICENSE.txt). Go to the project inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info: home page for more info:
https://github.com/benhoyt/inih https://github.com/benhoyt/inih
*/ */
// clang-format off
#ifndef __INI_H__ #ifndef INI_H
#define __INI_H__ #define INI_H
/* Make this header file easier to include in C++ code */ /* Make this header file easier to include in C++ code */
#ifdef __cplusplus #ifdef __cplusplus
@ -28,12 +32,12 @@ typedef int (*ini_handler)(void* user, const char* section,
const char* name, const char* value, const char* name, const char* value,
int lineno); int lineno);
#else #else
typedef int (*ini_handler)(void *user, const char *section, typedef int (*ini_handler)(void* user, const char* section,
const char *name, const char *value); const char* name, const char* value);
#endif #endif
/* Typedef for prototype of fgets-style reader function. */ /* Typedef for prototype of fgets-style reader function. */
typedef char *(*ini_reader)(char *str, int num, void *stream); typedef char* (*ini_reader)(char* str, int num, void* stream);
/* Parse given INI-style file. May have [section]s, name=value pairs /* Parse given INI-style file. May have [section]s, name=value pairs
(whitespace stripped), and comments starting with ';' (semicolon). Section (whitespace stripped), and comments starting with ';' (semicolon). Section
@ -48,22 +52,22 @@ typedef char *(*ini_reader)(char *str, int num, void *stream);
stop on first error), -1 on file open error, or -2 on memory allocation stop on first error), -1 on file open error, or -2 on memory allocation
error (only when INI_USE_STACK is zero). error (only when INI_USE_STACK is zero).
*/ */
int ini_parse(const char *filename, ini_handler handler, void *user); int ini_parse(const char* filename, ini_handler handler, void* user);
/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
close the file when it's finished -- the caller must do that. */ close the file when it's finished -- the caller must do that. */
int ini_parse_file(FILE *file, ini_handler handler, void *user); int ini_parse_file(FILE* file, ini_handler handler, void* user);
/* Same as ini_parse(), but takes an ini_reader function pointer instead of /* Same as ini_parse(), but takes an ini_reader function pointer instead of
filename. Used for implementing custom or string-based I/O (see also filename. Used for implementing custom or string-based I/O (see also
ini_parse_string). */ ini_parse_string). */
int ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void *user); void* user);
/* Same as ini_parse(), but takes a zero-terminated string with the INI data /* Same as ini_parse(), but takes a zero-terminated string with the INI data
instead of a file. Useful for parsing INI data from a network socket or instead of a file. Useful for parsing INI data from a network socket or
already in memory. */ already in memory. */
int ini_parse_string(const char *string, ini_handler handler, void *user); int ini_parse_string(const char* string, ini_handler handler, void* user);
/* Nonzero to allow multi-line value parsing, in the style of Python's /* Nonzero to allow multi-line value parsing, in the style of Python's
configparser. If allowed, ini_parse() will call the handler with the same configparser. If allowed, ini_parse() will call the handler with the same
@ -73,7 +77,7 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
#endif #endif
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
the file. See http://code.google.com/p/inih/issues/detail?id=21 */ the file. See https://github.com/benhoyt/inih/issues/21 */
#ifndef INI_ALLOW_BOM #ifndef INI_ALLOW_BOM
#define INI_ALLOW_BOM 1 #define INI_ALLOW_BOM 1
#endif #endif
@ -123,8 +127,31 @@ int ini_parse_string(const char *string, ini_handler handler, void *user);
#define INI_STOP_ON_FIRST_ERROR 0 #define INI_STOP_ON_FIRST_ERROR 0
#endif #endif
/* Nonzero to call the handler at the start of each new section (with
name and value NULL). Default is to only call the handler on
each name=value pair. */
#ifndef INI_CALL_HANDLER_ON_NEW_SECTION
#define INI_CALL_HANDLER_ON_NEW_SECTION 0
#endif
/* Nonzero to allow a name without a value (no '=' or ':' on the line) and
call the handler with value NULL in this case. Default is to treat
no-value lines as an error. */
#ifndef INI_ALLOW_NO_VALUE
#define INI_ALLOW_NO_VALUE 0
#endif
/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory
allocation functions (INI_USE_STACK must also be 0). These functions must
have the same signatures as malloc/free/realloc and behave in a similar
way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */
#ifndef INI_CUSTOM_ALLOCATOR
#define INI_CUSTOM_ALLOCATOR 0
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* __INI_H__ */ #endif /* INI_H */

View File

@ -1,19 +1,19 @@
#ifdef DEBUG #ifdef DEBUG
#include <stdint.h> #include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h> #include <whb/log_cafe.h>
#include <whb/log_module.h> #include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false; uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false; uint32_t cafeLogInit = false;
uint32_t udpLogInit = false; uint32_t udpLogInit = false;
#endif // DEBUG #endif // DEBUG
void initLogging() { void initLogging() {
#ifdef DEBUG #ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) { if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit(); cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit(); udpLogInit = WHBLogUdpInit();
} }
#endif // DEBUG #endif // DEBUG
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <whb/log.h>
#include <string.h> #include <string.h>
#include <whb/log.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -9,26 +9,28 @@ extern "C" {
#ifdef DEBUG #ifdef DEBUG
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0) } while (0)
#else #else
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#endif #endif
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,6 +1,6 @@
#include "utils/logger.h"
#include <string.h> #include <string.h>
#include <whb/log.h> #include <whb/log.h>
#include "utils/logger.h"
#define PRINTF_BUFFER_LENGTH 2048 #define PRINTF_BUFFER_LENGTH 2048

View File

@ -6,28 +6,29 @@
extern "C" { extern "C" {
#endif #endif
#define LIMIT(x, min, max) \ #define LIMIT(x, min, max) \
({ \ ({ \
typeof( x ) _x = x; \ typeof(x) _x = x; \
typeof( min ) _min = min; \ typeof(min) _min = min; \
typeof( max ) _max = max; \ typeof(max) _max = max; \
( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ (((_x) < (_min)) ? (_min) : ((_x) > (_max)) ? (_max) \
}) : (_x)); \
})
#define DegToRad(a) ( (a) * 0.01745329252f ) #define DegToRad(a) ((a) *0.01745329252f)
#define RadToDeg(a) ( (a) * 57.29577951f ) #define RadToDeg(a) ((a) *57.29577951f)
#define ALIGN4(x) (((x) + 3) & ~3) #define ALIGN4(x) (((x) + 3) & ~3)
#define ALIGN32(x) (((x) + 31) & ~31) #define ALIGN32(x) (((x) + 31) & ~31)
// 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)
#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8))) #define le16(i) ((((uint16_t) ((i) &0xFF)) << 8) | ((uint16_t) (((i) &0xFF00) >> 8)))
#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16))) #define le32(i) ((((uint32_t) le16((i) &0xFFFF)) << 16) | ((uint32_t) le16(((i) &0xFFFF0000) >> 16)))
#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) #define le64(i) ((((uint64_t) le32((i) &0xFFFFFFFFLL)) << 32) | ((uint64_t) le32(((i) &0xFFFFFFFF00000000LL) >> 32)))
//Needs to have log_init() called beforehand. //Needs to have log_init() called beforehand.
void dumpHex(const void *data, size_t size); void dumpHex(const void *data, size_t size);