More WIP on moving to taking native paths

This commit is contained in:
UnknownShadow200 2024-06-17 18:58:11 +10:00
parent 7899dd51d5
commit 932fca0b0b
25 changed files with 119 additions and 153 deletions

View File

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

View File

@ -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. */

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) { }

View File

@ -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) { }

View File

@ -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) { }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) */

View File

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

View File

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

View File

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