From 6c530c44bdc174fbbefc8c1c99178cbb023edee8 Mon Sep 17 00:00:00 2001 From: Tobi-D7 Date: Thu, 14 Apr 2022 10:37:12 +0200 Subject: [PATCH] Fix --- external/fs.c | 27 +++++++++++++++++++++++++++ external/fs.h | 1 + 2 files changed, 28 insertions(+) diff --git a/external/fs.c b/external/fs.c index ad7caf5..f93b4bb 100644 --- a/external/fs.c +++ b/external/fs.c @@ -5,6 +5,9 @@ #include #include +#include + +#define WORKING_DIR "/" void Utils_U8_To_U16(u16 *buf, const u8 *input, size_t bufsize) { ssize_t units = utf8_to_utf16(buf, input, bufsize); @@ -344,6 +347,30 @@ FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) { return filePath; } +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, "")); + + for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) { + char bak = *(slashpos); + *(slashpos) = '\0'; + Handle dirHandle; + + ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath); + if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle); + else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY); + + *(slashpos) = bak; + } + + FSUSER_CloseArchive(archive); + + return ret; +} Result openFile(Handle* fileHandle, const char * path, bool write) { FS_ArchiveID archive; diff --git a/external/fs.h b/external/fs.h index bd960b0..1e1a574 100644 --- a/external/fs.h +++ b/external/fs.h @@ -26,6 +26,7 @@ Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf); Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size); char *FS_GetFileTimestamp(const char *path); +Result makeDirs(const char * path); Result openFile(Handle* fileHandle, const char * path, bool write); #endif \ No newline at end of file