mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
More WIP on moving to taking native paths
This commit is contained in:
parent
932fca0b0b
commit
1069733086
@ -54,12 +54,11 @@ cc_bool Platform_DescribeErrorExt(cc_result res, cc_string* dst, void* lib);
|
|||||||
|
|
||||||
#ifdef CC_BUILD_WIN
|
#ifdef CC_BUILD_WIN
|
||||||
typedef cc_winstring cc_filepath;
|
typedef cc_winstring cc_filepath;
|
||||||
typedef cc_winstring* cc_filepath_ptr;
|
|
||||||
#else
|
#else
|
||||||
typedef char cc_filepath[NATIVE_STR_LEN];
|
typedef struct cc_filepath_ { char buffer[NATIVE_STR_LEN]; } cc_filepath;
|
||||||
typedef char* cc_filepath_ptr;
|
#define FILEPATH_RAW(raw) ((cc_filepath*)raw)
|
||||||
#endif
|
#endif
|
||||||
void Platform_EncodePath(cc_filepath_ptr dst, const cc_string* src);
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* src);
|
||||||
|
|
||||||
/* Initialises the platform specific state. */
|
/* Initialises the platform specific state. */
|
||||||
void Platform_Init(void);
|
void Platform_Init(void);
|
||||||
@ -192,7 +191,7 @@ CC_API cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end);
|
|||||||
int Stopwatch_ElapsedMS(cc_uint64 beg, cc_uint64 end);
|
int Stopwatch_ElapsedMS(cc_uint64 beg, cc_uint64 end);
|
||||||
|
|
||||||
/* Attempts to create a new directory. */
|
/* Attempts to create a new directory. */
|
||||||
cc_result Directory_Create(cc_filepath_ptr path);
|
cc_result Directory_Create(const cc_filepath* path);
|
||||||
/* Callback function invoked for each file found. */
|
/* Callback function invoked for each file found. */
|
||||||
typedef void (*Directory_EnumCallback)(const cc_string* filename, void* obj, int isDirectory);
|
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) */
|
/* Invokes a callback function on all filenames in the given directory (and its sub-directories) */
|
||||||
@ -203,11 +202,11 @@ void Directory_GetCachePath(cc_string* path);
|
|||||||
|
|
||||||
/* Attempts to create a new (or overwrite) file for writing. */
|
/* Attempts to create a new (or overwrite) file for writing. */
|
||||||
/* NOTE: If the file already exists, its contents are discarded. */
|
/* NOTE: If the file already exists, its contents are discarded. */
|
||||||
cc_result File_Create(cc_file* file, cc_filepath_ptr path);
|
cc_result File_Create(cc_file* file, const cc_filepath* path);
|
||||||
/* Attempts to open an existing file for reading. */
|
/* Attempts to open an existing file for reading. */
|
||||||
cc_result File_Open(cc_file* file, cc_filepath_ptr path);
|
cc_result File_Open(cc_file* file, const cc_filepath* path);
|
||||||
/* Attempts to open an existing or create a new file for reading and writing. */
|
/* Attempts to open an existing or create a new file for reading and writing. */
|
||||||
cc_result File_OpenOrCreate(cc_file* file, cc_filepath_ptr path);
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path);
|
||||||
/* Attempts to read data from the file. */
|
/* Attempts to read data from the file. */
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead);
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead);
|
||||||
/* Attempts to write data to the file. */
|
/* Attempts to write data to the file. */
|
||||||
|
@ -91,14 +91,15 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("sdmc:/3ds/ClassiCube/");
|
static const cc_string root_path = String_FromConst("sdmc:/3ds/ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return mkdir(path, 0666) == -1 ? errno : 0; // FS has no permissions anyways
|
return mkdir(path->buffer, 0666) == -1 ? errno : 0; // FS has no permissions anyways
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -149,14 +150,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -187,14 +187,15 @@ static cc_result VMUFile_Close(cc_file file) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static cc_string root_path = String_FromConst("/cd/");
|
static cc_string root_path = String_FromConst("/cd/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path {
|
||||||
int res = fs_mkdir(path);
|
int res = fs_mkdir(path->buffer);
|
||||||
int err = res == -1 ? errno : 0;
|
int err = res == -1 ? errno : 0;
|
||||||
|
|
||||||
// Filesystem returns EINVAL when operation unsupported (e.g. CD system)
|
// Filesystem returns EINVAL when operation unsupported (e.g. CD system)
|
||||||
@ -249,7 +250,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result File_Do(cc_file* file, char* path, int mode) {
|
static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
||||||
// CD filesystem loader doesn't usually set errno
|
// CD filesystem loader doesn't usually set errno
|
||||||
// when it can't find the requested file
|
// when it can't find the requested file
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -268,14 +269,14 @@ static cc_result File_Do(cc_file* file, char* path, int mode) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -119,17 +119,18 @@ static bool fat_available;
|
|||||||
// FindDevice() returns -1 when no matching device, however the code still unconditionally does "if (devoptab_list[dev]->mkdir_r) {"
|
// FindDevice() returns -1 when no matching device, however the code still unconditionally does "if (devoptab_list[dev]->mkdir_r) {"
|
||||||
// - so will either attempt to access or execute invalid memory
|
// - so will either attempt to access or execute invalid memory
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
*str++ = '/';
|
*str++ = '/';
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
if (!fat_available) return ENOSYS;
|
if (!fat_available) return ENOSYS;
|
||||||
|
|
||||||
return mkdir(path, 0) == -1 ? errno : 0;
|
return mkdir(path->buffer, 0) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -181,24 +182,24 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result File_Do(cc_file* file, char* path, int mode) {
|
static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
||||||
*file = open(path, mode, 0);
|
*file = open(path, mode, 0);
|
||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
if (!fat_available) return ReturnCode_FileNotFound;
|
if (!fat_available) return ReturnCode_FileNotFound;
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
if (!fat_available) return ENOTSUP;
|
if (!fat_available) return ENOTSUP;
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
if (!fat_available) return ENOTSUP;
|
if (!fat_available) return ENOTSUP;
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -165,8 +165,8 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static int retrievedWD, wd_refNum, wd_dirID;
|
static int retrievedWD, wd_refNum, wd_dirID;
|
||||||
|
|
||||||
void Platform_EncodePath(char* dst, const cc_string* src) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
char* str = dst;
|
char* str = dst->buffer;
|
||||||
str++; // placeholder for length later
|
str++; // placeholder for length later
|
||||||
*str++ = ':';
|
*str++ = ':';
|
||||||
|
|
||||||
@ -231,8 +231,8 @@ static int DoCreateFolder(char* name) {
|
|||||||
|
|
||||||
void Directory_GetCachePath(cc_string* path) { }
|
void Directory_GetCachePath(cc_string* path) { }
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return DoCreateFolder(path);
|
return DoCreateFolder(path->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -246,22 +246,22 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return DoOpenDF(path, fsRdPerm, file);
|
return DoOpenDF(path->buffer, fsRdPerm, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
int res = DoCreateFile(path);
|
int res = DoCreateFile(path->buffer);
|
||||||
if (res && res != dupFNErr) return res;
|
if (res && res != dupFNErr) return res;
|
||||||
|
|
||||||
return DoOpenDF(path, fsWrPerm, file);
|
return DoOpenDF(path->buffer, fsWrPerm, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
int res = DoCreateFile(path);
|
int res = DoCreateFile(path->buffer);
|
||||||
if (res && res != dupFNErr) return res;
|
if (res && res != dupFNErr) return res;
|
||||||
|
|
||||||
return DoOpenDF(path, fsRdWrPerm, file);
|
return DoOpenDF(path->buffer, fsRdWrPerm, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -70,7 +70,8 @@ void DateTime_CurrentLocal(struct DateTime* t) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("/");
|
static const cc_string root_path = String_FromConst("/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
// TODO temp hack
|
// TODO temp hack
|
||||||
cc_string path_ = *path;
|
cc_string path_ = *path;
|
||||||
int idx = String_IndexOf(path, '/');
|
int idx = String_IndexOf(path, '/');
|
||||||
@ -81,7 +82,7 @@ void Platform_EncodePath(char* str, const cc_string* path) {
|
|||||||
String_EncodeUtf8(str, &path_);
|
String_EncodeUtf8(str, &path_);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return ERR_NOT_SUPPORTED; // TODO add support
|
return ERR_NOT_SUPPORTED; // TODO add support
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result File_Do(cc_file* file, char* path) {
|
static cc_result File_Do(cc_file* file, const char* path) {
|
||||||
//*file = -1;
|
//*file = -1;
|
||||||
//return ReturnCode_FileNotFound;
|
//return ReturnCode_FileNotFound;
|
||||||
// TODO: Why does trying this code break everything
|
// TODO: Why does trying this code break everything
|
||||||
@ -106,18 +107,18 @@ static cc_result File_Do(cc_file* file, char* path) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path);
|
return File_Do(file, path->buffer);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
*file = -1;
|
*file = -1;
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
//return File_Do(file, path);
|
//return File_Do(file, path->buffer);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
*file = -1;
|
*file = -1;
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
//return File_Do(file, path);
|
//return File_Do(file, path->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -109,17 +109,18 @@ void DateTime_CurrentLocal(struct DateTime* t) {
|
|||||||
static cc_string root_path = String_FromConst("fat:/"); // may be overriden in InitFilesystem
|
static cc_string root_path = String_FromConst("fat:/"); // may be overriden in InitFilesystem
|
||||||
static bool fat_available;
|
static bool fat_available;
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
if (!fat_available) return 0;
|
if (!fat_available) return 0;
|
||||||
|
|
||||||
Platform_Log1("mkdir %c", path);
|
Platform_Log1("mkdir %c", path->buffer);
|
||||||
return mkdir(path, 0) == -1 ? errno : 0;
|
return mkdir(path->buffer, 0) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -170,26 +171,26 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cc_result File_Do(cc_file* file, char* path, int mode, const char* type) {
|
static cc_result File_Do(cc_file* file, const char* path, int mode, const char* type) {
|
||||||
Platform_Log2("%c %c", type, path);
|
Platform_Log2("%c %c", type, path);
|
||||||
|
|
||||||
*file = open(path, mode, 0);
|
*file = open(path, mode, 0);
|
||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
if (!fat_available) return ReturnCode_FileNotFound;
|
if (!fat_available) return ReturnCode_FileNotFound;
|
||||||
return File_Do(file, path, O_RDONLY, "Open");
|
return File_Do(file, path->buffer, O_RDONLY, "Open");
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
if (!fat_available) return ENOTSUP;
|
if (!fat_available) return ENOTSUP;
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC, "Create");
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC, "Create");
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
if (!fat_available) return ENOTSUP;
|
if (!fat_available) return ENOTSUP;
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT, "Update");
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT, "Update");
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -87,13 +87,14 @@ static void Stopwatch_Init(void) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("cdrom:/");
|
static const cc_string root_path = String_FromConst("cdrom:/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,15 +106,15 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, const char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,14 +107,15 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("mass:/ClassiCube/");
|
static const cc_string root_path = String_FromConst("mass:/ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* pathh) {
|
||||||
return fioMkdir(path);
|
return fioMkdir(path->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -178,14 +179,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return res < 0 ? res : 0;
|
return res < 0 ? res : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, FIO_O_RDONLY);
|
return File_Do(file, path->buffer, FIO_O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, FIO_O_RDWR | FIO_O_CREAT | FIO_O_TRUNC);
|
return File_Do(file, path->buffer, FIO_O_RDWR | FIO_O_CREAT | FIO_O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, FIO_O_RDWR | FIO_O_CREAT);
|
return File_Do(file, path->buffer, FIO_O_RDWR | FIO_O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -95,16 +95,17 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("/dev_hdd0/ClassiCube/");
|
static const cc_string root_path = String_FromConst("/dev_hdd0/ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
/* read/write/search permissions for owner and group, and with read/search permissions for others. */
|
/* read/write/search permissions for owner and group, and with read/search permissions for others. */
|
||||||
/* TODO: Is the default mode in all cases */
|
/* TODO: Is the default mode in all cases */
|
||||||
return sysLv2FsMkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
return sysLv2FsMkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -164,14 +165,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, SYS_O_RDONLY);
|
return File_Do(file, path->buffer, SYS_O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, SYS_O_RDWR | SYS_O_CREAT | SYS_O_TRUNC);
|
return File_Do(file, path->buffer, SYS_O_RDWR | SYS_O_CREAT | SYS_O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, SYS_O_RDWR | SYS_O_CREAT);
|
return File_Do(file, path->buffer, SYS_O_RDWR | SYS_O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
@ -444,7 +445,9 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Platform_Init(void) {
|
void Platform_Init(void) {
|
||||||
netInitialize();
|
netInitialize();
|
||||||
Directory_Create(root_path.buffer);
|
|
||||||
|
cc_filepath* root = FILEPATH_RAW(root_path.buffer);
|
||||||
|
Directory_Create(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_Free(void) { }
|
void Platform_Free(void) { }
|
||||||
|
@ -86,7 +86,8 @@ cc_uint64 Stopwatch_Measure(void) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("ms0:/PSP/GAME/ClassiCube/");
|
static const cc_string root_path = String_FromConst("ms0:/PSP/GAME/ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
@ -94,8 +95,8 @@ void Platform_EncodePath(char* str, const cc_string* path) {
|
|||||||
|
|
||||||
#define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF)
|
#define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF)
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
int result = sceIoMkdir(str, 0777);
|
int result = sceIoMkdir(path->buffer, 0777);
|
||||||
return GetSCEResult(result);
|
return GetSCEResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,14 +145,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return GetSCEResult(result);
|
return GetSCEResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, PSP_O_RDONLY);
|
return File_Do(file, path->buffer, PSP_O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC);
|
return File_Do(file, path->buffer, PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, PSP_O_RDWR | PSP_O_CREAT);
|
return File_Do(file, path->buffer, PSP_O_RDWR | PSP_O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
@ -429,7 +430,8 @@ void Platform_Init(void) {
|
|||||||
// TODO: work out why this error is actually happening (inexact or underflow?) and properly fix it
|
// TODO: work out why this error is actually happening (inexact or underflow?) and properly fix it
|
||||||
pspSdkDisableFPUExceptions();
|
pspSdkDisableFPUExceptions();
|
||||||
|
|
||||||
Directory_Create(root_path.buffer);
|
cc_filepath* root = FILEPATH_RAW(root_path.buffer);
|
||||||
|
Directory_Create(root);
|
||||||
}
|
}
|
||||||
void Platform_Free(void) { }
|
void Platform_Free(void) { }
|
||||||
|
|
||||||
|
@ -69,7 +69,8 @@ cc_uint64 Stopwatch_Measure(void) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("ux0:data/ClassiCube/");
|
static const cc_string root_path = String_FromConst("ux0:data/ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
@ -77,8 +78,8 @@ void Platform_EncodePath(char* str, const cc_string* path) {
|
|||||||
|
|
||||||
#define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF)
|
#define GetSCEResult(result) (result >= 0 ? 0 : result & 0xFFFF)
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
int result = sceIoMkdir(path, 0777);
|
int result = sceIoMkdir(path->buffer, 0777);
|
||||||
return GetSCEResult(result);
|
return GetSCEResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,14 +128,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return GetSCEResult(result);
|
return GetSCEResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, SCE_O_RDONLY);
|
return File_Do(file, path->buffer, SCE_O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC);
|
return File_Do(file, path->buffer, SCE_O_RDWR | SCE_O_CREAT | SCE_O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, SCE_O_RDWR | SCE_O_CREAT);
|
return File_Do(file, path->buffer, SCE_O_RDWR | SCE_O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
@ -385,7 +386,9 @@ void Platform_Init(void) {
|
|||||||
/*pspDebugSioInit();*/
|
/*pspDebugSioInit();*/
|
||||||
InitNetworking();
|
InitNetworking();
|
||||||
epoll_id = sceNetEpollCreate("CC poll", 0);
|
epoll_id = sceNetEpollCreate("CC poll", 0);
|
||||||
Directory_Create(root_path.buffer);
|
|
||||||
|
cc_filepath* root = FILEPATH_RAW(root_path.buffer);
|
||||||
|
Directory_Create(root);
|
||||||
}
|
}
|
||||||
void Platform_Free(void) { }
|
void Platform_Free(void) { }
|
||||||
|
|
||||||
|
@ -189,7 +189,8 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,10 +202,10 @@ void Platform_EncodePath(char* str, const cc_string* path) {
|
|||||||
void Directory_GetCachePath(cc_string* path) { }
|
void Directory_GetCachePath(cc_string* path) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
/* read/write/search permissions for owner and group, and with read/search permissions for others. */
|
/* read/write/search permissions for owner and group, and with read/search permissions for others. */
|
||||||
/* TODO: Is the default mode in all cases */
|
/* TODO: Is the default mode in all cases */
|
||||||
return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
|
return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -270,25 +271,25 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
#if !defined CC_BUILD_OS2
|
#if !defined CC_BUILD_OS2
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
#else
|
#else
|
||||||
return File_Do(file, path, O_RDONLY | O_BINARY);
|
return File_Do(file, path->buffer, O_RDONLY | O_BINARY);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
#if !defined CC_BUILD_OS2
|
#if !defined CC_BUILD_OS2
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
#else
|
#else
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC | O_BINARY);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
#if !defined CC_BUILD_OS2
|
#if !defined CC_BUILD_OS2
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
#else
|
#else
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_BINARY);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_BINARY);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,11 +85,12 @@ static void Stopwatch_Init(void) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,15 +102,15 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
|
|||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return ERR_NOT_SUPPORTED;
|
return ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +109,15 @@ void DateTime_CurrentLocal(struct DateTime* t) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
static const cc_string root_path = String_FromConst("sdmc:/switch/ClassiCube/");
|
static const cc_string root_path = String_FromConst("sdmc:/switch/ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return mkdir(path, 0) == -1 ? errno : 0;
|
return mkdir(path->buffer, 0) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -169,14 +170,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -100,14 +100,15 @@ void DateTime_CurrentLocal(struct DateTime* t) {
|
|||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
*-----------------------------------------------------Directory/File------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Directory_GetCachePath(cc_string* path) { }
|
void Directory_GetCachePath(cc_string* path) { }
|
||||||
|
|
||||||
extern void interop_InitFilesystem(void);
|
extern void interop_InitFilesystem(void);
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
/* Web filesystem doesn't need directories */
|
/* Web filesystem doesn't need directories */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -152,14 +153,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int interop_FileRead(int fd, void* data, int count);
|
extern int interop_FileRead(int fd, void* data, int count);
|
||||||
|
@ -103,16 +103,17 @@ cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end) {
|
|||||||
|
|
||||||
static const cc_string root_path = String_FromConst("ClassiCube/");
|
static const cc_string root_path = String_FromConst("ClassiCube/");
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
/* read/write/search permissions for owner and group, and with read/search permissions for others. */
|
/* read/write/search permissions for owner and group, and with read/search permissions for others. */
|
||||||
/* TODO: Is the default mode in all cases */
|
/* TODO: Is the default mode in all cases */
|
||||||
return mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
|
return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -168,14 +169,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, const char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path, O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, const char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, const char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -180,11 +180,11 @@ cc_uint64 Stopwatch_Measure(void) {
|
|||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
void Directory_GetCachePath(cc_string* path) { }
|
void Directory_GetCachePath(cc_string* path) { }
|
||||||
|
|
||||||
void Platform_EncodePath(cc_filepath_ptr dst, const cc_string* src) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* src) {
|
||||||
Platform_EncodeString(dst, src);
|
Platform_EncodeString(dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(cc_filepath_ptr path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
cc_result res;
|
cc_result res;
|
||||||
if (CreateDirectoryW(path->uni, NULL)) return 0;
|
if (CreateDirectoryW(path->uni, NULL)) return 0;
|
||||||
/* Windows 9x does not support W API functions */
|
/* Windows 9x does not support W API functions */
|
||||||
@ -280,13 +280,13 @@ static cc_result DoFile(cc_file* file, const cc_filepath* path, DWORD access, DW
|
|||||||
return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError();
|
return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, cc_filepath_ptr path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return DoFile(file, path, GENERIC_READ, OPEN_EXISTING);
|
return DoFile(file, path, GENERIC_READ, OPEN_EXISTING);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, cc_filepath_ptr path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS);
|
return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, cc_filepath_ptr path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS);
|
return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,8 @@ static void Stopwatch_Init(void) {
|
|||||||
static cc_string root_path = String_FromConst("E:\\ClassiCube\\");
|
static cc_string root_path = String_FromConst("E:\\ClassiCube\\");
|
||||||
static BOOL hdd_mounted;
|
static BOOL hdd_mounted;
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* src) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
|
|
||||||
@ -100,10 +101,10 @@ void Platform_EncodePath(char* str, const cc_string* src) {
|
|||||||
*str = '\0';
|
*str = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
if (!hdd_mounted) return ERR_NOT_SUPPORTED;
|
if (!hdd_mounted) return ERR_NOT_SUPPORTED;
|
||||||
|
|
||||||
return CreateDirectoryA(path, NULL) ? 0 : GetLastError();
|
return CreateDirectoryA(path->buffer, NULL) ? 0 : GetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -168,19 +169,19 @@ static cc_result DoFile(cc_file* file, const char* path, DWORD access, DWORD cre
|
|||||||
return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError();
|
return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
if (!hdd_mounted) return ReturnCode_FileNotFound;
|
if (!hdd_mounted) return ReturnCode_FileNotFound;
|
||||||
return DoFile(file, path, GENERIC_READ, OPEN_EXISTING);
|
return DoFile(file, path->buffer, GENERIC_READ, OPEN_EXISTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
if (!hdd_mounted) return ERR_NOT_SUPPORTED;
|
if (!hdd_mounted) return ERR_NOT_SUPPORTED;
|
||||||
return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS);
|
return DoFile(file, path->buffer, GENERIC_WRITE | GENERIC_READ, CREATE_ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
if (!hdd_mounted) return ERR_NOT_SUPPORTED;
|
if (!hdd_mounted) return ERR_NOT_SUPPORTED;
|
||||||
return DoFile(file, path, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS);
|
return DoFile(file, path->buffer, GENERIC_WRITE | GENERIC_READ, OPEN_ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
@ -411,7 +412,9 @@ static void InitHDD(void) {
|
|||||||
Platform_LogConst("Failed to mount E:/ from Data partition");
|
Platform_LogConst("Failed to mount E:/ from Data partition");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Directory_Create(root_path.buffer);
|
|
||||||
|
cc_filepath* root = FILEPATH_RAW(root_path.buffer);
|
||||||
|
Directory_Create(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_Init(void) {
|
void Platform_Init(void) {
|
||||||
|
@ -78,14 +78,15 @@ cc_uint64 Stopwatch_Measure(void) {
|
|||||||
static char root_buffer[NATIVE_STR_LEN];
|
static char root_buffer[NATIVE_STR_LEN];
|
||||||
static cc_string root_path = String_FromArray(root_buffer);
|
static cc_string root_path = String_FromArray(root_buffer);
|
||||||
|
|
||||||
void Platform_EncodePath(char* str, const cc_string* path) {
|
void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
|
||||||
|
char* str = dst->buffer;
|
||||||
Mem_Copy(str, root_path.buffer, root_path.length);
|
Mem_Copy(str, root_path.buffer, root_path.length);
|
||||||
str += root_path.length;
|
str += root_path.length;
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result Directory_Create(char* path) {
|
cc_result Directory_Create(const cc_filepath* path) {
|
||||||
return mkdir(path, 0) == -1 ? errno : 0;
|
return mkdir(path->buffer, 0) == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int File_Exists(const cc_string* path) {
|
int File_Exists(const cc_string* path) {
|
||||||
@ -138,14 +139,14 @@ static cc_result File_Do(cc_file* file, const char* path, int mode) {
|
|||||||
return *file == -1 ? errno : 0;
|
return *file == -1 ? errno : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Open(cc_file* file, char* path) {
|
cc_result File_Open(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDONLY);
|
return File_Do(file, path->buffer, O_RDONLY);
|
||||||
}
|
}
|
||||||
cc_result File_Create(cc_file* file, char* path) {
|
cc_result File_Create(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT | O_TRUNC);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT | O_TRUNC);
|
||||||
}
|
}
|
||||||
cc_result File_OpenOrCreate(cc_file* file, char* path) {
|
cc_result File_OpenOrCreate(cc_file* file, const cc_filepath* path) {
|
||||||
return File_Do(file, path, O_RDWR | O_CREAT);
|
return File_Do(file, path->buffer, O_RDWR | O_CREAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
cc_result File_Read(cc_file file, void* data, cc_uint32 count, cc_uint32* bytesRead) {
|
||||||
|
@ -450,7 +450,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* save_args) {
|
|||||||
if (!save_args->defaultName.length) return SFD_ERR_NEED_DEFAULT_NAME;
|
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
|
// save the item to a temp file, which is then (usually) later deleted by intent callback
|
||||||
Directory_Create("Exported");
|
Directory_Create(FILEPATH_RAW("Exported"));
|
||||||
|
|
||||||
cc_string path; char pathBuffer[FILENAME_SIZE];
|
cc_string path; char pathBuffer[FILENAME_SIZE];
|
||||||
String_InitArray(path, pathBuffer);
|
String_InitArray(path, pathBuffer);
|
||||||
|
@ -668,7 +668,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) {
|
|||||||
// UIDocumentPickerViewController - iOS 8.0
|
// UIDocumentPickerViewController - iOS 8.0
|
||||||
|
|
||||||
// save the item to a temp file, which is then (usually) later deleted by picker callbacks
|
// save the item to a temp file, which is then (usually) later deleted by picker callbacks
|
||||||
Directory_Create("Exported");
|
Directory_Create(FILEPATH_RAW("Exported")));
|
||||||
|
|
||||||
save_path.length = 0;
|
save_path.length = 0;
|
||||||
String_Format2(&save_path, "Exported/%s%c", &args->defaultName, args->filters[0]);
|
String_Format2(&save_path, "Exported/%s%c", &args->defaultName, args->filters[0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user