Windows 9x: Fix file existence check not working properly

This commit is contained in:
UnknownShadow200 2024-06-30 22:25:37 +10:00
parent 690692b8fb
commit ede1a368f5
25 changed files with 75 additions and 94 deletions

View File

@ -209,7 +209,7 @@ clean:
$(ENAME): $(BUILD_DIR) $(OBJECTS)
$(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(EXTRALIBS) $(LIBS)
$(CC) $(LDFLAGS) -o $@$(OEXT) $(OBJECTS) $(EXTRA_LIBS) $(LIBS)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
@ -222,21 +222,21 @@ DEPFILES := $(patsubst $(SOURCE_DIR)/%.c, $(BUILD_DIR)/%.d, $(C_SOURCES))
$(DEPFILES):
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c $(BUILD_DIR)/%.d
$(CC) $(CFLAGS) $(EXTRAFLAGS) $(DEPFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(DEPFLAGS) -c $< -o $@
include $(wildcard $(DEPFILES))
# === Compiling WITHOUT dependency tracking ===
else
$(C_OBJECTS): $(BUILD_DIR)/%.o : $(SOURCE_DIR)/%.c
$(CC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
endif
# === Platform specific file compiling ===
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.m
$(CC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.cpp
$(CC) $(CFLAGS) $(EXTRAFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
# EXTRAFLAGS and EXTRALIBS are not defined in the makefile intentionally -
# EXTRA_CFLAGS and EXTRA_LIBS are not defined in the makefile intentionally -
# define them on the command line as a simple way of adding CFLAGS/LIBS

View File

@ -1396,6 +1396,7 @@ static void SaveLevelScreen_Save(void* screen, void* widget) {
struct ButtonWidget* btn = (struct ButtonWidget*)widget;
cc_string path; char pathBuffer[FILENAME_SIZE];
cc_string file = s->input.base.text;
cc_filepath str;
cc_result res;
if (!file.length) {
@ -1407,7 +1408,8 @@ static void SaveLevelScreen_Save(void* screen, void* widget) {
String_Format1(&path, "maps/%s.cw", &file);
String_Copy(&World.Name, &file);
if (File_Exists(&path) && !btn->optName) {
Platform_EncodePath(&str, &path);
if (File_Exists(&str) && !btn->optName) {
btn->optName = "";
SaveLevelScreen_UpdateSave(s);
return;

View File

@ -197,7 +197,7 @@ typedef void (*Directory_EnumCallback)(const cc_string* filename, void* obj, int
/* Invokes a callback function on all filenames in the given directory (and its sub-directories) */
CC_API cc_result Directory_Enum(const cc_string* path, void* obj, Directory_EnumCallback callback);
/* Returns non-zero if the given file exists. */
CC_API int File_Exists(const cc_string* path);
int File_Exists(const cc_filepath* path);
void Directory_GetCachePath(cc_string* path);
/* Attempts to create a new (or overwrite) file for writing. */

View File

@ -102,12 +102,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return mkdir(path->buffer, 0666) == -1 ? errno : 0; // FS has no permissions anyways
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
struct stat sb;
Platform_EncodePath(&str, path);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -208,11 +208,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return err;
}
int File_Exists(const cc_string* path) {
cc_filepath str;;
int File_Exists(const cc_filepath* path) {
struct stat sb;
Platform_EncodePath(&str, path);
return fs_stat(str.buffer, &sb, 0) == 0 && S_ISREG(sb.st_mode);
return fs_stat(path->buffer, &sb, 0) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -133,13 +133,11 @@ cc_result Directory_Create(const cc_filepath* path) {
return mkdir(path->buffer, 0) == -1 ? errno : 0;
}
int File_Exists(const cc_string* path) {
int File_Exists(const cc_filepath* path) {
if (!fat_available) return false;
cc_filepath str;
struct stat sb;
Platform_EncodePath(&str, path);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -236,11 +236,8 @@ cc_result Directory_Create(const cc_filepath* path) {
return DoCreateFolder(path->buffer);
}
int File_Exists(const cc_string* path) {
cc_filepath str;
Platform_EncodePath(&str, path);
return 0;
int File_Exists(const cc_filepath* path) {
return false; // TODO
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -86,7 +86,7 @@ cc_result Directory_Create(const cc_filepath* path) {
return ERR_NOT_SUPPORTED;
}
int File_Exists(const cc_string* path) {
int File_Exists(const cc_filepath* path) {
return false;
}

View File

@ -118,19 +118,16 @@ void Platform_EncodePath(cc_filepath* dst, const cc_string* path) {
cc_result Directory_Create(const cc_filepath* path) {
if (!fat_available) return 0;
Platform_Log1("mkdir %c", path->buffer);
Platform_Log1("mkdir %c", path->buffer);
return mkdir(path->buffer, 0) == -1 ? errno : 0;
}
int File_Exists(const cc_string* path) {
int File_Exists(const cc_filepath* path) {
if (!fat_available) return false;
cc_filepath str;
struct stat sb;
Platform_EncodePath(&str, path);
Platform_Log1("Check %c", str.buffer);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
Platform_Log1("Check %c", path->buffer);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -98,8 +98,8 @@ cc_result Directory_Create(const cc_filepath* path) {
return ERR_NOT_SUPPORTED;
}
int File_Exists(const cc_string* path) {
return ERR_NOT_SUPPORTED;
int File_Exists(const cc_filepath* path) {
return false;
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -116,11 +116,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return fioMkdir(path->buffer);
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
io_stat_t sb;
Platform_EncodePath(&str, path);
return fioGetstat(str.buffer, &sb) >= 0 && (sb.mode & FIO_SO_IFREG);
return fioGetstat(path->buffer, &sb) >= 0 && (sb.mode & FIO_SO_IFREG);
}
// For some reason fioDread seems to be returning a iox_dirent_t, instead of a io_dirent_t

View File

@ -108,11 +108,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return sysLv2FsMkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
sysFSStat sb;
Platform_EncodePath(&str, path);
return sysLv2FsStat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return sysLv2FsStat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -100,11 +100,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return GetSCEResult(result);
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
SceIoStat sb;
Platform_EncodePath(&str, path);
return sceIoGetstat(str.buffer, &sb) == 0 && (sb.st_attr & FIO_SO_IFREG) != 0;
return sceIoGetstat(path->buffer, &sb) == 0 && (sb.st_attr & FIO_SO_IFREG) != 0;
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -83,11 +83,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return GetSCEResult(result);
}
int File_Exists(const cc_string* path) {
cc_filepath str;;
int File_Exists(const cc_filepath* path) {
SceIoStat sb;
Platform_EncodePath(&str, path);
return sceIoGetstat(str.buffer, &sb) == 0 && SCE_S_ISREG(sb.st_mode) != 0;
return sceIoGetstat(path->buffer, &sb) == 0 && SCE_S_ISREG(sb.st_mode) != 0;
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -211,12 +211,9 @@ cc_result Directory_Create(const cc_filepath* path) {
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_filepath* path) {
struct stat sb;
cc_filepath str;
Platform_EncodePath(&str, path);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -94,8 +94,8 @@ cc_result Directory_Create(const cc_filepath* path) {
return ReturnCode_DirectoryExists;
}
int File_Exists(const cc_string* path) {
return ERR_NOT_SUPPORTED;
int File_Exists(const cc_filepath* path) {
return false;
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -120,11 +120,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return mkdir(path->buffer, 0) == -1 ? errno : 0;
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
struct stat sb;
Platform_EncodePath(&str, path);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -114,10 +114,8 @@ cc_result Directory_Create(const cc_filepath* path) {
}
extern int interop_FileExists(const char* path);
int File_Exists(const cc_string* path) {
cc_filepath str;
Platform_EncodePath(&str, path);
return interop_FileExists(str.buffer);
int File_Exists(const cc_filepath* path) {
return interop_FileExists(path->buffer);
}
static void* enum_obj;

View File

@ -116,11 +116,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return mkdir(path->buffer, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1 ? errno : 0;
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
struct stat sb;
Platform_EncodePath(&str, path);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -193,12 +193,11 @@ cc_result Directory_Create(const cc_filepath* path) {
return CreateDirectoryA(path->ansi, NULL) ? 0 : GetLastError();
}
int File_Exists(const cc_string* path) {
cc_filepath str;
DWORD attribs;
Platform_EncodePath(&str, path);
attribs = GetFileAttributesW(str.uni);
int File_Exists(const cc_filepath* path) {
DWORD attribs = GetFileAttributesW(path->uni);
if (attribs == INVALID_FILE_ATTRIBUTES)
attribs = GetFileAttributesA(path->ansi);
return attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY);
}

View File

@ -107,15 +107,10 @@ cc_result Directory_Create(const cc_filepath* path) {
return CreateDirectoryA(path->buffer, NULL) ? 0 : GetLastError();
}
int File_Exists(const cc_string* path) {
int File_Exists(const cc_filepath* path) {
if (!hdd_mounted) return 0;
cc_filepath str;
DWORD attribs;
Platform_EncodePath(&str, path);
attribs = GetFileAttributesA(str.buffer);
DWORD attribs = GetFileAttributesA(path->buffer);
return attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY);
}

View File

@ -89,11 +89,9 @@ cc_result Directory_Create(const cc_filepath* path) {
return mkdir(path->buffer, 0) == -1 ? errno : 0;
}
int File_Exists(const cc_string* path) {
cc_filepath str;
int File_Exists(const cc_filepath* path) {
struct stat sb;
Platform_EncodePath(&str, path);
return stat(str.buffer, &sb) == 0 && S_ISREG(sb.st_mode);
return stat(path->buffer, &sb) == 0 && S_ISREG(sb.st_mode);
}
cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCallback callback) {

View File

@ -399,6 +399,7 @@ static struct MusicAsset {
static void MusicAssets_CheckExistence(void) {
cc_string path; char pathBuffer[FILENAME_SIZE];
cc_filepath str;
int i;
String_InitArray(path, pathBuffer);
@ -407,7 +408,8 @@ static void MusicAssets_CheckExistence(void) {
path.length = 0;
String_Format1(&path, "audio/%c", musicAssets[i].name);
musicAssets[i].downloaded = File_Exists(&path);
Platform_EncodePath(&str, &path);
musicAssets[i].downloaded = File_Exists(&str);
}
}
@ -679,7 +681,10 @@ static cc_bool ccTexturesExist, ccTexturesDownloaded;
static int ccTexturesReqID;
static void CCTextures_CheckExistence(void) {
ccTexturesExist = File_Exists(&ccTexPack);
cc_filepath path;
Platform_EncodePath(&path, &ccTexPack);
ccTexturesExist = File_Exists(&path);
}
static void CCTextures_CountMissing(void) {

View File

@ -336,11 +336,16 @@ CC_NOINLINE static void MakeCachePath(cc_string* mainPath, cc_string* altPath, c
static int IsCached(const cc_string* url) {
cc_string mainPath; char mainBuffer[FILENAME_SIZE];
cc_string altPath; char altBuffer[FILENAME_SIZE];
cc_filepath mainStr, altStr;
String_InitArray(mainPath, mainBuffer);
String_InitArray(altPath, altBuffer);
MakeCachePath(&mainPath, &altPath, url);
return File_Exists(&mainPath) || (altPath.length && File_Exists(&altPath));
Platform_EncodePath(&mainStr, &mainPath);
Platform_EncodePath(&altStr, &altPath);
return File_Exists(&mainStr) || (altPath.length && File_Exists(&altStr));
}
/* Attempts to open the cached data stream for the given url */

View File

@ -69,7 +69,14 @@ static void SetupProgram(int argc, char** argv) {
String_InitArray(Server.Address, ipBuffer);
}
#define SP_HasDir(path) (String_IndexOf(&path, '/') >= 0 || String_IndexOf(&path, '\\') >= 0)
#define SP_HasDir(path) (String_IndexOf(path, '/') >= 0 || String_IndexOf(path, '\\') >= 0)
static cc_bool IsOpenableFile(const cc_string* path) {
cc_filepath str;
if (!SP_HasDir(path)) return false;
Platform_EncodePath(&str, path);
return File_Exists(&str);
}
static int RunProgram(int argc, char** argv) {
cc_string args[GAME_MAX_CMDARGS];
@ -93,7 +100,7 @@ static int RunProgram(int argc, char** argv) {
String_Copy(&Launcher_AutoHash, &args[0]);
Launcher_Run();
/* File path to auto load a map in singleplayer */
} else if (argsCount == 1 && SP_HasDir(args[0]) && File_Exists(&args[0])) {
} else if (argsCount == 1 && IsOpenableFile(&args[0])) {
Options_Get(LOPT_USERNAME, &Game_Username, DEFAULT_USERNAME);
String_Copy(&SP_AutoloadMap, &args[0]); /* TODO: don't copy args? */
RunGame();