Add support for specifying gameinfo search path when using valveFS in file natives
This commit is contained in:
parent
b95e7ff145
commit
73115f7afa
@ -82,7 +82,6 @@ class IFileSystem_Logic
|
||||
{
|
||||
public:
|
||||
virtual const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) = 0;
|
||||
virtual const char *FindFirst(const char *pWildCard, FileFindHandle_t *pHandle) = 0;
|
||||
virtual const char *FindNext(FileFindHandle_t handle) = 0;
|
||||
virtual bool FindIsDirectory(FileFindHandle_t handle) = 0;
|
||||
virtual void FindClose(FileFindHandle_t handle) = 0;
|
||||
|
@ -59,10 +59,10 @@ public:
|
||||
_fstype = fstype;
|
||||
}
|
||||
public:
|
||||
inline void *Open(const char *filename, const char *mode)
|
||||
inline void *Open(const char *filename, const char *mode, const char *pathID)
|
||||
{
|
||||
if (_fstype == FSType::VALVE)
|
||||
return smcore.filesystem->Open(filename, mode);
|
||||
return smcore.filesystem->Open(filename, mode, pathID);
|
||||
else
|
||||
return fopen(filename, mode);
|
||||
}
|
||||
@ -123,16 +123,16 @@ public:
|
||||
fclose((FILE *)pFile);
|
||||
}
|
||||
|
||||
inline bool Remove(const char *pFilePath)
|
||||
inline bool Remove(const char *pFilePath, const char *pathID)
|
||||
{
|
||||
if (_fstype == FSType::VALVE)
|
||||
{
|
||||
if (!smcore.filesystem->FileExists(pFilePath))
|
||||
if (!smcore.filesystem->FileExists(pFilePath, pathID))
|
||||
return false;
|
||||
|
||||
smcore.filesystem->RemoveFile(pFilePath);
|
||||
smcore.filesystem->RemoveFile(pFilePath, pathID);
|
||||
|
||||
if (smcore.filesystem->FileExists(pFilePath))
|
||||
if (smcore.filesystem->FileExists(pFilePath, pathID))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -263,7 +263,15 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
|
||||
char wildcardedPath[PLATFORM_MAX_PATH];
|
||||
snprintf(wildcardedPath, sizeof(wildcardedPath), "%s*", path);
|
||||
ValveDirectory *valveDir = new ValveDirectory;
|
||||
const char *pFirst = smcore.filesystem->FindFirst(wildcardedPath, &valveDir->hndl);
|
||||
|
||||
char *pathID;
|
||||
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *pFirst = smcore.filesystem->FindFirstEx(wildcardedPath, pathID, &valveDir->hndl);
|
||||
if (pFirst)
|
||||
{
|
||||
valveDir->bHandledFirstPath = false;
|
||||
@ -409,6 +417,7 @@ static cell_t sm_OpenFile(IPluginContext *pContext, const cell_t *params)
|
||||
HandleType_t handleType;
|
||||
FSHelper fshelper;
|
||||
const char *openpath;
|
||||
char *pathID;
|
||||
if (params[0] <= 2 || !params[3])
|
||||
{
|
||||
handleType = g_FileType;
|
||||
@ -420,12 +429,18 @@ static cell_t sm_OpenFile(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((err=pContext->LocalToStringNULL(params[4], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
handleType = g_ValveFileType;
|
||||
fshelper.SetFSType(FSType::VALVE);
|
||||
openpath = name;
|
||||
}
|
||||
|
||||
void *pFile = fshelper.Open(openpath, mode);
|
||||
void *pFile = fshelper.Open(openpath, mode, pathID);
|
||||
if (pFile)
|
||||
{
|
||||
handle = handlesys->CreateHandle(handleType, pFile, pContext->GetIdentity(), g_pCoreIdent, NULL);
|
||||
@ -446,6 +461,7 @@ static cell_t sm_DeleteFile(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
FSHelper fshelper;
|
||||
const char *filepath;
|
||||
char *pathID;
|
||||
if (params[0] < 2 || !params[2])
|
||||
{
|
||||
fshelper.SetFSType(FSType::STDIO);
|
||||
@ -455,11 +471,17 @@ static cell_t sm_DeleteFile(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fshelper.SetFSType(FSType::VALVE);
|
||||
filepath = name;
|
||||
}
|
||||
|
||||
return fshelper.Remove(filepath) ? 1 : 0;
|
||||
return fshelper.Remove(filepath, pathID) ? 1 : 0;
|
||||
}
|
||||
|
||||
static cell_t sm_ReadFileLine(IPluginContext *pContext, const cell_t *params)
|
||||
@ -594,7 +616,17 @@ static cell_t sm_FileExists(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (params[0] >= 2 && params[2] == 1)
|
||||
{
|
||||
return smcore.filesystem->FileExists(name) ? 1 : 0;
|
||||
char *pathID = NULL;
|
||||
if (params[0] >= 3)
|
||||
{
|
||||
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return smcore.filesystem->FileExists(name, pathID) ? 1 : 0;
|
||||
}
|
||||
|
||||
char realpath[PLATFORM_MAX_PATH];
|
||||
@ -641,7 +673,14 @@ static cell_t sm_RenameFile(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (params[0] >= 3 && params[3] == 1)
|
||||
{
|
||||
smcore.filesystem->RenameFile(oldpath, newpath);
|
||||
char *pathID;
|
||||
if ((err=pContext->LocalToStringNULL(params[4], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
smcore.filesystem->RenameFile(oldpath, newpath, pathID);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -669,7 +708,14 @@ static cell_t sm_DirExists(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (params[0] >= 2 && params[2] == 1)
|
||||
{
|
||||
return smcore.filesystem->IsDirectory(name) ? 1 : 0;
|
||||
char *pathID;
|
||||
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return smcore.filesystem->IsDirectory(name, pathID) ? 1 : 0;
|
||||
}
|
||||
|
||||
char realpath[PLATFORM_MAX_PATH];
|
||||
@ -711,9 +757,19 @@ static cell_t sm_FileSize(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (params[0] >= 2 && params[2] == 1)
|
||||
{
|
||||
if (smcore.filesystem->FileExists(name))
|
||||
char *pathID = NULL;
|
||||
if (params[0] >= 3)
|
||||
{
|
||||
return smcore.filesystem->Size(name);
|
||||
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
pContext->ThrowNativeErrorEx(err, NULL);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (smcore.filesystem->FileExists(name, pathID))
|
||||
{
|
||||
return smcore.filesystem->Size(name, pathID);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -755,12 +811,19 @@ static cell_t sm_CreateDirectory(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
if (params[0] >= 3 && params[3] == 1)
|
||||
{
|
||||
if (smcore.filesystem->IsDirectory(name))
|
||||
int err;
|
||||
char *pathID;
|
||||
if ((err=pContext->LocalToStringNULL(params[4], &pathID)) != SP_ERROR_NONE)
|
||||
{
|
||||
return pContext->ThrowNativeErrorEx(err, NULL);
|
||||
}
|
||||
|
||||
if (smcore.filesystem->IsDirectory(name, pathID))
|
||||
return 0;
|
||||
|
||||
smcore.filesystem->CreateDirHierarchy(name);
|
||||
smcore.filesystem->CreateDirHierarchy(name, pathID);
|
||||
|
||||
if (smcore.filesystem->IsDirectory(name))
|
||||
if (smcore.filesystem->IsDirectory(name, pathID))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
@ -142,10 +142,6 @@ public:
|
||||
{
|
||||
return filesystem->FindFirstEx(pWildCard, pPathID, pHandle);
|
||||
}
|
||||
const char *FindFirst(const char *pWildCard, FileFindHandle_t *pHandle)
|
||||
{
|
||||
return filesystem->FindFirst(pWildCard, pHandle);
|
||||
}
|
||||
const char *FindNext(FileFindHandle_t handle)
|
||||
{
|
||||
return filesystem->FindNext(handle);
|
||||
|
@ -110,11 +110,12 @@ native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[],
|
||||
* @param path Path to open.
|
||||
* @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
|
||||
* the Valve search paths, rather than solely files
|
||||
* existing directly in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return A Handle to the directory, INVALID_HANDLE on open error.
|
||||
*/
|
||||
native Handle:OpenDirectory(const String:path[], bool:use_valve_fs=false);
|
||||
native Handle:OpenDirectory(const String:path[], bool:use_valve_fs=false, const String:valve_path_id[]="GAME");
|
||||
|
||||
/**
|
||||
* Reads the current directory entry as a local filename, then moves to the next file.
|
||||
@ -141,24 +142,26 @@ native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=
|
||||
* @param file File to open.
|
||||
* @param mode Open mode.
|
||||
* @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.
|
||||
* This can be used to find files existing in valve
|
||||
* search paths, rather than solely files existing directly
|
||||
* in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return A Handle to the file, INVALID_HANDLE on open error.
|
||||
*/
|
||||
native Handle:OpenFile(const String:file[], const String:mode[], bool:use_valve_fs=false);
|
||||
native Handle:OpenFile(const String:file[], const String:mode[], bool:use_valve_fs=false, const String:valve_path_id[]="GAME");
|
||||
|
||||
/**
|
||||
* Deletes a file.
|
||||
*
|
||||
* @param path Path of the file to delete.
|
||||
* @param use_valve_fs If true, the Valve file system will be used instead.
|
||||
* This can be used to delete files existing in the game's
|
||||
* DEFAULT_WRITE_PATH search path, rather than solely files
|
||||
* existing directly in the gamedir.
|
||||
* This can be used to delete files existing in the Valve
|
||||
* search path, rather than solely files existing directly
|
||||
* in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
native bool:DeleteFile(const String:path[], bool:use_valve_fs=false);
|
||||
native bool:DeleteFile(const String:path[], bool:use_valve_fs=false, const String:valve_path_id="DEFAULT_WRITE_PATH");
|
||||
|
||||
/**
|
||||
* Reads a line from a text file.
|
||||
@ -316,11 +319,12 @@ 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 find files existing in any of
|
||||
* the GAME search paths, rather than solely files
|
||||
* the Valve search paths, rather than solely files
|
||||
* existing directly in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return True if the file exists, false otherwise.
|
||||
*/
|
||||
native bool:FileExists(const String:path[], bool:use_valve_fs=false);
|
||||
native bool:FileExists(const String:path[], bool:use_valve_fs=false, const String:valve_path_id="GAME");
|
||||
|
||||
/**
|
||||
* Renames a file.
|
||||
@ -329,10 +333,11 @@ native bool:FileExists(const String:path[], bool:use_valve_fs=false);
|
||||
* @param oldpath Path to the existing file.
|
||||
* @param use_valve_fs If true, the Valve file system will be used instead.
|
||||
* This can be used to rename files in the game's
|
||||
* DEFAULT_WRITE_PATH search path, rather than directly in the gamedir.
|
||||
* Valve search paths, rather than directly in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return True on success or use_valve_fs specified, false otherwise.
|
||||
*/
|
||||
native bool:RenameFile(const String:newpath[], const String:oldpath[], bool:use_valve_fs=false);
|
||||
native bool:RenameFile(const String:newpath[], const String:oldpath[], bool:use_valve_fs=false, const String:valve_path_id="DEFAULT_WRITE_PATH");
|
||||
|
||||
/**
|
||||
* Checks if a directory exists.
|
||||
@ -340,11 +345,12 @@ native bool:RenameFile(const String:newpath[], const String:oldpath[], bool:use_
|
||||
* @param path Path to the directory.
|
||||
* @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
|
||||
* the Valve search paths, rather than solely files
|
||||
* existing directly in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return True if the directory exists, false otherwise.
|
||||
*/
|
||||
native bool:DirExists(const String:path[], bool:use_valve_fs=false);
|
||||
native bool:DirExists(const String:path[], bool:use_valve_fs=false, const String:valve_path_id="GAME");
|
||||
|
||||
/**
|
||||
* Get the file size in bytes.
|
||||
@ -352,11 +358,12 @@ native bool:DirExists(const String:path[], bool:use_valve_fs=false);
|
||||
* @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
|
||||
* the Valve search paths, rather than solely files
|
||||
* existing directly in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for all search paths.
|
||||
* @return File size in bytes, -1 if file not found.
|
||||
*/
|
||||
native FileSize(const String:path[], bool:use_valve_fs=false);
|
||||
native FileSize(const String:path[], bool:use_valve_fs=false, const String:valve_path_id="GAME");
|
||||
|
||||
/**
|
||||
* Flushes a file's buffered output; any buffered output
|
||||
@ -395,7 +402,8 @@ native bool:RemoveDir(const String:path[]);
|
||||
* the execute bit set on Linux. On Windows, the mode is ignored.
|
||||
* @param use_valve_fs If true, the Valve file system will be used instead.
|
||||
* This can be used to create folders in the game's
|
||||
* DEFAULT_WRITE_PATH search path, rather than directly in the gamedir.
|
||||
* Valve search paths, rather than directly in the gamedir.
|
||||
* @param valve_path_id If use_valve_fs, a search path from gameinfo or NULL_STRING for default.
|
||||
* In this case, mode is ignored.
|
||||
*/
|
||||
native bool:CreateDirectory(const String:path[], mode, bool:use_valve_fs=false);
|
||||
|
Loading…
Reference in New Issue
Block a user