Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/engine/RefAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ struct refimport_t {
// a -1 return means the file does not exist
// nullptr can be passed for buf to just determine existence
int ( *FS_ReadFile )( const char* name, void** buf );
void ( *FS_FreeFile )( void* buf );
char** ( *FS_ListFiles )( const char* name, const char* extension, int* numfilesfound );
void ( *FS_FreeFileList )( char** filelist );
void ( *FS_WriteFile )( const char* qpath, const void* buffer, int size );
int ( *FS_Seek )( fileHandle_t f, long offset, fsOrigin_t origin );
int ( *FS_FTell )( fileHandle_t f );
Expand Down
3 changes: 0 additions & 3 deletions src/engine/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2216,10 +2216,7 @@ static bool CL_InitRef()
ri.Hunk_FreeTempMemory = Hunk_FreeTempMemory;

ri.FS_ReadFile = FS_ReadFile;
ri.FS_FreeFile = FS_FreeFile;
ri.FS_WriteFile = FS_WriteFile;
ri.FS_FreeFileList = FS_FreeFileList;
ri.FS_ListFiles = FS_ListFiles;
ri.FS_Seek = FS_Seek;
ri.FS_FTell = FS_FTell;
ri.FS_Read = FS_Read;
Expand Down
114 changes: 30 additions & 84 deletions src/engine/qcommon/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,58 +479,6 @@ int FS_ReadFile(const char* path, void** buffer)
return length;
}

void FS_FreeFile(void* buffer)
{
char* buf = static_cast<char*>(buffer);
delete[] buf;
}

char** FS_ListFiles(const char* directory, const char* extension, int* numFiles)
{
std::vector<char*> files;
bool dirsOnly = extension && !strcmp(extension, "/");

try {
for (const std::string& x: FS::PakPath::ListFiles(directory)) {
if (extension && !Str::IsSuffix(extension, x))
continue;
if (dirsOnly != (x.back() == '/'))
continue;
char* s = new char[x.size() + 1];
memcpy(s, x.data(), x.size());
s[x.size() - (x.back() == '/')] = '\0';
files.push_back(s);
}
} catch (std::system_error&) {}
try {
for (const std::string& x: FS::HomePath::ListFiles(directory)) {
if (extension && !Str::IsSuffix(extension, x))
continue;
if (dirsOnly != (x.back() == '/'))
continue;
char* s = new char[x.size() + 1];
memcpy(s, x.data(), x.size());
s[x.size() - (x.back() == '/')] = '\0';
files.push_back(s);
}
} catch (std::system_error&) {}

*numFiles = files.size();
char** list = new char*[files.size() + 1];
std::copy(files.begin(), files.end(), list);
list[files.size()] = nullptr;
return list;
}

void FS_FreeFileList(char** list)
{
if (!list)
return;
for (char** i = list; *i; i++)
delete[] *i;
delete[] list;
}

int FS_GetFileList(const char* path, const char* extension, char* listBuf, int bufSize)
{
// Mods are not yet supported in the new filesystem
Expand All @@ -540,38 +488,36 @@ int FS_GetFileList(const char* path, const char* extension, char* listBuf, int b
int numFiles = 0;
bool dirsOnly = extension && !strcmp(extension, "/");

try {
for (const std::string& x: FS::PakPath::ListFiles(path)) {
if (extension && !Str::IsSuffix(extension, x))
continue;
if (dirsOnly != (x.back() == '/'))
continue;
int length = x.size() + (x.back() != '/');
if (bufSize < length)
return numFiles;
memcpy(listBuf, x.c_str(), length);
listBuf[length - 1] = '\0';
listBuf += length;
bufSize -= length;
numFiles++;
}
} catch (std::system_error&) {}
try {
for (const std::string& x: FS::HomePath::ListFiles(FS::Path::Build("game", path))) {
if (extension && !Str::IsSuffix(extension, x))
continue;
if (dirsOnly != (x.back() == '/'))
continue;
int length = x.size() + (x.back() != '/');
if (bufSize < length)
return numFiles;
memcpy(listBuf, x.c_str(), length);
listBuf[length - 1] = '\0';
listBuf += length;
bufSize -= length;
numFiles++;
}
} catch (std::system_error&) {}
for (const std::string& x: FS::PakPath::ListFiles(path)) {
if (extension && !Str::IsSuffix(extension, x))
continue;
if (dirsOnly != (x.back() == '/'))
continue;
int length = x.size() + (x.back() != '/');
if (bufSize < length)
return numFiles;
memcpy(listBuf, x.c_str(), length);
listBuf[length - 1] = '\0';
listBuf += length;
bufSize -= length;
numFiles++;
}

std::error_code ignored;
for (const std::string& x: FS::HomePath::ListFiles(FS::Path::Build("game", path), ignored)) {
if (extension && !Str::IsSuffix(extension, x))
continue;
if (dirsOnly != (x.back() == '/'))
continue;
int length = x.size() + (x.back() != '/');
if (bufSize < length)
return numFiles;
memcpy(listBuf, x.c_str(), length);
listBuf[length - 1] = '\0';
listBuf += length;
bufSize -= length;
numFiles++;
}

return numFiles;
}
Expand Down
8 changes: 0 additions & 8 deletions src/engine/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,10 @@ issues.
==============================================================
*/

char **FS_ListFiles( const char *directory, const char *extension, int *numfiles );

// directory should not have either a leading or trailing /
// if extension is "/", only subdirectories will be returned
// the returned files will not include any directories or /

void FS_FreeFileList( char **list );

int FS_GetFileList( const char *path, const char *extension, char *listbuf, int bufsize );
int FS_GetFileListRecursive( const char* path, const char* extension, char* listBuf, int bufSize );

Expand Down Expand Up @@ -395,10 +391,6 @@ void FS_ForceFlush( fileHandle_t f );

// forces flush on files we're writing to.

void FS_FreeFile( void *buffer );

// frees the memory returned by FS_ReadFile

void FS_WriteFile( const char *qpath, const void *buffer, int size );

// writes a complete file, creating any subdirectories needed
Expand Down
Loading