diff --git a/src/Chat.c b/src/Chat.c index b7aed8244..0c0f7236d 100644 --- a/src/Chat.c +++ b/src/Chat.c @@ -99,6 +99,7 @@ void Chat_DisableLogging(void) { static cc_bool CreateLogsDirectory(void) { static const cc_string dir = String_FromConst("logs"); + cc_filepath str; cc_result res; /* Utils_EnsureDirectory cannot be used here because it causes a stack overflow */ /* when running the game and an error occurs when trying to create the directory */ @@ -111,7 +112,8 @@ static cc_bool CreateLogsDirectory(void) { /* --> Utils_EnsureDirectory --> Logger_SysWarn2 --> Chat_Add --> AppendChatLog -> OpenChatLog */ /* --> Utils_EnsureDirectory --> Logger_SysWarn2 --> Chat_Add --> AppendChatLog ... */ /* and so on, until eventually the stack overflows */ - res = Directory_Create(&dir); + Platform_EncodePath(&str, &dir); + res = Directory_Create(&str); if (!res || res == ReturnCode_DirectoryExists) return true; Chat_DisableLogging(); diff --git a/src/Platform.h b/src/Platform.h index 1c5197b0d..fe551df5a 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -192,7 +192,7 @@ CC_API cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end); int Stopwatch_ElapsedMS(cc_uint64 beg, cc_uint64 end); /* Attempts to create a new directory. */ -CC_API cc_result Directory_Create(const cc_string* path); +cc_result Directory_Create(cc_filepath_ptr path); /* Callback function invoked for each file found. */ typedef void (*Directory_EnumCallback)(const cc_string* filename, void* obj, int isDirectory); /* Invokes a callback function on all filenames in the given directory (and its sub-directories) */ @@ -203,11 +203,11 @@ void Directory_GetCachePath(cc_string* path); /* Attempts to create a new (or overwrite) file for writing. */ /* NOTE: If the file already exists, its contents are discarded. */ -cc_result File_Create(cc_file* file, const cc_filepath_ptr path); +cc_result File_Create(cc_file* file, cc_filepath_ptr path); /* Attempts to open an existing file for reading. */ -cc_result File_Open(cc_file* file, const cc_filepath_ptr path); +cc_result File_Open(cc_file* file, cc_filepath_ptr path); /* Attempts to open an existing or create a new file for reading and writing. */ -cc_result File_OpenOrCreate(cc_file* file, const cc_filepath_ptr path); +cc_result File_OpenOrCreate(cc_file* file, cc_filepath_ptr path); /* Attempts to read data from the file. */ cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead); /* Attempts to write data to the file. */ diff --git a/src/Platform_3DS.c b/src/Platform_3DS.c index ab7c35a51..3925f87dc 100644 --- a/src/Platform_3DS.c +++ b/src/Platform_3DS.c @@ -97,11 +97,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); - - return mkdir(str, 0666) == -1 ? errno : 0; // FS has no permissions anyways +cc_result Directory_Create(char* path) { + return mkdir(path, 0666) == -1 ? errno : 0; // FS has no permissions anyways } int File_Exists(const cc_string* path) { @@ -152,13 +149,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT); } diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index 99024be74..217139ad8 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -193,11 +193,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); - - int res = fs_mkdir(str); +cc_result Directory_Create(char* path) { + int res = fs_mkdir(path); int err = res == -1 ? errno : 0; // Filesystem returns EINVAL when operation unsupported (e.g. CD system) @@ -252,7 +249,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return err; } -static cc_result File_Do(cc_file* file, const char* path, int mode) { +static cc_result File_Do(cc_file* file, char* path, int mode) { // CD filesystem loader doesn't usually set errno // when it can't find the requested file errno = 0; @@ -271,13 +268,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return err; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT); } diff --git a/src/Platform_GCWii.c b/src/Platform_GCWii.c index e2cd88ad8..81a8e6cfa 100644 --- a/src/Platform_GCWii.c +++ b/src/Platform_GCWii.c @@ -126,12 +126,10 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { if (!fat_available) return ENOSYS; - - cc_filepath str;; - Platform_EncodePath(str, path); - return mkdir(str, 0) == -1 ? errno : 0; + + return mkdir(path, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -183,22 +181,22 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return res; } -static cc_result File_Do(cc_file* file, const char* path, int mode) { +static cc_result File_Do(cc_file* file, char* path, int mode) { *file = open(path, mode, 0); return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { if (!fat_available) return ReturnCode_FileNotFound; return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { if (!fat_available) return ENOTSUP; return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { if (!fat_available) return ENOTSUP; return File_Do(file, path, O_RDWR | O_CREAT); } diff --git a/src/Platform_MacClassic.c b/src/Platform_MacClassic.c index d22ab672b..6273614e4 100644 --- a/src/Platform_MacClassic.c +++ b/src/Platform_MacClassic.c @@ -231,10 +231,8 @@ static int DoCreateFolder(char* name) { void Directory_GetCachePath(cc_string* path) { } -cc_result Directory_Create(const cc_string* path) { - char buffer[NATIVE_STR_LEN]; - Platform_EncodePath(buffer, path); - return DoCreateFolder(buffer); +cc_result Directory_Create(char* path) { + return DoCreateFolder(path); } int File_Exists(const cc_string* path) { @@ -248,18 +246,18 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return DoOpenDF(path, fsRdPerm, file); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { int res = DoCreateFile(path); if (res && res != dupFNErr) return res; return DoOpenDF(path, fsWrPerm, file); } -cc_result File_OpenOrCreate(cc_file* file, const cc_string* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { int res = DoCreateFile(path); if (res && res != dupFNErr) return res; diff --git a/src/Platform_N64.c b/src/Platform_N64.c index 588ef30fe..da239b617 100644 --- a/src/Platform_N64.c +++ b/src/Platform_N64.c @@ -81,7 +81,7 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, &path_); } -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { return ERR_NOT_SUPPORTED; } @@ -93,7 +93,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; // TODO add support } -static cc_result File_Do(cc_file* file, const char* path) { +static cc_result File_Do(cc_file* file, char* path) { //*file = -1; //return ReturnCode_FileNotFound; // TODO: Why does trying this code break everything @@ -106,15 +106,15 @@ static cc_result File_Do(cc_file* file, const char* path) { return 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { *file = -1; return ERR_NOT_SUPPORTED; //return File_Do(file, path); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { *file = -1; return ERR_NOT_SUPPORTED; //return File_Do(file, path); diff --git a/src/Platform_NDS.c b/src/Platform_NDS.c index d08164598..7b9cb0028 100644 --- a/src/Platform_NDS.c +++ b/src/Platform_NDS.c @@ -115,14 +115,11 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { if (!fat_available) return 0; - cc_filepath str; - Platform_EncodePath(str, path); - Platform_Log1("mkdir %c", str); - - return mkdir(str, 0) == -1 ? errno : 0; + Platform_Log1("mkdir %c", path); + return mkdir(path, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -173,24 +170,24 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return res; } -static cc_result File_Do(cc_file* file, const char* path, int mode, const char* type) { +static cc_result File_Do(cc_file* file, char* path, int mode, const char* type) { Platform_Log2("%c %c", type, path); *file = open(path, mode, 0); return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { if (!fat_available) return ReturnCode_FileNotFound; return File_Do(file, path, O_RDONLY, "Open"); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { if (!fat_available) return ENOTSUP; return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC, "Create"); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { if (!fat_available) return ENOTSUP; return File_Do(file, path, O_RDWR | O_CREAT, "Update"); } diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c index 18e780fda..0ae0612f3 100644 --- a/src/Platform_PS1.c +++ b/src/Platform_PS1.c @@ -93,7 +93,7 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { return ERR_NOT_SUPPORTED; } @@ -109,11 +109,11 @@ cc_result File_Open(cc_file* file, const char* path) { return ERR_NOT_SUPPORTED; } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return ERR_NOT_SUPPORTED; } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return ERR_NOT_SUPPORTED; } diff --git a/src/Platform_PS2.c b/src/Platform_PS2.c index f32528dc1..ea0d0ad67 100644 --- a/src/Platform_PS2.c +++ b/src/Platform_PS2.c @@ -113,10 +113,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); - return fioMkdir(str); +cc_result Directory_Create(char* path) { + return fioMkdir(path); } int File_Exists(const cc_string* path) { @@ -180,13 +178,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return res < 0 ? res : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, FIO_O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, FIO_O_RDWR | FIO_O_CREAT | FIO_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, FIO_O_RDWR | FIO_O_CREAT); } diff --git a/src/Platform_PS3.c b/src/Platform_PS3.c index 2f7623a8e..d65ac91ba 100644 --- a/src/Platform_PS3.c +++ b/src/Platform_PS3.c @@ -101,12 +101,10 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); +cc_result Directory_Create(char* path) { /* read/write/search permissions for owner and group, and with read/search permissions for others. */ /* TODO: Is the default mode in all cases */ - return sysLv2FsMkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + return sysLv2FsMkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); } int File_Exists(const cc_string* path) { @@ -166,13 +164,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { } } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, SYS_O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, SYS_O_RDWR | SYS_O_CREAT | SYS_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, SYS_O_RDWR | SYS_O_CREAT); } @@ -446,8 +444,7 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) { *#########################################################################################################################*/ void Platform_Init(void) { netInitialize(); - // Create root directory - Directory_Create(&String_Empty); + Directory_Create(root_path.buffer); } void Platform_Free(void) { } diff --git a/src/Platform_PSP.c b/src/Platform_PSP.c index df1a08fce..3fa627b7a 100644 --- a/src/Platform_PSP.c +++ b/src/Platform_PSP.c @@ -94,10 +94,7 @@ void Platform_EncodePath(char* str, const cc_string* path) { #define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF) -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); - +cc_result Directory_Create(char* path) { int result = sceIoMkdir(str, 0777); return GetSCEResult(result); } @@ -147,13 +144,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return GetSCEResult(result); } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, PSP_O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, PSP_O_RDWR | PSP_O_CREAT); } @@ -431,9 +428,8 @@ void Platform_Init(void) { // *tx = vel->x == 0.0f ? MATH_LARGENUM : Math_AbsF(dx / vel->x); // TODO: work out why this error is actually happening (inexact or underflow?) and properly fix it pspSdkDisableFPUExceptions(); - - // Create root directory - Directory_Create(&String_Empty); + + Directory_Create(root_path.buffer); } void Platform_Free(void) { } diff --git a/src/Platform_PSVita.c b/src/Platform_PSVita.c index 6bd5c370e..0b53f69e3 100644 --- a/src/Platform_PSVita.c +++ b/src/Platform_PSVita.c @@ -77,11 +77,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { #define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF) -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); - - int result = sceIoMkdir(str, 0777); +cc_result Directory_Create(char* path) { + int result = sceIoMkdir(path, 0777); return GetSCEResult(result); } @@ -130,13 +127,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return GetSCEResult(result); } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, SCE_O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, SCE_O_RDWR | SCE_O_CREAT); } @@ -388,8 +385,7 @@ void Platform_Init(void) { /*pspDebugSioInit();*/ InitNetworking(); epoll_id = sceNetEpollCreate("CC poll", 0); - // Create root directory - Directory_Create(&String_Empty); + Directory_Create(root_path.buffer); } void Platform_Free(void) { } diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index 488699ab4..e162cc5bf 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -201,12 +201,10 @@ void Platform_EncodePath(char* str, const cc_string* path) { void Directory_GetCachePath(cc_string* path) { } #endif -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); +cc_result Directory_Create(char* path) { /* read/write/search permissions for owner and group, and with read/search permissions for others. */ /* TODO: Is the default mode in all cases */ - return mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; + return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -272,21 +270,21 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { #if !defined CC_BUILD_OS2 return File_Do(file, path, O_RDONLY); #else return File_Do(file, path, O_RDONLY | O_BINARY); #endif } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { #if !defined CC_BUILD_OS2 return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); #else return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY); #endif } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { #if !defined CC_BUILD_OS2 return File_Do(file, path, O_RDWR | O_CREAT); #else diff --git a/src/Platform_Saturn.c b/src/Platform_Saturn.c index ca7e719b2..e884af59a 100644 --- a/src/Platform_Saturn.c +++ b/src/Platform_Saturn.c @@ -89,7 +89,7 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { return ERR_NOT_SUPPORTED; } @@ -101,15 +101,15 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall return ERR_NOT_SUPPORTED; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return ERR_NOT_SUPPORTED; } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return ERR_NOT_SUPPORTED; } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return ERR_NOT_SUPPORTED; } diff --git a/src/Platform_Switch.c b/src/Platform_Switch.c index 277283d4b..b93677b21 100644 --- a/src/Platform_Switch.c +++ b/src/Platform_Switch.c @@ -115,10 +115,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); - return mkdir(str, 0) == -1 ? errno : 0; +cc_result Directory_Create(char* path) { + return mkdir(path, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -171,13 +169,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT); } diff --git a/src/Platform_Web.c b/src/Platform_Web.c index b4db53390..970b348b6 100644 --- a/src/Platform_Web.c +++ b/src/Platform_Web.c @@ -107,7 +107,7 @@ void Platform_EncodePath(char* str, const cc_string* path) { void Directory_GetCachePath(cc_string* path) { } extern void interop_InitFilesystem(void); -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { /* Web filesystem doesn't need directories */ return 0; } @@ -152,13 +152,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { } } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT); } diff --git a/src/Platform_WiiU.c b/src/Platform_WiiU.c index e0cf5ff42..36ec1d1a4 100644 --- a/src/Platform_WiiU.c +++ b/src/Platform_WiiU.c @@ -109,12 +109,10 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; - Platform_EncodePath(str, path); +cc_result Directory_Create(char* path) { /* read/write/search permissions for owner and group, and with read/search permissions for others. */ /* TODO: Is the default mode in all cases */ - return mkdir(str, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; + return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { diff --git a/src/Platform_Windows.c b/src/Platform_Windows.c index 6ed7a7aec..282edc7d5 100644 --- a/src/Platform_Windows.c +++ b/src/Platform_Windows.c @@ -184,16 +184,13 @@ void Platform_EncodePath(cc_filepath_ptr dst, const cc_string* src) { Platform_EncodeString(dst, src); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str; +cc_result Directory_Create(cc_filepath_ptr path) { cc_result res; - - Platform_EncodePath(&str, path); - if (CreateDirectoryW(str.uni, NULL)) return 0; + if (CreateDirectoryW(path->uni, NULL)) return 0; /* Windows 9x does not support W API functions */ if ((res = GetLastError()) != ERROR_CALL_NOT_IMPLEMENTED) return res; - return CreateDirectoryA(str.ansi, NULL) ? 0 : GetLastError(); + return CreateDirectoryA(path->ansi, NULL) ? 0 : GetLastError(); } int File_Exists(const cc_string* path) { @@ -283,13 +280,13 @@ static cc_result DoFile(cc_file* file, const cc_filepath* path, DWORD access, DW return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError(); } -cc_result File_Open(cc_file* file, const cc_filepath_ptr path) { +cc_result File_Open(cc_file* file, cc_filepath_ptr path) { return DoFile(file, path, GENERIC_READ, OPEN_EXISTING); } -cc_result File_Create(cc_file* file, const cc_filepath_ptr path) { +cc_result File_Create(cc_file* file, cc_filepath_ptr path) { return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS); } -cc_result File_OpenOrCreate(cc_file* file, const cc_filepath_ptr path) { +cc_result File_OpenOrCreate(cc_file* file, cc_filepath_ptr path) { return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS); } diff --git a/src/Platform_Xbox.c b/src/Platform_Xbox.c index 0340f1904..e981f3931 100644 --- a/src/Platform_Xbox.c +++ b/src/Platform_Xbox.c @@ -100,14 +100,10 @@ void Platform_EncodePath(char* str, const cc_string* src) { *str = '\0'; } -cc_result Directory_Create(const cc_string* path) { +cc_result Directory_Create(char* path) { if (!hdd_mounted) return ERR_NOT_SUPPORTED; - cc_filepath str; - cc_result res; - - Platform_EncodePath(str, path); - return CreateDirectoryA(str, NULL) ? 0 : GetLastError(); + return CreateDirectoryA(path, NULL) ? 0 : GetLastError(); } int File_Exists(const cc_string* path) { @@ -172,17 +168,17 @@ static cc_result DoFile(cc_file* file, const char* path, DWORD access, DWORD cre return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError(); } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { if (!hdd_mounted) return ReturnCode_FileNotFound; return DoFile(file, path, GENERIC_READ, OPEN_EXISTING); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { if (!hdd_mounted) return ERR_NOT_SUPPORTED; return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { if (!hdd_mounted) return ERR_NOT_SUPPORTED; return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS); } @@ -415,7 +411,7 @@ static void InitHDD(void) { Platform_LogConst("Failed to mount E:/ from Data partition"); return; } - Directory_Create(&String_Empty); // create root ClassiCube folder + Directory_Create(root_path.buffer); } void Platform_Init(void) { diff --git a/src/Platform_Xbox360.c b/src/Platform_Xbox360.c index adc0c4a4d..0a5565270 100644 --- a/src/Platform_Xbox360.c +++ b/src/Platform_Xbox360.c @@ -84,10 +84,8 @@ void Platform_EncodePath(char* str, const cc_string* path) { String_EncodeUtf8(str, path); } -cc_result Directory_Create(const cc_string* path) { - cc_filepath str;; - Platform_EncodePath(str, path); - return mkdir(str, 0) == -1 ? errno : 0; +cc_result Directory_Create(char* path) { + return mkdir(path, 0) == -1 ? errno : 0; } int File_Exists(const cc_string* path) { @@ -140,13 +138,13 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) { return *file == -1 ? errno : 0; } -cc_result File_Open(cc_file* file, const char* path) { +cc_result File_Open(cc_file* file, char* path) { return File_Do(file, path, O_RDONLY); } -cc_result File_Create(cc_file* file, const char* path) { +cc_result File_Create(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC); } -cc_result File_OpenOrCreate(cc_file* file, const char* path) { +cc_result File_OpenOrCreate(cc_file* file, char* path) { return File_Do(file, path, O_RDWR | O_CREAT); } diff --git a/src/TexturePack.c b/src/TexturePack.c index af50b9bab..b66c58635 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -255,11 +255,13 @@ CC_INLINE static void HashUrl(cc_string* key, const cc_string* url) { static cc_bool createdCache, cacheInvalid; static cc_bool UseDedicatedCache(cc_string* path, const cc_string* key) { cc_result res; + cc_filepath str; Directory_GetCachePath(path); if (!path->length || cacheInvalid) return false; String_AppendConst(path, "/texturecache"); - res = Directory_Create(path); + Platform_EncodePath(&str, path); + res = Directory_Create(&str); /* Check if something is deleting the cache directory behind our back */ /* (Several users have reported this happening on some Android devices) */ diff --git a/src/Utils.c b/src/Utils.c index 6ec7a57b7..8fffdaeea 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -24,8 +24,13 @@ cc_bool Utils_IsUrlPrefix(const cc_string* value) { } cc_bool Utils_EnsureDirectory(const char* dirName) { - cc_string dir = String_FromReadonly(dirName); - cc_result res = Directory_Create(&dir); + cc_filepath path; + cc_string dir; + cc_result res; + + dir = String_FromReadonly(dirName); + Platform_EncodePath(&path, &dir); + res = Directory_Create(&path); if (!res || res == ReturnCode_DirectoryExists) return true; Logger_SysWarn2(res, "creating directory", &dir); diff --git a/src/Window_Android.c b/src/Window_Android.c index 7167e8454..70f52e6c6 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -450,12 +450,11 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* save_args) { if (!save_args->defaultName.length) return SFD_ERR_NEED_DEFAULT_NAME; // save the item to a temp file, which is then (usually) later deleted by intent callback - cc_string tmpDir = String_FromConst("Exported"); - Directory_Create(&tmpDir); + Directory_Create("Exported"); cc_string path; char pathBuffer[FILENAME_SIZE]; String_InitArray(path, pathBuffer); - String_Format3(&path, "%s/%s%c", &tmpDir, &save_args->defaultName, save_args->filters[0]); + String_Format2(&path, "Exported/%s%c", &save_args->defaultName, save_args->filters[0]); save_args->Callback(&path); // TODO kinda ugly, maybe a better way? cc_string file = String_UNSAFE_SubstringAt(&path, String_IndexOf(&path, '/') + 1); diff --git a/src/interop_ios.m b/src/interop_ios.m index c496aa5e5..48d726b40 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -668,11 +668,10 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { // UIDocumentPickerViewController - iOS 8.0 // save the item to a temp file, which is then (usually) later deleted by picker callbacks - cc_string tmpDir = String_FromConst("Exported"); - Directory_Create(&tmpDir); + Directory_Create("Exported"); save_path.length = 0; - String_Format3(&save_path, "%s/%s%c", &tmpDir, &args->defaultName, args->filters[0]); + String_Format2(&save_path, "Exported/%s%c", &args->defaultName, args->filters[0]); args->Callback(&save_path); NSString* str = ToNSString(&save_path);