diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 6575c3d5..87b95ec0 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -116,7 +116,7 @@ void UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms, char *pM void UTIL_IntToString(int value, char *output); void UTIL_ShowMOTD( edict_t *client , char *motd, int mlen, const char *name); void UTIL_ShowMenu( edict_t* pEntity, int slots, int time, char *menu, int mlen ); -const char *UTIL_VarArgs(const char *fmt, ...); +char *UTIL_VarArgs(const char *fmt, ...); #define GET_PLAYER_POINTER(e) (&g_players[ENTINDEX(e)]) diff --git a/amxmodx/file.cpp b/amxmodx/file.cpp index 9c210969..d59bf55a 100755 --- a/amxmodx/file.cpp +++ b/amxmodx/file.cpp @@ -36,18 +36,18 @@ #endif #ifdef __GNUC__ - -//#include #include #include +#include #include - #endif // header file for unlink() #ifdef __linux__ #include #else +#define WINDOWS_LEAN_AND_MEAN +#include #include #endif @@ -234,13 +234,45 @@ static cell AMX_NATIVE_CALL delete_file(AMX *amx, cell *params) /* 1 param */ static cell AMX_NATIVE_CALL file_exists(AMX *amx, cell *params) /* 1 param */ { int iLen; - char* sFile = get_amxstring(amx,params[1],0,iLen); - FILE* fp = fopen(build_pathname("%s",sFile),"r"); - if ( fp != NULL) { - fclose(fp); - return 1; - } + char *sFile = get_amxstring(amx,params[1],0,iLen); + char *file = build_pathname("%s",sFile); +#if defined WIN32 || defined _WIN32 + DWORD attr = GetFileAttributes(file); + if (attr == INVALID_FILE_ATTRIBUTES) + return 0; + if (attr == FILE_ATTRIBUTE_DIRECTORY) + return 0; + return 1; +#else + struct stat s; + if (stat(file, &s) != 0) + return 0; + if (S_ISDIR(s.st_mode)) + return 0; + return 1; +#endif +} + +static cell AMX_NATIVE_CALL dir_exists(AMX *amx, cell *params) /* 1 param */ +{ + int iLen; + char *sFile = get_amxstring(amx,params[1],0,iLen); + char *file = build_pathname("%s",sFile); +#if defined WIN32 || defined _WIN32 + DWORD attr = GetFileAttributes(file); + if (attr == INVALID_FILE_ATTRIBUTES) + return 0; + if (attr == FILE_ATTRIBUTE_DIRECTORY) + return 1; return 0; +#else + struct stat s; + if (stat(file, &s) != 0) + return 0; + if (S_ISDIR(s.st_mode)) + return 1; + return 0; +#endif } static cell AMX_NATIVE_CALL file_size(AMX *amx, cell *params) /* 1 param */ @@ -643,6 +675,7 @@ AMX_NATIVE_INFO file_Natives[] = { { "fgetf", amx_fgetf }, { "fputf", amx_fputf }, { "build_pathname", amx_build_pathname}, + { "dir_exists", dir_exists }, { NULL, NULL } }; diff --git a/amxmodx/util.cpp b/amxmodx/util.cpp index 2591da17..ebb95012 100755 --- a/amxmodx/util.cpp +++ b/amxmodx/util.cpp @@ -37,7 +37,7 @@ #define _vsnprintf vsnprintf #endif -const char *UTIL_VarArgs(const char *fmt, ...) +char *UTIL_VarArgs(const char *fmt, ...) { va_list ap; static char string[4096]; diff --git a/plugins/include/file.inc b/plugins/include/file.inc index c24d0c07..b467f8a4 100755 --- a/plugins/include/file.inc +++ b/plugins/include/file.inc @@ -28,6 +28,9 @@ native delete_file(const file[]); /* Checks for file. If file exists function returns 1, in other case 0. */ native file_exists(const file[]); +/* Checks if a directory exists */ +native dir_exists(const dir[]); + /* Returns a file size in bytes if flag is set to 0. * When flag is set to 1 returns number of lines in the file, * and when flags is 2, function returns 1 if the file ends