WIP always using platform native paths

This commit is contained in:
UnknownShadow200 2025-10-13 07:09:54 +11:00
parent e465b9ccba
commit f150f0c649
11 changed files with 70 additions and 37 deletions

View File

@ -122,6 +122,7 @@ static cc_bool CreateLogsDirectory(void) {
} }
static void OpenChatLog(struct cc_datetime* now) { static void OpenChatLog(struct cc_datetime* now) {
cc_filepath raw_path;
cc_result res; cc_result res;
int i; int i;
if (Platform_ReadonlyFilesystem || !CreateLogsDirectory()) return; if (Platform_ReadonlyFilesystem || !CreateLogsDirectory()) return;
@ -137,7 +138,9 @@ static void OpenChatLog(struct cc_datetime* now) {
String_Format1(&logPath, "%s.txt", &logName); String_Format1(&logPath, "%s.txt", &logName);
} }
res = Stream_AppendFile(&logStream, &logPath); Platform_EncodePath(&raw_path, &logPath);
res = Stream_AppendPath(&logStream, &raw_path);
if (res && res != ReturnCode_FileShareViolation) { if (res && res != ReturnCode_FileShareViolation) {
Chat_DisableLogging(); Chat_DisableLogging();
Logger_SysWarn2(res, "appending to", &logPath); Logger_SysWarn2(res, "appending to", &logPath);

View File

@ -594,10 +594,10 @@ void Game_TakeScreenshot(void) {
cc_string filename; char fileBuffer[STRING_SIZE]; cc_string filename; char fileBuffer[STRING_SIZE];
cc_string path; char pathBuffer[FILENAME_SIZE]; cc_string path; char pathBuffer[FILENAME_SIZE];
struct cc_datetime now; struct cc_datetime now;
cc_filepath raw_path;
cc_result res; cc_result res;
#ifdef CC_BUILD_WEB
cc_filepath str; #ifndef CC_BUILD_WEB
#else
struct Stream stream; struct Stream stream;
#endif #endif
Game_ScreenshotRequested = false; Game_ScreenshotRequested = false;
@ -609,14 +609,15 @@ void Game_TakeScreenshot(void) {
#ifdef CC_BUILD_WEB #ifdef CC_BUILD_WEB
extern void interop_TakeScreenshot(const char* path); extern void interop_TakeScreenshot(const char* path);
Platform_EncodePath(&str, &filename); Platform_EncodePath(&raw_path, &filename);
interop_TakeScreenshot(str.buffer); interop_TakeScreenshot(raw_path.buffer);
#else #else
if (!Utils_EnsureDirectory("screenshots")) return; if (!Utils_EnsureDirectory("screenshots")) return;
String_InitArray(path, pathBuffer); String_InitArray(path, pathBuffer);
String_Format1(&path, "screenshots/%s", &filename); String_Format1(&path, "screenshots/%s", &filename);
res = Stream_CreateFile(&stream, &path); Platform_EncodePath(&raw_path, &path);
res = Stream_CreatePath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "creating", &path); return; } if (res) { Logger_SysWarn2(res, "creating", &path); return; }
res = Gfx_TakeScreenshot(&stream); res = Gfx_TakeScreenshot(&stream);

View File

@ -1165,10 +1165,14 @@ static struct Stream logStream;
static cc_bool logOpen; static cc_bool logOpen;
void Logger_Log(const cc_string* msg) { void Logger_Log(const cc_string* msg) {
static const cc_string path = String_FromConst("client.log"); static const cc_string log_path = String_FromConst("client.log");
cc_filepath raw_path;
if (!logOpen) { if (!logOpen) {
logOpen = true; logOpen = true;
Stream_AppendFile(&logStream, &path);
Platform_EncodePath(&raw_path, &log_path);
Stream_AppendPath(&logStream, &raw_path);
} }
if (!logStream.meta.file) return; if (!logStream.meta.file) return;

View File

@ -1363,10 +1363,13 @@ static cc_result DoSaveMap(const cc_string* path, struct GZipState* state) {
static const cc_string schematic = String_FromConst(".schematic"); static const cc_string schematic = String_FromConst(".schematic");
static const cc_string mine = String_FromConst(".mine"); static const cc_string mine = String_FromConst(".mine");
struct Stream stream, compStream; struct Stream stream, compStream;
cc_filepath raw_path;
cc_result res; cc_result res;
res = Stream_CreateFile(&stream, path); Platform_EncodePath(&raw_path, path);
res = Stream_CreatePath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "creating", path); return res; } if (res) { Logger_SysWarn2(res, "creating", path); return res; }
GZip_MakeStream(&compStream, state, &stream); GZip_MakeStream(&compStream, state, &stream);
if (String_CaselessEnds(path, &schematic)) { if (String_CaselessEnds(path, &schematic)) {

View File

@ -237,9 +237,9 @@ void Platform_EncodePath(cc_filepath* dst, const cc_string* src) {
void Platform_DecodePath(cc_string* dst, const cc_filepath* path) { void Platform_DecodePath(cc_string* dst, const cc_filepath* path) {
int i; int i;
for (i = 0; i < FILENAME_SIZE && dst->uni[i]; i++) for (i = 0; i < FILENAME_SIZE && path->uni[i]; i++)
{ {
String_Append(dst, Convert_CodepointToCP437(dst->uni[i])); String_Append(dst, Convert_CodepointToCP437(path->uni[i]));
} }
} }

View File

@ -307,9 +307,9 @@ void Platform_EncodePath(cc_filepath* dst, const cc_string* src) {
void Platform_DecodePath(cc_string* dst, const cc_filepath* path) { void Platform_DecodePath(cc_string* dst, const cc_filepath* path) {
int i; int i;
for (i = 0; i < FILENAME_SIZE && dst->uni[i]; i++) for (i = 0; i < FILENAME_SIZE && path->uni[i]; i++)
{ {
String_Append(dst, Convert_CodepointToCP437(dst->uni[i])); String_Append(dst, Convert_CodepointToCP437(path->uni[i]));
} }
} }

View File

@ -65,8 +65,10 @@ static void ZipFile_InspectEntries(const cc_string* path, Zip_SelectEntry select
struct Stream stream; struct Stream stream;
cc_result res; cc_result res;
struct ZipEntry entries[64]; struct ZipEntry entries[64];
cc_filepath raw_path;
res = Stream_OpenFile(&stream, path); Platform_EncodePath(&raw_path, path);
res = Stream_OpenPath(&stream, &raw_path);
if (res == ReturnCode_FileNotFound) return; if (res == ReturnCode_FileNotFound) return;
if (res) { Logger_SysWarn2(res, "opening", path); return; } if (res) { Logger_SysWarn2(res, "opening", path); return; }
@ -267,9 +269,11 @@ static cc_result ZipFile_WriteEntries(struct Stream* s, struct ResourceZipEntry*
static void ZipFile_Create(const cc_string* path, struct ResourceZipEntry* entries, int numEntries) { static void ZipFile_Create(const cc_string* path, struct ResourceZipEntry* entries, int numEntries) {
struct Stream s; struct Stream s;
cc_filepath raw_path;
cc_result res; cc_result res;
res = Stream_CreateFile(&s, path); Platform_EncodePath(&raw_path, path);
res = Stream_CreatePath(&s, &raw_path);
if (res) { if (res) {
Logger_SysWarn2(res, "creating", path); return; Logger_SysWarn2(res, "creating", path); return;
} }

View File

@ -114,33 +114,39 @@ static cc_result Stream_FileLength(struct Stream* s, cc_uint32* length) {
cc_result Stream_OpenFile(struct Stream* s, const cc_string* path) { cc_result Stream_OpenFile(struct Stream* s, const cc_string* path) {
cc_filepath str; cc_filepath str;
cc_file file;
cc_result res;
Platform_EncodePath(&str, path); Platform_EncodePath(&str, path);
res = File_Open(&file, &str); return Stream_OpenPath(s, &str);
Stream_FromFile(s, file);
return res;
} }
cc_result Stream_CreateFile(struct Stream* s, const cc_string* path) { cc_result Stream_CreateFile(struct Stream* s, const cc_string* path) {
cc_filepath str; cc_filepath str;
cc_file file;
cc_result res;
Platform_EncodePath(&str, path); Platform_EncodePath(&str, path);
res = File_Create(&file, &str); return Stream_CreatePath(s, &str);
}
cc_result Stream_OpenPath(struct Stream* s, const cc_filepath* path) {
cc_file file;
cc_result res = File_Open(&file, path);
Stream_FromFile(s, file); Stream_FromFile(s, file);
return res; return res;
} }
cc_result Stream_AppendFile(struct Stream* s, const cc_string* path) { cc_result Stream_CreatePath(struct Stream* s, const cc_filepath* path) {
cc_filepath str; cc_file file;
cc_result res = File_Create(&file, path);
Stream_FromFile(s, file);
return res;
}
cc_result Stream_AppendPath(struct Stream* s, const cc_filepath* path) {
cc_file file; cc_file file;
cc_result res; cc_result res;
Platform_EncodePath(&str, path);
if ((res = File_OpenOrCreate(&file, &str))) return res; if ((res = File_OpenOrCreate(&file, path))) return res;
if ((res = File_Seek(file, 0, FILE_SEEKFROM_END))) return res; if ((res = File_Seek(file, 0, FILE_SEEKFROM_END))) return res;
Stream_FromFile(s, file); Stream_FromFile(s, file);
return res; return res;
@ -149,8 +155,10 @@ cc_result Stream_AppendFile(struct Stream* s, const cc_string* path) {
cc_result Stream_WriteAllTo(const cc_string* path, const cc_uint8* data, cc_uint32 length) { cc_result Stream_WriteAllTo(const cc_string* path, const cc_uint8* data, cc_uint32 length) {
struct Stream stream; struct Stream stream;
cc_result res, closeRes; cc_result res, closeRes;
cc_filepath raw_path;
res = Stream_CreateFile(&stream, path); Platform_EncodePath(&raw_path, path);
res = Stream_CreatePath(&stream, &raw_path);
if (res) return res; if (res) return res;
res = Stream_Write(&stream, data, length); res = Stream_Write(&stream, data, length);

View File

@ -49,14 +49,20 @@ typedef cc_result (*FP_Stream_Write)(struct Stream* s, const cc_uint8* buffer, c
/* Initialises default function pointers for a stream. (all read, write, seeks return an error) */ /* Initialises default function pointers for a stream. (all read, write, seeks return an error) */
void Stream_Init(struct Stream* s); void Stream_Init(struct Stream* s);
/* Wrapper for File_Open() then Stream_FromFile() */ /* Wrapper for Stream_OpenPath() */
CC_API cc_result Stream_OpenFile( struct Stream* s, const cc_string* path); CC_API cc_result Stream_OpenFile( struct Stream* s, const cc_string* path);
typedef cc_result (*FP_Stream_OpenFile)(struct Stream* s, const cc_string* path); typedef cc_result (*FP_Stream_OpenFile)(struct Stream* s, const cc_string* path);
/* Wrapper for File_Create() then Stream_FromFile() */ /* Wrapper for Stream_CreatePath() */
CC_API cc_result Stream_CreateFile( struct Stream* s, const cc_string* path); CC_API cc_result Stream_CreateFile( struct Stream* s, const cc_string* path);
typedef cc_result (*FP_Stream_CreateFile)(struct Stream* s, const cc_string* path); typedef cc_result (*FP_Stream_CreateFile)(struct Stream* s, const cc_string* path);
/* Wrapper for File_Open() then Stream_FromFile() */
cc_result Stream_OpenPath( struct Stream* s, const cc_filepath* path);
/* Wrapper for File_Create() then Stream_FromFile() */
cc_result Stream_CreatePath(struct Stream* s, const cc_filepath* path);
/* Wrapper for File_OpenOrCreate, then File_Seek(END), then Stream_FromFile() */ /* Wrapper for File_OpenOrCreate, then File_Seek(END), then Stream_FromFile() */
cc_result Stream_AppendFile(struct Stream* s, const cc_string* path); cc_result Stream_AppendPath(struct Stream* s, const cc_filepath* path);
/* Creates or overwrites a file, setting the contents to the given data. */ /* Creates or overwrites a file, setting the contents to the given data. */
cc_result Stream_WriteAllTo(const cc_string* path, const cc_uint8* data, cc_uint32 length); cc_result Stream_WriteAllTo(const cc_string* path, const cc_uint8* data, cc_uint32 length);
/* Wraps a file, allowing reading from/writing to/seeking in the file. */ /* Wraps a file, allowing reading from/writing to/seeking in the file. */

View File

@ -224,9 +224,9 @@ void Platform_EncodePath(cc_filepath* dst, const cc_string* src) {
void Platform_DecodePath(cc_string* dst, const cc_filepath* path) { void Platform_DecodePath(cc_string* dst, const cc_filepath* path) {
int i; int i;
for (i = 0; i < FILENAME_SIZE && dst->uni[i]; i++) for (i = 0; i < FILENAME_SIZE && path->uni[i]; i++)
{ {
String_Append(dst, Convert_CodepointToCP437(dst->uni[i])); String_Append(dst, Convert_CodepointToCP437(path->uni[i]));
} }
} }

View File

@ -239,12 +239,14 @@ cc_result EntryList_Load(struct StringsBuffer* list, const char* file, char sepa
cc_uint8 buffer[2048]; cc_uint8 buffer[2048];
struct Stream stream, buffered; struct Stream stream, buffered;
cc_filepath raw_path;
cc_result res; cc_result res;
path = String_FromReadonly(file); path = String_FromReadonly(file);
maxLen = list->_lenMask ? list->_lenMask : STRINGSBUFFER_DEF_LEN_MASK; maxLen = list->_lenMask ? list->_lenMask : STRINGSBUFFER_DEF_LEN_MASK;
res = Stream_OpenFile(&stream, &path); Platform_EncodePath(&raw_path, &path);
res = Stream_OpenPath(&stream, &raw_path);
if (res == ReturnCode_FileNotFound) return res; if (res == ReturnCode_FileNotFound) return res;
if (res) { Logger_SysWarn2(res, "opening", &path); return res; } if (res) { Logger_SysWarn2(res, "opening", &path); return res; }
@ -294,13 +296,15 @@ cc_result EntryList_UNSAFE_Load(struct StringsBuffer* list, const char* file) {
void EntryList_Save(struct StringsBuffer* list, const char* file) { void EntryList_Save(struct StringsBuffer* list, const char* file) {
cc_string path, entry; char pathBuffer[FILENAME_SIZE]; cc_string path, entry; char pathBuffer[FILENAME_SIZE];
struct Stream stream; struct Stream stream;
int i; cc_filepath raw_path;
cc_result res; cc_result res;
int i;
String_InitArray(path, pathBuffer); String_InitArray(path, pathBuffer);
String_AppendConst(&path, file); String_AppendConst(&path, file);
res = Stream_CreateFile(&stream, &path); Platform_EncodePath(&raw_path, &path);
res = Stream_CreatePath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "creating", &path); return; } if (res) { Logger_SysWarn2(res, "creating", &path); return; }
for (i = 0; i < list->count; i++) { for (i = 0; i < list->count; i++) {