Update FS functions

Removed FS_RecursiveMakeDir because it is unused.
This commit is contained in:
Joel16 2018-08-02 23:08:33 -05:00
parent 833fbad1c4
commit 2dcd466f97
5 changed files with 35 additions and 16 deletions

View File

@ -2,6 +2,7 @@
#include <string.h>
#include "fs.h"
#include "utils.h"
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID)
{
@ -27,7 +28,10 @@ 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)))
@ -80,7 +87,10 @@ 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)))

View File

@ -5,10 +5,9 @@
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);

View File

@ -1,5 +1,4 @@
#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -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);

View File

@ -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);