mirror of
https://github.com/wiiu-env/homebrew_on_menu_plugin.git
synced 2024-11-25 11:56:53 +01:00
Formatting
This commit is contained in:
parent
8b349029d0
commit
3d2363d171
@ -12,12 +12,12 @@ CFile::CFile() {
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const std::string & filepath, eOpenTypes mode) {
|
CFile::CFile(const std::string &filepath, eOpenTypes mode) {
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
this->open(filepath, mode);
|
this->open(filepath, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::CFile(const uint8_t * mem, int32_t size) {
|
CFile::CFile(const uint8_t *mem, int32_t size) {
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
this->open(mem, size);
|
this->open(mem, size);
|
||||||
}
|
}
|
||||||
@ -26,27 +26,27 @@ CFile::~CFile() {
|
|||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
|
||||||
this->close();
|
this->close();
|
||||||
int32_t openMode = 0;
|
int32_t openMode = 0;
|
||||||
|
|
||||||
// This depend on the devoptab implementation.
|
// This depend on the devoptab implementation.
|
||||||
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
|
// see https://github.com/devkitPro/wut/blob/master/libraries/wutdevoptab/devoptab_fs_open.c#L21 fpr reference
|
||||||
|
|
||||||
switch(mode) {
|
switch (mode) {
|
||||||
default:
|
default:
|
||||||
case ReadOnly: // file must exist
|
case ReadOnly: // file must exist
|
||||||
openMode = O_RDONLY;
|
openMode = O_RDONLY;
|
||||||
break;
|
break;
|
||||||
case WriteOnly: // file will be created / zerod
|
case WriteOnly: // file will be created / zerod
|
||||||
openMode = O_TRUNC | O_CREAT | O_WRONLY;
|
openMode = O_TRUNC | O_CREAT | O_WRONLY;
|
||||||
break;
|
break;
|
||||||
case ReadWrite: // file must exist
|
case ReadWrite: // file must exist
|
||||||
openMode = O_RDWR;
|
openMode = O_RDWR;
|
||||||
break;
|
break;
|
||||||
case Append: // append to file, file will be created if missing. write only
|
case Append: // append to file, file will be created if missing. write only
|
||||||
openMode = O_CREAT | O_APPEND | O_WRONLY;
|
openMode = O_CREAT | O_APPEND | O_WRONLY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Using fopen works only on the first launch as expected
|
//! 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
|
//! the .data sections which is needed for a normal application to re-init
|
||||||
//! this will be added with launching as RPX
|
//! this will be added with launching as RPX
|
||||||
iFd = ::open(filepath.c_str(), openMode);
|
iFd = ::open(filepath.c_str(), openMode);
|
||||||
if(iFd < 0)
|
if (iFd < 0)
|
||||||
return iFd;
|
return iFd;
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
|||||||
return 0;
|
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();
|
this->close();
|
||||||
|
|
||||||
mem_file = mem;
|
mem_file = mem;
|
||||||
@ -74,7 +74,7 @@ int32_t CFile::open(const uint8_t * mem, int32_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CFile::close() {
|
void CFile::close() {
|
||||||
if(iFd >= 0)
|
if (iFd >= 0)
|
||||||
::close(iFd);
|
::close(iFd);
|
||||||
|
|
||||||
iFd = -1;
|
iFd = -1;
|
||||||
@ -83,24 +83,24 @@ void CFile::close() {
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::read(uint8_t * ptr, size_t size) {
|
int32_t CFile::read(uint8_t *ptr, size_t size) {
|
||||||
if(iFd >= 0) {
|
if (iFd >= 0) {
|
||||||
int32_t ret = ::read(iFd, ptr,size);
|
int32_t ret = ::read(iFd, ptr, size);
|
||||||
if(ret > 0)
|
if (ret > 0)
|
||||||
pos += ret;
|
pos += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t readsize = size;
|
int32_t readsize = size;
|
||||||
|
|
||||||
if(readsize > (int64_t) (filesize-pos))
|
if (readsize > (int64_t) (filesize - pos))
|
||||||
readsize = filesize-pos;
|
readsize = filesize - pos;
|
||||||
|
|
||||||
if(readsize <= 0)
|
if (readsize <= 0)
|
||||||
return readsize;
|
return readsize;
|
||||||
|
|
||||||
if(mem_file != NULL) {
|
if (mem_file != NULL) {
|
||||||
memcpy(ptr, mem_file+pos, readsize);
|
memcpy(ptr, mem_file + pos, readsize);
|
||||||
pos += readsize;
|
pos += readsize;
|
||||||
return readsize;
|
return readsize;
|
||||||
}
|
}
|
||||||
@ -108,12 +108,12 @@ int32_t CFile::read(uint8_t * ptr, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CFile::write(const uint8_t * ptr, size_t size) {
|
int32_t CFile::write(const uint8_t *ptr, size_t size) {
|
||||||
if(iFd >= 0) {
|
if (iFd >= 0) {
|
||||||
size_t done = 0;
|
size_t done = 0;
|
||||||
while(done < size) {
|
while (done < size) {
|
||||||
int32_t ret = ::write(iFd, ptr, size - done);
|
int32_t ret = ::write(iFd, ptr, size - done);
|
||||||
if(ret <= 0)
|
if (ret <= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ptr += ret;
|
ptr += ret;
|
||||||
@ -130,25 +130,25 @@ int32_t CFile::seek(long int offset, int32_t origin) {
|
|||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
int64_t newPos = pos;
|
int64_t newPos = pos;
|
||||||
|
|
||||||
if(origin == SEEK_SET) {
|
if (origin == SEEK_SET) {
|
||||||
newPos = offset;
|
newPos = offset;
|
||||||
} else if(origin == SEEK_CUR) {
|
} else if (origin == SEEK_CUR) {
|
||||||
newPos += offset;
|
newPos += offset;
|
||||||
} else if(origin == SEEK_END) {
|
} else if (origin == SEEK_END) {
|
||||||
newPos = filesize+offset;
|
newPos = filesize + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newPos < 0) {
|
if (newPos < 0) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
} else {
|
} else {
|
||||||
pos = newPos;
|
pos = newPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iFd >= 0)
|
if (iFd >= 0)
|
||||||
ret = ::lseek(iFd, pos, SEEK_SET);
|
ret = ::lseek(iFd, pos, SEEK_SET);
|
||||||
|
|
||||||
if(mem_file != NULL) {
|
if (mem_file != NULL) {
|
||||||
if(pos > filesize) {
|
if (pos > filesize) {
|
||||||
pos = filesize;
|
pos = filesize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,8 +163,8 @@ int32_t CFile::fwrite(const char *format, ...) {
|
|||||||
|
|
||||||
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)) {
|
||||||
result = this->write((uint8_t *)tmp, strlen(tmp));
|
result = this->write((uint8_t *) tmp, strlen(tmp));
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
@ -18,18 +18,22 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
CFile();
|
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();
|
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 {
|
||||||
if(iFd >= 0)
|
if (iFd >= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(mem_file)
|
if (mem_file)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -37,23 +41,29 @@ 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32_t iFd;
|
int32_t iFd;
|
||||||
const uint8_t * mem_file;
|
const uint8_t *mem_file;
|
||||||
uint64_t filesize;
|
uint64_t filesize;
|
||||||
uint64_t pos;
|
uint64_t pos;
|
||||||
};
|
};
|
||||||
|
@ -42,7 +42,7 @@ DirList::DirList() {
|
|||||||
Depth = 0;
|
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->LoadPath(path, filter, flags, maxDepth);
|
||||||
this->SortList();
|
this->SortList();
|
||||||
}
|
}
|
||||||
@ -51,8 +51,8 @@ DirList::~DirList() {
|
|||||||
ClearList();
|
ClearList();
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
BOOL DirList::LoadPath(const std::string &folder, const char *filter, uint32_t flags, uint32_t maxDepth) {
|
||||||
if(folder.empty())
|
if (folder.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
@ -66,11 +66,11 @@ BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t
|
|||||||
StringTools::RemoveDoubleSlashs(folderpath);
|
StringTools::RemoveDoubleSlashs(folderpath);
|
||||||
|
|
||||||
//! remove last slash if exists
|
//! remove last slash if exists
|
||||||
if(length > 0 && folderpath[length-1] == '/')
|
if (length > 0 && folderpath[length - 1] == '/')
|
||||||
folderpath.erase(length-1);
|
folderpath.erase(length - 1);
|
||||||
|
|
||||||
//! add root slash if missing
|
//! add root slash if missing
|
||||||
if(folderpath.find('/') == std::string::npos) {
|
if (folderpath.find('/') == std::string::npos) {
|
||||||
folderpath += '/';
|
folderpath += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ BOOL DirList::LoadPath(const std::string & folder, const char *filter, uint32_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
||||||
if(folderpath.size() < 3)
|
if (folderpath.size() < 3)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
struct dirent *dirent = NULL;
|
struct dirent *dirent = NULL;
|
||||||
@ -92,13 +92,13 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
BOOL isDir = dirent->d_type & DT_DIR;
|
BOOL isDir = dirent->d_type & DT_DIR;
|
||||||
const char *filename = dirent->d_name;
|
const char *filename = dirent->d_name;
|
||||||
|
|
||||||
if(isDir) {
|
if (isDir) {
|
||||||
if(strcmp(filename,".") == 0 || strcmp(filename,"..") == 0)
|
if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if((Flags & CheckSubfolders) && (Depth > 0)) {
|
if ((Flags & CheckSubfolders) && (Depth > 0)) {
|
||||||
int32_t length = folderpath.size();
|
int32_t length = folderpath.size();
|
||||||
if(length > 2 && folderpath[length-1] != '/') {
|
if (length > 2 && folderpath[length - 1] != '/') {
|
||||||
folderpath += '/';
|
folderpath += '/';
|
||||||
}
|
}
|
||||||
folderpath += filename;
|
folderpath += filename;
|
||||||
@ -109,18 +109,18 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
Depth++;
|
Depth++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(Flags & Dirs))
|
if (!(Flags & Dirs))
|
||||||
continue;
|
continue;
|
||||||
} else if(!(Flags & Files)) {
|
} else if (!(Flags & Files)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Filter) {
|
if (Filter) {
|
||||||
char * fileext = strrchr(filename, '.');
|
char *fileext = strrchr(filename, '.');
|
||||||
if(!fileext)
|
if (!fileext)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(StringTools::strtokcmp(fileext, Filter, ",") == 0)
|
if (StringTools::strtokcmp(fileext, Filter, ",") == 0)
|
||||||
AddEntrie(folderpath, filename, isDir);
|
AddEntrie(folderpath, filename, isDir);
|
||||||
} else {
|
} else {
|
||||||
AddEntrie(folderpath, filename, isDir);
|
AddEntrie(folderpath, filename, isDir);
|
||||||
@ -131,16 +131,16 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL isDir) {
|
void DirList::AddEntrie(const std::string &filepath, const char *filename, BOOL isDir) {
|
||||||
if(!filename)
|
if (!filename)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int32_t pos = FileInfo.size();
|
int32_t pos = FileInfo.size();
|
||||||
|
|
||||||
FileInfo.resize(pos+1);
|
FileInfo.resize(pos + 1);
|
||||||
|
|
||||||
FileInfo[pos].FilePath = (char *) malloc(filepath.size()+strlen(filename)+2);
|
FileInfo[pos].FilePath = (char *) malloc(filepath.size() + strlen(filename) + 2);
|
||||||
if(!FileInfo[pos].FilePath) {
|
if (!FileInfo[pos].FilePath) {
|
||||||
FileInfo.resize(pos);
|
FileInfo.resize(pos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -150,8 +150,8 @@ void DirList::AddEntrie(const std::string &filepath, const char * filename, BOOL
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DirList::ClearList() {
|
void DirList::ClearList() {
|
||||||
for(uint32_t i = 0; i < FileInfo.size(); ++i) {
|
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||||
if(FileInfo[i].FilePath) {
|
if (FileInfo[i].FilePath) {
|
||||||
free(FileInfo[i].FilePath);
|
free(FileInfo[i].FilePath);
|
||||||
FileInfo[i].FilePath = NULL;
|
FileInfo[i].FilePath = NULL;
|
||||||
}
|
}
|
||||||
@ -161,37 +161,37 @@ void DirList::ClearList() {
|
|||||||
std::vector<DirEntry>().swap(FileInfo);
|
std::vector<DirEntry>().swap(FileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * DirList::GetFilename(int32_t ind) const {
|
const char *DirList::GetFilename(int32_t ind) const {
|
||||||
if (!valid(ind))
|
if (!valid(ind))
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
|
return StringTools::FullpathToFilename(FileInfo[ind].FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL SortCallback(const DirEntry & f1, const DirEntry & f2) {
|
static BOOL SortCallback(const DirEntry &f1, const DirEntry &f2) {
|
||||||
if(f1.isDir && !(f2.isDir))
|
if (f1.isDir && !(f2.isDir))
|
||||||
return true;
|
return true;
|
||||||
if(!(f1.isDir) && f2.isDir)
|
if (!(f1.isDir) && f2.isDir)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(f1.FilePath && !f2.FilePath)
|
if (f1.FilePath && !f2.FilePath)
|
||||||
return true;
|
return true;
|
||||||
if(!f1.FilePath)
|
if (!f1.FilePath)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
if (strcasecmp(f1.FilePath, f2.FilePath) > 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList() {
|
void DirList::SortList() {
|
||||||
if(FileInfo.size() > 1)
|
if (FileInfo.size() > 1)
|
||||||
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
|
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);
|
std::sort(FileInfo.begin(), FileInfo.end(), SortFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,14 +199,14 @@ uint64_t DirList::GetFilesize(int32_t index) const {
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
const char *path = GetFilepath(index);
|
const char *path = GetFilepath(index);
|
||||||
|
|
||||||
if(!path || stat(path, &st) != 0)
|
if (!path || stat(path, &st) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return st.st_size;
|
return st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DirList::GetFileIndex(const char *filename) const {
|
int32_t DirList::GetFileIndex(const char *filename) const {
|
||||||
if(!filename)
|
if (!filename)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include <wut_types.h>
|
#include <wut_types.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char * FilePath;
|
char *FilePath;
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
} DirEntry;
|
} DirEntry;
|
||||||
|
|
||||||
@ -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,26 +64,33 @@ 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 {
|
||||||
if(!valid(index))
|
if (!valid(index))
|
||||||
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());
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
|
int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
|
||||||
//! always initialze input
|
//! always initialze input
|
||||||
*inbuffer = NULL;
|
*inbuffer = NULL;
|
||||||
if(size)
|
if (size)
|
||||||
*size = 0;
|
*size = 0;
|
||||||
|
|
||||||
int32_t iFd = open(filepath, O_RDONLY);
|
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;
|
uint32_t done = 0;
|
||||||
int32_t readBytes = 0;
|
int32_t readBytes = 0;
|
||||||
|
|
||||||
while(done < filesize) {
|
while (done < filesize) {
|
||||||
if(done + blocksize > filesize) {
|
if (done + blocksize > filesize) {
|
||||||
blocksize = filesize - done;
|
blocksize = filesize - done;
|
||||||
}
|
}
|
||||||
readBytes = read(iFd, buffer + done, blocksize);
|
readBytes = read(iFd, buffer + done, blocksize);
|
||||||
if(readBytes <= 0)
|
if (readBytes <= 0)
|
||||||
break;
|
break;
|
||||||
done += readBytes;
|
done += readBytes;
|
||||||
}
|
}
|
||||||
@ -51,27 +51,27 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
|
|||||||
*inbuffer = buffer;
|
*inbuffer = buffer;
|
||||||
|
|
||||||
//! sign is optional input
|
//! sign is optional input
|
||||||
if(size) {
|
if (size) {
|
||||||
*size = filesize;
|
*size = filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filesize;
|
return filesize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FSUtils::CheckFile(const char * filepath) {
|
int32_t FSUtils::CheckFile(const char *filepath) {
|
||||||
if(!filepath)
|
if (!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);
|
||||||
|
|
||||||
while(dirnoslash[strlen(dirnoslash)-1] == '/')
|
while (dirnoslash[strlen(dirnoslash) - 1] == '/')
|
||||||
dirnoslash[strlen(dirnoslash)-1] = '\0';
|
dirnoslash[strlen(dirnoslash) - 1] = '\0';
|
||||||
|
|
||||||
char * notRoot = strrchr(dirnoslash, '/');
|
char *notRoot = strrchr(dirnoslash, '/');
|
||||||
if(!notRoot) {
|
if (!notRoot) {
|
||||||
strcat(dirnoslash, "/");
|
strcat(dirnoslash, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,29 +81,29 @@ int32_t FSUtils::CheckFile(const char * filepath) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t FSUtils::CreateSubfolder(const char * fullpath) {
|
int32_t FSUtils::CreateSubfolder(const char *fullpath) {
|
||||||
if(!fullpath)
|
if (!fullpath)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int32_t result = 0;
|
int32_t result = 0;
|
||||||
|
|
||||||
char dirnoslash[strlen(fullpath)+1];
|
char dirnoslash[strlen(fullpath) + 1];
|
||||||
strcpy(dirnoslash, fullpath);
|
strcpy(dirnoslash, fullpath);
|
||||||
|
|
||||||
int32_t pos = strlen(dirnoslash)-1;
|
int32_t pos = strlen(dirnoslash) - 1;
|
||||||
while(dirnoslash[pos] == '/') {
|
while (dirnoslash[pos] == '/') {
|
||||||
dirnoslash[pos] = '\0';
|
dirnoslash[pos] = '\0';
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(CheckFile(dirnoslash)) {
|
if (CheckFile(dirnoslash)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
char parentpath[strlen(dirnoslash)+2];
|
char parentpath[strlen(dirnoslash) + 2];
|
||||||
strcpy(parentpath, dirnoslash);
|
strcpy(parentpath, dirnoslash);
|
||||||
char * ptr = strrchr(parentpath, '/');
|
char *ptr = strrchr(parentpath, '/');
|
||||||
|
|
||||||
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;
|
||||||
@ -119,7 +119,7 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
|
|||||||
result = CreateSubfolder(parentpath);
|
result = CreateSubfolder(parentpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!result)
|
if (!result)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mkdir(dirnoslash, 0777) == -1) {
|
if (mkdir(dirnoslash, 0777) == -1) {
|
||||||
@ -129,13 +129,13 @@ int32_t FSUtils::CreateSubfolder(const char * fullpath) {
|
|||||||
return 1;
|
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);
|
CFile file(path, CFile::WriteOnly);
|
||||||
if (!file.isOpen()) {
|
if (!file.isOpen()) {
|
||||||
DEBUG_FUNCTION_LINE("Failed to open %s\n",path);
|
DEBUG_FUNCTION_LINE("Failed to open %s\n", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int32_t written = file.write((const uint8_t*) buffer, size);
|
int32_t written = file.write((const uint8_t *) buffer, size);
|
||||||
file.close();
|
file.close();
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@ public:
|
|||||||
static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);
|
static int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size);
|
||||||
|
|
||||||
//! 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 saveBufferToFile(const char * path, void * buffer, uint32_t size);
|
static int32_t CheckFile(const char *filepath);
|
||||||
|
|
||||||
|
static int32_t saveBufferToFile(const char *path, void *buffer, uint32_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __FS_UTILS_H_
|
#endif // __FS_UTILS_H_
|
||||||
|
252
src/main.cpp
252
src/main.cpp
@ -45,11 +45,11 @@ BOOL gHomebrewLaunched __attribute__((section(".data")));
|
|||||||
WUPS_USE_WUT_CRT()
|
WUPS_USE_WUT_CRT()
|
||||||
|
|
||||||
INITIALIZE_PLUGIN() {
|
INITIALIZE_PLUGIN() {
|
||||||
memset((void*) &template_title,0,sizeof(template_title));
|
memset((void *) &template_title, 0, sizeof(template_title));
|
||||||
memset((void*) &gLaunchXML,0,sizeof(gLaunchXML));
|
memset((void *) &gLaunchXML, 0, sizeof(gLaunchXML));
|
||||||
memset((void*) &gFileInfos,0,sizeof(gFileInfos));
|
memset((void *) &gFileInfos, 0, sizeof(gFileInfos));
|
||||||
memset((void*) &gFileReadInformation,0,sizeof(gFileReadInformation));
|
memset((void *) &gFileReadInformation, 0, sizeof(gFileReadInformation));
|
||||||
memset((void*) &gIconCache,0,sizeof(gIconCache));
|
memset((void *) &gIconCache, 0, sizeof(gIconCache));
|
||||||
gHomebrewLaunched = FALSE;
|
gHomebrewLaunched = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ ON_APPLICATION_START(args) {
|
|||||||
log_init();
|
log_init();
|
||||||
DEBUG_FUNCTION_LINE("IN PLUGIN\n");
|
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");
|
DEBUG_FUNCTION_LINE("gHomebrewLaunched to FALSE\n");
|
||||||
gHomebrewLaunched = FALSE;
|
gHomebrewLaunched = FALSE;
|
||||||
}
|
}
|
||||||
@ -70,14 +70,14 @@ ON_APPLICATION_END() {
|
|||||||
unmountAllRomfs();
|
unmountAllRomfs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf) {
|
void fillXmlForTitleID(uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *out_buf) {
|
||||||
if(titleid_lower >= FILE_INFO_SIZE) {
|
if (titleid_lower >= FILE_INFO_SIZE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
out_buf->title_id = ((uint64_t)titleid_upper * 0x100000000) + titleid_lower;
|
out_buf->title_id = ((uint64_t) titleid_upper * 0x100000000) + titleid_lower;
|
||||||
strncpy(out_buf->longname_en,gFileInfos[titleid_lower].name,511);
|
strncpy(out_buf->longname_en, gFileInfos[titleid_lower].name, 511);
|
||||||
strncpy(out_buf->shortname_en,gFileInfos[titleid_lower].name,255);
|
strncpy(out_buf->shortname_en, gFileInfos[titleid_lower].name, 255);
|
||||||
strncpy(out_buf->publisher_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 = 1;
|
||||||
out_buf->e_manual_version = 0;
|
out_buf->e_manual_version = 0;
|
||||||
out_buf->title_version = 1;
|
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->group_id = 0x400;
|
||||||
out_buf->drc_use = 1;
|
out_buf->drc_use = 1;
|
||||||
out_buf->version = 1;
|
out_buf->version = 1;
|
||||||
out_buf->reserved_flag0 = 0x00010001;
|
out_buf->reserved_flag0 = 0x00010001;
|
||||||
out_buf->reserved_flag6 = 0x00000003;
|
out_buf->reserved_flag6 = 0x00000003;
|
||||||
out_buf->pc_usk = 128;
|
out_buf->pc_usk = 128;
|
||||||
strncpy(out_buf->product_code,"WUP-P-HBLD",strlen("WUP-P-HBLD"));
|
strncpy(out_buf->product_code, "WUP-P-HBLD", strlen("WUP-P-HBLD"));
|
||||||
strncpy(out_buf->content_platform,"WUP",strlen("WUP"));
|
strncpy(out_buf->content_platform, "WUP", strlen("WUP"));
|
||||||
strncpy(out_buf->company_code,"0001",strlen("0001"));
|
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);
|
int32_t result = real_MCP_TitleList(handle, outTitleCount, titleList, size);
|
||||||
uint32_t titlecount = *outTitleCount;
|
uint32_t titlecount = *outTitleCount;
|
||||||
|
|
||||||
@ -106,47 +106,47 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount,
|
|||||||
dirList.SortList();
|
dirList.SortList();
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(int i = 0; i < dirList.GetFilecount(); i++) {
|
for (int i = 0; i < dirList.GetFilecount(); i++) {
|
||||||
if(j >= FILE_INFO_SIZE) {
|
if (j >= FILE_INFO_SIZE) {
|
||||||
DEBUG_FUNCTION_LINE("TOO MANY TITLES\n");
|
DEBUG_FUNCTION_LINE("TOO MANY TITLES\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//! skip our own application in the listing
|
//! 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;
|
continue;
|
||||||
}
|
}
|
||||||
//! skip our own application in the listing
|
//! skip our own application in the listing
|
||||||
if(strcasecmp(dirList.GetFilename(i), "temp.rpx") == 0) {
|
if (strcasecmp(dirList.GetFilename(i), "temp.rpx") == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! skip hidden linux and mac files
|
//! 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer [25];
|
char buffer[25];
|
||||||
snprintf(buffer,25,"/custom/%08X%08X", 0x0005000F, j);
|
snprintf(buffer, 25, "/custom/%08X%08X", 0x0005000F, j);
|
||||||
strcpy(template_title.path,buffer);
|
strcpy(template_title.path, buffer);
|
||||||
|
|
||||||
char * repl = (char*)"fs:/vol/external01/";
|
char *repl = (char *) "fs:/vol/external01/";
|
||||||
char * with = (char*)"";
|
char *with = (char *) "";
|
||||||
char * input = (char*) dirList.GetFilepath(i);
|
char *input = (char *) dirList.GetFilepath(i);
|
||||||
|
|
||||||
char * path = StringTools::str_replace(input,repl, with);
|
char *path = StringTools::str_replace(input, repl, with);
|
||||||
if(path != NULL) {
|
if (path != NULL) {
|
||||||
strncpy(gFileInfos[j].path,path, 255);
|
strncpy(gFileInfos[j].path, path, 255);
|
||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(gFileInfos[j].name, dirList.GetFilename(i),255);
|
strncpy(gFileInfos[j].name, dirList.GetFilename(i), 255);
|
||||||
gFileInfos[j].source = 0; //SD Card;
|
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";
|
const char *indexedDevice = "mlc";
|
||||||
strcpy(template_title.indexedDevice,indexedDevice);
|
strcpy(template_title.indexedDevice, indexedDevice);
|
||||||
if(StringTools::EndsWith(gFileInfos[j].name, ".wbf")) {
|
if (StringTools::EndsWith(gFileInfos[j].name, ".wbf")) {
|
||||||
|
|
||||||
template_title.appType = MCP_APP_TYPE_GAME;
|
template_title.appType = MCP_APP_TYPE_GAME;
|
||||||
} else {
|
} else {
|
||||||
@ -161,7 +161,7 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount,
|
|||||||
template_title.sdkVersion = __OSGetProcessSDKVersion();
|
template_title.sdkVersion = __OSGetProcessSDKVersion();
|
||||||
template_title.unk0x60 = 0;
|
template_title.unk0x60 = 0;
|
||||||
|
|
||||||
memcpy(&(titleList[titlecount]), &template_title,sizeof(template_title));
|
memcpy(&(titleList[titlecount]), &template_title, sizeof(template_title));
|
||||||
|
|
||||||
titlecount++;
|
titlecount++;
|
||||||
j++;
|
j++;
|
||||||
@ -172,13 +172,13 @@ DECL_FUNCTION(int32_t, MCP_TitleList, uint32_t handle, uint32_t* outTitleCount,
|
|||||||
return result;
|
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) {
|
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) {
|
if (gHomebrewLaunched) {
|
||||||
memcpy(title, &(template_title), sizeof(MCPTitleListType));
|
memcpy(title, &(template_title), sizeof(MCPTitleListType));
|
||||||
} else if(titleid_upper == 0x0005000F) {
|
} else if (titleid_upper == 0x0005000F) {
|
||||||
char buffer [25];
|
char buffer[25];
|
||||||
snprintf(buffer,25,"/custom/%08X%08X", titleid_upper, titleid_lower_2);
|
snprintf(buffer, 25, "/custom/%08X%08X", titleid_upper, titleid_lower_2);
|
||||||
strcpy(template_title.path,buffer);
|
strcpy(template_title.path, buffer);
|
||||||
template_title.titleId = 0x0005000F00000000 + titleid_lower_1;
|
template_title.titleId = 0x0005000F00000000 + titleid_lower_1;
|
||||||
memcpy(title, &(template_title), sizeof(MCPTitleListType));
|
memcpy(title, &(template_title), sizeof(MCPTitleListType));
|
||||||
return 0;
|
return 0;
|
||||||
@ -195,15 +195,15 @@ typedef struct __attribute((packed)) {
|
|||||||
uint32_t fileoffset;
|
uint32_t fileoffset;
|
||||||
char path[256];
|
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) {
|
DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType *title, uint32_t u2) {
|
||||||
if((title->titleId & 0x0005000F00000000) == 0x0005000F00000000 && (uint32_t)(title->titleId & 0xFFFFFFFF) < FILE_INFO_SIZE) {
|
if ((title->titleId & 0x0005000F00000000) == 0x0005000F00000000 && (uint32_t) (title->titleId & 0xFFFFFFFF) < FILE_INFO_SIZE) {
|
||||||
DEBUG_FUNCTION_LINE("Started homebrew\n");
|
DEBUG_FUNCTION_LINE("Started homebrew\n");
|
||||||
gHomebrewLaunched = TRUE;
|
gHomebrewLaunched = TRUE;
|
||||||
fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32,(title->titleId & 0xFFFFFFFF), &gLaunchXML);
|
fillXmlForTitleID((title->titleId & 0xFFFFFFFF00000000) >> 32, (title->titleId & 0xFFFFFFFF), &gLaunchXML);
|
||||||
|
|
||||||
LOAD_REQUEST request;
|
LOAD_REQUEST request;
|
||||||
memset(&request, 0, sizeof(request));
|
memset(&request, 0, sizeof(request));
|
||||||
@ -214,23 +214,22 @@ DECL_FUNCTION(int32_t, ACPCheckTitleLaunchByTitleListTypeEx, MCPTitleListType* t
|
|||||||
request.fileoffset = 0; //
|
request.fileoffset = 0; //
|
||||||
|
|
||||||
romfs_fileInfo info;
|
romfs_fileInfo info;
|
||||||
int res = getRPXInfoForID((title->titleId & 0xFFFFFFFF),&info);
|
int res = getRPXInfoForID((title->titleId & 0xFFFFFFFF), &info);
|
||||||
if(res >= 0) {
|
if (res >= 0) {
|
||||||
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];
|
||||||
loadFileIntoBuffer((title->titleId & 0xFFFFFFFF),"meta/iconTex.tga",gIconCache,sizeof(gIconCache));
|
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);
|
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));
|
||||||
|
|
||||||
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));
|
||||||
IOS_Close(mcpFd);
|
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) {
|
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 *start = "/vol/storage_mlc01/sys/title/0005000F";
|
||||||
char * icon = ".tga";
|
char *icon = ".tga";
|
||||||
char * iconTex = "iconTex.tga";
|
char *iconTex = "iconTex.tga";
|
||||||
char * sound = ".btsnd";
|
char *sound = ".btsnd";
|
||||||
|
|
||||||
if(StringTools::EndsWith(path,icon) || StringTools::EndsWith(path,sound)) {
|
if (StringTools::EndsWith(path, icon) || StringTools::EndsWith(path, sound)) {
|
||||||
if(strncmp(path,start,strlen(start)) == 0) {
|
if (strncmp(path, start, strlen(start)) == 0) {
|
||||||
int res = FS_STATUS_NOT_FOUND;
|
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
|
// fallback to dummy icon if loaded homebrew is no .wbf
|
||||||
//*handle = 0x1337;
|
//*handle = 0x1337;
|
||||||
res = FS_STATUS_NOT_FOUND;
|
res = FS_STATUS_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
char * id = path+1+strlen(start);
|
char *id = path + 1 + strlen(start);
|
||||||
id[8] = 0;
|
id[8] = 0;
|
||||||
char * ending = id+9;
|
char *ending = id + 9;
|
||||||
sscanf(id,"%08X", &val);
|
sscanf(id, "%08X", &val);
|
||||||
if(FSOpenFile_for_ID(val, ending, handle) < 0) {
|
if (FSOpenFile_for_ID(val, ending, handle) < 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return FS_STATUS_OK;
|
return FS_STATUS_OK;
|
||||||
} else if(gHomebrewLaunched) {
|
} else if (gHomebrewLaunched) {
|
||||||
socket_lib_init();
|
socket_lib_init();
|
||||||
log_init();
|
log_init();
|
||||||
if(StringTools::EndsWith(path,iconTex)) {
|
if (StringTools::EndsWith(path, iconTex)) {
|
||||||
*handle = 0x13371337;
|
*handle = 0x13371337;
|
||||||
DEBUG_FUNCTION_LINE("yooo let's do it\n");
|
DEBUG_FUNCTION_LINE("yooo let's do it\n");
|
||||||
return FS_STATUS_OK;
|
return FS_STATUS_OK;
|
||||||
}else{
|
} else {
|
||||||
DEBUG_FUNCTION_LINE("%s\n",path);
|
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) {
|
DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFileHandle handle, uint32_t flags) {
|
||||||
if(handle == 0x13371337) {
|
if (handle == 0x13371337) {
|
||||||
return FS_STATUS_OK;
|
return FS_STATUS_OK;
|
||||||
}
|
}
|
||||||
if((handle & 0xFF000000) == 0xFF000000) {
|
if ((handle & 0xFF000000) == 0xFF000000) {
|
||||||
int32_t fd = (handle & 0x00000FFF);
|
int32_t fd = (handle & 0x00000FFF);
|
||||||
int32_t romid = (handle & 0x00FFF000) >> 12;
|
int32_t romid = (handle & 0x00FFF000) >> 12;
|
||||||
DEBUG_FUNCTION_LINE("Close %d %d\n", fd, romid);
|
DEBUG_FUNCTION_LINE("Close %d %d\n", fd, romid);
|
||||||
DeInitFile(fd);
|
DeInitFile(fd);
|
||||||
if(gFileInfos[romid].openedFiles--) {
|
if (gFileInfos[romid].openedFiles--) {
|
||||||
if(gFileInfos[romid].openedFiles <= 0) {
|
if (gFileInfos[romid].openedFiles <= 0) {
|
||||||
DEBUG_FUNCTION_LINE("unmount romfs no more handles\n");
|
DEBUG_FUNCTION_LINE("unmount romfs no more handles\n");
|
||||||
unmountRomfs(romid);
|
unmountRomfs(romid);
|
||||||
}
|
}
|
||||||
@ -304,85 +303,84 @@ DECL_FUNCTION(FSStatus, FSCloseFile, FSClient *client, FSCmdBlock *block, FSFile
|
|||||||
//unmountAllRomfs();
|
//unmountAllRomfs();
|
||||||
return FS_STATUS_OK;
|
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) {
|
||||||
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;
|
if (sizeof(gIconCache) < cpySize) {
|
||||||
if(sizeof(gIconCache) < cpySize) {
|
|
||||||
cpySize = sizeof(gIconCache);
|
cpySize = sizeof(gIconCache);
|
||||||
}
|
}
|
||||||
memcpy(buffer, gIconCache, cpySize);
|
memcpy(buffer, gIconCache, cpySize);
|
||||||
DEBUG_FUNCTION_LINE("DUMMY\n");
|
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 fd = (handle & 0x00000FFF);
|
||||||
int32_t romid = (handle & 0x00FFF000) >> 12;
|
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);
|
FSStatus result = real_FSReadFile(client, block, buffer, size, count, handle, unk1, flags);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(int32_t, ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* out_buf, uint32_t device, uint32_t u1) {
|
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);
|
int result = real_ACPGetTitleMetaXmlByDevice(titleid_upper, titleid_lower, out_buf, device, u1);
|
||||||
if(titleid_upper == 0x0005000F) {
|
if (titleid_upper == 0x0005000F) {
|
||||||
fillXmlForTitleID(titleid_upper,titleid_lower, out_buf);
|
fillXmlForTitleID(titleid_upper, titleid_lower, out_buf);
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(int32_t, ACPGetTitleMetaDirByDevice, uint32_t titleid_upper, uint32_t titleid_lower, char* out_buf, uint32_t size, int device) {
|
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) {
|
if (titleid_upper == 0x0005000F) {
|
||||||
snprintf(out_buf,53,"/vol/storage_mlc01/sys/title/%08X/%08X/meta", titleid_upper, titleid_lower);
|
snprintf(out_buf, 53, "/vol/storage_mlc01/sys/title/%08X/%08X/meta", titleid_upper, titleid_lower);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int result = real_ACPGetTitleMetaDirByDevice(titleid_upper, titleid_lower, out_buf, size, device);
|
int result = real_ACPGetTitleMetaDirByDevice(titleid_upper, titleid_lower, out_buf, size, device);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char* pathToLoad, uint32_t u2) {
|
DECL_FUNCTION(int32_t, _SYSLaunchTitleByPathFromLauncher, char *pathToLoad, uint32_t u2) {
|
||||||
const char * start = "/custom/";
|
const char *start = "/custom/";
|
||||||
if(strncmp(pathToLoad,start,strlen(start)) == 0) {
|
if (strncmp(pathToLoad, start, strlen(start)) == 0) {
|
||||||
strcpy(template_title.path,pathToLoad);
|
strcpy(template_title.path, pathToLoad);
|
||||||
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
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));
|
int32_t result = real__SYSLaunchTitleByPathFromLauncher(pathToLoad, strlen(pathToLoad));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml * metaxml) {
|
DECL_FUNCTION(int32_t, ACPGetLaunchMetaXml, ACPMetaXml *metaxml) {
|
||||||
int result = real_ACPGetLaunchMetaXml(metaxml);
|
int result = real_ACPGetLaunchMetaXml(metaxml);
|
||||||
if(gHomebrewLaunched) {
|
if (gHomebrewLaunched) {
|
||||||
memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML));
|
memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(uint32_t, ACPGetApplicationBox,uint32_t * u1, uint32_t * u2, uint32_t u3, uint32_t u4) {
|
DECL_FUNCTION(uint32_t, ACPGetApplicationBox, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4) {
|
||||||
if(u3 == 0x0005000F) {
|
if (u3 == 0x0005000F) {
|
||||||
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
||||||
u3 = (uint32_t) (titleID >> 32);
|
u3 = (uint32_t) (titleID >> 32);
|
||||||
u4 = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t * param ) {
|
DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t *param) {
|
||||||
if(param[2] == 0x0005000F) {
|
if (param[2] == 0x0005000F) {
|
||||||
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
||||||
param[2] = (uint32_t) (titleID >> 32);
|
param[2] = (uint32_t) (titleID >> 32);
|
||||||
param[3] = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
param[3] = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
||||||
@ -391,18 +389,18 @@ DECL_FUNCTION(uint32_t, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, uint32_t *
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t * u1, uint32_t * u2, uint32_t u3, uint32_t u4, uint32_t u5) {
|
DECL_FUNCTION(uint32_t, MCP_RightCheckLaunchable, uint32_t *u1, uint32_t *u2, uint32_t u3, uint32_t u4, uint32_t u5) {
|
||||||
if(u3 == 0x0005000F) {
|
if (u3 == 0x0005000F) {
|
||||||
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
uint64_t titleID = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_HEALTH_AND_SAFETY);
|
||||||
u3 = (uint32_t) (titleID >> 32);
|
u3 = (uint32_t) (titleID >> 32);
|
||||||
u4 = (uint32_t) (0x00000000FFFFFFFF & titleID);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml* metaxml, uint32_t device) {
|
DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_upper, uint32_t titleid_lower, ACPMetaXml *metaxml, uint32_t device) {
|
||||||
if(gHomebrewLaunched) {
|
if (gHomebrewLaunched) {
|
||||||
memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML));
|
memcpy(metaxml, &gLaunchXML, sizeof(gLaunchXML));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -410,19 +408,19 @@ DECL_FUNCTION(int32_t, HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, uint32_t titleid_u
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44);
|
WUPS_MUST_REPLACE_PHYSICAL(HBM_NN_ACP_ACPGetTitleMetaXmlByDevice, 0x2E36CE44, 0x0E36CE44);
|
||||||
WUPS_MUST_REPLACE(ACPGetApplicationBox, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetApplicationBox );
|
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(PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg, WUPS_LOADER_LIBRARY_DRMAPP, PatchChkStart__3RplFRCQ3_2nn6drmapp8StartArg);
|
||||||
WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT, MCP_RightCheckLaunchable );
|
WUPS_MUST_REPLACE(MCP_RightCheckLaunchable, WUPS_LOADER_LIBRARY_COREINIT, MCP_RightCheckLaunchable);
|
||||||
|
|
||||||
WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile);
|
WUPS_MUST_REPLACE(FSReadFile, WUPS_LOADER_LIBRARY_COREINIT, FSReadFile);
|
||||||
WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile);
|
WUPS_MUST_REPLACE(FSOpenFile, WUPS_LOADER_LIBRARY_COREINIT, FSOpenFile);
|
||||||
WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile);
|
WUPS_MUST_REPLACE(FSCloseFile, WUPS_LOADER_LIBRARY_COREINIT, FSCloseFile);
|
||||||
WUPS_MUST_REPLACE(MCP_TitleList, WUPS_LOADER_LIBRARY_COREINIT, MCP_TitleList);
|
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(MCP_GetTitleInfoByTitleAndDevice, WUPS_LOADER_LIBRARY_COREINIT, MCP_GetTitleInfoByTitleAndDevice);
|
||||||
|
|
||||||
WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx );
|
WUPS_MUST_REPLACE(ACPCheckTitleLaunchByTitleListTypeEx, WUPS_LOADER_LIBRARY_NN_ACP, ACPCheckTitleLaunchByTitleListTypeEx);
|
||||||
WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice );
|
WUPS_MUST_REPLACE(ACPGetTitleMetaXmlByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaXmlByDevice);
|
||||||
WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml );
|
WUPS_MUST_REPLACE(ACPGetLaunchMetaXml, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetLaunchMetaXml);
|
||||||
WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice );
|
WUPS_MUST_REPLACE(ACPGetTitleMetaDirByDevice, WUPS_LOADER_LIBRARY_NN_ACP, ACPGetTitleMetaDirByDevice);
|
||||||
WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher);
|
WUPS_MUST_REPLACE(_SYSLaunchTitleByPathFromLauncher, WUPS_LOADER_LIBRARY_SYSAPP, _SYSLaunchTitleByPathFromLauncher);
|
||||||
|
@ -4,16 +4,14 @@
|
|||||||
#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"
|
||||||
|
|
||||||
fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE] __attribute__((section(".data")));
|
fileReadInformation gFileReadInformation[FILE_READ_INFO_SIZE] __attribute__((section(".data")));
|
||||||
|
|
||||||
int readFile(int slot, uint8_t * buffer, uint32_t size) {
|
int readFile(int slot, uint8_t *buffer, uint32_t size) {
|
||||||
fileReadInformation * info = &gFileReadInformation[slot];
|
fileReadInformation *info = &gFileReadInformation[slot];
|
||||||
if(!info->compressed) {
|
if (!info->compressed) {
|
||||||
//DEBUG_FUNCTION_LINE("non compressed\n");
|
//DEBUG_FUNCTION_LINE("non compressed\n");
|
||||||
return read(info->fd, buffer, size);
|
return read(info->fd, buffer, size);
|
||||||
} else {
|
} else {
|
||||||
@ -25,11 +23,11 @@ int readFile(int slot, uint8_t * buffer, uint32_t size) {
|
|||||||
do {
|
do {
|
||||||
int CHUNK = 0x1000;
|
int CHUNK = 0x1000;
|
||||||
int nextOut = CHUNK;
|
int nextOut = CHUNK;
|
||||||
if(nextOut > size) {
|
if (nextOut > size) {
|
||||||
nextOut = size;
|
nextOut = size;
|
||||||
}
|
}
|
||||||
//DEBUG_FUNCTION_LINE("nextOut = %d\n",nextOut);
|
//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);
|
//DEBUG_FUNCTION_LINE("Reading %d from compressed stream\n",CHUNK);
|
||||||
info->strm.avail_in = read(info->fd, info->in, CHUNK);
|
info->strm.avail_in = read(info->fd, info->in, CHUNK);
|
||||||
if (info->strm.avail_in == 0) {
|
if (info->strm.avail_in == 0) {
|
||||||
@ -45,7 +43,7 @@ int readFile(int slot, uint8_t * buffer, uint32_t size) {
|
|||||||
do {
|
do {
|
||||||
//DEBUG_FUNCTION_LINE("newSize %d, size %d, info->strm.avail_out %d\n", newSize, size, info->strm.avail_out);
|
//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;
|
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);
|
//DEBUG_FUNCTION_LINE("info->strm.next_out = %08X\n",info->strm.next_out);
|
||||||
ret = inflate(&info->strm, Z_NO_FLUSH);
|
ret = inflate(&info->strm, Z_NO_FLUSH);
|
||||||
//DEBUG_FUNCTION_LINE("ret = %d\n",ret);
|
//DEBUG_FUNCTION_LINE("ret = %d\n",ret);
|
||||||
if(ret == Z_STREAM_ERROR) {
|
if (ret == Z_STREAM_ERROR) {
|
||||||
DEBUG_FUNCTION_LINE("Z_STREAM_ERROR\n");
|
DEBUG_FUNCTION_LINE("Z_STREAM_ERROR\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
DEBUG_FUNCTION_LINE("Z_NEED_DICT\n");
|
DEBUG_FUNCTION_LINE("Z_NEED_DICT\n");
|
||||||
ret = Z_DATA_ERROR; /* and fall through */
|
ret = Z_DATA_ERROR; /* 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\n");
|
DEBUG_FUNCTION_LINE("Z_MEM_ERROR or Z_DATA_ERROR\n");
|
||||||
(void)inflateEnd(&info->strm);
|
(void) inflateEnd(&info->strm);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int canBeWritten = CHUNK - info->strm.avail_out;
|
int canBeWritten = CHUNK - info->strm.avail_out;
|
||||||
//DEBUG_FUNCTION_LINE("canBeWritten = %d\n",canBeWritten);
|
//DEBUG_FUNCTION_LINE("canBeWritten = %d\n",canBeWritten);
|
||||||
|
|
||||||
newSize = info->strm.total_out - startValue;
|
newSize = info->strm.total_out - startValue;
|
||||||
if(newSize == size) {
|
if (newSize == size) {
|
||||||
//DEBUG_FUNCTION_LINE("newSize was as wanted %d\n", newSize);
|
//DEBUG_FUNCTION_LINE("newSize was as wanted %d\n", newSize);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nextOut = CHUNK;
|
nextOut = CHUNK;
|
||||||
if(newSize + nextOut >= (size)) {
|
if (newSize + nextOut >= (size)) {
|
||||||
nextOut = (size) - newSize;
|
nextOut = (size) - newSize;
|
||||||
}
|
}
|
||||||
//DEBUG_FUNCTION_LINE("newSize = %d\n",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) {
|
bool DeInitFile(int slot) {
|
||||||
if(gFileReadInformation[slot].compressed && gFileReadInformation[slot].cInitDone) {
|
if (gFileReadInformation[slot].compressed && gFileReadInformation[slot].cInitDone) {
|
||||||
/* clean up and return */
|
/* clean up and return */
|
||||||
(void)inflateEnd(&(gFileReadInformation[slot].strm));
|
(void) inflateEnd(&(gFileReadInformation[slot].strm));
|
||||||
}
|
}
|
||||||
|
|
||||||
close(gFileReadInformation[slot].fd);
|
close(gFileReadInformation[slot].fd);
|
||||||
gFileReadInformation[slot].inUse = false;
|
gFileReadInformation[slot].inUse = false;
|
||||||
memset(&gFileReadInformation[slot],0, sizeof(fileReadInformation));
|
memset(&gFileReadInformation[slot], 0, sizeof(fileReadInformation));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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];
|
||||||
if(info->inUse) {
|
if (info->inUse) {
|
||||||
DeInitFile(i);
|
DeInitFile(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int fileReadInformation_getSlot() {
|
int fileReadInformation_getSlot() {
|
||||||
for(int i = 0; i<32; i++) {
|
for (int i = 0; i < 32; i++) {
|
||||||
if(gFileReadInformation[i].inUse == false) {
|
if (gFileReadInformation[i].inUse == false) {
|
||||||
gFileReadInformation[i].inUse = true;
|
gFileReadInformation[i].inUse = true;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -129,12 +126,12 @@ int fileReadInformation_getSlot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool initCompressedFileReadInformation(fileReadInformation * info) {
|
bool initCompressedFileReadInformation(fileReadInformation *info) {
|
||||||
if(info == NULL || !info->compressed) {
|
if (info == NULL || !info->compressed) {
|
||||||
info->cInitDone = false;
|
info->cInitDone = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(info->cInitDone) {
|
if (info->cInitDone) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/* allocate inflate state */
|
/* allocate inflate state */
|
||||||
@ -154,12 +151,12 @@ bool initCompressedFileReadInformation(fileReadInformation * info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t loadFileIntoBuffer(uint32_t id, char * filepath, char * buffer, int sizeToRead) {
|
int32_t loadFileIntoBuffer(uint32_t id, char *filepath, char *buffer, int sizeToRead) {
|
||||||
if(!mountRomfs(id)) {
|
if (!mountRomfs(id)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int handle = 0;
|
int handle = 0;
|
||||||
if(FSOpenFile_for_ID(id, filepath, &handle) != 0){
|
if (FSOpenFile_for_ID(id, filepath, &handle) != 0) {
|
||||||
return -2;
|
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);
|
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);
|
DEBUG_FUNCTION_LINE("Close %d %d\n", fd, romid);
|
||||||
DeInitFile(fd);
|
DeInitFile(fd);
|
||||||
if(gFileInfos[romid].openedFiles--){
|
if (gFileInfos[romid].openedFiles--) {
|
||||||
if(gFileInfos[romid].openedFiles <= 0){
|
if (gFileInfos[romid].openedFiles <= 0) {
|
||||||
DEBUG_FUNCTION_LINE("unmount romfs no more handles\n");
|
DEBUG_FUNCTION_LINE("unmount romfs no more handles\n");
|
||||||
unmountRomfs(romid);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
char romName [10];
|
char romName[10];
|
||||||
snprintf(romName,10,"%08X", id);
|
snprintf(romName, 10, "%08X", id);
|
||||||
|
|
||||||
char * test = (char *) malloc(strlen(filepath)+1);
|
char *test = (char *) malloc(strlen(filepath) + 1);
|
||||||
char last = 0;
|
char last = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(int i = 0; filepath[i] != 0; i++) {
|
for (int i = 0; filepath[i] != 0; i++) {
|
||||||
if(filepath[i] == '/' ) {
|
if (filepath[i] == '/') {
|
||||||
if(filepath[i] != last) {
|
if (filepath[i] != last) {
|
||||||
test[j++] = filepath[i];
|
test[j++] = filepath[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -207,29 +202,29 @@ int32_t FSOpenFile_for_ID(uint32_t id, const char * filepath, int * handle) {
|
|||||||
}
|
}
|
||||||
test[j++] = 0;
|
test[j++] = 0;
|
||||||
|
|
||||||
char buffer [256];
|
char buffer[256];
|
||||||
snprintf(buffer,256,"%s:/%s.gz",romName, test);
|
snprintf(buffer, 256, "%s:/%s.gz", romName, test);
|
||||||
|
|
||||||
bool nonCompressed = false;
|
bool nonCompressed = false;
|
||||||
if(!FSUtils::CheckFile(buffer)) {
|
if (!FSUtils::CheckFile(buffer)) {
|
||||||
snprintf(buffer,256,"%s:/%s",romName, test);
|
snprintf(buffer, 256, "%s:/%s", romName, test);
|
||||||
if(!FSUtils::CheckFile(buffer)) {
|
if (!FSUtils::CheckFile(buffer)) {
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
nonCompressed = true;
|
nonCompressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = open(buffer,0);
|
int fd = open(buffer, 0);
|
||||||
if(fd >= 0) {
|
if (fd >= 0) {
|
||||||
DEBUG_FUNCTION_LINE("Opened %s from %s \n",buffer, romName );
|
DEBUG_FUNCTION_LINE("Opened %s from %s \n", buffer, romName);
|
||||||
int slot = fileReadInformation_getSlot();
|
int slot = fileReadInformation_getSlot();
|
||||||
if(slot < 0) {
|
if (slot < 0) {
|
||||||
DEBUG_FUNCTION_LINE("Failed to get a slot\n");
|
DEBUG_FUNCTION_LINE("Failed to get a slot\n");
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
fileReadInformation * info = &gFileReadInformation[slot];
|
fileReadInformation *info = &gFileReadInformation[slot];
|
||||||
info->fd = fd;
|
info->fd = fd;
|
||||||
if(!nonCompressed) {
|
if (!nonCompressed) {
|
||||||
info->compressed = true;
|
info->compressed = true;
|
||||||
initCompressedFileReadInformation(info);
|
initCompressedFileReadInformation(info);
|
||||||
DEBUG_FUNCTION_LINE("Init compressed, got slot %d\n", slot);
|
DEBUG_FUNCTION_LINE("Init compressed, got slot %d\n", slot);
|
||||||
|
@ -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,25 +14,22 @@ 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);
|
||||||
|
|
||||||
bool DeInitFile(int slot);
|
bool DeInitFile(int slot);
|
||||||
|
|
||||||
void DeInitAllFiles();
|
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();
|
int fileReadInformation_getSlot();
|
||||||
|
|
||||||
|
bool initCompressedFileReadInformation(fileReadInformation *info);
|
||||||
bool initCompressedFileReadInformation(fileReadInformation * info);
|
|
@ -7,37 +7,37 @@
|
|||||||
FileInfos gFileInfos[FILE_INFO_SIZE] __attribute__((section(".data")));
|
FileInfos gFileInfos[FILE_INFO_SIZE] __attribute__((section(".data")));
|
||||||
|
|
||||||
void unmountRomfs(uint32_t id) {
|
void unmountRomfs(uint32_t id) {
|
||||||
if(id >= FILE_INFO_SIZE) {
|
if (id >= FILE_INFO_SIZE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(gFileInfos[id].romfsMounted) {
|
if (gFileInfos[id].romfsMounted) {
|
||||||
char romName [10];
|
char romName[10];
|
||||||
snprintf(romName,10,"%08X", id);
|
snprintf(romName, 10, "%08X", id);
|
||||||
DEBUG_FUNCTION_LINE("Unmounting %s\n", romName);
|
DEBUG_FUNCTION_LINE("Unmounting %s\n", romName);
|
||||||
int res = romfsUnmount(romName);
|
int res = romfsUnmount(romName);
|
||||||
DEBUG_FUNCTION_LINE("res: %d\n",res);
|
DEBUG_FUNCTION_LINE("res: %d\n", res);
|
||||||
gFileInfos[id].romfsMounted = false;
|
gFileInfos[id].romfsMounted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unmountAllRomfs() {
|
void unmountAllRomfs() {
|
||||||
for(int i = 0; i < FILE_INFO_SIZE; i++) {
|
for (int i = 0; i < FILE_INFO_SIZE; i++) {
|
||||||
unmountRomfs(i);
|
unmountRomfs(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mountRomfs(uint32_t id) {
|
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);
|
DEBUG_FUNCTION_LINE("HANDLE WAS TOO BIG %d\n", id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(!gFileInfos[id].romfsMounted) {
|
if (!gFileInfos[id].romfsMounted) {
|
||||||
char buffer [256];
|
char buffer[256];
|
||||||
snprintf(buffer,256,"fs:/vol/external01/%s", gFileInfos[id].path);
|
snprintf(buffer, 256, "fs:/vol/external01/%s", gFileInfos[id].path);
|
||||||
char romName [10];
|
char romName[10];
|
||||||
snprintf(romName,10,"%08X", id);
|
snprintf(romName, 10, "%08X", id);
|
||||||
DEBUG_FUNCTION_LINE("Mount %s as %s\n", buffer, romName);
|
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");
|
DEBUG_FUNCTION_LINE("Mounted successfully \n");
|
||||||
gFileInfos[id].romfsMounted = true;
|
gFileInfos[id].romfsMounted = true;
|
||||||
return 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;
|
return -1;
|
||||||
}
|
}
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
char romName [10];
|
char romName[10];
|
||||||
snprintf(romName,10,"%08X", id);
|
snprintf(romName, 10, "%08X", id);
|
||||||
|
|
||||||
char root[12];
|
char root[12];
|
||||||
snprintf(root,12,"%08X:/", id);
|
snprintf(root, 12, "%08X:/", id);
|
||||||
|
|
||||||
if (!(dir = opendir(root))) {
|
if (!(dir = opendir(root))) {
|
||||||
return -2;
|
return -2;
|
||||||
@ -70,8 +68,8 @@ int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info) {
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
int res = -3;
|
int res = -3;
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
if(StringTools::EndsWith(entry->d_name, ".rpx")) {
|
if (StringTools::EndsWith(entry->d_name, ".rpx")) {
|
||||||
if(romfs_GetFileInfoPerPath(romName, entry->d_name, info) >= 0) {
|
if (romfs_GetFileInfoPerPath(romName, entry->d_name, info) >= 0) {
|
||||||
found = true;
|
found = true;
|
||||||
res = 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
@ -81,7 +79,7 @@ int32_t getRPXInfoForID(uint32_t id, romfs_fileInfo * info) {
|
|||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
if(!found) {
|
if (!found) {
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -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);
|
||||||
|
@ -36,13 +36,13 @@
|
|||||||
#include <utils/StringTools.h>
|
#include <utils/StringTools.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());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * StringTools::byte_to_binary(int32_t x) {
|
const char *StringTools::byte_to_binary(int32_t x) {
|
||||||
static char b[9];
|
static char b[9];
|
||||||
b[0] = '\0';
|
b[0] = '\0';
|
||||||
|
|
||||||
@ -54,25 +54,25 @@ const char * StringTools::byte_to_binary(int32_t x) {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringTools::removeCharFromString(std::string& input,char toBeRemoved) {
|
std::string StringTools::removeCharFromString(std::string &input, char toBeRemoved) {
|
||||||
std::string output = input;
|
std::string output = input;
|
||||||
size_t position;
|
size_t position;
|
||||||
while(1) {
|
while (1) {
|
||||||
position = output.find(toBeRemoved);
|
position = output.find(toBeRemoved);
|
||||||
if(position == std::string::npos)
|
if (position == std::string::npos)
|
||||||
break;
|
break;
|
||||||
output.erase(position, 1);
|
output.erase(position, 1);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * StringTools::fmt(const char * format, ...) {
|
const char *StringTools::fmt(const char *format, ...) {
|
||||||
static char strChar[512];
|
static char strChar[512];
|
||||||
strChar[0] = 0;
|
strChar[0] = 0;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
if((vsprintf(strChar, format, va) >= 0)) {
|
if ((vsprintf(strChar, format, va) >= 0)) {
|
||||||
va_end(va);
|
va_end(va);
|
||||||
return (const char *) strChar;
|
return (const char *) strChar;
|
||||||
}
|
}
|
||||||
@ -81,26 +81,26 @@ const char * StringTools::fmt(const char * format, ...) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t * StringTools::wfmt(const char * format, ...) {
|
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;
|
||||||
|
|
||||||
if(strcmp(format, "") == 0)
|
if (strcmp(format, "") == 0)
|
||||||
return (const wchar_t *) strWChar;
|
return (const wchar_t *) strWChar;
|
||||||
|
|
||||||
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)) {
|
||||||
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;
|
||||||
return (const wchar_t *) strWChar;
|
return (const wchar_t *) strWChar;
|
||||||
}
|
}
|
||||||
@ -110,14 +110,14 @@ const wchar_t * StringTools::wfmt(const char * format, ...) {
|
|||||||
return NULL;
|
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];
|
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();
|
||||||
}
|
}
|
||||||
@ -126,14 +126,14 @@ int32_t StringTools::strprintf(std::string &str, const char * format, ...) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string StringTools::strfmt(const char * format, ...) {
|
std::string StringTools::strfmt(const char *format, ...) {
|
||||||
std::string str;
|
std::string str;
|
||||||
static char tmp[512];
|
static char tmp[512];
|
||||||
tmp[0] = 0;
|
tmp[0] = 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;
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -141,11 +141,11 @@ std::string StringTools::strfmt(const char * format, ...) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
|
BOOL StringTools::char2wchar_t(const char *strChar, wchar_t *dest) {
|
||||||
if(!strChar || !dest)
|
if (!strChar || !dest)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int bt;
|
int bt;
|
||||||
bt = mbstowcs(dest, strChar, strlen(strChar));
|
bt = mbstowcs(dest, strChar, strlen(strChar));
|
||||||
if (bt > 0) {
|
if (bt > 0) {
|
||||||
dest[bt] = 0;
|
dest[bt] = 0;
|
||||||
@ -155,39 +155,39 @@ BOOL StringTools::char2wchar_t(const char * strChar, wchar_t * dest) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringTools::strtokcmp(const char * string, const char * compare, const char * separator) {
|
int32_t StringTools::strtokcmp(const char *string, const char *compare, const char *separator) {
|
||||||
if(!string || !compare)
|
if (!string || !compare)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
char TokCopy[512];
|
char TokCopy[512];
|
||||||
strncpy(TokCopy, compare, sizeof(TokCopy));
|
strncpy(TokCopy, compare, sizeof(TokCopy));
|
||||||
TokCopy[511] = '\0';
|
TokCopy[511] = '\0';
|
||||||
|
|
||||||
char * strTok = strtok(TokCopy, separator);
|
char *strTok = strtok(TokCopy, separator);
|
||||||
|
|
||||||
while (strTok != NULL) {
|
while (strTok != NULL) {
|
||||||
if (strcasecmp(string, strTok) == 0) {
|
if (strcasecmp(string, strTok) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
strTok = strtok(NULL,separator);
|
strTok = strtok(NULL, separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringTools::strextcmp(const char * string, const char * extension, char seperator) {
|
int32_t StringTools::strextcmp(const char *string, const char *extension, char seperator) {
|
||||||
if(!string || !extension)
|
if (!string || !extension)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
char *ptr = strrchr(string, seperator);
|
char *ptr = strrchr(string, seperator);
|
||||||
if(!ptr)
|
if (!ptr)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return strcasecmp(ptr + 1, extension);
|
return strcasecmp(ptr + 1, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> StringTools::stringSplit(const std::string & inValue, const std::string & splitter) {
|
std::vector<std::string> StringTools::stringSplit(const std::string &inValue, const std::string &splitter) {
|
||||||
std::string value = inValue;
|
std::string value = inValue;
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -202,7 +202,7 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
|
|||||||
result.push_back("");
|
result.push_back("");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(index + splitter.size() > value.length()) {
|
if (index + splitter.size() > value.length()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
value = value.substr(index + splitter.size(), value.length());
|
value = value.substr(index + splitter.size(), value.length());
|
||||||
@ -211,39 +211,39 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * StringTools::FullpathToFilename(const char *path) {
|
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') {
|
||||||
if(ptr[0] == '/' && ptr[1] != '\0')
|
if (ptr[0] == '/' && ptr[1] != '\0')
|
||||||
Filename = ptr+1;
|
Filename = ptr + 1;
|
||||||
|
|
||||||
++ptr;
|
++ptr;
|
||||||
}
|
|
||||||
|
|
||||||
return Filename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Filename;
|
||||||
|
}
|
||||||
|
|
||||||
void StringTools::RemoveDoubleSlashs(std::string &str) {
|
void StringTools::RemoveDoubleSlashs(std::string &str) {
|
||||||
uint32_t length = str.size();
|
uint32_t length = str.size();
|
||||||
|
|
||||||
//! clear path of double slashes
|
//! clear path of double slashes
|
||||||
for(uint32_t i = 1; i < length; ++i) {
|
for (uint32_t i = 1; i < length; ++i) {
|
||||||
if(str[i-1] == '/' && str[i] == '/') {
|
if (str[i - 1] == '/' && str[i] == '/') {
|
||||||
str.erase(i, 1);
|
str.erase(i, 1);
|
||||||
i--;
|
i--;
|
||||||
length--;
|
length--;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
@ -268,7 +268,7 @@ char * StringTools::str_replace(char *orig, char *rep, char *with) {
|
|||||||
ins = tmp + len_rep;
|
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)
|
if (!result)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -32,20 +32,33 @@
|
|||||||
|
|
||||||
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 std::string removeCharFromString(std::string& input,char toBeRemoved);
|
static const char *byte_to_binary(int32_t x);
|
||||||
static const char * fmt(const char * format, ...);
|
|
||||||
static const wchar_t * wfmt(const char * format, ...);
|
static std::string removeCharFromString(std::string &input, char toBeRemoved);
|
||||||
static int32_t strprintf(std::string &str, const char * format, ...);
|
|
||||||
static std::string strfmt(const char * format, ...);
|
static const char *fmt(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 const wchar_t *wfmt(const char *format, ...);
|
||||||
static int32_t strextcmp(const char * string, const char * extension, char seperator);
|
|
||||||
|
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 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __STRING_TOOLS_H */
|
#endif /* __STRING_TOOLS_H */
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <coreinit/systeminfo.h>
|
#include <coreinit/systeminfo.h>
|
||||||
#include <coreinit/thread.h>
|
#include <coreinit/thread.h>
|
||||||
|
|
||||||
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 struct sockaddr_in connect_addr __attribute__((section(".data")));
|
||||||
static volatile int log_lock __attribute__((section(".data"))) = 0;
|
static volatile int log_lock __attribute__((section(".data"))) = 0;
|
||||||
|
|
||||||
@ -30,11 +30,11 @@ void log_init_() {
|
|||||||
|
|
||||||
void log_print_(const char *str) {
|
void log_print_(const char *str) {
|
||||||
// socket is always 0 initially as it is in the BSS
|
// socket is always 0 initially as it is in the BSS
|
||||||
if(log_socket < 0) {
|
if (log_socket < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(log_lock)
|
while (log_lock)
|
||||||
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
OSSleepTicks(OSMicrosecondsToTicks(1000));
|
||||||
log_lock = 1;
|
log_lock = 1;
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ void log_print_(const char *str) {
|
|||||||
int ret;
|
int ret;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
|
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));
|
ret = sendto(log_socket, str, block, 0, (struct sockaddr *) &connect_addr, sizeof(struct sockaddr_in));
|
||||||
if(ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
len -= ret;
|
len -= ret;
|
||||||
@ -58,14 +58,14 @@ void OSFatal_printf(const char *format, ...) {
|
|||||||
tmp[0] = 0;
|
tmp[0] = 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)) {
|
||||||
OSFatal(tmp);
|
OSFatal(tmp);
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_printf_(const char *format, ...) {
|
void log_printf_(const char *format, ...) {
|
||||||
if(log_socket < 0) {
|
if (log_socket < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ void log_printf_(const char *format, ...) {
|
|||||||
|
|
||||||
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)) {
|
||||||
log_print_(tmp);
|
log_print_(tmp);
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
@ -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)
|
||||||
|
@ -7,31 +7,31 @@
|
|||||||
#include <utils/logger.h>
|
#include <utils/logger.h>
|
||||||
|
|
||||||
// https://gist.github.com/ccbrown/9722406
|
// 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];
|
char ascii[17];
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
ascii[16] = '\0';
|
ascii[16] = '\0';
|
||||||
DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data);
|
DEBUG_FUNCTION_LINE("0x%08X (0x0000): ", data);
|
||||||
for (i = 0; i < size; ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
log_printf("%02X ", ((unsigned char*)data)[i]);
|
log_printf("%02X ", ((unsigned char *) data)[i]);
|
||||||
if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') {
|
if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') {
|
||||||
ascii[i % 16] = ((unsigned char*)data)[i];
|
ascii[i % 16] = ((unsigned char *) data)[i];
|
||||||
} else {
|
} else {
|
||||||
ascii[i % 16] = '.';
|
ascii[i % 16] = '.';
|
||||||
}
|
}
|
||||||
if ((i+1) % 8 == 0 || i+1 == size) {
|
if ((i + 1) % 8 == 0 || i + 1 == size) {
|
||||||
log_printf(" ");
|
log_printf(" ");
|
||||||
if ((i+1) % 16 == 0) {
|
if ((i + 1) % 16 == 0) {
|
||||||
log_printf("| %s \n", ascii);
|
log_printf("| %s \n", ascii);
|
||||||
if(i + 1 < size) {
|
if (i + 1 < size) {
|
||||||
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1,i+1);
|
DEBUG_FUNCTION_LINE("0x%08X (0x%04X); ", data + i + 1, i + 1);
|
||||||
}
|
}
|
||||||
} else if (i+1 == size) {
|
} else if (i + 1 == size) {
|
||||||
ascii[(i+1) % 16] = '\0';
|
ascii[(i + 1) % 16] = '\0';
|
||||||
if ((i+1) % 16 <= 8) {
|
if ((i + 1) % 16 <= 8) {
|
||||||
log_printf(" ");
|
log_printf(" ");
|
||||||
}
|
}
|
||||||
for (j = (i+1) % 16; j < 16; ++j) {
|
for (j = (i + 1) % 16; j < 16; ++j) {
|
||||||
log_printf(" ");
|
log_printf(" ");
|
||||||
}
|
}
|
||||||
log_printf("| %s \n", ascii);
|
log_printf("| %s \n", ascii);
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
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 )
|
||||||
@ -26,7 +26,7 @@ extern "C" {
|
|||||||
#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);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user