Formatting

This commit is contained in:
Maschell 2020-06-17 13:45:15 +02:00
parent 8b349029d0
commit 3d2363d171
17 changed files with 462 additions and 433 deletions

View File

@ -18,11 +18,15 @@ public:
}; };
CFile(); CFile();
CFile(const std::string &filepath, eOpenTypes mode); CFile(const std::string &filepath, eOpenTypes mode);
CFile(const uint8_t *memory, int32_t memsize); CFile(const uint8_t *memory, int32_t memsize);
virtual ~CFile(); virtual ~CFile();
int32_t open(const std::string &filepath, eOpenTypes mode); int32_t open(const std::string &filepath, eOpenTypes mode);
int32_t open(const uint8_t *memory, int32_t memsize); int32_t open(const uint8_t *memory, int32_t memsize);
BOOL isOpen() const { BOOL isOpen() const {
@ -38,15 +42,21 @@ public:
void close(); void close();
int32_t read(uint8_t *ptr, size_t size); int32_t read(uint8_t *ptr, size_t size);
int32_t write(const uint8_t *ptr, size_t size); int32_t write(const uint8_t *ptr, size_t size);
int32_t fwrite(const char *format, ...); int32_t fwrite(const char *format, ...);
int32_t seek(long int offset, int32_t origin); int32_t seek(long int offset, int32_t origin);
uint64_t tell() { uint64_t tell() {
return pos; return pos;
}; };
uint64_t size() { uint64_t size() {
return filesize; return filesize;
}; };
void rewind() { void rewind() {
this->seek(0, SEEK_SET); this->seek(0, SEEK_SET);
}; };

View File

@ -40,17 +40,22 @@ class DirList {
public: public:
//!Constructor //!Constructor
DirList(void); DirList(void);
//!\param path Path from where to load the filelist of all files //!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered //!\param filter A fileext that needs to be filtered
//!\param flags search/filter flags from the enum //!\param flags search/filter flags from the enum
DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//!Destructor //!Destructor
virtual ~DirList(); virtual ~DirList();
//! Load all the files from a directory //! Load all the files from a directory
BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff); BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
//! Get a filename of the list //! Get a filename of the list
//!\param list index //!\param list index
const char *GetFilename(int32_t index) const; const char *GetFilename(int32_t index) const;
//! Get the a filepath of the list //! Get the a filepath of the list
//!\param list index //!\param list index
const char *GetFilepath(int32_t index) const { const char *GetFilepath(int32_t index) const {
@ -59,9 +64,11 @@ public:
else else
return FileInfo[index].FilePath; return FileInfo[index].FilePath;
} }
//! Get the a filesize of the list //! Get the a filesize of the list
//!\param list index //!\param list index
uint64_t GetFilesize(int32_t index) const; uint64_t GetFilesize(int32_t index) const;
//! Is index a dir or a file //! Is index a dir or a file
//!\param list index //!\param list index
BOOL IsDir(int32_t index) const { BOOL IsDir(int32_t index) const {
@ -69,16 +76,21 @@ public:
return false; return false;
return FileInfo[index].isDir; return FileInfo[index].isDir;
}; };
//! Get the filecount of the whole list //! Get the filecount of the whole list
int32_t GetFilecount() const { int32_t GetFilecount() const {
return FileInfo.size(); return FileInfo.size();
}; };
//! Sort list by filepath //! Sort list by filepath
void SortList(); void SortList();
//! Custom sort command for custom sort functions definitions //! Custom sort command for custom sort functions definitions
void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)); void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b));
//! Get the index of the specified filename //! Get the index of the specified filename
int32_t GetFileIndex(const char *filename) const; int32_t GetFileIndex(const char *filename) const;
//! Enum for search/filter flags //! Enum for search/filter flags
enum { enum {
Files = 0x01, Files = 0x01,
@ -88,10 +100,13 @@ public:
protected: protected:
// Internal parser // Internal parser
BOOL InternalLoadPath(std::string &path); BOOL InternalLoadPath(std::string &path);
//!Add a list entrie //!Add a list entrie
void AddEntrie(const std::string &filepath, const char *filename, BOOL isDir); void AddEntrie(const std::string &filepath, const char *filename, BOOL isDir);
//! Clear the list //! Clear the list
void ClearList(); void ClearList();
//! Check if valid pos is requested //! Check if valid pos is requested
inline BOOL valid(uint32_t pos) const { inline BOOL valid(uint32_t pos) const {
return (pos < FileInfo.size()); return (pos < FileInfo.size());

View File

@ -9,7 +9,9 @@ public:
//! todo: C++ class //! todo: C++ class
static int32_t CreateSubfolder(const char *fullpath); static int32_t CreateSubfolder(const char *fullpath);
static int32_t CheckFile(const char *filepath); static int32_t CheckFile(const char *filepath);
static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size); static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size);
}; };

View File

@ -224,7 +224,6 @@ DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* t
strncpy(request.path, gFileInfos[(uint32_t) (title->titleId & 0xFFFFFFFF)].path, 255); strncpy(request.path, gFileInfos[(uint32_t) (title->titleId & 0xFFFFFFFF)].path, 255);
DEBUG_FUNCTION_LINE("Loading file %s size: %08X offset: %08X\n", request.path, request.filesize, request.fileoffset); DEBUG_FUNCTION_LINE("Loading file %s size: %08X offset: %08X\n", request.path, request.filesize, request.fileoffset);
DCFlushRange(&request, sizeof(LOAD_REQUEST)); DCFlushRange(&request, sizeof(LOAD_REQUEST));
@ -308,7 +307,6 @@ DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFile
} }
DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle, uint32_t unk1, uint32_t flags) { DECL_FUNCTION(FSStatus, FSReadFile, FSClient *client, FSCmdBlock *block, uint8_t *buffer, uint32_t size, uint32_t count, FSFileHandle handle, uint32_t unk1, uint32_t flags) {
if (handle == 0x13371337) { if (handle == 0x13371337) {
int cpySize = size * count; int cpySize = size * count;

View File

@ -4,8 +4,6 @@
#include <unistd.h> #include <unistd.h>
#include <malloc.h> #include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "romfs_helper.h" #include "romfs_helper.h"
@ -108,7 +106,6 @@ bool DeInitFile(int slot) {
} }
void DeInitAllFiles() { void DeInitAllFiles() {
for (int i = 0; i < FILE_READ_INFO_SIZE; i++) { for (int i = 0; i < FILE_READ_INFO_SIZE; i++) {
fileReadInformation *info = &gFileReadInformation[i]; fileReadInformation *info = &gFileReadInformation[i];
@ -183,8 +180,6 @@ int32_t loadFileIntoBuffer(uint32_t id, char * filepath, char * buffer, int size
} }
int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) { int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) {
if (!mountRomfs(id)) { if (!mountRomfs(id)) {
return -1; return -1;

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <zlib.h> #include <zlib.h>
@ -13,12 +14,10 @@ typedef struct {
unsigned char in[0x1000]; unsigned char in[0x1000];
} fileReadInformation; } fileReadInformation;
#define FILE_READ_INFO_SIZE 32 #define FILE_READ_INFO_SIZE 32
extern fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE]; extern fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE];
bool initFile(int slot); bool initFile(int slot);
int readFile(int slot, uint8_t *buffer, uint32_t size); int readFile(int slot, uint8_t *buffer, uint32_t size);
@ -33,5 +32,4 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char * filepath, int * handle);
int fileReadInformation_getSlot(); int fileReadInformation_getSlot();
bool initCompressedFileReadInformation(fileReadInformation *info); bool initCompressedFileReadInformation(fileReadInformation *info);

View File

@ -50,8 +50,6 @@ bool mountRomfs(uint32_t id) {
} }
int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info) { int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info) {
if (!mountRomfs(id)) { if (!mountRomfs(id)) {
return -1; return -1;

View File

@ -4,8 +4,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <wut_romfs_dev.h> #include <wut_romfs_dev.h>
typedef struct WUT_PACKED FileInfos_ { typedef struct WUT_PACKED FileInfos_ {
char path[256]; char path[256];
char name[256]; char name[256];
@ -17,10 +15,10 @@ typedef struct WUT_PACKED FileInfos_ {
#define FILE_INFO_SIZE 300 #define FILE_INFO_SIZE 300
extern FileInfos gFileInfos[FILE_INFO_SIZE]; extern FileInfos gFileInfos[FILE_INFO_SIZE];
void unmountAllRomfs(); void unmountAllRomfs();
void unmountRomfs(uint32_t id); void unmountRomfs(uint32_t id);
bool mountRomfs(uint32_t id); bool mountRomfs(uint32_t id);
int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info); int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info);

View File

@ -33,18 +33,31 @@
class StringTools { class StringTools {
public: public:
static BOOL EndsWith(const std::string &a, const std::string &b); static BOOL EndsWith(const std::string &a, const std::string &b);
static const char *byte_to_binary(int32_t x); static const char *byte_to_binary(int32_t x);
static std::string removeCharFromString(std::string &input, char toBeRemoved); static std::string removeCharFromString(std::string &input, char toBeRemoved);
static const char *fmt(const char *format, ...); static const char *fmt(const char *format, ...);
static const wchar_t *wfmt(const char *format, ...); static const wchar_t *wfmt(const char *format, ...);
static int32_t strprintf(std::string &str, const char *format, ...); static int32_t strprintf(std::string &str, const char *format, ...);
static std::string strfmt(const char *format, ...); static std::string strfmt(const char *format, ...);
static BOOL char2wchar_t(const char *src, wchar_t *dest); static BOOL char2wchar_t(const char *src, wchar_t *dest);
static int32_t strtokcmp(const char *string, const char *compare, const char *separator); static int32_t strtokcmp(const char *string, const char *compare, const char *separator);
static int32_t strextcmp(const char *string, const char *extension, char seperator); static int32_t strextcmp(const char *string, const char *extension, char seperator);
static char *str_replace(char *orig, char *rep, char *with); static char *str_replace(char *orig, char *rep, char *with);
static const char *FullpathToFilename(const char *path); static const char *FullpathToFilename(const char *path);
static void RemoveDoubleSlashs(std::string &str); static void RemoveDoubleSlashs(std::string &str);
static std::vector<std::string> stringSplit(const std::string &value, const std::string &splitter); static std::vector<std::string> stringSplit(const std::string &value, const std::string &splitter);
}; };

View File

@ -8,9 +8,12 @@ extern "C" {
#include <string.h> #include <string.h>
void log_init_(); void log_init_();
//void log_deinit_(void); //void log_deinit_(void);
void log_print_(const char *str); void log_print_(const char *str);
void log_printf_(const char *format, ...); void log_printf_(const char *format, ...);
void OSFatal_printf(const char *format, ...); void OSFatal_printf(const char *format, ...);
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
@ -21,7 +24,6 @@ void OSFatal_printf(const char *format, ...);
} while (0) } while (0)
#define log_init() log_init_() #define log_init() log_init_()
//#define log_deinit() log_deinit_() //#define log_deinit() log_deinit_()
#define log_print(str) log_print_(str) #define log_print(str) log_print_(str)