Formatting

This commit is contained in:
Maschell 2020-06-03 19:45:51 +02:00
parent 0d33e1a9b6
commit 80586bb5de
20 changed files with 545 additions and 485 deletions

View File

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

View File

@ -40,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());

View File

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

View File

@ -12,7 +12,6 @@ WUPS_USE_WUT_CRT()
TcpReceiver *thread = NULL; TcpReceiver *thread = NULL;
/* Entry point */ /* Entry point */
ON_APPLICATION_START(args) { ON_APPLICATION_START(args) {
WHBInitializeSocketLibrary(); WHBInitializeSocketLibrary();

View File

@ -29,10 +29,7 @@ public:
//! 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
@ -58,39 +55,47 @@ public:
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
@ -109,6 +114,7 @@ public:
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;

View File

@ -33,14 +33,23 @@
class StringTools { class StringTools {
public: public:
static BOOL EndsWith(const std::string &a, const std::string &b); static BOOL EndsWith(const std::string &a, const std::string &b);
static const char *byte_to_binary(int32_t x); static const char *byte_to_binary(int32_t x);
static std::string removeCharFromString(std::string &input, char toBeRemoved); static std::string removeCharFromString(std::string &input, char toBeRemoved);
static const char *fmt(const char *format, ...); static const char *fmt(const char *format, ...);
static const wchar_t *wfmt(const char *format, ...); static const wchar_t *wfmt(const char *format, ...);
static int32_t strprintf(std::string &str, const char *format, ...); static int32_t strprintf(std::string &str, const char *format, ...);
static std::string strfmt(const char *format, ...); static std::string strfmt(const char *format, ...);
static BOOL char2wchar_t(const char *src, wchar_t *dest); static BOOL char2wchar_t(const char *src, wchar_t *dest);
static int32_t strtokcmp(const char *string, const char *compare, const char *separator); static int32_t strtokcmp(const char *string, const char *compare, const char *separator);
static int32_t strextcmp(const char *string, const char *extension, char seperator); static int32_t strextcmp(const char *string, const char *extension, char seperator);
static const char *FullpathToFilename(const char *path) { static const char *FullpathToFilename(const char *path) {
@ -49,8 +58,7 @@ class StringTools{
const char *ptr = path; const char *ptr = path;
const char *Filename = ptr; const char *Filename = ptr;
while(*ptr != '\0') while (*ptr != '\0') {
{
if (ptr[0] == '/' && ptr[1] != '\0') if (ptr[0] == '/' && ptr[1] != '\0')
Filename = ptr + 1; Filename = ptr + 1;
@ -64,10 +72,8 @@ class StringTools{
uint32_t length = str.size(); uint32_t length = str.size();
//! clear path of double slashes //! clear path of double slashes
for(uint32_t i = 1; i < length; ++i) for (uint32_t i = 1; i < length; ++i) {
{ if (str[i - 1] == '/' && str[i] == '/') {
if(str[i-1] == '/' && str[i] == '/')
{
str.erase(i, 1); str.erase(i, 1);
i--; i--;
length--; length--;

View File

@ -23,11 +23,9 @@ 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();
} }

View File

@ -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,7 +27,9 @@ 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;

View File

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

View File

@ -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

View File

@ -78,15 +78,25 @@ static bool _romfs_read_chk(romfs_mount *mount, uint64_t offset, void* buffer, u
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
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 int romfs_close(struct _reent *r, void *fd);
static ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len); static ssize_t romfs_read(struct _reent *r, void *fd, char *ptr, size_t len);
static off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir); 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 int romfs_fstat(struct _reent *r, void *fd, struct stat *st);
static int romfs_stat(struct _reent *r, const char *path, struct stat *st); static int romfs_stat(struct _reent *r, const char *path, struct stat *st);
static int romfs_chdir(struct _reent *r, const char *path); 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 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_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_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_dirclose(struct _reent *r, DIR_ITER *dirState);
typedef struct { typedef struct {
@ -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) {