Add support for Valve search paths to GetFileSize native (bug 5931, r=asherkin).

This commit is contained in:
Nicholas Hastings 2014-01-07 14:24:53 -05:00
parent 310f77d96a
commit ad5740f8a7
4 changed files with 26 additions and 5 deletions

View File

@ -51,7 +51,7 @@ using namespace SourceHook;
* Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries
*/
#define SM_LOGIC_MAGIC (0x0F47C0DE - 26)
#define SM_LOGIC_MAGIC (0x0F47C0DE - 27)
#if defined SM_LOGIC
class IVEngineServer
@ -82,6 +82,7 @@ public:
virtual char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) = 0;
virtual bool EndOfFile(FileHandle_t file) = 0;
virtual bool FileExists(const char *pFileName, const char *pPathID = 0) = 0;
virtual unsigned int Size(const char *pFileName, const char *pPathID = 0) = 0;
};
namespace SourceMod

View File

@ -426,6 +426,18 @@ static cell_t sm_FileSize(IPluginContext *pContext, const cell_t *params)
return -1;
}
if (params[0] >= 2 && params[2] == 1)
{
if (smcore.filesystem->FileExists(name))
{
return smcore.filesystem->Size(name);
}
else
{
return -1;
}
}
char realpath[PLATFORM_MAX_PATH];
g_pSM->BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name);
#ifdef PLATFORM_WINDOWS

View File

@ -138,6 +138,10 @@ public:
{
return filesystem->FileExists(pFileName, pPathID);
}
unsigned int Size(const char *pFileName, const char *pPathID = 0)
{
return filesystem->Size(pFileName, pPathID);
}
};
static VFileSystem_Logic logic_filesystem;

View File

@ -303,9 +303,9 @@ native FilePosition(Handle:file);
*
* @param path Path to the file.
* @param use_valve_fs If true, the Valve file system will be used instead.
* This can be used to check for the existance of files
* inside GCFs or the game cache, rather than solely files
* that are on disk.
* This can be used to find files existing in any of
* the GAME search paths, rather than solely files
* existing directly in the gamedir.
* @return True if the file exists, false otherwise.
*/
native bool:FileExists(const String:path[], bool:use_valve_fs=false);
@ -331,9 +331,13 @@ native bool:DirExists(const String:path[]);
* Get the file size in bytes.
*
* @param path Path to the file.
* @param use_valve_fs If true, the Valve file system will be used instead.
* This can be used to find files existing in any of
* the GAME search paths, rather than solely files
* existing directly in the gamedir.
* @return File size in bytes, -1 if file not found.
*/
native FileSize(const String:path[]);
native FileSize(const String:path[], bool:use_valve_fs=false);
/**
* Flushes a file's buffered output; any buffered output