From: terencehill Date: Tue, 22 Mar 2011 20:31:30 +0000 (+0100) Subject: Move fexists from server/miscfunctions.qc to common/util.qc so that it's available... X-Git-Tag: xonotic-v0.5.0~263^2^2 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=80811920732c5756699249adb24ed8d241699d73 Move fexists from server/miscfunctions.qc to common/util.qc so that it's available in csqc and menu too; use it when possible Remove from server/g_world.qc the never called function TryFile, which is a copy of fexists --- diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc index d38b7c9ba0..1b1eaadb77 100644 --- a/qcsrc/client/miscfunctions.qc +++ b/qcsrc/client/miscfunctions.qc @@ -325,34 +325,11 @@ float PreviewExists(string name) if(autocvar_cl_readpicture_force) return false; - file = strcat(name, ".tga"); - f = fopen(file, FILE_READ); - if(f >= 0) - { - fclose(f); - return true; - } - file = strcat(name, ".png"); - f = fopen(file, FILE_READ); - if(f >= 0) - { - fclose(f); - return true; - } - file = strcat(name, ".jpg"); - f = fopen(file, FILE_READ); - if(f >= 0) - { - fclose(f); - return true; - } - file = strcat(name, ".pcx"); - f = fopen(file, FILE_READ); - if(f >= 0) - { - fclose(f); - return true; - } + if (fexists(strcat(name, ".tga"))) return true; + if (fexists(strcat(name, ".png"))) return true; + if (fexists(strcat(name, ".jpg"))) return true; + if (fexists(strcat(name, ".pcx"))) return true; + return false; } diff --git a/qcsrc/common/gamecommand.qc b/qcsrc/common/gamecommand.qc index 3b93c4cae9..518cf74971 100644 --- a/qcsrc/common/gamecommand.qc +++ b/qcsrc/common/gamecommand.qc @@ -210,10 +210,8 @@ float GameCommand_Generic(string command) { if(argv(1) == "add" && argc == 3) { - f = fopen(strcat("maps/", argv(2), ".bsp"), FILE_READ); - if(f != -1) - fclose(f); - else { + if (!fexists(strcat("maps/", argv(2), ".bsp"))) + { print("maplist: ERROR: ", argv(2), " does not exist!\n"); return TRUE; } @@ -771,10 +769,8 @@ float GameCommand_Generic(string command) s = rpn_pop(); if(!rpn_error) { - f = fopen(s, FILE_READ); - if(f != -1) - fclose(f); - else { + if (!fexists(s)) + { print("rpn: ERROR: ", s, " does not exist!\n"); rpn_error = TRUE; } @@ -783,13 +779,10 @@ float GameCommand_Generic(string command) s = rpn_get(); if(!rpn_error) { - f = fopen(s, FILE_READ); - if(f != -1) { - fclose(f); + if (fexists(s)) rpn_setf(1); - } else { + else rpn_setf(0); - } } } else if(rpncmd == "localtime") { rpn_set(strftime(TRUE, rpn_get())); diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index 58f0cc852a..a6b0788088 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -875,12 +875,8 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype if(MapInfo_Map_supportedGametypes & i) fputs(fh, sprintf("gametype %s // defaults: %s\n", MapInfo_Type_ToString(i), _MapInfo_GetDefaultEx(i))); - fh2 = fopen(strcat("scripts/", pFilename, ".arena"), FILE_READ); - if(fh2 >= 0) - { - fclose(fh2); + if(fexists(strcat("scripts/", pFilename, ".arena"))) fputs(fh, "settemp_for_type all sv_q3acompat_machineshotgunswap 1\n"); - } fputs(fh, "// optional: fog density red green blue alpha mindist maxdist\n"); fputs(fh, "// optional: settemp_for_type (all|gametypename) cvarname value\n"); diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index fc86c3a842..05152d4bb5 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -236,6 +236,16 @@ string fstrunzone(string s) return sc; } +float fexists(string f) +{ + float fh; + fh = fopen(f, FILE_READ); + if (fh < 0) + return FALSE; + fclose(fh); + return TRUE; +} + // Databases (hash tables) #define DB_BUCKETS 8192 void db_save(float db, string pFilename) diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index a158557532..c3ae491660 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -34,6 +34,8 @@ float median(float a, float b, float c); // works for up to 10 decimals! string ftos_decimals(float number, float decimals); +float fexists(string f); + vector colormapPaletteColor(float c, float isPants); // unzone the string, and return it as tempstring. Safe to be called on string_null diff --git a/qcsrc/menu/xonotic/util.qc b/qcsrc/menu/xonotic/util.qc index 1d21ba4910..c24693e6d4 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -474,15 +474,11 @@ string HUD_Panel_GetSettingName(float theSetting) float updateCompression() { - float fh; float have_dds, have_jpg, have_tga; float can_dds; - if((have_dds = ((fh = fopen("dds/particles/particlefont.dds", FILE_READ)) >= 0))) - fclose(fh); - if((have_jpg = ((fh = fopen("particles/particlefont.jpg", FILE_READ)) >= 0))) - fclose(fh); - if((have_tga = ((fh = fopen("particles/particlefont.tga", FILE_READ)) >= 0))) - fclose(fh); + have_dds = (fexists("dds/particles/particlefont.dds")); + have_dds = (fexists("particles/particlefont.jpg")); + have_dds = (fexists("particles/particlefont.tga")); can_dds = GL_Have_TextureCompression(); if(have_dds && (have_jpg || have_tga)) { diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index 4c41852ebb..5cfe2fb239 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -940,19 +940,6 @@ void spawnfunc_light (void) remove(self); } -float TryFile( string pFilename ) -{ - local float lHandle; - dprint("TryFile(\"", pFilename, "\")\n"); - lHandle = fopen( pFilename, FILE_READ ); - if( lHandle != -1 ) { - fclose( lHandle ); - return TRUE; - } else { - return FALSE; - } -}; - string GetGametype() { return GametypeNameFromType(game); @@ -996,14 +983,12 @@ float MapHasRightSize(string map) if(autocvar_g_maplist_check_waypoints) { dprint("checkwp "); dprint(map); - fh = fopen(strcat("maps/", map, ".waypoints"), FILE_READ); - if(fh < 0) + if(!fexists(strcat("maps/", map, ".waypoints"))) { dprint(": no waypoints\n"); return FALSE; } dprint(": has waypoints\n"); - fclose(fh); } // open map size restriction file diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 4cf479fa9f..c424bc797d 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -625,16 +625,6 @@ void GetCvars(float f) } } -float fexists(string f) -{ - float fh; - fh = fopen(f, FILE_READ); - if (fh < 0) - return FALSE; - fclose(fh); - return TRUE; -} - void backtrace(string msg) { float dev, war;