From 3d2363d1716598409786aa33660041a1e9fc8d8e Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 17 Jun 2020 13:45:15 +0200 Subject: [PATCH] Formatting --- src/fs/CFile.cpp | 86 ++++++------- src/fs/CFile.hpp | 28 +++-- src/fs/DirList.cpp | 70 +++++------ src/fs/DirList.h | 27 +++- src/fs/FSUtils.cpp | 50 ++++---- src/fs/FSUtils.h | 8 +- src/main.cpp | 252 +++++++++++++++++++------------------- src/readFileWrapper.cpp | 111 ++++++++--------- src/readFileWrapper.h | 12 +- src/romfs_helper.cpp | 44 ++++--- src/romfs_helper.h | 8 +- src/utils/StringTools.cpp | 104 ++++++++-------- src/utils/StringTools.h | 37 ++++-- src/utils/logger.c | 16 +-- src/utils/logger.h | 4 +- src/utils/utils.c | 24 ++-- src/utils/utils.h | 14 +-- 17 files changed, 462 insertions(+), 433 deletions(-) diff --git a/src/fs/CFile.cpp b/src/fs/CFile.cpp index c2a7ae6..c8e78d2 100644 --- a/src/fs/CFile.cpp +++ b/src/fs/CFile.cpp @@ -12,12 +12,12 @@ CFile::CFile() { pos = 0; } -CFile::CFile(const std::string & filepath, eOpenTypes mode) { +CFile::CFile(const std::string &filepath, eOpenTypes mode) { iFd = -1; this->open(filepath, mode); } -CFile::CFile(const uint8_t * mem, int32_t size) { +CFile::CFile(const uint8_t *mem, int32_t size) { iFd = -1; this->open(mem, size); } @@ -26,27 +26,27 @@ CFile::~CFile() { this->close(); } -int32_t CFile::open(const std::string & filepath, eOpenTypes mode) { +int32_t CFile::open(const std::string &filepath, eOpenTypes mode) { this->close(); int32_t openMode = 0; // This depend on the devoptab implementation. // see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference - switch(mode) { - default: - case ReadOnly: // file must exist - openMode = O_RDONLY; - break; - case WriteOnly: // file will be created / zerod - openMode = O_TRUNC | O_CREAT | O_WRONLY; - break; - case ReadWrite: // file must exist - openMode = O_RDWR; - break; - case Append: // append to file, file will be created if missing. write only - openMode = O_CREAT | O_APPEND | O_WRONLY; - break; + switch (mode) { + default: + case ReadOnly: // file must exist + openMode = O_RDONLY; + break; + case WriteOnly: // file will be created / zerod + openMode = O_TRUNC | O_CREAT | O_WRONLY; + break; + case ReadWrite: // file must exist + openMode = O_RDWR; + break; + case Append: // append to file, file will be created if missing. write only + openMode = O_CREAT | O_APPEND | O_WRONLY; + break; } //! Using fopen works only on the first launch as expected @@ -54,7 +54,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) { //! the .data sections which is needed for a normal application to re-init //! this will be added with launching as RPX iFd = ::open(filepath.c_str(), openMode); - if(iFd < 0) + if (iFd < 0) return iFd; @@ -64,7 +64,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) { return 0; } -int32_t CFile::open(const uint8_t * mem, int32_t size) { +int32_t CFile::open(const uint8_t *mem, int32_t size) { this->close(); mem_file = mem; @@ -74,7 +74,7 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) { } void CFile::close() { - if(iFd >= 0) + if (iFd >= 0) ::close(iFd); iFd = -1; @@ -83,24 +83,24 @@ void CFile::close() { pos = 0; } -int32_t CFile::read(uint8_t * ptr, size_t size) { - if(iFd >= 0) { - int32_t ret = ::read(iFd, ptr,size); - if(ret > 0) +int32_t CFile::read(uint8_t *ptr, size_t size) { + if (iFd >= 0) { + int32_t ret = ::read(iFd, ptr, size); + if (ret > 0) pos += ret; return ret; } int32_t readsize = size; - if(readsize > (int64_t) (filesize-pos)) - readsize = filesize-pos; + if (readsize > (int64_t) (filesize - pos)) + readsize = filesize - pos; - if(readsize <= 0) + if (readsize <= 0) return readsize; - if(mem_file != NULL) { - memcpy(ptr, mem_file+pos, readsize); + if (mem_file != NULL) { + memcpy(ptr, mem_file + pos, readsize); pos += readsize; return readsize; } @@ -108,12 +108,12 @@ int32_t CFile::read(uint8_t * ptr, size_t size) { return -1; } -int32_t CFile::write(const uint8_t * ptr, size_t size) { - if(iFd >= 0) { +int32_t CFile::write(const uint8_t *ptr, size_t size) { + if (iFd >= 0) { size_t done = 0; - while(done < size) { + while (done < size) { int32_t ret = ::write(iFd, ptr, size - done); - if(ret <= 0) + if (ret <= 0) return ret; ptr += ret; @@ -130,25 +130,25 @@ int32_t CFile::seek(long int offset, int32_t origin) { int32_t ret = 0; int64_t newPos = pos; - if(origin == SEEK_SET) { + if (origin == SEEK_SET) { newPos = offset; - } else if(origin == SEEK_CUR) { + } else if (origin == SEEK_CUR) { newPos += offset; - } else if(origin == SEEK_END) { - newPos = filesize+offset; + } else if (origin == SEEK_END) { + newPos = filesize + offset; } - if(newPos < 0) { + if (newPos < 0) { pos = 0; } else { pos = newPos; } - if(iFd >= 0) + if (iFd >= 0) ret = ::lseek(iFd, pos, SEEK_SET); - if(mem_file != NULL) { - if(pos > filesize) { + if (mem_file != NULL) { + if (pos > filesize) { pos = filesize; } } @@ -163,8 +163,8 @@ int32_t CFile::fwrite(const char *format, ...) { va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { - result = this->write((uint8_t *)tmp, strlen(tmp)); + if ((vsprintf(tmp, format, va) >= 0)) { + result = this->write((uint8_t *) tmp, strlen(tmp)); } va_end(va); diff --git a/src/fs/CFile.hpp b/src/fs/CFile.hpp index 8816a49..6c0421b 100644 --- a/src/fs/CFile.hpp +++ b/src/fs/CFile.hpp @@ -18,18 +18,22 @@ public: }; CFile(); - CFile(const std::string & filepath, eOpenTypes mode); - CFile(const uint8_t * memory, int32_t memsize); + + CFile(const std::string &filepath, eOpenTypes mode); + + CFile(const uint8_t *memory, int32_t memsize); + virtual ~CFile(); - int32_t open(const std::string & filepath, eOpenTypes mode); - int32_t open(const uint8_t * memory, int32_t memsize); + int32_t open(const std::string &filepath, eOpenTypes mode); + + int32_t open(const uint8_t *memory, int32_t memsize); BOOL isOpen() const { - if(iFd >= 0) + if (iFd >= 0) return true; - if(mem_file) + if (mem_file) return true; return false; @@ -37,23 +41,29 @@ public: void close(); - int32_t read(uint8_t * ptr, size_t size); - int32_t write(const 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 fwrite(const char *format, ...); + int32_t seek(long int offset, int32_t origin); + uint64_t tell() { return pos; }; + uint64_t size() { return filesize; }; + void rewind() { this->seek(0, SEEK_SET); }; protected: int32_t iFd; - const uint8_t * mem_file; + const uint8_t *mem_file; uint64_t filesize; uint64_t pos; }; diff --git a/src/fs/DirList.cpp b/src/fs/DirList.cpp index 450d4b6..ab2fea4 100644 --- a/src/fs/DirList.cpp +++ b/src/fs/DirList.cpp @@ -42,7 +42,7 @@ DirList::DirList() { Depth = 0; } -DirList::DirList(const std::string & path, const char *filter, uint32_t flags, uint32_t maxDepth) { +DirList::DirList(const std::string &path, const char *filter, uint32_t flags, uint32_t maxDepth) { this->LoadPath(path, filter, flags, maxDepth); this->SortList(); } @@ -51,8 +51,8 @@ DirList::~DirList() { ClearList(); } -BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t flags, uint32_t maxDepth) { - if(folder.empty()) +BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t flags, uint32_t maxDepth) { + if (folder.empty()) return false; Flags = flags; @@ -66,11 +66,11 @@ BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t StringTools::RemoveDoubleSlashs(folderpath); //! remove last slash if exists - if(length > 0 && folderpath[length-1] == '/') - folderpath.erase(length-1); + if (length > 0 && folderpath[length - 1] == '/') + folderpath.erase(length - 1); //! add root slash if missing - if(folderpath.find('/') == std::string::npos) { + if (folderpath.find('/') == std::string::npos) { folderpath += '/'; } @@ -78,7 +78,7 @@ BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t } BOOL DirList::InternalLoadPath(std::string &folderpath) { - if(folderpath.size() < 3) + if (folderpath.size() < 3) return false; struct dirent *dirent = NULL; @@ -92,13 +92,13 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) { BOOL isDir = dirent->d_type & DT_DIR; const char *filename = dirent->d_name; - if(isDir) { - if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0) + if (isDir) { + if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0) continue; - if((Flags & CheckSubfolders) && (Depth > 0)) { + if ((Flags & CheckSubfolders) && (Depth > 0)) { int32_t length = folderpath.size(); - if(length > 2 && folderpath[length-1] != '/') { + if (length > 2 && folderpath[length - 1] != '/') { folderpath += '/'; } folderpath += filename; @@ -109,18 +109,18 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) { Depth++; } - if(!(Flags & Dirs)) + if (!(Flags & Dirs)) continue; - } else if(!(Flags & Files)) { + } else if (!(Flags & Files)) { continue; } - if(Filter) { - char * fileext = strrchr(filename, '.'); - if(!fileext) + if (Filter) { + char *fileext = strrchr(filename, '.'); + if (!fileext) continue; - if(StringTools::strtokcmp(fileext, Filter, ",") == 0) + if (StringTools::strtokcmp(fileext, Filter, ",") == 0) AddEntrie(folderpath, filename, isDir); } else { AddEntrie(folderpath, filename, isDir); @@ -131,16 +131,16 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) { return true; } -void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL isDir) { - if(!filename) +void DirList::AddEntrie(const std::string &filepath, const char *filename, BOOL isDir) { + if (!filename) return; int32_t pos = FileInfo.size(); - FileInfo.resize(pos+1); + FileInfo.resize(pos + 1); - FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2); - if(!FileInfo[pos].FilePath) { + FileInfo[pos].FilePath = (char *) malloc(filepath.size() + strlen(filename) + 2); + if (!FileInfo[pos].FilePath) { FileInfo.resize(pos); return; } @@ -150,8 +150,8 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL } void DirList::ClearList() { - for(uint32_t i = 0; i < FileInfo.size(); ++i) { - if(FileInfo[i].FilePath) { + for (uint32_t i = 0; i < FileInfo.size(); ++i) { + if (FileInfo[i].FilePath) { free(FileInfo[i].FilePath); FileInfo[i].FilePath = NULL; } @@ -161,37 +161,37 @@ void DirList::ClearList() { std::vector().swap(FileInfo); } -const char * DirList::GetFilename(int32_t ind) const { +const char *DirList::GetFilename(int32_t ind) const { if (!valid(ind)) return ""; return StringTools::FullpathToFilename(FileInfo[ind].FilePath); } -static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) { - if(f1.isDir && !(f2.isDir)) +static BOOL SortCallback(const DirEntry &f1, const DirEntry &f2) { + if (f1.isDir && !(f2.isDir)) return true; - if(!(f1.isDir) && f2.isDir) + if (!(f1.isDir) && f2.isDir) return false; - if(f1.FilePath && !f2.FilePath) + if (f1.FilePath && !f2.FilePath) return true; - if(!f1.FilePath) + if (!f1.FilePath) return false; - if(strcasecmp(f1.FilePath, f2.FilePath) > 0) + if (strcasecmp(f1.FilePath, f2.FilePath) > 0) return false; return true; } void DirList::SortList() { - if(FileInfo.size() > 1) + if (FileInfo.size() > 1) std::sort(FileInfo.begin(), FileInfo.end(), SortCallback); } void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) { - if(FileInfo.size() > 1) + if (FileInfo.size() > 1) std::sort(FileInfo.begin(), FileInfo.end(), SortFunc); } @@ -199,14 +199,14 @@ uint64_t DirList::GetFilesize(int32_t index) const { struct stat st; const char *path = GetFilepath(index); - if(!path || stat(path, &st) != 0) + if (!path || stat(path, &st) != 0) return 0; return st.st_size; } int32_t DirList::GetFileIndex(const char *filename) const { - if(!filename) + if (!filename) return -1; for (uint32_t i = 0; i < FileInfo.size(); ++i) { diff --git a/src/fs/DirList.h b/src/fs/DirList.h index b9559aa..08b3fbc 100644 --- a/src/fs/DirList.h +++ b/src/fs/DirList.h @@ -32,7 +32,7 @@ #include typedef struct { - char * FilePath; + char *FilePath; BOOL isDir; } DirEntry; @@ -40,17 +40,22 @@ class DirList { public: //!Constructor DirList(void); + //!\param path Path from where to load the filelist of all files //!\param filter A fileext that needs to be filtered //!\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 virtual ~DirList(); + //! 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 //!\param list index - const char * GetFilename(int32_t index) const; + const char *GetFilename(int32_t index) const; + //! Get the a filepath of the list //!\param list index const char *GetFilepath(int32_t index) const { @@ -59,26 +64,33 @@ public: else return FileInfo[index].FilePath; } + //! Get the a filesize of the list //!\param list index uint64_t GetFilesize(int32_t index) const; + //! Is index a dir or a file //!\param list index BOOL IsDir(int32_t index) const { - if(!valid(index)) + if (!valid(index)) return false; return FileInfo[index].isDir; }; + //! Get the filecount of the whole list int32_t GetFilecount() const { return FileInfo.size(); }; + //! Sort list by filepath void SortList(); + //! Custom sort command for custom sort functions definitions void SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)); + //! Get the index of the specified filename int32_t GetFileIndex(const char *filename) const; + //! Enum for search/filter flags enum { Files = 0x01, @@ -88,10 +100,13 @@ public: protected: // Internal parser BOOL InternalLoadPath(std::string &path); + //!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 void ClearList(); + //! Check if valid pos is requested inline BOOL valid(uint32_t pos) const { return (pos < FileInfo.size()); diff --git a/src/fs/FSUtils.cpp b/src/fs/FSUtils.cpp index 5a0579f..c51a254 100644 --- a/src/fs/FSUtils.cpp +++ b/src/fs/FSUtils.cpp @@ -10,7 +10,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) { //! always initialze input *inbuffer = NULL; - if(size) + if (size) *size = 0; int32_t iFd = open(filepath, O_RDONLY); @@ -30,12 +30,12 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_ uint32_t done = 0; int32_t readBytes = 0; - while(done < filesize) { - if(done + blocksize > filesize) { + while (done < filesize) { + if (done + blocksize > filesize) { blocksize = filesize - done; } readBytes = read(iFd, buffer + done, blocksize); - if(readBytes <= 0) + if (readBytes <= 0) break; done += readBytes; } @@ -51,27 +51,27 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_ *inbuffer = buffer; //! sign is optional input - if(size) { + if (size) { *size = filesize; } return filesize; } -int32_t FSUtils::CheckFile(const char * filepath) { - if(!filepath) +int32_t FSUtils::CheckFile(const char *filepath) { + if (!filepath) return 0; struct stat filestat; - char dirnoslash[strlen(filepath)+2]; + char dirnoslash[strlen(filepath) + 2]; snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath); - while(dirnoslash[strlen(dirnoslash)-1] == '/') - dirnoslash[strlen(dirnoslash)-1] = '\0'; + while (dirnoslash[strlen(dirnoslash) - 1] == '/') + dirnoslash[strlen(dirnoslash) - 1] = '\0'; - char * notRoot = strrchr(dirnoslash, '/'); - if(!notRoot) { + char *notRoot = strrchr(dirnoslash, '/'); + if (!notRoot) { strcat(dirnoslash, "/"); } @@ -81,29 +81,29 @@ int32_t FSUtils::CheckFile(const char * filepath) { return 0; } -int32_t FSUtils::CreateSubfolder(const char * fullpath) { - if(!fullpath) +int32_t FSUtils::CreateSubfolder(const char *fullpath) { + if (!fullpath) return 0; int32_t result = 0; - char dirnoslash[strlen(fullpath)+1]; + char dirnoslash[strlen(fullpath) + 1]; strcpy(dirnoslash, fullpath); - int32_t pos = strlen(dirnoslash)-1; - while(dirnoslash[pos] == '/') { + int32_t pos = strlen(dirnoslash) - 1; + while (dirnoslash[pos] == '/') { dirnoslash[pos] = '\0'; pos--; } - if(CheckFile(dirnoslash)) { + if (CheckFile(dirnoslash)) { return 1; } else { - char parentpath[strlen(dirnoslash)+2]; + char parentpath[strlen(dirnoslash) + 2]; strcpy(parentpath, dirnoslash); - char * ptr = strrchr(parentpath, '/'); + char *ptr = strrchr(parentpath, '/'); - if(!ptr) { + if (!ptr) { //!Device root directory (must be with '/') strcat(parentpath, "/"); struct stat filestat; @@ -119,7 +119,7 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) { result = CreateSubfolder(parentpath); } - if(!result) + if (!result) return 0; if (mkdir(dirnoslash, 0777) == -1) { @@ -129,13 +129,13 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) { return 1; } -int32_t FSUtils::saveBufferToFile(const char * path, void * buffer, uint32_t size) { +int32_t FSUtils::saveBufferToFile(const char *path, void *buffer, uint32_t size) { CFile file(path, CFile::WriteOnly); if (!file.isOpen()) { - DEBUG_FUNCTION_LINE("Failed to open %s\n",path); + DEBUG_FUNCTION_LINE("Failed to open %s\n", path); return 0; } - int32_t written = file.write((const uint8_t*) buffer, size); + int32_t written = file.write((const uint8_t *) buffer, size); file.close(); return written; } diff --git a/src/fs/FSUtils.h b/src/fs/FSUtils.h index 9ee748a..7899406 100644 --- a/src/fs/FSUtils.h +++ b/src/fs/FSUtils.h @@ -8,9 +8,11 @@ public: static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size); //! todo: C++ class - static int32_t CreateSubfolder(const char * fullpath); - static int32_t CheckFile(const char * filepath); - static int32_t saveBufferToFile(const char * path, void * buffer, uint32_t size); + static int32_t CreateSubfolder(const char *fullpath); + + static int32_t CheckFile(const char *filepath); + + static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size); }; #endif // __FS_UTILS_H_ diff --git a/src/main.cpp b/src/main.cpp index 07ad9e7..7c83019 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,11 +45,11 @@ BOOL gHomebrewLaunched __attribute__((section(".data"))); WUPS_USE_WUT_CRT() INITIALIZE_PLUGIN() { - memset((void*) &template_title,0,sizeof(template_title)); - memset((void*) &gLaunchXML,0,sizeof(gLaunchXML)); - memset((void*) &gFileInfos,0,sizeof(gFileInfos)); - memset((void*) &gFileReadInformation,0,sizeof(gFileReadInformation)); - memset((void*) &gIconCache,0,sizeof(gIconCache)); + memset((void *) &template_title, 0, sizeof(template_title)); + memset((void *) &gLaunchXML, 0, sizeof(gLaunchXML)); + memset((void *) &gFileInfos, 0, sizeof(gFileInfos)); + memset((void *) &gFileReadInformation, 0, sizeof(gFileReadInformation)); + memset((void *) &gIconCache, 0, sizeof(gIconCache)); gHomebrewLaunched = FALSE; } @@ -59,7 +59,7 @@ ON_APPLICATION_START(args) { log_init(); DEBUG_FUNCTION_LINE("IN PLUGIN\n"); - if(_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { + if (_SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY) != OSGetTitleID()) { DEBUG_FUNCTION_LINE("gHomebrewLaunched to FALSE\n"); gHomebrewLaunched = FALSE; } @@ -70,14 +70,14 @@ ON_APPLICATION_END() { unmountAllRomfs(); } -void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf) { - if(titleid_lower >= FILE_INFO_SIZE) { +void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *out_buf) { + if (titleid_lower >= FILE_INFO_SIZE) { return; } - out_buf->title_id = ((uint64_t)titleid_upper * 0x100000000) + titleid_lower; - strncpy(out_buf->longname_en,gFileInfos[titleid_lower].name,511); - strncpy(out_buf->shortname_en,gFileInfos[titleid_lower].name,255); - strncpy(out_buf->publisher_en,gFileInfos[titleid_lower].name,255); + out_buf->title_id = ((uint64_t) titleid_upper * 0x100000000) + titleid_lower; + strncpy(out_buf->longname_en, gFileInfos[titleid_lower].name, 511); + strncpy(out_buf->shortname_en, gFileInfos[titleid_lower].name, 255); + strncpy(out_buf->publisher_en, gFileInfos[titleid_lower].name, 255); out_buf->e_manual = 1; out_buf->e_manual_version = 0; out_buf->title_version = 1; @@ -90,15 +90,15 @@ void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXm out_buf->group_id = 0x400; out_buf->drc_use = 1; out_buf->version = 1; - out_buf->reserved_flag0 = 0x00010001; - out_buf->reserved_flag6 = 0x00000003; - out_buf->pc_usk = 128; - strncpy(out_buf->product_code,"WUP-P-HBLD",strlen("WUP-P-HBLD")); - strncpy(out_buf->content_platform,"WUP",strlen("WUP")); - strncpy(out_buf->company_code,"0001",strlen("0001")); + out_buf->reserved_flag0 = 0x00010001; + out_buf->reserved_flag6 = 0x00000003; + out_buf->pc_usk = 128; + strncpy(out_buf->product_code, "WUP-P-HBLD", strlen("WUP-P-HBLD")); + strncpy(out_buf->content_platform, "WUP", strlen("WUP")); + strncpy(out_buf->company_code, "0001", strlen("0001")); } -DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount, MCPTitleListType* titleList, uint32_t size) { +DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t *outTitleCount, MCPTitleListType *titleList, uint32_t size) { int32_t result = real_MCP_TitleList(handle, outTitleCount, titleList, size); uint32_t titlecount = *outTitleCount; @@ -106,47 +106,47 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount, dirList.SortList(); int j = 0; - for(int i = 0; i < dirList.GetFilecount(); i++) { - if(j >= FILE_INFO_SIZE) { + for (int i = 0; i < dirList.GetFilecount(); i++) { + if (j >= FILE_INFO_SIZE) { DEBUG_FUNCTION_LINE("TOO MANY TITLES\n"); break; } //! skip our own application in the listing - if(strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0) { + if (strcasecmp(dirList.GetFilename(i), "homebrew_launcher.rpx") == 0) { continue; } //! skip our own application in the listing - if(strcasecmp(dirList.GetFilename(i), "temp.rpx") == 0) { + if (strcasecmp(dirList.GetFilename(i), "temp.rpx") == 0) { continue; } //! skip hidden linux and mac files - if(dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_') { + if (dirList.GetFilename(i)[0] == '.' || dirList.GetFilename(i)[0] == '_') { continue; } - char buffer [25]; - snprintf(buffer,25,"/custom/%08X%08X", 0x0005000F, j); - strcpy(template_title.path,buffer); + char buffer[25]; + snprintf(buffer, 25, "/custom/%08X%08X", 0x0005000F, j); + strcpy(template_title.path, buffer); - char * repl = (char*)"fs:/vol/external01/"; - char * with = (char*)""; - char * input = (char*) dirList.GetFilepath(i); + char *repl = (char *) "fs:/vol/external01/"; + char *with = (char *) ""; + char *input = (char *) dirList.GetFilepath(i); - char * path = StringTools::str_replace(input,repl, with); - if(path != NULL) { - strncpy(gFileInfos[j].path,path, 255); + char *path = StringTools::str_replace(input, repl, with); + if (path != NULL) { + strncpy(gFileInfos[j].path, path, 255); free(path); } - strncpy(gFileInfos[j].name, dirList.GetFilename(i),255); + strncpy(gFileInfos[j].name, dirList.GetFilename(i), 255); gFileInfos[j].source = 0; //SD Card; - DEBUG_FUNCTION_LINE("[%d] %s\n",j, gFileInfos[j].path); + DEBUG_FUNCTION_LINE("[%d] %s\n", j, gFileInfos[j].path); - const char * indexedDevice = "mlc"; - strcpy(template_title.indexedDevice,indexedDevice); - if(StringTools::EndsWith(gFileInfos[j].name, ".wbf")) { + const char *indexedDevice = "mlc"; + strcpy(template_title.indexedDevice, indexedDevice); + if (StringTools::EndsWith(gFileInfos[j].name, ".wbf")) { template_title.appType = MCP_APP_TYPE_GAME; } else { @@ -161,7 +161,7 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount, template_title.sdkVersion = __OSGetProcessSDKVersion(); template_title.unk0x60 = 0; - memcpy(&(titleList[titlecount]), &template_title,sizeof(template_title)); + memcpy(&(titleList[titlecount]), &template_title, sizeof(template_title)); titlecount++; j++; @@ -172,13 +172,13 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount, return result; } -DECL_FUNCTION(int32_t, MCP_GetTitleInfoByTitleAndDevice, uint32_t mcp_handle, uint32_t titleid_lower_1, uint32_t titleid_upper, uint32_t titleid_lower_2, uint32_t unknown, MCPTitleListType* title) { - if(gHomebrewLaunched) { +DECL_FUNCTION(int32_t, MCP_GetTitleInfoByTitleAndDevice, uint32_t mcp_handle, uint32_t titleid_lower_1, uint32_t titleid_upper, uint32_t titleid_lower_2, uint32_t unknown, MCPTitleListType *title) { + if (gHomebrewLaunched) { memcpy(title, &(template_title), sizeof(MCPTitleListType)); - } else if(titleid_upper == 0x0005000F) { - char buffer [25]; - snprintf(buffer,25,"/custom/%08X%08X", titleid_upper, titleid_lower_2); - strcpy(template_title.path,buffer); + } else if (titleid_upper == 0x0005000F) { + char buffer[25]; + snprintf(buffer, 25, "/custom/%08X%08X", titleid_upper, titleid_lower_2); + strcpy(template_title.path, buffer); template_title.titleId = 0x0005000F00000000 + titleid_lower_1; memcpy(title, &(template_title), sizeof(MCPTitleListType)); return 0; @@ -195,15 +195,15 @@ typedef struct __attribute((packed)) { uint32_t fileoffset; char path[256]; } -LOAD_REQUEST; + LOAD_REQUEST; -int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info); +int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info); -DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* title, uint32_t u2) { - if((title->titleId & 0x0005000F00000000) == 0x0005000F00000000 && (uint32_t)(title->titleId & 0xFFFFFFFF) < FILE_INFO_SIZE) { +DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType *title, uint32_t u2) { + if ((title->titleId & 0x0005000F00000000) == 0x0005000F00000000 && (uint32_t) (title->titleId & 0xFFFFFFFF) < FILE_INFO_SIZE) { DEBUG_FUNCTION_LINE("Started homebrew\n"); gHomebrewLaunched = TRUE; - fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32,(title->titleId & 0xFFFFFFFF), &gLaunchXML); + fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32, (title->titleId & 0xFFFFFFFF), &gLaunchXML); LOAD_REQUEST request; memset(&request, 0, sizeof(request)); @@ -214,23 +214,22 @@ DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* t request.fileoffset = 0; // romfs_fileInfo info; - int res = getRPXInfoForID((title->titleId & 0xFFFFFFFF),&info); - if(res >= 0) { - request.filesize = ((uint32_t*)&info.length)[1]; - request.fileoffset = ((uint32_t*)&info.offset)[1]; - loadFileIntoBuffer((title->titleId & 0xFFFFFFFF),"meta/iconTex.tga",gIconCache,sizeof(gIconCache)); + int res = getRPXInfoForID((title->titleId & 0xFFFFFFFF), &info); + if (res >= 0) { + request.filesize = ((uint32_t *) &info.length)[1]; + request.fileoffset = ((uint32_t *) &info.offset)[1]; + loadFileIntoBuffer((title->titleId & 0xFFFFFFFF), "meta/iconTex.tga", gIconCache, sizeof(gIconCache)); } - 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); DCFlushRange(&request, sizeof(LOAD_REQUEST)); - int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode)0); - if(mcpFd >= 0) { + int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0); + if (mcpFd >= 0) { int out = 0; IOS_Ioctl(mcpFd, 100, &request, sizeof(request), &out, sizeof(out)); IOS_Close(mcpFd); @@ -244,38 +243,38 @@ DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* t } DECL_FUNCTION(int, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, const char *mode, int *handle, int error) { - char * start = "/vol/storage_mlc01/sys/title/0005000F"; - char * icon = ".tga"; - char * iconTex = "iconTex.tga"; - char * sound = ".btsnd"; + char *start = "/vol/storage_mlc01/sys/title/0005000F"; + char *icon = ".tga"; + char *iconTex = "iconTex.tga"; + char *sound = ".btsnd"; - if(StringTools::EndsWith(path,icon) || StringTools::EndsWith(path,sound)) { - if(strncmp(path,start,strlen(start)) == 0) { + if (StringTools::EndsWith(path, icon) || StringTools::EndsWith(path, sound)) { + if (strncmp(path, start, strlen(start)) == 0) { int res = FS_STATUS_NOT_FOUND; - if(StringTools::EndsWith(path,iconTex)) { + if (StringTools::EndsWith(path, iconTex)) { // fallback to dummy icon if loaded homebrew is no .wbf //*handle = 0x1337; res = FS_STATUS_NOT_FOUND; } uint32_t val; - char * id = path+1+strlen(start); + char *id = path + 1 + strlen(start); id[8] = 0; - char * ending = id+9; - sscanf(id,"%08X", &val); - if(FSOpenFile_for_ID(val, ending, handle) < 0) { + char *ending = id + 9; + sscanf(id, "%08X", &val); + if (FSOpenFile_for_ID(val, ending, handle) < 0) { return res; } return FS_STATUS_OK; - } else if(gHomebrewLaunched) { + } else if (gHomebrewLaunched) { socket_lib_init(); log_init(); - if(StringTools::EndsWith(path,iconTex)) { + if (StringTools::EndsWith(path, iconTex)) { *handle = 0x13371337; DEBUG_FUNCTION_LINE("yooo let's do it\n"); return FS_STATUS_OK; - }else{ - DEBUG_FUNCTION_LINE("%s\n",path); + } else { + DEBUG_FUNCTION_LINE("%s\n", path); } } @@ -287,16 +286,16 @@ DECL_FUNCTION(int, FSOpenFile, FSClient *client, FSCmdBlock *block, char *path, DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFileHandle handle, uint32_t flags) { - if(handle == 0x13371337) { + if (handle == 0x13371337) { return FS_STATUS_OK; } - if((handle & 0xFF000000) == 0xFF000000) { + if ((handle & 0xFF000000) == 0xFF000000) { int32_t fd = (handle & 0x00000FFF); int32_t romid = (handle & 0x00FFF000) >> 12; DEBUG_FUNCTION_LINE("Close %d %d\n", fd, romid); DeInitFile(fd); - if(gFileInfos[romid].openedFiles--) { - if(gFileInfos[romid].openedFiles <= 0) { + if (gFileInfos[romid].openedFiles--) { + if (gFileInfos[romid].openedFiles <= 0) { DEBUG_FUNCTION_LINE("unmount romfs no more handles\n"); unmountRomfs(romid); } @@ -304,85 +303,84 @@ DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFile //unmountAllRomfs(); return FS_STATUS_OK; } - return real_FSCloseFile(client,block,handle,flags); + return real_FSCloseFile(client, block, handle, 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) { - int cpySize = size*count; - if(sizeof(gIconCache) < cpySize) { +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) { + int cpySize = size * count; + if (sizeof(gIconCache) < cpySize) { cpySize = sizeof(gIconCache); } memcpy(buffer, gIconCache, cpySize); DEBUG_FUNCTION_LINE("DUMMY\n"); - return (FSStatus)(cpySize/size); + return (FSStatus) (cpySize / size); } - if((handle & 0xFF000000) == 0xFF000000) { + if ((handle & 0xFF000000) == 0xFF000000) { int32_t fd = (handle & 0x00000FFF); int32_t romid = (handle & 0x00FFF000) >> 12; - DEBUG_FUNCTION_LINE("READ %d from %d rom: %d\n", size*count, fd, romid); + DEBUG_FUNCTION_LINE("READ %d from %d rom: %d\n", size * count, fd, romid); - int readSize = readFile(fd, buffer, (size*count)); + int readSize = readFile(fd, buffer, (size * count)); - return (FSStatus)(readSize / size); + return (FSStatus) (readSize / size); } FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags); return result; } -DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf, uint32_t device, uint32_t u1) { - int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, out_buf, device,u1); - if(titleid_upper == 0x0005000F) { - fillXmlForTitleID(titleid_upper,titleid_lower, out_buf); +DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *out_buf, uint32_t device, uint32_t u1) { + int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, out_buf, device, u1); + if (titleid_upper == 0x0005000F) { + fillXmlForTitleID(titleid_upper, titleid_lower, out_buf); result = 0; } return result; } -DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint32_t titleid_lower, char* out_buf, uint32_t size, int device) { - if(titleid_upper == 0x0005000F) { - snprintf(out_buf,53,"/vol/storage_mlc01/sys/title/%08X/%08X/meta", titleid_upper, titleid_lower); +DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint32_t titleid_lower, char *out_buf, uint32_t size, int device) { + if (titleid_upper == 0x0005000F) { + snprintf(out_buf, 53, "/vol/storage_mlc01/sys/title/%08X/%08X/meta", titleid_upper, titleid_lower); return 0; } int result = real_ACPGetTitleMetaDirByDevice(titleid_upper, titleid_lower, out_buf, size, device); return result; } -DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char* pathToLoad, uint32_t u2) { - const char * start = "/custom/"; - if(strncmp(pathToLoad,start,strlen(start)) == 0) { - strcpy(template_title.path,pathToLoad); +DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char *pathToLoad, uint32_t u2) { + const char *start = "/custom/"; + if (strncmp(pathToLoad, start, strlen(start)) == 0) { + strcpy(template_title.path, pathToLoad); uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); - snprintf(pathToLoad,47,"/vol/storage_mlc01/sys/title/%08x/%08x", (uint32_t) (titleID >> 32), (uint32_t) (0x00000000FFFFFFFF & titleID)); + snprintf(pathToLoad, 47, "/vol/storage_mlc01/sys/title/%08x/%08x", (uint32_t) (titleID >> 32), (uint32_t) (0x00000000FFFFFFFF & titleID)); } int32_t result = real__SYSLaunchTitleByPathFromLauncher(pathToLoad, strlen(pathToLoad)); return result; } -DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml * metaxml) { +DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) { int result = real_ACPGetLaunchMetaXml(metaxml); - if(gHomebrewLaunched) { + if (gHomebrewLaunched) { memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); } return result; } -DECL_FUNCTION(uint32_t, ACPGetApplicationBox,uint32_t * u1, uint32_t * u2, uint32_t u3, uint32_t u4) { - if(u3 == 0x0005000F) { +DECL_FUNCTION(uint32_t, ACPGetApplicationBox, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4) { + if (u3 == 0x0005000F) { uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); u3 = (uint32_t) (titleID >> 32); u4 = (uint32_t) (0x00000000FFFFFFFF & titleID); } - uint32_t result = real_ACPGetApplicationBox(u1,u2,u3,u4); + uint32_t result = real_ACPGetApplicationBox(u1, u2, u3, u4); return result; } -DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t * param ) { - if(param[2] == 0x0005000F) { +DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t *param) { + if (param[2] == 0x0005000F) { uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); param[2] = (uint32_t) (titleID >> 32); param[3] = (uint32_t) (0x00000000FFFFFFFF & titleID); @@ -391,18 +389,18 @@ DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t * return result; } -DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t * u1, uint32_t * u2, uint32_t u3, uint32_t u4, uint32_t u5) { - if(u3 == 0x0005000F) { +DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4, uint32_t u5) { + if (u3 == 0x0005000F) { uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY); u3 = (uint32_t) (titleID >> 32); u4 = (uint32_t) (0x00000000FFFFFFFF & titleID); } - uint32_t result = real_MCP_RightCheckLaunchable(u1,u2,u3,u4,u5); + uint32_t result = real_MCP_RightCheckLaunchable(u1, u2, u3, u4, u5); return result; } -DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* metaxml, uint32_t device) { - if(gHomebrewLaunched) { +DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) { + if (gHomebrewLaunched) { memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML)); return 0; } @@ -410,19 +408,19 @@ DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_u return result; } -WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44); -WUPS_MUST_REPLACE(ACPGetApplicationBox, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetApplicationBox ); -WUPS_MUST_REPLACE(PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, WUPS_LOADER_LIBRARY_DRMAPP, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg ); -WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT, MCP_RightCheckLaunchable ); +WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44); +WUPS_MUST_REPLACE(ACPGetApplicationBox, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetApplicationBox); +WUPS_MUST_REPLACE(PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, WUPS_LOADER_LIBRARY_DRMAPP, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg); +WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT, MCP_RightCheckLaunchable); -WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile); -WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile); -WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile); -WUPS_MUST_REPLACE(MCP_TitleList, WUPS_LOADER_LIBRARY_COREINIT, MCP_TitleList); -WUPS_MUST_REPLACE(MCP_GetTitleInfoByTitleAndDevice, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetTitleInfoByTitleAndDevice ); +WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile); +WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile); +WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile); +WUPS_MUST_REPLACE(MCP_TitleList, WUPS_LOADER_LIBRARY_COREINIT, MCP_TitleList); +WUPS_MUST_REPLACE(MCP_GetTitleInfoByTitleAndDevice, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetTitleInfoByTitleAndDevice); -WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx ); -WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice ); -WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml ); -WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice ); -WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher); +WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx); +WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice); +WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml); +WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice); +WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher); diff --git a/src/readFileWrapper.cpp b/src/readFileWrapper.cpp index 4f50acd..333f278 100644 --- a/src/readFileWrapper.cpp +++ b/src/readFileWrapper.cpp @@ -4,16 +4,14 @@ #include #include #include -#include -#include #include #include "romfs_helper.h" fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE] __attribute__((section(".data"))); -int readFile(int slot, uint8_t * buffer, uint32_t size) { - fileReadInformation * info = &gFileReadInformation[slot]; - if(!info->compressed) { +int readFile(int slot, uint8_t *buffer, uint32_t size) { + fileReadInformation *info = &gFileReadInformation[slot]; + if (!info->compressed) { //DEBUG_FUNCTION_LINE("non compressed\n"); return read(info->fd, buffer, size); } else { @@ -25,11 +23,11 @@ int readFile(int slot, uint8_t * buffer, uint32_t size) { do { int CHUNK = 0x1000; int nextOut = CHUNK; - if(nextOut > size) { + if (nextOut > size) { nextOut = size; } //DEBUG_FUNCTION_LINE("nextOut = %d\n",nextOut); - if(info->strm.avail_in == 0) { + if (info->strm.avail_in == 0) { //DEBUG_FUNCTION_LINE("Reading %d from compressed stream\n",CHUNK); info->strm.avail_in = read(info->fd, info->in, CHUNK); if (info->strm.avail_in == 0) { @@ -45,7 +43,7 @@ int readFile(int slot, uint8_t * buffer, uint32_t size) { do { //DEBUG_FUNCTION_LINE("newSize %d, size %d, info->strm.avail_out %d\n", newSize, size, info->strm.avail_out); - if(nextOut > size - newSize) { + if (nextOut > size - newSize) { nextOut = size - newSize; } @@ -55,32 +53,32 @@ int readFile(int slot, uint8_t * buffer, uint32_t size) { //DEBUG_FUNCTION_LINE("info->strm.next_out = %08X\n",info->strm.next_out); ret = inflate(&info->strm, Z_NO_FLUSH); //DEBUG_FUNCTION_LINE("ret = %d\n",ret); - if(ret == Z_STREAM_ERROR) { + if (ret == Z_STREAM_ERROR) { DEBUG_FUNCTION_LINE("Z_STREAM_ERROR\n"); return 0; } switch (ret) { - case Z_NEED_DICT: - DEBUG_FUNCTION_LINE("Z_NEED_DICT\n"); - ret = Z_DATA_ERROR; /* and fall through */ - case Z_DATA_ERROR: - case Z_MEM_ERROR: - DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR\n"); - (void)inflateEnd(&info->strm); - return ret; + case Z_NEED_DICT: + DEBUG_FUNCTION_LINE("Z_NEED_DICT\n"); + ret = Z_DATA_ERROR; /* and fall through */ + case Z_DATA_ERROR: + case Z_MEM_ERROR: + DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR\n"); + (void) inflateEnd(&info->strm); + return ret; } int canBeWritten = CHUNK - info->strm.avail_out; //DEBUG_FUNCTION_LINE("canBeWritten = %d\n",canBeWritten); newSize = info->strm.total_out - startValue; - if(newSize == size) { + if (newSize == size) { //DEBUG_FUNCTION_LINE("newSize was as wanted %d\n", newSize); break; } nextOut = CHUNK; - if(newSize + nextOut >= (size)) { + if (newSize + nextOut >= (size)) { nextOut = (size) - newSize; } //DEBUG_FUNCTION_LINE("newSize = %d\n",newSize); @@ -96,31 +94,30 @@ int readFile(int slot, uint8_t * buffer, uint32_t size) { bool DeInitFile(int slot) { - if(gFileReadInformation[slot].compressed && gFileReadInformation[slot].cInitDone) { + if (gFileReadInformation[slot].compressed && gFileReadInformation[slot].cInitDone) { /* clean up and return */ - (void)inflateEnd(&(gFileReadInformation[slot].strm)); + (void) inflateEnd(&(gFileReadInformation[slot].strm)); } close(gFileReadInformation[slot].fd); gFileReadInformation[slot].inUse = false; - memset(&gFileReadInformation[slot],0, sizeof(fileReadInformation)); + memset(&gFileReadInformation[slot], 0, sizeof(fileReadInformation)); return true; } - void DeInitAllFiles() { - for(int i = 0; iinUse) { + for (int i = 0; i < FILE_READ_INFO_SIZE; i++) { + fileReadInformation *info = &gFileReadInformation[i]; + if (info->inUse) { DeInitFile(i); } } } int fileReadInformation_getSlot() { - for(int i = 0; i<32; i++) { - if(gFileReadInformation[i].inUse == false) { + for (int i = 0; i < 32; i++) { + if (gFileReadInformation[i].inUse == false) { gFileReadInformation[i].inUse = true; return i; } @@ -129,12 +126,12 @@ int fileReadInformation_getSlot() { } -bool initCompressedFileReadInformation(fileReadInformation * info) { - if(info == NULL || !info->compressed) { +bool initCompressedFileReadInformation(fileReadInformation *info) { + if (info == NULL || !info->compressed) { info->cInitDone = false; return false; } - if(info->cInitDone) { + if (info->cInitDone) { return true; } /* allocate inflate state */ @@ -154,12 +151,12 @@ bool initCompressedFileReadInformation(fileReadInformation * info) { } -int32_t loadFileIntoBuffer(uint32_t id, char * filepath, char * buffer, int sizeToRead) { - if(!mountRomfs(id)) { +int32_t loadFileIntoBuffer(uint32_t id, char *filepath, char *buffer, int sizeToRead) { + if (!mountRomfs(id)) { return -1; } int handle = 0; - if(FSOpenFile_for_ID(id, filepath, &handle) != 0){ + if (FSOpenFile_for_ID(id, filepath, &handle) != 0) { return -2; } @@ -168,12 +165,12 @@ int32_t loadFileIntoBuffer(uint32_t id, char * filepath, char * buffer, int size DEBUG_FUNCTION_LINE("READ %d from %d rom: %d\n", sizeToRead, fd, romid); - int readSize = readFile(fd, (uint8_t*)buffer, (sizeToRead)); + int readSize = readFile(fd, (uint8_t *) buffer, (sizeToRead)); DEBUG_FUNCTION_LINE("Close %d %d\n", fd, romid); DeInitFile(fd); - if(gFileInfos[romid].openedFiles--){ - if(gFileInfos[romid].openedFiles <= 0){ + if (gFileInfos[romid].openedFiles--) { + if (gFileInfos[romid].openedFiles <= 0) { DEBUG_FUNCTION_LINE("unmount romfs no more handles\n"); unmountRomfs(romid); } @@ -183,21 +180,19 @@ 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) { - if(!mountRomfs(id)) { +int32_t FSOpenFile_for_ID(uint32_t id, const char *filepath, int *handle) { + if (!mountRomfs(id)) { return -1; } - char romName [10]; - snprintf(romName,10,"%08X", id); + char romName[10]; + snprintf(romName, 10, "%08X", id); - char * test = (char *) malloc(strlen(filepath)+1); + char *test = (char *) malloc(strlen(filepath) + 1); char last = 0; int j = 0; - for(int i = 0; filepath[i] != 0; i++) { - if(filepath[i] == '/' ) { - if(filepath[i] != last) { + for (int i = 0; filepath[i] != 0; i++) { + if (filepath[i] == '/') { + if (filepath[i] != last) { test[j++] = filepath[i]; } } else { @@ -207,29 +202,29 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char * filepath, int * handle) { } test[j++] = 0; - char buffer [256]; - snprintf(buffer,256,"%s:/%s.gz",romName, test); + char buffer[256]; + snprintf(buffer, 256, "%s:/%s.gz", romName, test); bool nonCompressed = false; - if(!FSUtils::CheckFile(buffer)) { - snprintf(buffer,256,"%s:/%s",romName, test); - if(!FSUtils::CheckFile(buffer)) { + if (!FSUtils::CheckFile(buffer)) { + snprintf(buffer, 256, "%s:/%s", romName, test); + if (!FSUtils::CheckFile(buffer)) { return -3; } nonCompressed = true; } - int fd = open(buffer,0); - if(fd >= 0) { - DEBUG_FUNCTION_LINE("Opened %s from %s \n",buffer, romName ); + int fd = open(buffer, 0); + if (fd >= 0) { + DEBUG_FUNCTION_LINE("Opened %s from %s \n", buffer, romName); int slot = fileReadInformation_getSlot(); - if(slot < 0) { + if (slot < 0) { DEBUG_FUNCTION_LINE("Failed to get a slot\n"); return -5; } - fileReadInformation * info = &gFileReadInformation[slot]; + fileReadInformation *info = &gFileReadInformation[slot]; info->fd = fd; - if(!nonCompressed) { + if (!nonCompressed) { info->compressed = true; initCompressedFileReadInformation(info); DEBUG_FUNCTION_LINE("Init compressed, got slot %d\n", slot); diff --git a/src/readFileWrapper.h b/src/readFileWrapper.h index 5cd47c1..79e930c 100644 --- a/src/readFileWrapper.h +++ b/src/readFileWrapper.h @@ -1,4 +1,5 @@ #pragma once + #include #include #include @@ -13,25 +14,22 @@ typedef struct { unsigned char in[0x1000]; } fileReadInformation; - #define FILE_READ_INFO_SIZE 32 extern fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE]; - bool initFile(int slot); -int readFile(int slot, uint8_t * buffer, uint32_t size); +int readFile(int slot, uint8_t *buffer, uint32_t size); bool DeInitFile(int slot); void DeInitAllFiles(); -int32_t loadFileIntoBuffer(uint32_t id, char * filepath, char * buffer, int sizeToRead) ; +int32_t loadFileIntoBuffer(uint32_t id, char *filepath, char *buffer, int sizeToRead); -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); int fileReadInformation_getSlot(); - -bool initCompressedFileReadInformation(fileReadInformation * info); +bool initCompressedFileReadInformation(fileReadInformation *info); \ No newline at end of file diff --git a/src/romfs_helper.cpp b/src/romfs_helper.cpp index 7886932..6e8a444 100644 --- a/src/romfs_helper.cpp +++ b/src/romfs_helper.cpp @@ -7,37 +7,37 @@ FileInfos gFileInfos[FILE_INFO_SIZE] __attribute__((section(".data"))); void unmountRomfs(uint32_t id) { - if(id >= FILE_INFO_SIZE) { + if (id >= FILE_INFO_SIZE) { return; } - if(gFileInfos[id].romfsMounted) { - char romName [10]; - snprintf(romName,10,"%08X", id); + if (gFileInfos[id].romfsMounted) { + char romName[10]; + snprintf(romName, 10, "%08X", id); DEBUG_FUNCTION_LINE("Unmounting %s\n", romName); int res = romfsUnmount(romName); - DEBUG_FUNCTION_LINE("res: %d\n",res); + DEBUG_FUNCTION_LINE("res: %d\n", res); gFileInfos[id].romfsMounted = false; } } void unmountAllRomfs() { - for(int i = 0; i < FILE_INFO_SIZE; i++) { + for (int i = 0; i < FILE_INFO_SIZE; i++) { unmountRomfs(i); } } bool mountRomfs(uint32_t id) { - if(id >= FILE_INFO_SIZE) { + if (id >= FILE_INFO_SIZE) { DEBUG_FUNCTION_LINE("HANDLE WAS TOO BIG %d\n", id); return false; } - if(!gFileInfos[id].romfsMounted) { - char buffer [256]; - snprintf(buffer,256,"fs:/vol/external01/%s", gFileInfos[id].path); - char romName [10]; - snprintf(romName,10,"%08X", id); + if (!gFileInfos[id].romfsMounted) { + char buffer[256]; + snprintf(buffer, 256, "fs:/vol/external01/%s", gFileInfos[id].path); + char romName[10]; + snprintf(romName, 10, "%08X", id); DEBUG_FUNCTION_LINE("Mount %s as %s\n", buffer, romName); - if(romfsMount(romName,buffer) == 0) { + if (romfsMount(romName, buffer) == 0) { DEBUG_FUNCTION_LINE("Mounted successfully \n"); gFileInfos[id].romfsMounted = true; return true; @@ -50,19 +50,17 @@ bool mountRomfs(uint32_t id) { } - - -int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info) { - if(!mountRomfs(id)) { +int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo *info) { + if (!mountRomfs(id)) { return -1; } DIR *dir; struct dirent *entry; - char romName [10]; - snprintf(romName,10,"%08X", id); + char romName[10]; + snprintf(romName, 10, "%08X", id); char root[12]; - snprintf(root,12,"%08X:/", id); + snprintf(root, 12, "%08X:/", id); if (!(dir = opendir(root))) { return -2; @@ -70,8 +68,8 @@ int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info) { bool found = false; int res = -3; while ((entry = readdir(dir)) != NULL) { - if(StringTools::EndsWith(entry->d_name, ".rpx")) { - if(romfs_GetFileInfoPerPath(romName, entry->d_name, info) >= 0) { + if (StringTools::EndsWith(entry->d_name, ".rpx")) { + if (romfs_GetFileInfoPerPath(romName, entry->d_name, info) >= 0) { found = true; res = 0; } @@ -81,7 +79,7 @@ int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info) { closedir(dir); - if(!found) { + if (!found) { return -4; } return res; diff --git a/src/romfs_helper.h b/src/romfs_helper.h index b8df57b..f4558b7 100644 --- a/src/romfs_helper.h +++ b/src/romfs_helper.h @@ -4,8 +4,6 @@ #include #include - - typedef struct WUT_PACKED FileInfos_ { char path[256]; char name[256]; @@ -17,10 +15,10 @@ typedef struct WUT_PACKED FileInfos_ { #define FILE_INFO_SIZE 300 extern FileInfos gFileInfos[FILE_INFO_SIZE]; - - void unmountAllRomfs(); + void unmountRomfs(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); diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index ec7cf68..d5c366f 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -36,13 +36,13 @@ #include -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()) return false; return std::equal(a.begin() + a.size() - b.size(), a.end(), b.begin()); } -const char * StringTools::byte_to_binary(int32_t x) { +const char *StringTools::byte_to_binary(int32_t x) { static char b[9]; b[0] = '\0'; @@ -54,25 +54,25 @@ const char * StringTools::byte_to_binary(int32_t x) { return b; } -std::string StringTools::removeCharFromString(std::string& input,char toBeRemoved) { +std::string StringTools::removeCharFromString(std::string &input, char toBeRemoved) { std::string output = input; size_t position; - while(1) { + while (1) { position = output.find(toBeRemoved); - if(position == std::string::npos) + if (position == std::string::npos) break; output.erase(position, 1); } return output; } -const char * StringTools::fmt(const char * format, ...) { +const char *StringTools::fmt(const char *format, ...) { static char strChar[512]; strChar[0] = 0; va_list va; va_start(va, format); - if((vsprintf(strChar, format, va) >= 0)) { + if ((vsprintf(strChar, format, va) >= 0)) { va_end(va); return (const char *) strChar; } @@ -81,26 +81,26 @@ const char * StringTools::fmt(const char * format, ...) { return NULL; } -const wchar_t * StringTools::wfmt(const char * format, ...) { +const wchar_t *StringTools::wfmt(const char *format, ...) { static char tmp[512]; static wchar_t strWChar[512]; strWChar[0] = 0; tmp[0] = 0; - if(!format) + if (!format) return (const wchar_t *) strWChar; - if(strcmp(format, "") == 0) + if (strcmp(format, "") == 0) return (const wchar_t *) strWChar; va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { - int bt; + if ((vsprintf(tmp, format, va) >= 0)) { + int bt; 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; return (const wchar_t *) strWChar; } @@ -110,14 +110,14 @@ const wchar_t * StringTools::wfmt(const char * format, ...) { return NULL; } -int32_t StringTools::strprintf(std::string &str, const char * format, ...) { +int32_t StringTools::strprintf(std::string &str, const char *format, ...) { static char tmp[512]; tmp[0] = 0; int32_t result = 0; va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { + if ((vsprintf(tmp, format, va) >= 0)) { str = tmp; result = str.size(); } @@ -126,14 +126,14 @@ int32_t StringTools::strprintf(std::string &str, const char * format, ...) { return result; } -std::string StringTools::strfmt(const char * format, ...) { +std::string StringTools::strfmt(const char *format, ...) { std::string str; static char tmp[512]; tmp[0] = 0; va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { + if ((vsprintf(tmp, format, va) >= 0)) { str = tmp; } va_end(va); @@ -141,11 +141,11 @@ std::string StringTools::strfmt(const char * format, ...) { return str; } -BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) { - if(!strChar || !dest) +BOOL StringTools::char2wchar_t(const char *strChar, wchar_t *dest) { + if (!strChar || !dest) return false; - int bt; + int bt; bt = mbstowcs(dest, strChar, strlen(strChar)); if (bt > 0) { dest[bt] = 0; @@ -155,39 +155,39 @@ BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) { return false; } -int32_t StringTools::strtokcmp(const char * string, const char * compare, const char * separator) { - if(!string || !compare) +int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) { + if (!string || !compare) return -1; char TokCopy[512]; strncpy(TokCopy, compare, sizeof(TokCopy)); TokCopy[511] = '\0'; - char * strTok = strtok(TokCopy, separator); + char *strTok = strtok(TokCopy, separator); while (strTok != NULL) { if (strcasecmp(string, strTok) == 0) { return 0; } - strTok = strtok(NULL,separator); + strTok = strtok(NULL, separator); } return -1; } -int32_t StringTools::strextcmp(const char * string, const char * extension, char seperator) { - if(!string || !extension) +int32_t StringTools::strextcmp(const char *string, const char *extension, char seperator) { + if (!string || !extension) return -1; char *ptr = strrchr(string, seperator); - if(!ptr) + if (!ptr) return -1; return strcasecmp(ptr + 1, extension); } -std::vector StringTools::stringSplit(const std::string & inValue, const std::string & splitter) { +std::vector StringTools::stringSplit(const std::string &inValue, const std::string &splitter) { std::string value = inValue; std::vector result; while (true) { @@ -202,7 +202,7 @@ std::vector StringTools::stringSplit(const std::string & inValue, c result.push_back(""); break; } - if(index + splitter.size() > value.length()) { + if (index + splitter.size() > value.length()) { break; } value = value.substr(index + splitter.size(), value.length()); @@ -211,39 +211,39 @@ std::vector StringTools::stringSplit(const std::string & inValue, c } -const char * StringTools::FullpathToFilename(const char *path) { - if(!path) - return path; +const char *StringTools::FullpathToFilename(const char *path) { + if (!path) + return path; - const char * ptr = path; - const char * Filename = ptr; + const char *ptr = path; + const char *Filename = ptr; - while(*ptr != '\0') { - if(ptr[0] == '/' && ptr[1] != '\0') - Filename = ptr+1; + while (*ptr != '\0') { + if (ptr[0] == '/' && ptr[1] != '\0') + Filename = ptr + 1; - ++ptr; - } - - return Filename; + ++ptr; } + return Filename; +} + void StringTools::RemoveDoubleSlashs(std::string &str) { - uint32_t length = str.size(); + uint32_t length = str.size(); - //! clear path of double slashes - for(uint32_t i = 1; i < length; ++i) { - if(str[i-1] == '/' && str[i] == '/') { - str.erase(i, 1); - i--; - length--; - } + //! clear path of double slashes + for (uint32_t i = 1; i < length; ++i) { + if (str[i - 1] == '/' && str[i] == '/') { + str.erase(i, 1); + i--; + length--; } } +} // 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 *ins; // the next insert point char *tmp; // varies @@ -268,7 +268,7 @@ char * StringTools::str_replace(char *orig, char *rep, char *with) { ins = tmp + len_rep; } - tmp = result = (char*)malloc(strlen(orig) + (len_with - len_rep) * count + 1); + tmp = result = (char *) malloc(strlen(orig) + (len_with - len_rep) * count + 1); if (!result) return NULL; diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index 8087a70..851aa73 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -32,20 +32,33 @@ class StringTools { public: - static BOOL EndsWith(const std::string& a, const std::string& b); - static const char * byte_to_binary(int32_t x); - static std::string removeCharFromString(std::string& input,char toBeRemoved); - static const char * fmt(const char * format, ...); - static const wchar_t * wfmt(const char * format, ...); - static int32_t strprintf(std::string &str, const char * format, ...); - static std::string strfmt(const char * format, ...); - 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 strextcmp(const char * string, const char * extension, char seperator); + static BOOL EndsWith(const std::string &a, const std::string &b); + + static const char *byte_to_binary(int32_t x); + + static std::string removeCharFromString(std::string &input, char toBeRemoved); + + static const char *fmt(const char *format, ...); + + static const wchar_t *wfmt(const char *format, ...); + + static int32_t strprintf(std::string &str, const char *format, ...); + + static std::string strfmt(const char *format, ...); + + 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 strextcmp(const char *string, const char *extension, char seperator); + 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 std::vector stringSplit(const std::string & value, const std::string & splitter); + + static std::vector stringSplit(const std::string &value, const std::string &splitter); }; #endif /* __STRING_TOOLS_H */ diff --git a/src/utils/logger.c b/src/utils/logger.c index 0922230..5413a70 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -10,7 +10,7 @@ #include #include -static int log_socket __attribute__((section(".data")))= -1; +static int log_socket __attribute__((section(".data"))) = -1; static struct sockaddr_in connect_addr __attribute__((section(".data"))); static volatile int log_lock __attribute__((section(".data"))) = 0; @@ -30,11 +30,11 @@ void log_init_() { void log_print_(const char *str) { // socket is always 0 initially as it is in the BSS - if(log_socket < 0) { + if (log_socket < 0) { return; } - while(log_lock) + while (log_lock) OSSleepTicks(OSMicrosecondsToTicks(1000)); log_lock = 1; @@ -42,8 +42,8 @@ void log_print_(const char *str) { int ret; while (len > 0) { int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet - ret = sendto(log_socket, str, block, 0, (struct sockaddr *)&connect_addr, sizeof(struct sockaddr_in)); - if(ret < 0) + ret = sendto(log_socket, str, block, 0, (struct sockaddr *) &connect_addr, sizeof(struct sockaddr_in)); + if (ret < 0) break; len -= ret; @@ -58,14 +58,14 @@ void OSFatal_printf(const char *format, ...) { tmp[0] = 0; va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { + if ((vsprintf(tmp, format, va) >= 0)) { OSFatal(tmp); } va_end(va); } void log_printf_(const char *format, ...) { - if(log_socket < 0) { + if (log_socket < 0) { return; } @@ -74,7 +74,7 @@ void log_printf_(const char *format, ...) { va_list va; va_start(va, format); - if((vsprintf(tmp, format, va) >= 0)) { + if ((vsprintf(tmp, format, va) >= 0)) { log_print_(tmp); } va_end(va); diff --git a/src/utils/logger.h b/src/utils/logger.h index d026b05..b6f1040 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -8,9 +8,12 @@ extern "C" { #include void log_init_(); + //void log_deinit_(void); void log_print_(const char *str); + void log_printf_(const char *format, ...); + void OSFatal_printf(const char *format, ...); #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) @@ -21,7 +24,6 @@ void OSFatal_printf(const char *format, ...); } while (0) - #define log_init() log_init_() //#define log_deinit() log_deinit_() #define log_print(str) log_print_(str) diff --git a/src/utils/utils.c b/src/utils/utils.c index 0042415..ef03e74 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -7,31 +7,31 @@ #include // https://gist.github.com/ccbrown/9722406 -void dumpHex(const void* data, size_t size) { +void dumpHex(const void *data, size_t size) { char ascii[17]; size_t i, j; ascii[16] = '\0'; DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data); for (i = 0; i < size; ++i) { - log_printf("%02X ", ((unsigned char*)data)[i]); - if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') { - ascii[i % 16] = ((unsigned char*)data)[i]; + log_printf("%02X ", ((unsigned char *) data)[i]); + if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { + ascii[i % 16] = ((unsigned char *) data)[i]; } else { ascii[i % 16] = '.'; } - if ((i+1) % 8 == 0 || i+1 == size) { + if ((i + 1) % 8 == 0 || i + 1 == size) { log_printf(" "); - if ((i+1) % 16 == 0) { + if ((i + 1) % 16 == 0) { log_printf("| %s \n", ascii); - if(i + 1 < size) { - DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1,i+1); + if (i + 1 < size) { + DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1); } - } else if (i+1 == size) { - ascii[(i+1) % 16] = '\0'; - if ((i+1) % 16 <= 8) { + } else if (i + 1 == size) { + ascii[(i + 1) % 16] = '\0'; + if ((i + 1) % 16 <= 8) { log_printf(" "); } - for (j = (i+1) % 16; j < 16; ++j) { + for (j = (i + 1) % 16; j < 16; ++j) { log_printf(" "); } log_printf("| %s \n", ascii); diff --git a/src/utils/utils.h b/src/utils/utils.h index 26caaaf..1d00f98 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -7,12 +7,12 @@ extern "C" { #endif -#define LIMIT(x, min, max) \ - ({ \ - typeof( x ) _x = x; \ - typeof( min ) _min = min; \ - typeof( max ) _max = max; \ - ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ +#define LIMIT(x, min, max) \ + ({ \ + typeof( x ) _x = x; \ + typeof( min ) _min = min; \ + typeof( max ) _max = max; \ + ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ }) #define DegToRad(a) ( (a) * 0.01745329252f ) @@ -26,7 +26,7 @@ extern "C" { #define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) //Needs to have log_init() called beforehand. -void dumpHex(const void* data, size_t size); +void dumpHex(const void *data, size_t size); #ifdef __cplusplus }