Switch to always opening using platform native paths

This commit is contained in:
UnknownShadow200 2025-10-13 19:13:37 +11:00
parent f150f0c649
commit 8374c79c5d
5 changed files with 29 additions and 13 deletions

View File

@ -221,9 +221,11 @@ static cc_result ProcessZipEntry(const cc_string* path, struct Stream* stream, s
static cc_result Sounds_ExtractZip(const cc_string* path) {
struct ZipEntry entries[128];
struct Stream stream;
cc_filepath raw_path;
cc_result res;
res = Stream_OpenFile(&stream, path);
Platform_EncodePath(&raw_path, path);
res = Stream_OpenPath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "opening", path); return res; }
res = Zip_Extract(&stream, SelectZipEntry, ProcessZipEntry,
@ -422,6 +424,7 @@ static void Music_RunLoop(void) {
cc_string path;
RNGState rnd;
struct Stream stream;
cc_filepath raw_path;
int idx, delay;
cc_result res = 0;
@ -438,7 +441,8 @@ static void Music_RunLoop(void) {
path = StringsBuffer_UNSAFE_Get(&files, idx);
Platform_Log1("playing music file: %s", &path);
res = Stream_OpenFile(&stream, &path);
Platform_EncodePath(&raw_path, &path);
res = Stream_OpenPath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "opening", &path); break; }
res = Music_PlayOgg(&stream);

View File

@ -67,11 +67,14 @@ cc_result Map_LoadFrom(const cc_string* path) {
struct LocationUpdate update = { 0 };
struct MapImporter* imp;
struct Stream stream;
cc_filepath raw_path;
cc_result res;
Game_Reset();
spawn_point = &update;
res = Stream_OpenFile(&stream, path);
Platform_EncodePath(&raw_path, path);
res = Stream_OpenPath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "opening", path); return res; }
imp = MapImporter_Find(path);

View File

@ -463,9 +463,11 @@ static cc_result Launcher_ProcessZipEntry(const cc_string* path, struct Stream*
static cc_result ExtractTexturePack(const cc_string* path) {
struct ZipEntry entries[32];
struct Stream stream;
cc_filepath raw_path;
cc_result res;
res = Stream_OpenFile(&stream, path);
Platform_EncodePath(&raw_path, path);
res = Stream_OpenPath(&stream, &raw_path);
if (res == ReturnCode_FileNotFound) return res;
if (res) { Logger_SysWarn(res, "opening texture pack"); return res; }

View File

@ -1466,15 +1466,15 @@ static void DecodeMachineID(char* tmp, int len, cc_uint32* key) {
#if defined CC_BUILD_LINUX
/* Read /var/lib/dbus/machine-id or /etc/machine-id for the key */
static cc_result GetMachineID(cc_uint32* key) {
const cc_string idFile = String_FromConst("/var/lib/dbus/machine-id");
const cc_string altFile = String_FromConst("/etc/machine-id");
const cc_filepath* id_path = FILEPATH_RAW("/var/lib/dbus/machine-id");
const cc_filepath* alt_path = FILEPATH_RAW("/etc/machine-id");
char tmp[MACHINEID_LEN];
struct Stream s;
cc_result res;
/* Some machines only have dbus id, others only have etc id */
res = Stream_OpenFile(&s, &idFile);
if (res) res = Stream_OpenFile(&s, &altFile);
res = Stream_OpenPath(&s, id_path);
if (res) res = Stream_OpenPath(&s, alt_path);
if (res) return res;
res = Stream_Read(&s, (cc_uint8*)tmp, MACHINEID_LEN);

View File

@ -375,17 +375,22 @@ static int IsCached(const cc_string* url) {
static cc_bool OpenCachedData(const cc_string* url, struct Stream* stream) {
cc_string mainPath; char mainBuffer[FILENAME_SIZE];
cc_string altPath; char altBuffer[FILENAME_SIZE];
cc_filepath raw_path;
cc_result res;
String_InitArray(mainPath, mainBuffer);
String_InitArray(altPath, altBuffer);
MakeCachePath(&mainPath, &altPath, url);
res = Stream_OpenFile(stream, &mainPath);
Platform_EncodePath(&raw_path, &mainPath);
res = Stream_OpenPath(stream, &raw_path);
/* try fallback cache if can't find in main cache */
if (res == ReturnCode_FileNotFound && altPath.length)
res = Stream_OpenFile(stream, &altPath);
if (res == ReturnCode_FileNotFound && altPath.length) {
Platform_EncodePath(&raw_path, &altPath);
res = Stream_OpenPath(stream, &raw_path);
}
if (res == ReturnCode_FileNotFound) return false;
if (res) { Logger_SysWarn2(res, "opening cache for", url); return false; }
@ -595,9 +600,11 @@ static cc_result ExtractFromFile(const cc_string* path) {
#else
static cc_result ExtractFromFile(const cc_string* path) {
struct Stream stream;
cc_filepath raw_path;
cc_result res;
res = Stream_OpenFile(&stream, path);
Platform_EncodePath(&raw_path, path);
res = Stream_OpenPath(&stream, &raw_path);
if (res) { Logger_SysWarn2(res, "opening", path); return res; }
res = ExtractFrom(&stream, path);