]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move fexists from server/miscfunctions.qc to common/util.qc so that it's available...
authorterencehill <piuntn@gmail.com>
Tue, 22 Mar 2011 20:31:30 +0000 (21:31 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 22 Mar 2011 20:31:30 +0000 (21:31 +0100)
Remove from server/g_world.qc the never called function TryFile, which is a copy of fexists

qcsrc/client/miscfunctions.qc
qcsrc/common/gamecommand.qc
qcsrc/common/mapinfo.qc
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/menu/xonotic/util.qc
qcsrc/server/g_world.qc
qcsrc/server/miscfunctions.qc

index d38b7c9ba0d4837de902f2b86a4d5bb6e2111d92..1b1eaadb774d52f0d4b54d71f205bfda208a66dc 100644 (file)
@@ -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;
 }
 
index 3b93c4cae9fb31e8e003b38d6f9f7cceeced7ddc..518cf74971a645dde3c412c1a1eaabee9b5ae1b8 100644 (file)
@@ -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()));
index 58f0cc852a6e07383df3dadd8ce1d4e466c5a15a..a6b0788088216c93b53f2a0dfa96aabc5ed5e820 100644 (file)
@@ -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");
index fc86c3a842d07704be28ccc1445fcfeccfe782d6..05152d4bb595b27e7137e1976edb4a681aad6363 100644 (file)
@@ -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)
index a15855753217765d2396f6ab38f89e127a5060dc..c3ae491660e116edcebc1adcee2d99340361ead8 100644 (file)
@@ -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
index 1d21ba4910a7a391b8d3a87b40bc27f988fe5353..c24693e6d43caa4b5d32e9ce22fe044aa957cb5f 100644 (file)
@@ -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))
        {
index 4c41852ebba66057b10d7d906c5b199a55994005..5cfe2fb2395376fb2fb02dbd3bfb2b5868f58fd2 100644 (file)
@@ -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
index 4cf479fa9fdaf34896db02d29aa555d8ade6a77d..c424bc797d53e9c59c483d11a888876a2f36db4d 100644 (file)
@@ -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;