implemented amb843 - GetFileTime()
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401376
This commit is contained in:
parent
294d6b9f8f
commit
d9866748f7
@ -543,6 +543,49 @@ static cell_t sm_LogError(IPluginContext *pContext, const cell_t *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
FileTime_LastAccess = 0, /* Last access (not available on FAT) */
|
||||
FileTime_Created = 1, /* Creation (not available on FAT) */
|
||||
FileTime_LastChange = 2, /* Last modification */
|
||||
};
|
||||
|
||||
static cell_t sm_GetFileTime(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *name;
|
||||
int err;
|
||||
if ((err=pContext->LocalToString(params[1], &name)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
char realpath[PLATFORM_MAX_PATH];
|
||||
g_SourceMod.BuildPath(Path_Game, realpath, sizeof(realpath), "%s", name);
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
struct _stat s;
|
||||
if (_stat(realpath, &s) != 0)
|
||||
#elif defined PLATFORM_POSIX
|
||||
struct stat s;
|
||||
if (stat(path, &s) != 0)
|
||||
#endif
|
||||
{
|
||||
return -1;
|
||||
} else {
|
||||
if (params[2] == FileTime_LastAccess)
|
||||
{
|
||||
return (cell_t)s.st_atime;
|
||||
} else if (params[2] == FileTime_Created) {
|
||||
return (cell_t)s.st_ctime;
|
||||
} else if (params[2] == FileTime_LastChange) {
|
||||
return (cell_t)s.st_mtime;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static FileNatives s_FileNatives;
|
||||
|
||||
REGISTER_NATIVES(filesystem)
|
||||
@ -566,5 +609,6 @@ REGISTER_NATIVES(filesystem)
|
||||
{"LogMessage", sm_LogMessage},
|
||||
{"LogError", sm_LogError},
|
||||
{"FlushFile", sm_FlushFile},
|
||||
{"GetFileTime", sm_GetFileTime},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
@ -47,6 +47,16 @@ enum FileType
|
||||
FileType_File = 2, /* File is a file */
|
||||
};
|
||||
|
||||
/**
|
||||
* File time modes.
|
||||
*/
|
||||
enum FileTimeMode
|
||||
{
|
||||
FileTime_LastAccess = 0, /* Last access (does not work on FAT) */
|
||||
FileTime_Created = 1, /* Creation (does not work on FAT) */
|
||||
FileTime_LastChange = 2, /* Last modification */
|
||||
};
|
||||
|
||||
#define PLATFORM_MAX_PATH 256 /**< Maximum path length. */
|
||||
|
||||
#define SEEK_SET 0 /**< Seek from start. */
|
||||
@ -213,3 +223,12 @@ native bool:RemoveDir(const String:path[]);
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);
|
||||
|
||||
/**
|
||||
* Returns a file timestamp as a unix timestamp.
|
||||
*
|
||||
* @param file File name.
|
||||
* @param tmode Time mode.
|
||||
* @return Time value, or -1 on failure.
|
||||
*/
|
||||
native GetFileTime(const String:file[], FileTimeMode:tmode);
|
||||
|
Loading…
Reference in New Issue
Block a user