Skip to content

Commit

Permalink
Formatting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Sep 24, 2021
1 parent e7cb6b4 commit feb1e52
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 91 deletions.
7 changes: 3 additions & 4 deletions src/fs/CFile.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstdarg>
#include <cstdio>
#include <strings.h>
#include <fs/CFile.hpp>

CFile::CFile() {
iFd = -1;
mem_file = NULL;
mem_file = nullptr;
filesize = 0;
pos = 0;
}
Expand Down
15 changes: 6 additions & 9 deletions src/fs/CFile.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef CFILE_HPP_
#define CFILE_HPP_
#pragma once

#include <stdio.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <cstring>
#include <fcntl.h>
#include <unistd.h>
#include <wut_types.h>
Expand All @@ -29,7 +28,7 @@ class CFile {

int32_t open(const uint8_t *memory, int32_t memsize);

BOOL isOpen() const {
[[nodiscard]] BOOL isOpen() const {
if (iFd >= 0)
return true;

Expand All @@ -49,11 +48,11 @@ class CFile {

int32_t seek(long int offset, int32_t origin);

uint64_t tell() {
[[nodiscard]] uint64_t tell() const {
return pos;
};

uint64_t size() {
[[nodiscard]] uint64_t size() const {
return filesize;
};

Expand All @@ -67,5 +66,3 @@ class CFile {
uint64_t filesize;
uint64_t pos;
};

#endif
8 changes: 4 additions & 4 deletions src/fs/DirList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ BOOL DirList::InternalLoadPath(std::string &folderpath) {
if (folderpath.size() < 3)
return false;

struct dirent *dirent = NULL;
struct dirent *dirent = nullptr;
DIR *dir = NULL;

dir = opendir(folderpath.c_str());
Expand Down Expand Up @@ -152,7 +152,7 @@ void DirList::ClearList() {
for (uint32_t i = 0; i < FileInfo.size(); ++i) {
if (FileInfo[i].FilePath) {
free(FileInfo[i].FilePath);
FileInfo[i].FilePath = NULL;
FileInfo[i].FilePath = nullptr;
}
}

Expand Down Expand Up @@ -191,7 +191,7 @@ void DirList::SortList(BOOL (*SortFunc)(const DirEntry &a, const DirEntry &b)) {
}

uint64_t DirList::GetFilesize(int32_t index) const {
struct stat st;
struct stat st{};
const char *path = GetFilepath(index);

if (!path || stat(path, &st) != 0)
Expand All @@ -204,7 +204,7 @@ int32_t DirList::GetFileIndex(const char *filename) const {
if (!filename)
return -1;

for (uint32_t i = 0; i < FileInfo.size(); ++i) {
for (int32_t i = 0; i < FileInfo.size(); ++i) {
if (strcasecmp(GetFilename(i), filename) == 0)
return i;
}
Expand Down
29 changes: 13 additions & 16 deletions src/fs/DirList.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* DirList Class
* for WiiXplorer 2010
***************************************************************************/
#ifndef ___DIRLIST_H_
#define ___DIRLIST_H_
#pragma once

#include <vector>
#include <string>
Expand All @@ -39,43 +38,43 @@ typedef struct {
class DirList {
public:
//!Constructor
DirList(void);
DirList();

//!\param path Path from where to load the filelist of all files
//!\param filter A fileext that needs to be filtered
//!\param flags search/filter flags from the enum
DirList(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
explicit DirList(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);

//!Destructor
virtual ~DirList();

//! Load all the files from a directory
BOOL LoadPath(const std::string &path, const char *filter = NULL, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);
BOOL LoadPath(const std::string &path, const char *filter = nullptr, uint32_t flags = Files | Dirs, uint32_t maxDepth = 0xffffffff);

//! Get a filename of the list
//!\param list index
const char *GetFilename(int32_t index) const;
[[nodiscard]] const char *GetFilename(int32_t index) const;

//! Get the a filepath of the list
//!\param list index
const char *GetFilepath(int32_t index) const {
[[nodiscard]] const char *GetFilepath(int32_t index) const {
if (!valid(index)) return "";
else return FileInfo[index].FilePath;
}

//! Get the a filesize of the list
//!\param list index
uint64_t GetFilesize(int32_t index) const;
[[nodiscard]] uint64_t GetFilesize(int32_t index) const;

//! Is index a dir or a file
//!\param list index
BOOL IsDir(int32_t index) const {
[[nodiscard]] BOOL IsDir(int32_t index) const {
if (!valid(index)) return false;
return FileInfo[index].isDir;
};

//! Get the filecount of the whole list
int32_t GetFilecount() const {
[[nodiscard]] int32_t GetFilecount() const {
return FileInfo.size();
};

Expand Down Expand Up @@ -105,14 +104,12 @@ class DirList {
void ClearList();

//! Check if valid pos is requested
inline BOOL valid(uint32_t pos) const {
[[nodiscard]] inline BOOL valid(uint32_t pos) const {
return (pos < FileInfo.size());
};

uint32_t Flags;
uint32_t Depth;
const char *Filter;
uint32_t Flags{};
uint32_t Depth{};
const char *Filter{};
std::vector<DirEntry> FileInfo;
};

#endif
12 changes: 6 additions & 6 deletions src/fs/FSUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size) {
//! always initialze input
*inbuffer = NULL;
*inbuffer = nullptr;
if (size)
*size = 0;

Expand All @@ -20,8 +20,8 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_
uint32_t filesize = lseek(iFd, 0, SEEK_END);
lseek(iFd, 0, SEEK_SET);

uint8_t *buffer = (uint8_t *) malloc(filesize);
if (buffer == NULL) {
auto *buffer = (uint8_t *) malloc(filesize);
if (buffer == nullptr) {
close(iFd);
return -2;
}
Expand All @@ -44,7 +44,7 @@ int32_t FSUtils::LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_

if (done != filesize) {
free(buffer);
buffer = NULL;
buffer = nullptr;
return -3;
}

Expand All @@ -62,7 +62,7 @@ int32_t FSUtils::CheckFile(const char *filepath) {
if (!filepath)
return 0;

struct stat filestat;
struct stat filestat{};

char dirnoslash[strlen(filepath) + 2];
snprintf(dirnoslash, sizeof(dirnoslash), "%s", filepath);
Expand Down Expand Up @@ -106,7 +106,7 @@ int32_t FSUtils::CreateSubfolder(const char *fullpath) {
if (!ptr) {
//!Device root directory (must be with '/')
strcat(parentpath, "/");
struct stat filestat;
struct stat filestat{};
if (stat(parentpath, &filestat) == 0)
return 1;

Expand Down
2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <wups.h>
#include "utils/TcpReceiver.h"
#include <whb/log_udp.h>
#include <coreinit/cache.h>
#include <sysapp/launch.h>

WUPS_PLUGIN_NAME("Wiiload");
WUPS_PLUGIN_DESCRIPTION("Wiiload Server");
Expand Down
3 changes: 1 addition & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <cstdint>
#include <nsysnet/socket.h>


#ifdef __cplusplus
}
#endif
Expand Down
43 changes: 20 additions & 23 deletions src/utils/CThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef CTHREAD_H_
#define CTHREAD_H_
#pragma once

#include <malloc.h>
#include <unistd.h>
Expand All @@ -28,7 +27,7 @@ class CThread {
typedef void (*Callback)(CThread *thread, void *arg);

//! constructor
CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
: pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) {
//! save attribute assignment
iAttributes = iAttr;
Expand All @@ -52,24 +51,24 @@ class CThread {
}

//! Get thread ID
virtual void *getThread() const {
[[nodiscard]] virtual void *getThread() const {
return pThread;
}

//! Thread entry function
virtual void executeThread(void) {
virtual void executeThread() {
if (pCallback)
pCallback(this, pCallbackArg);
}

//! Suspend thread
virtual void suspendThread(void) {
virtual void suspendThread() {
if (isThreadSuspended()) return;
if (pThread) OSSuspendThread(pThread);
}

//! Resume thread
virtual void resumeThread(void) {
virtual void resumeThread() {
if (!isThreadSuspended()) return;
if (pThread) OSResumeThread(pThread);
}
Expand All @@ -80,49 +79,49 @@ class CThread {
}

//! Check if thread is suspended
virtual BOOL isThreadSuspended(void) const {
[[nodiscard]] virtual BOOL isThreadSuspended() const {
if (pThread) return OSIsThreadSuspended(pThread);
return false;
}

//! Check if thread is terminated
virtual BOOL isThreadTerminated(void) const {
[[nodiscard]] virtual BOOL isThreadTerminated() const {
if (pThread) return OSIsThreadTerminated(pThread);
return false;
}

//! Check if thread is running
virtual BOOL isThreadRunning(void) const {
[[nodiscard]] virtual BOOL isThreadRunning() const {
return !isThreadSuspended() && !isThreadRunning();
}

//! Shutdown thread
virtual void shutdownThread(void) {
virtual void shutdownThread() {
//! wait for thread to finish
if (pThread && !(iAttributes & eAttributeDetach)) {
if (isThreadSuspended())
resumeThread();

OSJoinThread(pThread, NULL);
OSJoinThread(pThread, nullptr);
}
//! free the thread stack buffer
if (pThreadStack)
free(pThreadStack);
if (pThread)
free(pThread);

pThread = NULL;
pThreadStack = NULL;
pThread = nullptr;
pThreadStack = nullptr;
}

//! Thread attributes
enum eCThreadAttributes {
eAttributeNone = 0x07,
eAttributeAffCore0 = 0x01,
eAttributeAffCore1 = 0x02,
eAttributeAffCore2 = 0x04,
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
eAttributeNone = 0x07,
eAttributeAffCore0 = 0x01,
eAttributeAffCore1 = 0x02,
eAttributeAffCore2 = 0x04,
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
};
private:
static int threadCallback(int argc, const char **argv) {
Expand All @@ -136,6 +135,4 @@ class CThread {
uint8_t *pThreadStack;
Callback pCallback;
void *pCallbackArg;
};

#endif
};
Loading

0 comments on commit feb1e52

Please sign in to comment.