mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-22 02:29:15 +01:00
Formatting and cleanup
This commit is contained in:
parent
e7cb6b4572
commit
feb1e5237c
@ -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;
|
||||
}
|
||||
|
@ -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>
|
||||
@ -29,7 +28,7 @@ public:
|
||||
|
||||
int32_t open(const uint8_t *memory, int32_t memsize);
|
||||
|
||||
BOOL isOpen() const {
|
||||
[[nodiscard]] BOOL isOpen() const {
|
||||
if (iFd >= 0)
|
||||
return true;
|
||||
|
||||
@ -49,11 +48,11 @@ public:
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
@ -67,5 +66,3 @@ protected:
|
||||
uint64_t filesize;
|
||||
uint64_t pos;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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());
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
@ -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;
|
||||
}
|
||||
|
@ -24,8 +24,7 @@
|
||||
* DirList Class
|
||||
* for WiiXplorer 2010
|
||||
***************************************************************************/
|
||||
#ifndef ___DIRLIST_H_
|
||||
#define ___DIRLIST_H_
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -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();
|
||||
};
|
||||
|
||||
@ -105,14 +104,12 @@ protected:
|
||||
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
|
||||
|
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
@ -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;
|
||||
|
||||
|
@ -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");
|
||||
|
@ -4,10 +4,9 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <nsysnet/socket.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -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>
|
||||
@ -28,7 +27,7 @@ public:
|
||||
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;
|
||||
@ -52,24 +51,24 @@ public:
|
||||
}
|
||||
|
||||
//! 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);
|
||||
}
|
||||
@ -80,30 +79,30 @@ public:
|
||||
}
|
||||
|
||||
//! 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)
|
||||
@ -111,18 +110,18 @@ public:
|
||||
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) {
|
||||
@ -136,6 +135,4 @@ private:
|
||||
uint8_t *pThreadStack;
|
||||
Callback pCallback;
|
||||
void *pCallbackArg;
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
@ -34,7 +34,7 @@ void _SYSLaunchTitleWithStdArgsInNoSplash(uint64_t, uint32_t);
|
||||
}
|
||||
|
||||
TcpReceiver::TcpReceiver(int32_t port)
|
||||
: CThread(CThread::eAttributeAffCore1, 16,0x20000), exitRequested(false), serverPort(port), serverSocket(-1) {
|
||||
: CThread(CThread::eAttributeAffCore1, 16, 0x20000), exitRequested(false), serverPort(port), serverSocket(-1) {
|
||||
|
||||
resumeThread();
|
||||
}
|
||||
@ -58,7 +58,7 @@ void TcpReceiver::executeThread() {
|
||||
uint32_t enable = 1;
|
||||
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
|
||||
|
||||
struct sockaddr_in bindAddress;
|
||||
struct sockaddr_in bindAddress{};
|
||||
memset(&bindAddress, 0, sizeof(bindAddress));
|
||||
bindAddress.sin_family = AF_INET;
|
||||
bindAddress.sin_port = serverPort;
|
||||
@ -76,7 +76,7 @@ void TcpReceiver::executeThread() {
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_in clientAddr;
|
||||
struct sockaddr_in clientAddr{};
|
||||
memset(&clientAddr, 0, sizeof(clientAddr));
|
||||
int32_t addrlen = sizeof(struct sockaddr);
|
||||
|
||||
@ -91,9 +91,9 @@ void TcpReceiver::executeThread() {
|
||||
close(clientSocket);
|
||||
|
||||
if (result > 0)
|
||||
if (result >= 0){
|
||||
break;
|
||||
}
|
||||
if (result >= 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Server socket accept failed %i %d", clientSocket, errno);
|
||||
OSSleepTicks(OSMicrosecondsToTicks(100000));
|
||||
@ -105,6 +105,7 @@ void TcpReceiver::executeThread() {
|
||||
|
||||
|
||||
extern bool gDoRelaunch;
|
||||
|
||||
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress);
|
||||
|
||||
@ -120,13 +121,13 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes
|
||||
}
|
||||
|
||||
struct in_addr in;
|
||||
struct in_addr in{};
|
||||
uint32_t bytesRead = 0;
|
||||
in.s_addr = ipAddress;
|
||||
|
||||
DEBUG_FUNCTION_LINE("transfer start");
|
||||
|
||||
unsigned char *loadAddress = (unsigned char *) memalign(0x40, fileSize);
|
||||
auto *loadAddress = (unsigned char *) memalign(0x40, fileSize);
|
||||
if (!loadAddress) {
|
||||
OSSleepTicks(OSSecondsToTicks(1));
|
||||
return NOT_ENOUGH_MEMORY;
|
||||
@ -160,7 +161,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
|
||||
// Do we need to unzip this thing?
|
||||
if (haxx[4] > 0 || haxx[5] > 4) {
|
||||
unsigned char *inflatedData = NULL;
|
||||
unsigned char *inflatedData = nullptr;
|
||||
|
||||
// We need to unzip...
|
||||
if (loadAddress[0] == 'P' && loadAddress[1] == 'K' && loadAddress[2] == 0x03 && loadAddress[3] == 0x04) {
|
||||
@ -233,7 +234,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
FSUtils::CreateSubfolder(RPX_TEMP_PATH);
|
||||
res = FSUtils::saveBufferToFile(WUHB_TEMP_FILE, inflatedData, fileSize);
|
||||
file_path = WUHB_TEMP_FILE_EX;
|
||||
if(!res){
|
||||
if (!res) {
|
||||
// temp.wuhb might be mounted, let's try temp2.wuhb
|
||||
res = FSUtils::saveBufferToFile(WUHB_TEMP_FILE_2, inflatedData, fileSize);
|
||||
file_path = WUHB_TEMP_FILE_2_EX;
|
||||
@ -253,7 +254,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
std::vector<PluginContainer> finalList;
|
||||
|
||||
finalList.push_back(newContainer.value());
|
||||
for (auto &plugin : oldPlugins) {
|
||||
for (auto &plugin: oldPlugins) {
|
||||
if (plugin.metaInformation.getName() == newContainer->metaInformation.getName() &&
|
||||
plugin.metaInformation.getAuthor() == newContainer->metaInformation.getAuthor()
|
||||
) {
|
||||
@ -265,7 +266,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &plugin : finalList) {
|
||||
for (auto &plugin: finalList) {
|
||||
DEBUG_FUNCTION_LINE("name: %s", plugin.getMetaInformation().getName().c_str());
|
||||
DEBUG_FUNCTION_LINE("author: %s", plugin.getMetaInformation().getAuthor().c_str());
|
||||
DEBUG_FUNCTION_LINE("handle: %08X", plugin.getPluginData().getHandle());
|
||||
|
@ -17,20 +17,18 @@ public:
|
||||
NOT_A_VALID_PLUGIN = -5,
|
||||
};
|
||||
|
||||
TcpReceiver(int32_t port);
|
||||
explicit TcpReceiver(int32_t port);
|
||||
|
||||
~TcpReceiver();
|
||||
~TcpReceiver() override;
|
||||
|
||||
//sigslot::signal2<GuiElement *, uint32_t> serverReceiveStart;
|
||||
//sigslot::signal3<GuiElement *, uint32_t, int32_t> serverReceiveFinished;
|
||||
|
||||
private:
|
||||
|
||||
void executeThread();
|
||||
void executeThread() override;
|
||||
|
||||
int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
||||
|
||||
bool saveFileToSDCard(const char *path, void *buffer, uint32_t size);
|
||||
static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
||||
|
||||
bool exitRequested;
|
||||
int32_t serverPort;
|
||||
|
@ -16,11 +16,11 @@ extern "C" {
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ int32_t recvwait(int32_t sock, void *buffer, int32_t len) {
|
||||
while (socket_lock) {
|
||||
usleep(1000);
|
||||
}
|
||||
socket_lock = 1;
|
||||
int32_t ret;
|
||||
while (len > 0) {
|
||||
ret = recv(sock, buffer, len, 0);
|
||||
@ -45,6 +46,7 @@ int32_t checkbyte(int32_t sock) {
|
||||
while (socket_lock) {
|
||||
usleep(1000);
|
||||
}
|
||||
socket_lock = 1;
|
||||
unsigned char buffer[1];
|
||||
int32_t ret;
|
||||
|
||||
@ -61,6 +63,7 @@ int32_t sendwait(int32_t sock, const void *buffer, int32_t len) {
|
||||
while (socket_lock) {
|
||||
usleep(1000);
|
||||
}
|
||||
socket_lock = 1;
|
||||
int32_t ret;
|
||||
while (len > 0) {
|
||||
// For some reason the send blocks/crashes if the buffer is too big..
|
||||
|
@ -1,5 +1,4 @@
|
||||
#ifndef _UTILS_NET_H_
|
||||
#define _UTILS_NET_H_
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -32,6 +31,4 @@ int32_t sendbyte(int32_t sock, unsigned char byte);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user