From 2dcd466f9715341952dc6eb21a2dc84c2641198e Mon Sep 17 00:00:00 2001 From: Joel16 Date: Thu, 2 Aug 2018 23:08:33 -0500 Subject: [PATCH] Update FS functions Removed FS_RecursiveMakeDir because it is unused. --- common/fs.c | 22 ++++++++++++++++------ common/fs.h | 9 ++++----- common/screenshot.c | 9 ++++----- common/utils.c | 10 ++++++++++ common/utils.h | 1 + 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/common/fs.c b/common/fs.c index 130312d..f9e163f 100644 --- a/common/fs.c +++ b/common/fs.c @@ -2,8 +2,9 @@ #include #include "fs.h" +#include "utils.h" -Result FS_OpenArchive(FS_Archive * archive, FS_ArchiveID archiveID) +Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) { Result ret = 0; @@ -23,11 +24,14 @@ Result FS_CloseArchive(FS_Archive archive) return 0; } -Result FS_MakeDir(FS_Archive archive, const char * path) +Result FS_MakeDir(FS_Archive archive, const char *path) { Result ret = 0; - if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, path), 0))) + u16 path_u16[strlen(path) + 1]; + Utils_U8_To_U16(path_u16, path, strlen(path) + 1); + + if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_UTF16, path_u16), 0))) return ret; return 0; @@ -67,7 +71,10 @@ bool FS_FileExists(FS_Archive archive, const char * path) { Handle handle; - if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_READ, 0))) + u16 path_u16[strlen(path) + 1]; + Utils_U8_To_U16(path_u16, path, strlen(path) + 1); + + if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0))) return false; if (R_FAILED(FSFILE_Close(handle))) @@ -76,11 +83,14 @@ bool FS_FileExists(FS_Archive archive, const char * path) return true; } -bool FS_DirExists(FS_Archive archive, const char * path) +bool FS_DirExists(FS_Archive archive, const char *path) { Handle handle; - if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_ASCII, path)))) + u16 path_u16[strlen(path) + 1]; + Utils_U8_To_U16(path_u16, path, strlen(path) + 1); + + if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16)))) return false; if (R_FAILED(FSDIR_Close(handle))) diff --git a/common/fs.h b/common/fs.h index d645339..9180c80 100644 --- a/common/fs.h +++ b/common/fs.h @@ -5,11 +5,10 @@ FS_Archive archive; -Result FS_OpenArchive(FS_Archive * archive, FS_ArchiveID id); +Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID); Result FS_CloseArchive(FS_Archive archive); -Result FS_MakeDir(FS_Archive archive, const char * path); -Result FS_RecursiveMakeDir(FS_Archive archive, const char * dir); -bool FS_FileExists(FS_Archive archive, const char * path); -bool FS_DirExists(FS_Archive archive, const char * path); +Result FS_MakeDir(FS_Archive archive, const char *path); +bool FS_FileExists(FS_Archive archive, const char *path); +bool FS_DirExists(FS_Archive archive, const char *path); #endif \ No newline at end of file diff --git a/common/screenshot.c b/common/screenshot.c index 5b25a2d..039ebef 100644 --- a/common/screenshot.c +++ b/common/screenshot.c @@ -1,5 +1,4 @@ #include <3ds.h> - #include #include #include @@ -9,7 +8,7 @@ static int num = 0; -static Result generateScreenshot(const char * path) +static Result generateScreenshot(const char *path) { int x = 0, y = 0; Handle handle; @@ -19,15 +18,15 @@ static Result generateScreenshot(const char * path) Result ret = 0; // Get top/bottom framebuffers - u8 * gfxBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL); - u8 * gfxTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); + u8 *gfxBottom = gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, NULL, NULL); + u8 *gfxTopLeft = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); // Open file for writing screenshot if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), (FS_OPEN_CREATE | FS_OPEN_WRITE), 0))) return ret; // Some - u8 * buf = (u8*)malloc(size + 576000); + u8 *buf = (u8*)malloc(size + 576000); memset(buf, 0, size + 576000); buf[size + 576000] = 0; diff --git a/common/utils.c b/common/utils.c index e101a19..c9accc8 100644 --- a/common/utils.c +++ b/common/utils.c @@ -40,6 +40,16 @@ void Utils_U16_To_U8(char *buf, const u16 *input, size_t bufsize) buf[units] = 0; } +void Utils_U8_To_U16(u16 *buf, const char *input, size_t bufsize) +{ + ssize_t units = utf8_to_utf16(buf, (const uint8_t*)input, bufsize); + + if (units < 0) + units = 0; + + buf[units] = 0; +} + char *Utils_ExtractBetween(const char *string, const char *str1, const char *str2) { const char *i1 = strstr(string, str1); diff --git a/common/utils.h b/common/utils.h index a3cdff8..5596ca4 100644 --- a/common/utils.h +++ b/common/utils.h @@ -6,6 +6,7 @@ void Utils_GetSizeString(char *string, uint64_t size); bool Utils_IsN3DS(void); void Utils_U16_To_U8(char *buf, const u16 *input, size_t bufsize); +void Utils_U8_To_U16(u16 *buf, const char *input, size_t bufsize); char *Utils_ExtractBetween(const char *string, const char *str1, const char *str2); char *Utils_Base64Encode(u8 const *bytesToEnc, size_t bufLen);