WIP: Script-Creator!

This commit is contained in:
StackZ
2020-06-21 16:41:48 +02:00
parent 984d363533
commit 91615d7891
8 changed files with 131 additions and 155 deletions
+7 -35
View File
@@ -1,33 +1,11 @@
#include "files.h"
// Blacklist!
#define BLACKLIST_CTRNAND "ctrnand:/"
#define BLACKLIST_TWLP "twlp:/"
#define BLACKLIST_TWLN "twln:/"
#define BLACKLIST_SDROOT "sdmc:/"
#define BLACKLIST_ROOT "/"
#define BLACKLIST_NINTENDO3DS "sdmc:/Nintendo 3DS"
#define BLACKLIST_NINTENDO3DS2 "/Nintendo"
FS_Path getPathInfo(const char * path, FS_ArchiveID * archive)
{
FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) {
*archive = ARCHIVE_SDMC;
FS_Path filePath = {0};
unsigned int prefixlen = 0;
/* if (!strncmp(path, "ctrnand:/", 9)) {
*archive = ARCHIVE_NAND_CTR_FS;
prefixlen = 8;
}
else if (!strncmp(path, "twlp:/", 6)) {
*archive = ARCHIVE_TWL_PHOTO;
prefixlen = 5;
}
else if (!strncmp(path, "twln:/", 6)) {
*archive = ARCHIVE_NAND_TWL_FS;
prefixlen = 5;
}*/
if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5;
}
@@ -46,8 +24,7 @@ FS_Path getPathInfo(const char * path, FS_ArchiveID * archive)
return filePath;
}
Result makeDirs(const char * path)
{
Result makeDirs(const char * path) {
Result ret = 0;
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
@@ -61,10 +38,8 @@ Result makeDirs(const char * path)
Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret))
FSDIR_Close(dirHandle);
else
ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle);
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak;
}
@@ -74,8 +49,7 @@ Result makeDirs(const char * path)
return ret;
}
Result openFile(Handle* fileHandle, const char * path, bool write)
{
Result openFile(Handle* fileHandle, const char * path, bool write) {
FS_ArchiveID archive;
FS_Path filePath = getPathInfo(path, &archive);
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
@@ -83,14 +57,12 @@ Result openFile(Handle* fileHandle, const char * path, bool write)
Result ret = 0;
ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0);
if (write)
ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing
if (write) ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing
return ret;
}
Result deleteFile(const char * path)
{
Result deleteFile(const char * path) {
FS_ArchiveID archiveID;
FS_Path filePath = getPathInfo(path, &archiveID);
+3 -3
View File
@@ -29,11 +29,11 @@
// adapted from GM9i's byte parsing.
std::string formatBytes(int bytes) {
char out[32];
if(bytes == 1)
if (bytes == 1)
snprintf(out, sizeof(out), "%d Byte", bytes);
else if(bytes < 1024)
else if (bytes < 1024)
snprintf(out, sizeof(out), "%d Bytes", bytes);
else if(bytes < 1024 * 1024)
else if (bytes < 1024 * 1024)
snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
else if (bytes < 1024 * 1024 * 1024)
snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
+7 -14
View File
@@ -24,8 +24,7 @@ typedef struct _WavHeader {
} WavHeader;
static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes.");
sound::sound(const string& path, int channel, bool toloop)
{
sound::sound(const string& path, int channel, bool toloop) {
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
ndspSetOutputCount(2); // Num of buffers
@@ -58,8 +57,7 @@ sound::sound(const string& path, int channel, bool toloop)
if (wavHeader.totallength == 0 ||
(wavHeader.channels != 1 && wavHeader.channels != 2) ||
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16))
{
(wavHeader.bits_per_sample != 8 && wavHeader.bits_per_sample != 16)) {
// Unsupported WAV file.
printf("Corrupted wav file.\n");
fclose(fp);
@@ -104,8 +102,7 @@ sound::sound(const string& path, int channel, bool toloop)
chnl = channel;
}
sound::~sound()
{
sound::~sound() {
waveBuf.data_vaddr = 0;
waveBuf.nsamples = 0;
waveBuf.looping = false;
@@ -117,17 +114,13 @@ sound::~sound()
}
}
void sound::play()
{
if (!data)
return;
void sound::play() {
if (!data) return;
DSP_FlushDataCache(data, dataSize);
ndspChnWaveBufAdd(chnl, &waveBuf);
}
void sound::stop()
{
if (!data)
return;
void sound::stop() {
if (!data) return;
ndspChnWaveBufClear(chnl);
}
+2 -4
View File
@@ -1,13 +1,11 @@
#include "stringutils.hpp"
bool matchPattern(std::string pattern, std::string tested)
{
bool matchPattern(std::string pattern, std::string tested) {
std::regex patternRegex(pattern);
return regex_match(tested, patternRegex);
}
std::string StringUtils::format(const std::string& fmt_str, ...)
{
std::string StringUtils::format(const std::string& fmt_str, ...) {
va_list ap;
char* fp = NULL;
va_start(ap, fmt_str);