mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-22 10:39:16 +01:00
Formatting
This commit is contained in:
parent
0d33e1a9b6
commit
80586bb5de
@ -11,12 +11,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);
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ 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;
|
||||||
@ -33,20 +33,20 @@ int32_t CFile::open(const std::string & filepath, eOpenTypes mode) {
|
|||||||
// 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()) return false;
|
if (folder.empty()) return false;
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
Filter = filter;
|
Filter = filter;
|
||||||
@ -65,11 +65,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 += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,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;
|
||||||
@ -91,13 +91,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;
|
||||||
@ -108,18 +108,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);
|
||||||
@ -130,16 +130,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;
|
||||||
}
|
}
|
||||||
@ -149,8 +149,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;
|
||||||
}
|
}
|
||||||
@ -160,33 +160,33 @@ 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)) return true;
|
if (f1.isDir && !(f2.isDir)) return true;
|
||||||
if(!(f1.isDir) && f2.isDir) return false;
|
if (!(f1.isDir) && f2.isDir) return false;
|
||||||
|
|
||||||
if(f1.FilePath && !f2.FilePath) return true;
|
if (f1.FilePath && !f2.FilePath) return true;
|
||||||
if(!f1.FilePath) return false;
|
if (!f1.FilePath) 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,14 +194,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,42 +40,54 @@ 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 {
|
||||||
if (!valid(index)) return "";
|
if (!valid(index)) return "";
|
||||||
else return FileInfo[index].FilePath;
|
else 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)) return false;
|
if (!valid(index)) 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,
|
||||||
@ -85,10 +97,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL FSUtils::saveBufferToFile(const char * path, void * buffer, uint32_t size) {
|
BOOL 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 false;
|
return false;
|
||||||
}
|
}
|
||||||
file.write((const uint8_t*) buffer,size);
|
file.write((const uint8_t *) buffer, size);
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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 BOOL saveBufferToFile(const char * path, void * buffer, uint32_t size);
|
static int32_t CheckFile(const char *filepath);
|
||||||
|
|
||||||
|
static BOOL saveBufferToFile(const char *path, void *buffer, uint32_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __FS_UTILS_H_
|
#endif // __FS_UTILS_H_
|
||||||
|
11
src/main.cpp
11
src/main.cpp
@ -10,8 +10,7 @@ WUPS_PLUGIN_LICENSE("GPL");
|
|||||||
|
|
||||||
WUPS_USE_WUT_CRT()
|
WUPS_USE_WUT_CRT()
|
||||||
|
|
||||||
TcpReceiver * thread = NULL;
|
TcpReceiver *thread = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Entry point */
|
/* Entry point */
|
||||||
ON_APPLICATION_START(args) {
|
ON_APPLICATION_START(args) {
|
||||||
@ -19,18 +18,18 @@ ON_APPLICATION_START(args) {
|
|||||||
|
|
||||||
log_init();
|
log_init();
|
||||||
DEBUG_FUNCTION_LINE("Started wiiload thread\n");
|
DEBUG_FUNCTION_LINE("Started wiiload thread\n");
|
||||||
thread = new TcpReceiver(4299);
|
thread = new TcpReceiver(4299);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopThread(){
|
void stopThread() {
|
||||||
if(thread != NULL){
|
if (thread != NULL) {
|
||||||
delete thread;
|
delete thread;
|
||||||
thread = NULL;
|
thread = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ON_APPLICATION_END(){
|
ON_APPLICATION_END() {
|
||||||
DEBUG_FUNCTION_LINE("Kill thread\n");
|
DEBUG_FUNCTION_LINE("Kill thread\n");
|
||||||
stopThread();
|
stopThread();
|
||||||
|
|
||||||
|
@ -25,23 +25,20 @@
|
|||||||
|
|
||||||
class CThread {
|
class CThread {
|
||||||
public:
|
public:
|
||||||
typedef void (* Callback)(CThread *thread, void *arg);
|
typedef void (*Callback)(CThread *thread, void *arg);
|
||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||||
: pThread(NULL)
|
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
|
||||||
, pThreadStack(NULL)
|
|
||||||
, pCallback(callback)
|
|
||||||
, pCallbackArg(callbackArg) {
|
|
||||||
//! save attribute assignment
|
//! save attribute assignment
|
||||||
iAttributes = iAttr;
|
iAttributes = iAttr;
|
||||||
//! allocate the thread
|
//! allocate the thread
|
||||||
pThread = (OSThread*)memalign(8, sizeof(OSThread));
|
pThread = (OSThread *) memalign(8, sizeof(OSThread));
|
||||||
//! allocate the stack
|
//! allocate the stack
|
||||||
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
|
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
|
||||||
//! create the thread
|
//! create the thread
|
||||||
if(pThread && pThreadStack)
|
if (pThread && pThreadStack)
|
||||||
OSCreateThread(pThread, &CThread::threadCallback, 1, (char*)this, pThreadStack+iStackSize, iStackSize, iPriority, iAttributes);
|
OSCreateThread(pThread, &CThread::threadCallback, 1, (char *) this, pThreadStack + iStackSize, iStackSize, iPriority, iAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! destructor
|
//! destructor
|
||||||
@ -51,64 +48,73 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
|
static CThread *create(CThread::Callback callback, void *callbackArg, int32_t iAttr = eAttributeNone, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
|
||||||
return ( new CThread(iAttr, iPriority, iStackSize, callback, callbackArg) );
|
return (new CThread(iAttr, iPriority, iStackSize, callback, callbackArg));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Get thread ID
|
//! Get thread ID
|
||||||
virtual void* getThread() const {
|
virtual void *getThread() const {
|
||||||
return pThread;
|
return pThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Thread entry function
|
//! Thread entry function
|
||||||
virtual void executeThread(void) {
|
virtual void executeThread(void) {
|
||||||
if(pCallback)
|
if (pCallback)
|
||||||
pCallback(this, pCallbackArg);
|
pCallback(this, pCallbackArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Suspend thread
|
//! Suspend thread
|
||||||
virtual void suspendThread(void) {
|
virtual void suspendThread(void) {
|
||||||
if(isThreadSuspended()) return;
|
if (isThreadSuspended()) return;
|
||||||
if(pThread) OSSuspendThread(pThread);
|
if (pThread) OSSuspendThread(pThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Resume thread
|
//! Resume thread
|
||||||
virtual void resumeThread(void) {
|
virtual void resumeThread(void) {
|
||||||
if(!isThreadSuspended()) return;
|
if (!isThreadSuspended()) return;
|
||||||
if(pThread) OSResumeThread(pThread);
|
if (pThread) OSResumeThread(pThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Set thread priority
|
//! Set thread priority
|
||||||
virtual void setThreadPriority(int prio) {
|
virtual void setThreadPriority(int prio) {
|
||||||
if(pThread) OSSetThreadPriority(pThread, prio);
|
if (pThread) OSSetThreadPriority(pThread, prio);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Check if thread is suspended
|
//! Check if thread is suspended
|
||||||
virtual BOOL isThreadSuspended(void) const {
|
virtual BOOL isThreadSuspended(void) const {
|
||||||
if(pThread) return OSIsThreadSuspended(pThread);
|
if (pThread) return OSIsThreadSuspended(pThread);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Check if thread is terminated
|
//! Check if thread is terminated
|
||||||
virtual BOOL isThreadTerminated(void) const {
|
virtual BOOL isThreadTerminated(void) const {
|
||||||
if(pThread) return OSIsThreadTerminated(pThread);
|
if (pThread) return OSIsThreadTerminated(pThread);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Check if thread is running
|
//! Check if thread is running
|
||||||
virtual BOOL isThreadRunning(void) const {
|
virtual BOOL isThreadRunning(void) const {
|
||||||
return !isThreadSuspended() && !isThreadRunning();
|
return !isThreadSuspended() && !isThreadRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Shutdown thread
|
//! Shutdown thread
|
||||||
virtual void shutdownThread(void) {
|
virtual void shutdownThread(void) {
|
||||||
//! wait for thread to finish
|
//! wait for thread to finish
|
||||||
if(pThread && !(iAttributes & eAttributeDetach)) {
|
if (pThread && !(iAttributes & eAttributeDetach)) {
|
||||||
if(isThreadSuspended())
|
if (isThreadSuspended())
|
||||||
resumeThread();
|
resumeThread();
|
||||||
|
|
||||||
OSJoinThread(pThread, NULL);
|
OSJoinThread(pThread, NULL);
|
||||||
}
|
}
|
||||||
//! free the thread stack buffer
|
//! free the thread stack buffer
|
||||||
if(pThreadStack)
|
if (pThreadStack)
|
||||||
free(pThreadStack);
|
free(pThreadStack);
|
||||||
if(pThread)
|
if (pThread)
|
||||||
free(pThread);
|
free(pThread);
|
||||||
|
|
||||||
pThread = NULL;
|
pThread = NULL;
|
||||||
pThreadStack = NULL;
|
pThreadStack = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Thread attributes
|
//! Thread attributes
|
||||||
enum eCThreadAttributes {
|
enum eCThreadAttributes {
|
||||||
eAttributeNone = 0x07,
|
eAttributeNone = 0x07,
|
||||||
@ -124,6 +130,7 @@ private:
|
|||||||
((CThread *) argv)->executeThread();
|
((CThread *) argv)->executeThread();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int iAttributes;
|
int iAttributes;
|
||||||
OSThread *pThread;
|
OSThread *pThread;
|
||||||
uint8_t *pThreadStack;
|
uint8_t *pThreadStack;
|
||||||
|
@ -36,12 +36,12 @@
|
|||||||
#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()) return false;
|
if (b.size() > a.size()) 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';
|
||||||
|
|
||||||
@ -53,25 +53,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;
|
||||||
}
|
}
|
||||||
@ -80,26 +80,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;
|
||||||
}
|
}
|
||||||
@ -109,14 +109,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();
|
||||||
}
|
}
|
||||||
@ -125,14 +125,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);
|
||||||
@ -140,11 +140,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;
|
||||||
@ -154,39 +154,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) {
|
||||||
@ -201,7 +201,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());
|
||||||
|
@ -30,52 +30,58 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <wut_types.h>
|
#include <wut_types.h>
|
||||||
|
|
||||||
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 * fmt(const char * format, ...);
|
|
||||||
static const wchar_t * wfmt(const char * format, ...);
|
|
||||||
static int32_t strprintf(std::string &str, const char * format, ...);
|
|
||||||
static std::string strfmt(const char * format, ...);
|
|
||||||
static BOOL char2wchar_t(const char * src, wchar_t * dest);
|
|
||||||
static int32_t strtokcmp(const char * string, const char * compare, const char * separator);
|
|
||||||
static int32_t strextcmp(const char * string, const char * extension, char seperator);
|
|
||||||
|
|
||||||
static const char * FullpathToFilename(const char *path){
|
static const char *byte_to_binary(int32_t x);
|
||||||
if(!path) return path;
|
|
||||||
|
|
||||||
const char * ptr = path;
|
static std::string removeCharFromString(std::string &input, char toBeRemoved);
|
||||||
const char * Filename = ptr;
|
|
||||||
|
|
||||||
while(*ptr != '\0')
|
static const char *fmt(const char *format, ...);
|
||||||
{
|
|
||||||
if(ptr[0] == '/' && ptr[1] != '\0')
|
|
||||||
Filename = ptr+1;
|
|
||||||
|
|
||||||
++ptr;
|
static const wchar_t *wfmt(const char *format, ...);
|
||||||
}
|
|
||||||
|
|
||||||
return Filename;
|
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 const char *FullpathToFilename(const char *path) {
|
||||||
|
if (!path) return path;
|
||||||
|
|
||||||
|
const char *ptr = path;
|
||||||
|
const char *Filename = ptr;
|
||||||
|
|
||||||
|
while (*ptr != '\0') {
|
||||||
|
if (ptr[0] == '/' && ptr[1] != '\0')
|
||||||
|
Filename = ptr + 1;
|
||||||
|
|
||||||
|
++ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RemoveDoubleSlashs(std::string &str){
|
return Filename;
|
||||||
uint32_t length = str.size();
|
}
|
||||||
|
|
||||||
//! clear path of double slashes
|
static void RemoveDoubleSlashs(std::string &str) {
|
||||||
for(uint32_t i = 1; i < length; ++i)
|
uint32_t length = str.size();
|
||||||
{
|
|
||||||
if(str[i-1] == '/' && str[i] == '/')
|
//! clear path of double slashes
|
||||||
{
|
for (uint32_t i = 1; i < length; ++i) {
|
||||||
str.erase(i, 1);
|
if (str[i - 1] == '/' && str[i] == '/') {
|
||||||
i--;
|
str.erase(i, 1);
|
||||||
length--;
|
i--;
|
||||||
}
|
length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 */
|
||||||
|
@ -19,15 +19,13 @@
|
|||||||
#define RPX_TEMP_FILE "fs:/vol/external01/wiiu/apps/temp.rpx"
|
#define RPX_TEMP_FILE "fs:/vol/external01/wiiu/apps/temp.rpx"
|
||||||
#define RPX_TEMP_FILE_EX "wiiu/apps/temp.rpx"
|
#define RPX_TEMP_FILE_EX "wiiu/apps/temp.rpx"
|
||||||
|
|
||||||
extern "C"{
|
extern "C" {
|
||||||
uint64_t _SYSGetSystemApplicationTitleId(int32_t);
|
uint64_t _SYSGetSystemApplicationTitleId(int32_t);
|
||||||
void _SYSLaunchTitleWithStdArgsInNoSplash(uint64_t, uint32_t);
|
void _SYSLaunchTitleWithStdArgsInNoSplash(uint64_t, uint32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
TcpReceiver::TcpReceiver(int32_t port)
|
TcpReceiver::TcpReceiver(int32_t port)
|
||||||
: CThread(CThread::eAttributeAffCore0)
|
: CThread(CThread::eAttributeAffCore0), exitRequested(false), serverPort(port), serverSocket(-1) {
|
||||||
, exitRequested(false)
|
|
||||||
, serverPort(port)
|
|
||||||
, serverSocket(-1) {
|
|
||||||
|
|
||||||
resumeThread();
|
resumeThread();
|
||||||
}
|
}
|
||||||
@ -35,7 +33,7 @@ TcpReceiver::TcpReceiver(int32_t port)
|
|||||||
TcpReceiver::~TcpReceiver() {
|
TcpReceiver::~TcpReceiver() {
|
||||||
exitRequested = true;
|
exitRequested = true;
|
||||||
|
|
||||||
if(serverSocket >= 0) {
|
if (serverSocket >= 0) {
|
||||||
shutdown(serverSocket, SHUT_RDWR);
|
shutdown(serverSocket, SHUT_RDWR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,7 +60,7 @@ void TcpReceiver::executeThread() {
|
|||||||
|
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
if ((ret = bind(serverSocket, (struct sockaddr *)&bindAddress, 16)) < 0) {
|
if ((ret = bind(serverSocket, (struct sockaddr *) &bindAddress, 16)) < 0) {
|
||||||
socketclose(serverSocket);
|
socketclose(serverSocket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -80,12 +78,12 @@ void TcpReceiver::executeThread() {
|
|||||||
memset(&clientAddr, 0, sizeof(clientAddr));
|
memset(&clientAddr, 0, sizeof(clientAddr));
|
||||||
int32_t addrlen = sizeof(struct sockaddr);
|
int32_t addrlen = sizeof(struct sockaddr);
|
||||||
|
|
||||||
while(!exitRequested) {
|
while (!exitRequested) {
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("\n");
|
DEBUG_FUNCTION_LINE("\n");
|
||||||
len = 16;
|
len = 16;
|
||||||
int32_t clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &len);
|
int32_t clientSocket = accept(serverSocket, (struct sockaddr *) &clientAddr, &len);
|
||||||
if(clientSocket >= 0) {
|
if (clientSocket >= 0) {
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE("\n");
|
DEBUG_FUNCTION_LINE("\n");
|
||||||
uint32_t ipAddress = clientAddr.sin_addr.s_addr;
|
uint32_t ipAddress = clientAddr.sin_addr.s_addr;
|
||||||
@ -94,10 +92,10 @@ void TcpReceiver::executeThread() {
|
|||||||
//serverReceiveFinished(this, ipAddress, result);
|
//serverReceiveFinished(this, ipAddress, result);
|
||||||
socketclose(clientSocket);
|
socketclose(clientSocket);
|
||||||
|
|
||||||
if(result > 0)
|
if (result > 0)
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
DEBUG_FUNCTION_LINE("Server socket accept failed %i %d\n", clientSocket,wiiu_geterrno());
|
DEBUG_FUNCTION_LINE("Server socket accept failed %i %d\n", clientSocket, wiiu_geterrno());
|
||||||
OSSleepTicks(OSMicrosecondsToTicks(100000));
|
OSSleepTicks(OSMicrosecondsToTicks(100000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +109,7 @@ typedef struct __attribute((packed)) {
|
|||||||
uint32_t filesize;
|
uint32_t filesize;
|
||||||
uint32_t fileoffset;
|
uint32_t fileoffset;
|
||||||
char path[256];
|
char path[256];
|
||||||
}LOAD_REQUEST;
|
} LOAD_REQUEST;
|
||||||
|
|
||||||
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||||
DEBUG_FUNCTION_LINE("Loading file from ip %08X\n", ipAddress);
|
DEBUG_FUNCTION_LINE("Loading file from ip %08X\n", ipAddress);
|
||||||
@ -122,10 +120,10 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
memset(haxx, 0, sizeof(haxx));
|
memset(haxx, 0, sizeof(haxx));
|
||||||
//skip haxx
|
//skip haxx
|
||||||
recvwait(clientSocket, haxx, sizeof(haxx));
|
recvwait(clientSocket, haxx, sizeof(haxx));
|
||||||
recvwait(clientSocket, (unsigned char*)&fileSize, sizeof(fileSize));
|
recvwait(clientSocket, (unsigned char *) &fileSize, sizeof(fileSize));
|
||||||
|
|
||||||
if (haxx[4] > 0 || haxx[5] > 4) {
|
if (haxx[4] > 0 || haxx[5] > 4) {
|
||||||
recvwait(clientSocket, (unsigned char*)&fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
|
recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
@ -134,21 +132,21 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
|
|
||||||
DEBUG_FUNCTION_LINE("transfer start\n");
|
DEBUG_FUNCTION_LINE("transfer start\n");
|
||||||
|
|
||||||
unsigned char* loadAddress = (unsigned char*)memalign(0x40, fileSize);
|
unsigned char *loadAddress = (unsigned char *) memalign(0x40, fileSize);
|
||||||
if(!loadAddress) {
|
if (!loadAddress) {
|
||||||
OSSleepTicks(OSSecondsToTicks(1));
|
OSSleepTicks(OSSecondsToTicks(1));
|
||||||
return NOT_ENOUGH_MEMORY;
|
return NOT_ENOUGH_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy rpl in memory
|
// Copy rpl in memory
|
||||||
while(bytesRead < fileSize) {
|
while (bytesRead < fileSize) {
|
||||||
|
|
||||||
uint32_t blockSize = 0x1000;
|
uint32_t blockSize = 0x1000;
|
||||||
if(blockSize > (fileSize - bytesRead))
|
if (blockSize > (fileSize - bytesRead))
|
||||||
blockSize = fileSize - bytesRead;
|
blockSize = fileSize - bytesRead;
|
||||||
|
|
||||||
int32_t ret = recv(clientSocket, loadAddress + bytesRead, blockSize, 0);
|
int32_t ret = recv(clientSocket, loadAddress + bytesRead, blockSize, 0);
|
||||||
if(ret <= 0) {
|
if (ret <= 0) {
|
||||||
DEBUG_FUNCTION_LINE("Failure on reading file\n");
|
DEBUG_FUNCTION_LINE("Failure on reading file\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -156,7 +154,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
bytesRead += ret;
|
bytesRead += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bytesRead != fileSize) {
|
if (bytesRead != fileSize) {
|
||||||
free(loadAddress);
|
free(loadAddress);
|
||||||
DEBUG_FUNCTION_LINE("File loading not finished, %i of %i bytes received\n", bytesRead, fileSize);
|
DEBUG_FUNCTION_LINE("File loading not finished, %i of %i bytes received\n", bytesRead, fileSize);
|
||||||
return FILE_READ_ERROR;
|
return FILE_READ_ERROR;
|
||||||
@ -167,7 +165,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
|
|
||||||
// Do we need to unzip this thing?
|
// Do we need to unzip this thing?
|
||||||
if (haxx[4] > 0 || haxx[5] > 4) {
|
if (haxx[4] > 0 || haxx[5] > 4) {
|
||||||
unsigned char* inflatedData = NULL;
|
unsigned char *inflatedData = NULL;
|
||||||
|
|
||||||
// We need to unzip...
|
// We need to unzip...
|
||||||
if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) {
|
if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) {
|
||||||
@ -175,8 +173,8 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
//! mhmm this is incorrect, it has to parse the zip
|
//! mhmm this is incorrect, it has to parse the zip
|
||||||
|
|
||||||
// Section is compressed, inflate
|
// Section is compressed, inflate
|
||||||
inflatedData = (unsigned char*)malloc(fileSizeUnc);
|
inflatedData = (unsigned char *) malloc(fileSizeUnc);
|
||||||
if(!inflatedData) {
|
if (!inflatedData) {
|
||||||
free(loadAddress);
|
free(loadAddress);
|
||||||
|
|
||||||
return NOT_ENOUGH_MEMORY;
|
return NOT_ENOUGH_MEMORY;
|
||||||
@ -199,10 +197,10 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.avail_in = fileSize;
|
s.avail_in = fileSize;
|
||||||
s.next_in = (Bytef *)(&loadAddress[0]);
|
s.next_in = (Bytef *) (&loadAddress[0]);
|
||||||
|
|
||||||
s.avail_out = fileSizeUnc;
|
s.avail_out = fileSizeUnc;
|
||||||
s.next_out = (Bytef *)&inflatedData[0];
|
s.next_out = (Bytef *) &inflatedData[0];
|
||||||
|
|
||||||
ret = inflate(&s, Z_FINISH);
|
ret = inflate(&s, Z_FINISH);
|
||||||
if (ret != Z_OK && ret != Z_STREAM_END) {
|
if (ret != Z_OK && ret != Z_STREAM_END) {
|
||||||
@ -216,16 +214,16 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
fileSize = fileSizeUnc;
|
fileSize = fileSizeUnc;
|
||||||
} else {
|
} else {
|
||||||
// Section is compressed, inflate
|
// Section is compressed, inflate
|
||||||
inflatedData = (unsigned char*)malloc(fileSizeUnc);
|
inflatedData = (unsigned char *) malloc(fileSizeUnc);
|
||||||
if(!inflatedData) {
|
if (!inflatedData) {
|
||||||
free(loadAddress);
|
free(loadAddress);
|
||||||
|
|
||||||
return NOT_ENOUGH_MEMORY;
|
return NOT_ENOUGH_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
uLongf f = fileSizeUnc;
|
uLongf f = fileSizeUnc;
|
||||||
int32_t result = uncompress((Bytef*)&inflatedData[0], &f, (Bytef*)loadAddress, fileSize);
|
int32_t result = uncompress((Bytef *) &inflatedData[0], &f, (Bytef *) loadAddress, fileSize);
|
||||||
if(result != Z_OK) {
|
if (result != Z_OK) {
|
||||||
DEBUG_FUNCTION_LINE("uncompress failed %i\n", result);
|
DEBUG_FUNCTION_LINE("uncompress failed %i\n", result);
|
||||||
|
|
||||||
return FILE_READ_ERROR;
|
return FILE_READ_ERROR;
|
||||||
@ -235,16 +233,16 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
fileSize = fileSizeUnc;
|
fileSize = fileSizeUnc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] != 0xDE && inflatedData[0xA] != 0xAD){
|
if (inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] != 0xDE && inflatedData[0xA] != 0xAD) {
|
||||||
DEBUG_FUNCTION_LINE("Try to load a rpx\n");
|
DEBUG_FUNCTION_LINE("Try to load a rpx\n");
|
||||||
FSUtils::CreateSubfolder(RPX_TEMP_PATH);
|
FSUtils::CreateSubfolder(RPX_TEMP_PATH);
|
||||||
res = FSUtils::saveBufferToFile(RPX_TEMP_FILE,inflatedData, fileSize);
|
res = FSUtils::saveBufferToFile(RPX_TEMP_FILE, inflatedData, fileSize);
|
||||||
free(inflatedData);
|
free(inflatedData);
|
||||||
loadedRPX = true;
|
loadedRPX = true;
|
||||||
}else if(inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] == 0xDE && inflatedData[0xA] == 0xAD){
|
} else if (inflatedData[0x7] == 0xCA && inflatedData[0x8] == 0xFE && inflatedData[0x9] == 0xDE && inflatedData[0xA] == 0xAD) {
|
||||||
|
|
||||||
auto newContainer = PluginUtils::getPluginForBuffer((char*)inflatedData, fileSize);
|
auto newContainer = PluginUtils::getPluginForBuffer((char *) inflatedData, fileSize);
|
||||||
if(newContainer){
|
if (newContainer) {
|
||||||
auto oldPlugins = PluginUtils::getLoadedPlugins(8);
|
auto oldPlugins = PluginUtils::getLoadedPlugins(8);
|
||||||
std::vector<PluginContainer> finalList;
|
std::vector<PluginContainer> finalList;
|
||||||
|
|
||||||
@ -256,7 +254,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
DEBUG_FUNCTION_LINE("Skipping duplicate");
|
DEBUG_FUNCTION_LINE("Skipping duplicate");
|
||||||
PluginUtils::destroyPluginContainer(plugin);
|
PluginUtils::destroyPluginContainer(plugin);
|
||||||
continue;
|
continue;
|
||||||
}else{
|
} else {
|
||||||
finalList.push_back(plugin);
|
finalList.push_back(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,39 +269,39 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) {
|
if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) {
|
||||||
DEBUG_FUNCTION_LINE("Failed to load& link\n");
|
DEBUG_FUNCTION_LINE("Failed to load& link\n");
|
||||||
PluginUtils::destroyPluginContainer(finalList);
|
PluginUtils::destroyPluginContainer(finalList);
|
||||||
}else{
|
} else {
|
||||||
PluginUtils::destroyPluginContainer(finalList);
|
PluginUtils::destroyPluginContainer(finalList);
|
||||||
SYSRelaunchTitle(NULL,NULL);
|
SYSRelaunchTitle(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(inflatedData);
|
free(inflatedData);
|
||||||
free(loadAddress);
|
free(loadAddress);
|
||||||
|
|
||||||
return fileSize;
|
return fileSize;
|
||||||
}else{
|
} else {
|
||||||
DEBUG_FUNCTION_LINE("Failed to parse plugin\n");
|
DEBUG_FUNCTION_LINE("Failed to parse plugin\n");
|
||||||
}
|
}
|
||||||
free(inflatedData);
|
free(inflatedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if(loadAddress[0x7] == 0xCA && loadAddress[0x8] == 0xFE){
|
if (loadAddress[0x7] == 0xCA && loadAddress[0x8] == 0xFE) {
|
||||||
DEBUG_FUNCTION_LINE("Try to load a rpx\n");
|
DEBUG_FUNCTION_LINE("Try to load a rpx\n");
|
||||||
FSUtils::CreateSubfolder(RPX_TEMP_PATH);
|
FSUtils::CreateSubfolder(RPX_TEMP_PATH);
|
||||||
res = FSUtils::saveBufferToFile(RPX_TEMP_FILE,loadAddress, fileSize);
|
res = FSUtils::saveBufferToFile(RPX_TEMP_FILE, loadAddress, fileSize);
|
||||||
free(loadAddress);
|
free(loadAddress);
|
||||||
loadedRPX = true;
|
loadedRPX = true;
|
||||||
}else if(loadAddress[0x7] == 0xCA && loadAddress[0x8] == 0xFE && loadAddress[0x9] == 0xDE){
|
} else if (loadAddress[0x7] == 0xCA && loadAddress[0x8] == 0xFE && loadAddress[0x9] == 0xDE) {
|
||||||
OSFatal("Not implemented yet");
|
OSFatal("Not implemented yet");
|
||||||
free(loadAddress);
|
free(loadAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!res) {
|
if (!res) {
|
||||||
return NOT_ENOUGH_MEMORY;
|
return NOT_ENOUGH_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(loadedRPX){
|
if (loadedRPX) {
|
||||||
LOAD_REQUEST request;
|
LOAD_REQUEST request;
|
||||||
memset(&request, 0, sizeof(request));
|
memset(&request, 0, sizeof(request));
|
||||||
|
|
||||||
@ -315,12 +313,12 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
|
|
||||||
strncpy(request.path, RPX_TEMP_FILE_EX, 255);
|
strncpy(request.path, RPX_TEMP_FILE_EX, 255);
|
||||||
|
|
||||||
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);
|
||||||
if(out == 2) {
|
if (out == 2) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,7 +328,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
|||||||
return fileSize;
|
return fileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSRelaunchTitle(NULL,NULL);
|
SYSRelaunchTitle(NULL, NULL);
|
||||||
|
|
||||||
return fileSize;
|
return fileSize;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
TcpReceiver(int32_t port);
|
TcpReceiver(int32_t port);
|
||||||
|
|
||||||
~TcpReceiver();
|
~TcpReceiver();
|
||||||
|
|
||||||
//sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
|
//sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
|
||||||
@ -26,8 +27,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void executeThread();
|
void executeThread();
|
||||||
|
|
||||||
int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
||||||
bool saveFileToSDCard(const char * path, void * buffer,uint32_t size);
|
|
||||||
|
bool saveFileToSDCard(const char *path, void *buffer, uint32_t size);
|
||||||
|
|
||||||
bool exitRequested;
|
bool exitRequested;
|
||||||
int32_t serverPort;
|
int32_t serverPort;
|
||||||
|
@ -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)
|
||||||
|
@ -4,18 +4,18 @@
|
|||||||
static volatile int socket_lock __attribute__((section(".data"))) = 0;
|
static volatile int socket_lock __attribute__((section(".data"))) = 0;
|
||||||
|
|
||||||
int32_t recvwait(int32_t sock, void *buffer, int32_t len) {
|
int32_t recvwait(int32_t sock, void *buffer, int32_t len) {
|
||||||
while(socket_lock) {
|
while (socket_lock) {
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
ret = recv(sock, buffer, len, 0);
|
ret = recv(sock, buffer, len, 0);
|
||||||
if(ret < 0) {
|
if (ret < 0) {
|
||||||
socket_lock = 0;
|
socket_lock = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
len -= ret;
|
len -= ret;
|
||||||
buffer = (void *)(((char *) buffer) + ret);
|
buffer = (void *) (((char *) buffer) + ret);
|
||||||
}
|
}
|
||||||
socket_lock = 0;
|
socket_lock = 0;
|
||||||
return 0;
|
return 0;
|
||||||
@ -42,7 +42,7 @@ uint32_t recvword(int32_t sock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t checkbyte(int32_t sock) {
|
int32_t checkbyte(int32_t sock) {
|
||||||
while(socket_lock) {
|
while (socket_lock) {
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
unsigned char buffer[1];
|
unsigned char buffer[1];
|
||||||
@ -58,7 +58,7 @@ int32_t checkbyte(int32_t sock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t sendwait(int32_t sock, const void *buffer, int32_t len) {
|
int32_t sendwait(int32_t sock, const void *buffer, int32_t len) {
|
||||||
while(socket_lock) {
|
while (socket_lock) {
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
@ -66,12 +66,12 @@ int32_t sendwait(int32_t sock, const void *buffer, int32_t len) {
|
|||||||
// For some reason the send blocks/crashes if the buffer is too big..
|
// For some reason the send blocks/crashes if the buffer is too big..
|
||||||
int cur_length = len <= 0x30 ? len : 0x30;
|
int cur_length = len <= 0x30 ? len : 0x30;
|
||||||
ret = send(sock, buffer, cur_length, 0);
|
ret = send(sock, buffer, cur_length, 0);
|
||||||
if(ret < 0) {
|
if (ret < 0) {
|
||||||
socket_lock = 0;
|
socket_lock = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
len -= ret;
|
len -= ret;
|
||||||
buffer = (void *)(((char *) buffer) + ret);
|
buffer = (void *) (((char *) buffer) + ret);
|
||||||
}
|
}
|
||||||
socket_lock = 0;
|
socket_lock = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
#ifndef _UTILS_NET_H_
|
#ifndef _UTILS_NET_H_
|
||||||
#define _UTILS_NET_H_
|
#define _UTILS_NET_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <nsysnet/socket.h>
|
#include <nsysnet/socket.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int32_t recvwait(int32_t sock, void *buffer, int32_t len);
|
int32_t recvwait(int32_t sock, void *buffer, int32_t len);
|
||||||
|
|
||||||
uint8_t recvbyte(int32_t sock);
|
uint8_t recvbyte(int32_t sock);
|
||||||
|
|
||||||
uint32_t recvword(int32_t sock);
|
uint32_t recvword(int32_t sock);
|
||||||
|
|
||||||
int32_t checkbyte(int32_t sock);
|
int32_t checkbyte(int32_t sock);
|
||||||
|
|
||||||
int32_t sendwait(int32_t sock, const void *buffer, int32_t len);
|
int32_t sendwait(int32_t sock, const void *buffer, int32_t len);
|
||||||
|
|
||||||
int32_t sendbyte(int32_t sock, unsigned char byte);
|
int32_t sendbyte(int32_t sock, unsigned char byte);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -16,29 +16,29 @@ typedef enum {
|
|||||||
} RomfsSource;
|
} RomfsSource;
|
||||||
|
|
||||||
typedef struct romfs_mount {
|
typedef struct romfs_mount {
|
||||||
devoptab_t device;
|
devoptab_t device;
|
||||||
bool setup;
|
bool setup;
|
||||||
RomfsSource fd_type;
|
RomfsSource fd_type;
|
||||||
int32_t id;
|
int32_t id;
|
||||||
int32_t fd;
|
int32_t fd;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
romfs_header header;
|
romfs_header header;
|
||||||
romfs_dir *cwd;
|
romfs_dir *cwd;
|
||||||
uint32_t *dirHashTable, *fileHashTable;
|
uint32_t *dirHashTable, *fileHashTable;
|
||||||
void *dirTable, *fileTable;
|
void *dirTable, *fileTable;
|
||||||
char name[32];
|
char name[32];
|
||||||
} romfs_mount;
|
} romfs_mount;
|
||||||
|
|
||||||
extern int __system_argc;
|
extern int __system_argc;
|
||||||
extern char** __system_argv;
|
extern char **__system_argv;
|
||||||
|
|
||||||
//static char __thread __component[PATH_MAX+1];
|
//static char __thread __component[PATH_MAX+1];
|
||||||
static char __component[PATH_MAX+1];
|
static char __component[PATH_MAX + 1];
|
||||||
|
|
||||||
#define romFS_root(m) ((romfs_dir*)(m)->dirTable)
|
#define romFS_root(m) ((romfs_dir*)(m)->dirTable)
|
||||||
#define romFS_dir(m,x) ((romfs_dir*) ((uint8_t*)(m)->dirTable + (x)))
|
#define romFS_dir(m, x) ((romfs_dir*) ((uint8_t*)(m)->dirTable + (x)))
|
||||||
#define romFS_file(m,x) ((romfs_file*)((uint8_t*)(m)->fileTable + (x)))
|
#define romFS_file(m, x) ((romfs_file*)((uint8_t*)(m)->fileTable + (x)))
|
||||||
#define romFS_none ((uint32_t)~0)
|
#define romFS_none ((uint32_t)~0)
|
||||||
#define romFS_dir_mode (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH)
|
#define romFS_dir_mode (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH)
|
||||||
#define romFS_file_mode (S_IFREG | S_IRUSR | S_IRGRP | S_IROTH)
|
#define romFS_file_mode (S_IFREG | S_IRUSR | S_IRGRP | S_IROTH)
|
||||||
@ -47,7 +47,7 @@ uint64_t swapLong(uint64_t X) {
|
|||||||
uint64_t x = (uint64_t) X;
|
uint64_t x = (uint64_t) X;
|
||||||
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
|
x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32;
|
||||||
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
|
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
|
||||||
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
|
x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,12 +58,12 @@ uint64_t swapLong(uint64_t X) {
|
|||||||
((n & 0xFF0000) >> 8) | \
|
((n & 0xFF0000) >> 8) | \
|
||||||
((n & 0xFF000000) >> 24)))
|
((n & 0xFF000000) >> 24)))
|
||||||
|
|
||||||
static ssize_t _romfs_read(romfs_mount *mount, uint64_t offset, void* buffer, uint64_t size) {
|
static ssize_t _romfs_read(romfs_mount *mount, uint64_t offset, void *buffer, uint64_t size) {
|
||||||
uint64_t pos = mount->offset + offset;
|
uint64_t pos = mount->offset + offset;
|
||||||
size_t _read = 0;
|
size_t _read = 0;
|
||||||
if(mount->fd_type == RomfsSource_FileDescriptor) {
|
if (mount->fd_type == RomfsSource_FileDescriptor) {
|
||||||
off_t seek_offset = lseek(mount->fd, pos, SEEK_SET);
|
off_t seek_offset = lseek(mount->fd, pos, SEEK_SET);
|
||||||
if(pos != seek_offset) {
|
if (pos != seek_offset) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
_read = read(mount->fd, buffer, size);
|
_read = read(mount->fd, buffer, size);
|
||||||
@ -71,52 +71,62 @@ static ssize_t _romfs_read(romfs_mount *mount, uint64_t offset, void* buffer, ui
|
|||||||
return _read;
|
return _read;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _romfs_read_chk(romfs_mount *mount, uint64_t offset, void* buffer, uint64_t size) {
|
static bool _romfs_read_chk(romfs_mount *mount, uint64_t offset, void *buffer, uint64_t size) {
|
||||||
return _romfs_read(mount, offset, buffer, size) == size;
|
return _romfs_read(mount, offset, buffer, size) == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
|
static int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode);
|
||||||
static int romfs_close(struct _reent *r, void *fd);
|
|
||||||
static ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len);
|
static int romfs_close(struct _reent *r, void *fd);
|
||||||
static off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir);
|
|
||||||
static int romfs_fstat(struct _reent *r, void *fd, struct stat *st);
|
static ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len);
|
||||||
static int romfs_stat(struct _reent *r, const char *path, struct stat *st);
|
|
||||||
static int romfs_chdir(struct _reent *r, const char *path);
|
static off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir);
|
||||||
static DIR_ITER* romfs_diropen(struct _reent *r, DIR_ITER *dirState, const char *path);
|
|
||||||
static int romfs_dirreset(struct _reent *r, DIR_ITER *dirState);
|
static int romfs_fstat(struct _reent *r, void *fd, struct stat *st);
|
||||||
static int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
|
|
||||||
static int romfs_dirclose(struct _reent *r, DIR_ITER *dirState);
|
static int romfs_stat(struct _reent *r, const char *path, struct stat *st);
|
||||||
|
|
||||||
|
static int romfs_chdir(struct _reent *r, const char *path);
|
||||||
|
|
||||||
|
static DIR_ITER *romfs_diropen(struct _reent *r, DIR_ITER *dirState, const char *path);
|
||||||
|
|
||||||
|
static int romfs_dirreset(struct _reent *r, DIR_ITER *dirState);
|
||||||
|
|
||||||
|
static int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat);
|
||||||
|
|
||||||
|
static int romfs_dirclose(struct _reent *r, DIR_ITER *dirState);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
romfs_mount *mount;
|
romfs_mount *mount;
|
||||||
romfs_file *file;
|
romfs_file *file;
|
||||||
uint64_t offset, pos;
|
uint64_t offset, pos;
|
||||||
} romfs_fileobj;
|
} romfs_fileobj;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
romfs_mount *mount;
|
romfs_mount *mount;
|
||||||
romfs_dir* dir;
|
romfs_dir *dir;
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
uint32_t childDir;
|
uint32_t childDir;
|
||||||
uint32_t childFile;
|
uint32_t childFile;
|
||||||
} romfs_diriter;
|
} romfs_diriter;
|
||||||
|
|
||||||
static devoptab_t romFS_devoptab = {
|
static devoptab_t romFS_devoptab = {
|
||||||
.structSize = sizeof(romfs_fileobj),
|
.structSize = sizeof(romfs_fileobj),
|
||||||
.open_r = romfs_open,
|
.open_r = romfs_open,
|
||||||
.close_r = romfs_close,
|
.close_r = romfs_close,
|
||||||
.read_r = romfs_read,
|
.read_r = romfs_read,
|
||||||
.seek_r = romfs_seek,
|
.seek_r = romfs_seek,
|
||||||
.fstat_r = romfs_fstat,
|
.fstat_r = romfs_fstat,
|
||||||
.stat_r = romfs_stat,
|
.stat_r = romfs_stat,
|
||||||
.chdir_r = romfs_chdir,
|
.chdir_r = romfs_chdir,
|
||||||
.dirStateSize = sizeof(romfs_diriter),
|
.dirStateSize = sizeof(romfs_diriter),
|
||||||
.diropen_r = romfs_diropen,
|
.diropen_r = romfs_diropen,
|
||||||
.dirreset_r = romfs_dirreset,
|
.dirreset_r = romfs_dirreset,
|
||||||
.dirnext_r = romfs_dirnext,
|
.dirnext_r = romfs_dirnext,
|
||||||
.dirclose_r = romfs_dirclose,
|
.dirclose_r = romfs_dirclose,
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool romfs_initialised = false;
|
static bool romfs_initialised = false;
|
||||||
@ -125,6 +135,7 @@ static romfs_mount romfs_mounts[32];
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int32_t romfsMountCommon(const char *name, romfs_mount *mount);
|
static int32_t romfsMountCommon(const char *name, romfs_mount *mount);
|
||||||
|
|
||||||
static void romfsInitMtime(romfs_mount *mount);
|
static void romfsInitMtime(romfs_mount *mount);
|
||||||
|
|
||||||
static void _romfsResetMount(romfs_mount *mount, int32_t id) {
|
static void _romfsResetMount(romfs_mount *mount, int32_t id) {
|
||||||
@ -139,8 +150,8 @@ static void _romfsInit(void) {
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t total = sizeof(romfs_mounts) / sizeof(romfs_mount);
|
uint32_t total = sizeof(romfs_mounts) / sizeof(romfs_mount);
|
||||||
|
|
||||||
if(!romfs_initialised) {
|
if (!romfs_initialised) {
|
||||||
for(i = 0; i < total; i++) {
|
for (i = 0; i < total; i++) {
|
||||||
_romfsResetMount(&romfs_mounts[i], i);
|
_romfsResetMount(&romfs_mounts[i], i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,14 +166,14 @@ static romfs_mount *romfsFindMount(const char *name) {
|
|||||||
|
|
||||||
_romfsInit();
|
_romfsInit();
|
||||||
|
|
||||||
for(i=0; i<total; i++) {
|
for (i = 0; i < total; i++) {
|
||||||
mount = &romfs_mounts[i];
|
mount = &romfs_mounts[i];
|
||||||
|
|
||||||
if(name==NULL) { //Find an unused mount entry.
|
if (name == NULL) { //Find an unused mount entry.
|
||||||
if(!mount->setup)
|
if (!mount->setup)
|
||||||
return mount;
|
return mount;
|
||||||
} else if(mount->setup) { //Find the mount with the input name.
|
} else if (mount->setup) { //Find the mount with the input name.
|
||||||
if(strncmp(mount->name, name, sizeof(mount->name))==0)
|
if (strncmp(mount->name, name, sizeof(mount->name)) == 0)
|
||||||
return mount;
|
return mount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,9 +181,9 @@ static romfs_mount *romfsFindMount(const char *name) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) const char* __romfs_path = NULL;
|
__attribute__((weak)) const char *__romfs_path = NULL;
|
||||||
|
|
||||||
static romfs_mount* romfs_alloc(void) {
|
static romfs_mount *romfs_alloc(void) {
|
||||||
return romfsFindMount(NULL);
|
return romfsFindMount(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,15 +196,15 @@ static void romfs_free(romfs_mount *mount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void romfs_mountclose(romfs_mount *mount) {
|
static void romfs_mountclose(romfs_mount *mount) {
|
||||||
if(mount->fd_type == RomfsSource_FileDescriptor) {
|
if (mount->fd_type == RomfsSource_FileDescriptor) {
|
||||||
close(mount->fd);
|
close(mount->fd);
|
||||||
}
|
}
|
||||||
romfs_free(mount);
|
romfs_free(mount);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t romfsMount(const char *name, const char * filepath) {
|
int32_t romfsMount(const char *name, const char *filepath) {
|
||||||
romfs_mount *mount = romfs_alloc();
|
romfs_mount *mount = romfs_alloc();
|
||||||
if(mount == NULL)
|
if (mount == NULL)
|
||||||
return 99;
|
return 99;
|
||||||
|
|
||||||
// Regular RomFS
|
// Regular RomFS
|
||||||
@ -208,19 +219,19 @@ int32_t romfsMount(const char *name, const char * filepath) {
|
|||||||
romfsInitMtime(mount);
|
romfsInitMtime(mount);
|
||||||
return romfsMountCommon(name, mount);
|
return romfsMountCommon(name, mount);
|
||||||
|
|
||||||
_fail0:
|
_fail0:
|
||||||
romfs_mountclose(mount);
|
romfs_mountclose(mount);
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t romfsMountCommon(const char *name, romfs_mount *mount) {
|
int32_t romfsMountCommon(const char *name, romfs_mount *mount) {
|
||||||
memset(mount->name, 0, sizeof(mount->name));
|
memset(mount->name, 0, sizeof(mount->name));
|
||||||
strncpy(mount->name, name, sizeof(mount->name)-1);
|
strncpy(mount->name, name, sizeof(mount->name) - 1);
|
||||||
|
|
||||||
if (_romfs_read(mount, 0, &mount->header, sizeof(mount->header)) != sizeof(mount->header))
|
if (_romfs_read(mount, 0, &mount->header, sizeof(mount->header)) != sizeof(mount->header))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
mount->dirHashTable = (uint32_t*)malloc(swapLong(mount->header.dirHashTableSize));
|
mount->dirHashTable = (uint32_t *) malloc(swapLong(mount->header.dirHashTableSize));
|
||||||
if (!mount->dirHashTable)
|
if (!mount->dirHashTable)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (!_romfs_read_chk(mount, swapLong(mount->header.dirHashTableOff), mount->dirHashTable, swapLong(mount->header.dirHashTableSize)))
|
if (!_romfs_read_chk(mount, swapLong(mount->header.dirHashTableOff), mount->dirHashTable, swapLong(mount->header.dirHashTableSize)))
|
||||||
@ -231,7 +242,7 @@ int32_t romfsMountCommon(const char *name, romfs_mount *mount) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
if (!_romfs_read_chk(mount, swapLong(mount->header.dirTableOff), mount->dirTable, swapLong(mount->header.dirTableSize)))
|
if (!_romfs_read_chk(mount, swapLong(mount->header.dirTableOff), mount->dirTable, swapLong(mount->header.dirTableSize)))
|
||||||
goto fail;
|
goto fail;
|
||||||
mount->fileHashTable = (uint32_t*)malloc(swapLong(mount->header.fileHashTableSize));
|
mount->fileHashTable = (uint32_t *) malloc(swapLong(mount->header.fileHashTableSize));
|
||||||
if (!mount->fileHashTable)
|
if (!mount->fileHashTable)
|
||||||
goto fail;
|
goto fail;
|
||||||
if (!_romfs_read_chk(mount, swapLong(mount->header.fileHashTableOff), mount->fileHashTable, swapLong(mount->header.fileHashTableSize)))
|
if (!_romfs_read_chk(mount, swapLong(mount->header.fileHashTableOff), mount->fileHashTable, swapLong(mount->header.fileHashTableSize)))
|
||||||
@ -245,12 +256,12 @@ int32_t romfsMountCommon(const char *name, romfs_mount *mount) {
|
|||||||
mount->cwd = romFS_root(mount);
|
mount->cwd = romFS_root(mount);
|
||||||
|
|
||||||
// add device if this is the first one
|
// add device if this is the first one
|
||||||
if(AddDevice(&mount->device) < 0)
|
if (AddDevice(&mount->device) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
mount->setup = true;
|
mount->setup = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
romfs_mountclose(mount);
|
romfs_mountclose(mount);
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
@ -269,8 +280,8 @@ int32_t romfsUnmount(const char *name) {
|
|||||||
|
|
||||||
// Remove device
|
// Remove device
|
||||||
memset(tmpname, 0, sizeof(tmpname));
|
memset(tmpname, 0, sizeof(tmpname));
|
||||||
strncpy(tmpname, mount->name, sizeof(tmpname)-2);
|
strncpy(tmpname, mount->name, sizeof(tmpname) - 2);
|
||||||
strncat(tmpname, ":", sizeof(tmpname)-strlen(tmpname)-1);
|
strncat(tmpname, ":", sizeof(tmpname) - strlen(tmpname) - 1);
|
||||||
|
|
||||||
RemoveDevice(tmpname);
|
RemoveDevice(tmpname);
|
||||||
|
|
||||||
@ -281,20 +292,20 @@ int32_t romfsUnmount(const char *name) {
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static uint32_t calcHash(uint32_t parent, const uint8_t* name, uint32_t namelen, uint32_t total) {
|
static uint32_t calcHash(uint32_t parent, const uint8_t *name, uint32_t namelen, uint32_t total) {
|
||||||
uint32_t hash = parent ^ 123456789;
|
uint32_t hash = parent ^123456789;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
for (i = 0; i < namelen; i ++) {
|
for (i = 0; i < namelen; i++) {
|
||||||
hash = (hash >> 5) | (hash << 27);
|
hash = (hash >> 5) | (hash << 27);
|
||||||
hash ^= name[i];
|
hash ^= name[i];
|
||||||
}
|
}
|
||||||
return hash % total;
|
return hash % total;
|
||||||
}
|
}
|
||||||
|
|
||||||
static romfs_dir* searchForDir(romfs_mount *mount, romfs_dir* parent, const uint8_t* name, uint32_t namelen) {
|
static romfs_dir *searchForDir(romfs_mount *mount, romfs_dir *parent, const uint8_t *name, uint32_t namelen) {
|
||||||
uint64_t parentOff = (uintptr_t)parent - (uintptr_t)mount->dirTable;
|
uint64_t parentOff = (uintptr_t) parent - (uintptr_t) mount->dirTable;
|
||||||
uint32_t hash = calcHash(parentOff, name, namelen, swapLong(mount->header.dirHashTableSize)/4);
|
uint32_t hash = calcHash(parentOff, name, namelen, swapLong(mount->header.dirHashTableSize) / 4);
|
||||||
romfs_dir* curDir = NULL;
|
romfs_dir *curDir = NULL;
|
||||||
uint32_t curOff;
|
uint32_t curOff;
|
||||||
for (curOff = REVERSE_INT(mount->dirHashTable[hash]); curOff != romFS_none; curOff = REVERSE_INT(curDir->nextHash)) {
|
for (curOff = REVERSE_INT(mount->dirHashTable[hash]); curOff != romFS_none; curOff = REVERSE_INT(curDir->nextHash)) {
|
||||||
curDir = romFS_dir(mount, curOff);
|
curDir = romFS_dir(mount, curOff);
|
||||||
@ -309,10 +320,10 @@ static romfs_dir* searchForDir(romfs_mount *mount, romfs_dir* parent, const uint
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static romfs_file* searchForFile(romfs_mount *mount, romfs_dir* parent, const uint8_t* name, uint32_t namelen) {
|
static romfs_file *searchForFile(romfs_mount *mount, romfs_dir *parent, const uint8_t *name, uint32_t namelen) {
|
||||||
uint64_t parentOff = (uintptr_t)parent - (uintptr_t)mount->dirTable;
|
uint64_t parentOff = (uintptr_t) parent - (uintptr_t) mount->dirTable;
|
||||||
uint32_t hash = calcHash(parentOff, name, namelen, swapLong(mount->header.fileHashTableSize)/4);
|
uint32_t hash = calcHash(parentOff, name, namelen, swapLong(mount->header.fileHashTableSize) / 4);
|
||||||
romfs_file* curFile = NULL;
|
romfs_file *curFile = NULL;
|
||||||
uint32_t curOff;
|
uint32_t curOff;
|
||||||
for (curOff = REVERSE_INT(mount->fileHashTable[hash]); curOff != romFS_none; curOff = REVERSE_INT(curFile->nextHash)) {
|
for (curOff = REVERSE_INT(mount->fileHashTable[hash]); curOff != romFS_none; curOff = REVERSE_INT(curFile->nextHash)) {
|
||||||
curFile = romFS_file(mount, curOff);
|
curFile = romFS_file(mount, curOff);
|
||||||
@ -327,10 +338,10 @@ static romfs_file* searchForFile(romfs_mount *mount, romfs_dir* parent, const ui
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPath, bool isDir) {
|
static int navigateToDir(romfs_mount *mount, romfs_dir **ppDir, const char **pPath, bool isDir) {
|
||||||
char* colonPos = strchr(*pPath, ':');
|
char *colonPos = strchr(*pPath, ':');
|
||||||
if (colonPos)
|
if (colonPos)
|
||||||
*pPath = colonPos+1;
|
*pPath = colonPos + 1;
|
||||||
if (!**pPath)
|
if (!**pPath)
|
||||||
return EILSEQ;
|
return EILSEQ;
|
||||||
|
|
||||||
@ -341,8 +352,8 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (**pPath) {
|
while (**pPath) {
|
||||||
char* slashPos = strchr(*pPath, '/');
|
char *slashPos = strchr(*pPath, '/');
|
||||||
char* component = __component;
|
char *component = __component;
|
||||||
|
|
||||||
if (slashPos) {
|
if (slashPos) {
|
||||||
uint32_t len = slashPos - *pPath;
|
uint32_t len = slashPos - *pPath;
|
||||||
@ -353,23 +364,23 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa
|
|||||||
|
|
||||||
memcpy(component, *pPath, len);
|
memcpy(component, *pPath, len);
|
||||||
component[len] = 0;
|
component[len] = 0;
|
||||||
*pPath = slashPos+1;
|
*pPath = slashPos + 1;
|
||||||
} else if (isDir) {
|
} else if (isDir) {
|
||||||
component = (char*)*pPath;
|
component = (char *) *pPath;
|
||||||
*pPath += strlen(component);
|
*pPath += strlen(component);
|
||||||
} else
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (component[0]=='.') {
|
if (component[0] == '.') {
|
||||||
if (!component[1])
|
if (!component[1])
|
||||||
continue;
|
continue;
|
||||||
if (component[1]=='.' && !component[2]) {
|
if (component[1] == '.' && !component[2]) {
|
||||||
*ppDir = romFS_dir(mount, REVERSE_INT((*ppDir)->parent));
|
*ppDir = romFS_dir(mount, REVERSE_INT((*ppDir)->parent));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppDir = searchForDir(mount, *ppDir, (uint8_t*)component, strlen(component));
|
*ppDir = searchForDir(mount, *ppDir, (uint8_t *) component, strlen(component));
|
||||||
if (!*ppDir)
|
if (!*ppDir)
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
}
|
||||||
@ -381,25 +392,25 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ino_t dir_inode(romfs_mount *mount, romfs_dir *dir) {
|
static ino_t dir_inode(romfs_mount *mount, romfs_dir *dir) {
|
||||||
return (uint32_t*)dir - (uint32_t*)mount->dirTable;
|
return (uint32_t *) dir - (uint32_t *) mount->dirTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static off_t dir_size(romfs_dir *dir) {
|
static off_t dir_size(romfs_dir *dir) {
|
||||||
return sizeof(romfs_dir) + (REVERSE_INT(dir->nameLen)+3)/4;
|
return sizeof(romfs_dir) + (REVERSE_INT(dir->nameLen) + 3) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static nlink_t dir_nlink(romfs_mount *mount, romfs_dir *dir) {
|
static nlink_t dir_nlink(romfs_mount *mount, romfs_dir *dir) {
|
||||||
nlink_t count = 2; // one for self, one for parent
|
nlink_t count = 2; // one for self, one for parent
|
||||||
uint32_t offset = REVERSE_INT(dir->childDir);
|
uint32_t offset = REVERSE_INT(dir->childDir);
|
||||||
|
|
||||||
while(offset != romFS_none) {
|
while (offset != romFS_none) {
|
||||||
romfs_dir *tmp = romFS_dir(mount, offset);
|
romfs_dir *tmp = romFS_dir(mount, offset);
|
||||||
++count;
|
++count;
|
||||||
offset = REVERSE_INT(tmp->sibling);
|
offset = REVERSE_INT(tmp->sibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = REVERSE_INT(dir->childFile);
|
offset = REVERSE_INT(dir->childFile);
|
||||||
while(offset != romFS_none) {
|
while (offset != romFS_none) {
|
||||||
romfs_file *tmp = romFS_file(mount, offset);
|
romfs_file *tmp = romFS_file(mount, offset);
|
||||||
++count;
|
++count;
|
||||||
offset = REVERSE_INT(tmp->sibling);
|
offset = REVERSE_INT(tmp->sibling);
|
||||||
@ -409,24 +420,24 @@ static nlink_t dir_nlink(romfs_mount *mount, romfs_dir *dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ino_t file_inode(romfs_mount *mount, romfs_file *file) {
|
static ino_t file_inode(romfs_mount *mount, romfs_file *file) {
|
||||||
return ((uint32_t*)file - (uint32_t*)mount->fileTable) + swapLong(mount->header.dirTableSize)/4;
|
return ((uint32_t *) file - (uint32_t *) mount->fileTable) + swapLong(mount->header.dirTableSize) / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
int romfs_GetFileInfoPerPath(const char* romfs, const char *path, romfs_fileInfo* out) {
|
int romfs_GetFileInfoPerPath(const char *romfs, const char *path, romfs_fileInfo *out) {
|
||||||
if(out == NULL){
|
if (out == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
romfs_mount* mount = (romfs_mount*)romfsFindMount(romfs);
|
romfs_mount *mount = (romfs_mount *) romfsFindMount(romfs);
|
||||||
if(mount == NULL){
|
if (mount == NULL) {
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
romfs_dir* curDir = NULL;
|
romfs_dir *curDir = NULL;
|
||||||
int errno2 = navigateToDir(mount, &curDir, &path, false);
|
int errno2 = navigateToDir(mount, &curDir, &path, false);
|
||||||
if (errno2 != 0){
|
if (errno2 != 0) {
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
romfs_file* file = searchForFile(mount, curDir, (uint8_t*)path, strlen(path));
|
romfs_file *file = searchForFile(mount, curDir, (uint8_t *) path, strlen(path));
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
@ -441,35 +452,35 @@ int romfs_GetFileInfoPerPath(const char* romfs, const char *path, romfs_fileInfo
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) {
|
int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) {
|
||||||
romfs_fileobj* fileobj = (romfs_fileobj*)fileStruct;
|
romfs_fileobj *fileobj = (romfs_fileobj *) fileStruct;
|
||||||
|
|
||||||
fileobj->mount = (romfs_mount*)r->deviceData;
|
fileobj->mount = (romfs_mount *) r->deviceData;
|
||||||
|
|
||||||
if ((flags & O_ACCMODE) != O_RDONLY) {
|
if ((flags & O_ACCMODE) != O_RDONLY) {
|
||||||
r->_errno = EROFS;
|
r->_errno = EROFS;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
romfs_dir* curDir = NULL;
|
romfs_dir *curDir = NULL;
|
||||||
r->_errno = navigateToDir(fileobj->mount, &curDir, &path, false);
|
r->_errno = navigateToDir(fileobj->mount, &curDir, &path, false);
|
||||||
if (r->_errno != 0)
|
if (r->_errno != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
romfs_file* file = searchForFile(fileobj->mount, curDir, (uint8_t*)path, strlen(path));
|
romfs_file *file = searchForFile(fileobj->mount, curDir, (uint8_t *) path, strlen(path));
|
||||||
if (!file) {
|
if (!file) {
|
||||||
if(flags & O_CREAT)
|
if (flags & O_CREAT)
|
||||||
r->_errno = EROFS;
|
r->_errno = EROFS;
|
||||||
else
|
else
|
||||||
r->_errno = ENOENT;
|
r->_errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
} else if((flags & O_CREAT) && (flags & O_EXCL)) {
|
} else if ((flags & O_CREAT) && (flags & O_EXCL)) {
|
||||||
r->_errno = EEXIST;
|
r->_errno = EEXIST;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileobj->file = file;
|
fileobj->file = file;
|
||||||
fileobj->offset = swapLong(fileobj->mount->header.fileDataOff) + swapLong(file->dataOff);
|
fileobj->offset = swapLong(fileobj->mount->header.fileDataOff) + swapLong(file->dataOff);
|
||||||
fileobj->pos = 0;
|
fileobj->pos = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -479,20 +490,20 @@ int romfs_close(struct _reent *r, void *fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len) {
|
ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len) {
|
||||||
romfs_fileobj* file = (romfs_fileobj*)fd;
|
romfs_fileobj *file = (romfs_fileobj *) fd;
|
||||||
uint64_t endPos = file->pos + len;
|
uint64_t endPos = file->pos + len;
|
||||||
|
|
||||||
/* check if past end-of-file */
|
/* check if past end-of-file */
|
||||||
if(file->pos >= swapLong(file->file->dataSize))
|
if (file->pos >= swapLong(file->file->dataSize))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* truncate the read to end-of-file */
|
/* truncate the read to end-of-file */
|
||||||
if(endPos > swapLong(file->file->dataSize))
|
if (endPos > swapLong(file->file->dataSize))
|
||||||
endPos = swapLong(file->file->dataSize);
|
endPos = swapLong(file->file->dataSize);
|
||||||
len = endPos - file->pos;
|
len = endPos - file->pos;
|
||||||
|
|
||||||
ssize_t adv = _romfs_read(file->mount, file->offset + file->pos, ptr, len);
|
ssize_t adv = _romfs_read(file->mount, file->offset + file->pos, ptr, len);
|
||||||
if(adv >= 0) {
|
if (adv >= 0) {
|
||||||
file->pos += adv;
|
file->pos += adv;
|
||||||
return adv;
|
return adv;
|
||||||
}
|
}
|
||||||
@ -502,35 +513,35 @@ ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir) {
|
off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir) {
|
||||||
romfs_fileobj* file = (romfs_fileobj*)fd;
|
romfs_fileobj *file = (romfs_fileobj *) fd;
|
||||||
off_t start;
|
off_t start;
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case SEEK_SET:
|
case SEEK_SET:
|
||||||
start = 0;
|
start = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_CUR:
|
case SEEK_CUR:
|
||||||
start = file->pos;
|
start = file->pos;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SEEK_END:
|
case SEEK_END:
|
||||||
start = swapLong(file->file->dataSize);
|
start = swapLong(file->file->dataSize);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
r->_errno = EINVAL;
|
r->_errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* don't allow negative position */
|
/* don't allow negative position */
|
||||||
if(pos < 0) {
|
if (pos < 0) {
|
||||||
if(start + pos < 0) {
|
if (start + pos < 0) {
|
||||||
r->_errno = EINVAL;
|
r->_errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* check for overflow */
|
/* check for overflow */
|
||||||
else if(INT64_MAX - pos < start) {
|
else if (INT64_MAX - pos < start) {
|
||||||
r->_errno = EOVERFLOW;
|
r->_errno = EOVERFLOW;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -540,49 +551,49 @@ off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int romfs_fstat(struct _reent *r, void *fd, struct stat *st) {
|
int romfs_fstat(struct _reent *r, void *fd, struct stat *st) {
|
||||||
romfs_fileobj* file = (romfs_fileobj*)fd;
|
romfs_fileobj *file = (romfs_fileobj *) fd;
|
||||||
memset(st, 0, sizeof(struct stat));
|
memset(st, 0, sizeof(struct stat));
|
||||||
st->st_ino = file_inode(file->mount, file->file);
|
st->st_ino = file_inode(file->mount, file->file);
|
||||||
st->st_mode = romFS_file_mode;
|
st->st_mode = romFS_file_mode;
|
||||||
st->st_nlink = 1;
|
st->st_nlink = 1;
|
||||||
st->st_size = (off_t)swapLong(file->file->dataSize);
|
st->st_size = (off_t) swapLong(file->file->dataSize);
|
||||||
st->st_blksize = 512;
|
st->st_blksize = 512;
|
||||||
st->st_blocks = (st->st_blksize + 511) / 512;
|
st->st_blocks = (st->st_blksize + 511) / 512;
|
||||||
st->st_atime = st->st_mtime = st->st_ctime = file->mount->mtime;
|
st->st_atime = st->st_mtime = st->st_ctime = file->mount->mtime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int romfs_stat(struct _reent *r, const char *path, struct stat *st) {
|
int romfs_stat(struct _reent *r, const char *path, struct stat *st) {
|
||||||
romfs_mount* mount = (romfs_mount*)r->deviceData;
|
romfs_mount *mount = (romfs_mount *) r->deviceData;
|
||||||
romfs_dir* curDir = NULL;
|
romfs_dir *curDir = NULL;
|
||||||
r->_errno = navigateToDir(mount, &curDir, &path, false);
|
r->_errno = navigateToDir(mount, &curDir, &path, false);
|
||||||
if(r->_errno != 0)
|
if (r->_errno != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
romfs_dir* dir = searchForDir(mount, curDir, (uint8_t*)path, strlen(path));
|
romfs_dir *dir = searchForDir(mount, curDir, (uint8_t *) path, strlen(path));
|
||||||
if(dir) {
|
if (dir) {
|
||||||
memset(st, 0, sizeof(*st));
|
memset(st, 0, sizeof(*st));
|
||||||
st->st_ino = dir_inode(mount, dir);
|
st->st_ino = dir_inode(mount, dir);
|
||||||
st->st_mode = romFS_dir_mode;
|
st->st_mode = romFS_dir_mode;
|
||||||
st->st_nlink = dir_nlink(mount, dir);
|
st->st_nlink = dir_nlink(mount, dir);
|
||||||
st->st_size = dir_size(dir);
|
st->st_size = dir_size(dir);
|
||||||
st->st_blksize = 512;
|
st->st_blksize = 512;
|
||||||
st->st_blocks = (st->st_blksize + 511) / 512;
|
st->st_blocks = (st->st_blksize + 511) / 512;
|
||||||
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
romfs_file* file = searchForFile(mount, curDir, (uint8_t*)path, strlen(path));
|
romfs_file *file = searchForFile(mount, curDir, (uint8_t *) path, strlen(path));
|
||||||
if(file) {
|
if (file) {
|
||||||
memset(st, 0, sizeof(*st));
|
memset(st, 0, sizeof(*st));
|
||||||
st->st_ino = file_inode(mount, file);
|
st->st_ino = file_inode(mount, file);
|
||||||
st->st_mode = romFS_file_mode;
|
st->st_mode = romFS_file_mode;
|
||||||
st->st_nlink = 1;
|
st->st_nlink = 1;
|
||||||
st->st_size = swapLong(file->dataSize);
|
st->st_size = swapLong(file->dataSize);
|
||||||
st->st_blksize = 512;
|
st->st_blksize = 512;
|
||||||
st->st_blocks = (st->st_blksize + 511) / 512;
|
st->st_blocks = (st->st_blksize + 511) / 512;
|
||||||
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -593,8 +604,8 @@ int romfs_stat(struct _reent *r, const char *path, struct stat *st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int romfs_chdir(struct _reent *r, const char *path) {
|
int romfs_chdir(struct _reent *r, const char *path) {
|
||||||
romfs_mount* mount = (romfs_mount*)r->deviceData;
|
romfs_mount *mount = (romfs_mount *) r->deviceData;
|
||||||
romfs_dir* curDir = NULL;
|
romfs_dir *curDir = NULL;
|
||||||
r->_errno = navigateToDir(mount, &curDir, &path, false);
|
r->_errno = navigateToDir(mount, &curDir, &path, false);
|
||||||
if (r->_errno != 0)
|
if (r->_errno != 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -603,48 +614,48 @@ int romfs_chdir(struct _reent *r, const char *path) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR_ITER* romfs_diropen(struct _reent *r, DIR_ITER *dirState, const char *path) {
|
DIR_ITER *romfs_diropen(struct _reent *r, DIR_ITER *dirState, const char *path) {
|
||||||
romfs_diriter* iter = (romfs_diriter*)(dirState->dirStruct);
|
romfs_diriter *iter = (romfs_diriter *) (dirState->dirStruct);
|
||||||
romfs_dir* curDir = NULL;
|
romfs_dir *curDir = NULL;
|
||||||
iter->mount = (romfs_mount*)r->deviceData;
|
iter->mount = (romfs_mount *) r->deviceData;
|
||||||
|
|
||||||
r->_errno = navigateToDir(iter->mount, &curDir, &path, true);
|
r->_errno = navigateToDir(iter->mount, &curDir, &path, true);
|
||||||
if(r->_errno != 0)
|
if (r->_errno != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
iter->dir = curDir;
|
iter->dir = curDir;
|
||||||
iter->state = 0;
|
iter->state = 0;
|
||||||
iter->childDir = REVERSE_INT(curDir->childDir);
|
iter->childDir = REVERSE_INT(curDir->childDir);
|
||||||
iter->childFile = REVERSE_INT(curDir->childFile);
|
iter->childFile = REVERSE_INT(curDir->childFile);
|
||||||
|
|
||||||
return dirState;
|
return dirState;
|
||||||
}
|
}
|
||||||
|
|
||||||
int romfs_dirreset(struct _reent *r, DIR_ITER *dirState) {
|
int romfs_dirreset(struct _reent *r, DIR_ITER *dirState) {
|
||||||
romfs_diriter* iter = (romfs_diriter*)(dirState->dirStruct);
|
romfs_diriter *iter = (romfs_diriter *) (dirState->dirStruct);
|
||||||
|
|
||||||
iter->state = 0;
|
iter->state = 0;
|
||||||
iter->childDir = REVERSE_INT(iter->dir->childDir);
|
iter->childDir = REVERSE_INT(iter->dir->childDir);
|
||||||
iter->childFile = REVERSE_INT(iter->dir->childFile);
|
iter->childFile = REVERSE_INT(iter->dir->childFile);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) {
|
int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat) {
|
||||||
romfs_diriter* iter = (romfs_diriter*)(dirState->dirStruct);
|
romfs_diriter *iter = (romfs_diriter *) (dirState->dirStruct);
|
||||||
|
|
||||||
if(iter->state == 0) {
|
if (iter->state == 0) {
|
||||||
/* '.' entry */
|
/* '.' entry */
|
||||||
memset(filestat, 0, sizeof(*filestat));
|
memset(filestat, 0, sizeof(*filestat));
|
||||||
filestat->st_ino = dir_inode(iter->mount, iter->dir);
|
filestat->st_ino = dir_inode(iter->mount, iter->dir);
|
||||||
filestat->st_mode = romFS_dir_mode;
|
filestat->st_mode = romFS_dir_mode;
|
||||||
|
|
||||||
strcpy(filename, ".");
|
strcpy(filename, ".");
|
||||||
iter->state = 1;
|
iter->state = 1;
|
||||||
return 0;
|
return 0;
|
||||||
} else if(iter->state == 1) {
|
} else if (iter->state == 1) {
|
||||||
/* '..' entry */
|
/* '..' entry */
|
||||||
romfs_dir* dir = romFS_dir(iter->mount, REVERSE_INT(iter->dir->parent));
|
romfs_dir *dir = romFS_dir(iter->mount, REVERSE_INT(iter->dir->parent));
|
||||||
|
|
||||||
memset(filestat, 0, sizeof(*filestat));
|
memset(filestat, 0, sizeof(*filestat));
|
||||||
filestat->st_ino = dir_inode(iter->mount, dir);
|
filestat->st_ino = dir_inode(iter->mount, dir);
|
||||||
@ -655,8 +666,8 @@ int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct s
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iter->childDir != romFS_none) {
|
if (iter->childDir != romFS_none) {
|
||||||
romfs_dir* dir = romFS_dir(iter->mount, iter->childDir);
|
romfs_dir *dir = romFS_dir(iter->mount, iter->childDir);
|
||||||
iter->childDir = REVERSE_INT(dir->sibling);
|
iter->childDir = REVERSE_INT(dir->sibling);
|
||||||
|
|
||||||
memset(filestat, 0, sizeof(*filestat));
|
memset(filestat, 0, sizeof(*filestat));
|
||||||
@ -665,16 +676,16 @@ int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct s
|
|||||||
|
|
||||||
memset(filename, 0, NAME_MAX);
|
memset(filename, 0, NAME_MAX);
|
||||||
|
|
||||||
if(REVERSE_INT(dir->nameLen) >= NAME_MAX) {
|
if (REVERSE_INT(dir->nameLen) >= NAME_MAX) {
|
||||||
r->_errno = ENAMETOOLONG;
|
r->_errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(filename, (char*)dir->name, REVERSE_INT(dir->nameLen));
|
strncpy(filename, (char *) dir->name, REVERSE_INT(dir->nameLen));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if(iter->childFile != romFS_none) {
|
} else if (iter->childFile != romFS_none) {
|
||||||
romfs_file* file = romFS_file(iter->mount, iter->childFile);
|
romfs_file *file = romFS_file(iter->mount, iter->childFile);
|
||||||
iter->childFile = REVERSE_INT(file->sibling);
|
iter->childFile = REVERSE_INT(file->sibling);
|
||||||
|
|
||||||
memset(filestat, 0, sizeof(*filestat));
|
memset(filestat, 0, sizeof(*filestat));
|
||||||
@ -683,12 +694,12 @@ int romfs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename, struct s
|
|||||||
|
|
||||||
memset(filename, 0, NAME_MAX);
|
memset(filename, 0, NAME_MAX);
|
||||||
|
|
||||||
if(REVERSE_INT(file->nameLen) >= NAME_MAX) {
|
if (REVERSE_INT(file->nameLen) >= NAME_MAX) {
|
||||||
r->_errno = ENAMETOOLONG;
|
r->_errno = ENAMETOOLONG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(filename, (char*)file->name, REVERSE_INT(file->nameLen));
|
strncpy(filename, (char *) file->name, REVERSE_INT(file->nameLen));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ extern "C" {
|
|||||||
* @brief Mounts the Application's RomFS.
|
* @brief Mounts the Application's RomFS.
|
||||||
* @param name Device mount name.
|
* @param name Device mount name.
|
||||||
*/
|
*/
|
||||||
int32_t romfsMount(const char *name, const char * path);
|
int32_t romfsMount(const char *name, const char *path);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +82,7 @@ typedef struct {
|
|||||||
uint64_t offset; ///< Length of the file's data.
|
uint64_t offset; ///< Length of the file's data.
|
||||||
} romfs_fileInfo;
|
} romfs_fileInfo;
|
||||||
|
|
||||||
int romfs_GetFileInfoPerPath(const char* romfs, const char *path, romfs_fileInfo* out);
|
int romfs_GetFileInfoPerPath(const char *romfs, const char *path, romfs_fileInfo *out);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
@ -66,7 +66,7 @@ char *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;
|
||||||
|
@ -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 )
|
||||||
@ -29,7 +29,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);
|
||||||
char *str_replace(char *orig, char *rep, char *with);
|
char *str_replace(char *orig, char *rep, char *with);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
Reference in New Issue
Block a user