mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-03 00:39:02 +00:00
I think the last missing work for v1.0.0? :)
This commit is contained in:
+45
-10
@@ -1,12 +1,22 @@
|
||||
#include "utils/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)
|
||||
{
|
||||
*archive = ARCHIVE_SDMC;
|
||||
FS_Path filePath = {0};
|
||||
unsigned int prefixlen = 0;
|
||||
|
||||
if (!strncmp(path, "ctrnand:/", 9)) {
|
||||
/* if (!strncmp(path, "ctrnand:/", 9)) {
|
||||
*archive = ARCHIVE_NAND_CTR_FS;
|
||||
prefixlen = 8;
|
||||
}
|
||||
@@ -17,8 +27,8 @@ FS_Path getPathInfo(const char * path, FS_ArchiveID * archive)
|
||||
else if (!strncmp(path, "twln:/", 6)) {
|
||||
*archive = ARCHIVE_NAND_TWL_FS;
|
||||
prefixlen = 5;
|
||||
}
|
||||
else if (!strncmp(path, "sdmc:/", 6)) {
|
||||
}*/
|
||||
if (!strncmp(path, "sdmc:/", 6)) {
|
||||
prefixlen = 5;
|
||||
}
|
||||
else if (*path != '/') {
|
||||
@@ -36,9 +46,11 @@ FS_Path getPathInfo(const char * path, FS_ArchiveID * archive)
|
||||
return filePath;
|
||||
}
|
||||
|
||||
Result makeDirs(FS_ArchiveID archiveID, char * path)
|
||||
Result makeDirs(const char * path)
|
||||
{
|
||||
Result ret = 0;
|
||||
FS_ArchiveID archiveID;
|
||||
FS_Path filePath = getPathInfo(path, &archiveID);
|
||||
FS_Archive archive;
|
||||
|
||||
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
|
||||
@@ -46,21 +58,18 @@ Result makeDirs(FS_ArchiveID archiveID, char * path)
|
||||
for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) {
|
||||
char bak = *(slashpos);
|
||||
*(slashpos) = '\0';
|
||||
|
||||
FS_Path dirpath = fsMakePath(PATH_ASCII, path);
|
||||
Handle dirHandle;
|
||||
|
||||
ret = FSUSER_OpenDirectory(&dirHandle, archive, dirpath);
|
||||
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
|
||||
if (R_SUCCEEDED(ret))
|
||||
FSDIR_Close(dirHandle);
|
||||
else
|
||||
ret = FSUSER_CreateDirectory(archive, dirpath, FS_ATTRIBUTE_DIRECTORY);
|
||||
ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
|
||||
|
||||
*(slashpos) = bak;
|
||||
}
|
||||
|
||||
FSUSER_CloseArchive(archive);
|
||||
free(path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -72,7 +81,7 @@ Result openFile(Handle* fileHandle, const char * path, bool write)
|
||||
u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ);
|
||||
|
||||
Result ret = 0;
|
||||
ret = makeDirs(archive, strdup(path));
|
||||
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
|
||||
@@ -91,5 +100,31 @@ Result deleteFile(const char * path)
|
||||
ret = FSUSER_DeleteFile(archive, filePath);
|
||||
FSUSER_CloseArchive(archive);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result removeDir(const char *path) {
|
||||
FS_ArchiveID archiveID;
|
||||
FS_Path filePath = getPathInfo(path, &archiveID);
|
||||
FS_Archive archive;
|
||||
|
||||
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
|
||||
if (R_FAILED(ret)) return ret;
|
||||
ret = FSUSER_DeleteDirectory(archive, filePath);
|
||||
FSUSER_CloseArchive(archive);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result removeDirRecursive(const char *path) {
|
||||
FS_ArchiveID archiveID;
|
||||
FS_Path filePath = getPathInfo(path, &archiveID);
|
||||
FS_Archive archive;
|
||||
|
||||
Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
|
||||
if (R_FAILED(ret)) return ret;
|
||||
ret = FSUSER_DeleteDirectoryRecursively(archive, filePath);
|
||||
FSUSER_CloseArchive(archive);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user