diff --git a/polymer/eduke32/build/include/common.h b/polymer/eduke32/build/include/common.h index 594fd593b..e54dde762 100644 --- a/polymer/eduke32/build/include/common.h +++ b/polymer/eduke32/build/include/common.h @@ -51,7 +51,8 @@ void G_AddPath(const char *buffer); int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens); -int32_t check_file_exist(const char *fn); +int32_t testkopen(const char *filename, char searchfirst); // full-blown kopen4load +int32_t check_file_exist(const char *fn); // findfrompath with pathsearchmode=1 / search in zips void fnlist_clearnames(fnlist_t *fnl); int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern, diff --git a/polymer/eduke32/source/common.c b/polymer/eduke32/source/common.c index 94e952c21..a40c425d1 100644 --- a/polymer/eduke32/source/common.c +++ b/polymer/eduke32/source/common.c @@ -28,7 +28,6 @@ char *g_defNamePtr = NULL; // g_scriptNamePtr can ONLY point to a malloc'd block (length BMAX_PATH) char *g_scriptNamePtr = NULL; - void clearGrpNamePtr(void) { if (g_grpNamePtr != NULL) @@ -72,14 +71,14 @@ char *G_DefaultDefFile(void) return defaultdeffilename[GAME_WW2GI]; else if (NAPALM) { - if ((kopen4load(defaultdeffilename[GAME_NAPALM],0) < 0) && (kopen4load(defaultdeffilename[GAME_NAM],0) >= 0)) + if (!testkopen(defaultdeffilename[GAME_NAPALM],0) && testkopen(defaultdeffilename[GAME_NAM],0)) return defaultdeffilename[GAME_NAM]; // NAM/Napalm Sharing else return defaultdeffilename[GAME_NAPALM]; } else if (NAM) { - if ((kopen4load(defaultdeffilename[GAME_NAM],0) < 0) && (kopen4load(defaultdeffilename[GAME_NAPALM],0) >= 0)) + if (!testkopen(defaultdeffilename[GAME_NAM],0) && testkopen(defaultdeffilename[GAME_NAPALM],0)) return defaultdeffilename[GAME_NAPALM]; // NAM/Napalm Sharing else return defaultdeffilename[GAME_NAM]; @@ -89,15 +88,15 @@ char *G_DefaultDefFile(void) } char *G_DefaultConFile(void) { - if (DUKE && (kopen4load(defaultgameconfilename[GAME_DUKE],0) >= 0)) + if (DUKE && testkopen(defaultgameconfilename[GAME_DUKE],0)) return defaultgameconfilename[GAME_DUKE]; - else if (WW2GI && (kopen4load(defaultgameconfilename[GAME_WW2GI],0) >= 0)) + else if (WW2GI && testkopen(defaultgameconfilename[GAME_WW2GI],0)) return defaultgameconfilename[GAME_WW2GI]; else if (NAPALM) { - if (kopen4load(defaultgameconfilename[GAME_NAPALM],0) < 0) + if (!testkopen(defaultgameconfilename[GAME_NAPALM],0)) { - if (kopen4load(defaultgameconfilename[GAME_NAM],0) >= 0) + if (testkopen(defaultgameconfilename[GAME_NAM],0)) return defaultgameconfilename[GAME_NAM]; // NAM/Napalm Sharing } else @@ -105,9 +104,9 @@ char *G_DefaultConFile(void) } else if (NAM) { - if (kopen4load(defaultgameconfilename[GAME_NAM],0) < 0) + if (!testkopen(defaultgameconfilename[GAME_NAM],0)) { - if (kopen4load(defaultgameconfilename[GAME_NAPALM],0) >= 0) + if (testkopen(defaultgameconfilename[GAME_NAPALM],0)) return defaultgameconfilename[GAME_NAPALM]; // NAM/Napalm Sharing } else @@ -202,6 +201,15 @@ int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) ////////// +// returns: 1 if file could be opened, 0 else +int32_t testkopen(const char *filename, char searchfirst) +{ + int32_t fd = kopen4load(filename, searchfirst); + if (fd >= 0) + kclose(fd); + return (fd >= 0); +} + // checks from path and in ZIPs, returns 1 if NOT found int32_t check_file_exist(const char *fn) { diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index be9f5ed4f..7becc8d5a 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -213,14 +213,14 @@ const char *G_DefaultRtsFile(void) return defaultrtsfilename[GAME_WW2GI]; else if (NAPALM) { - if ((kopen4load(defaultrtsfilename[GAME_NAPALM],0) < 0) && (kopen4load(defaultrtsfilename[GAME_NAM],0) >= 0)) + if (!testkopen(defaultrtsfilename[GAME_NAPALM],0) && testkopen(defaultrtsfilename[GAME_NAM],0)) return defaultrtsfilename[GAME_NAM]; // NAM/Napalm Sharing else return defaultrtsfilename[GAME_NAPALM]; } else if (NAM) { - if ((kopen4load(defaultrtsfilename[GAME_NAM],0) < 0) && (kopen4load(defaultrtsfilename[GAME_NAPALM],0) >= 0)) + if (!testkopen(defaultrtsfilename[GAME_NAM],0) && testkopen(defaultrtsfilename[GAME_NAPALM],0)) return defaultrtsfilename[GAME_NAPALM]; // NAM/Napalm Sharing else return defaultrtsfilename[GAME_NAM];