mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
*** Merged Code from Multiplayer Branch Revision 2960 ***
- Virtual File System (VFS) by birdflu. This is needed for Multiplayer and is also used for Single Player. Very neat system :-) - Multiplayer Version 1.1 + some additional features and bugfixes * INFO: If you compile a new EXE and want to test, be sure to also use the latest SVN GameDir files in your JA2 install directory * git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2961 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// Snap: Implementation of the TReadDir class
|
||||
// This class reads the contents of a directory file-by-file
|
||||
//
|
||||
#include "iteratedir.h"
|
||||
#include "VFS/vfs_debug.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "utf8string.h"
|
||||
|
||||
#ifndef WIN32
|
||||
int file_select(struct direct *entry)
|
||||
{
|
||||
/* if((strcmp(entry->d_name,".") == 0) || ( strcmp(entry->d_name,"..") == 0))
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (TRUE);
|
||||
}*/
|
||||
return (TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
|
||||
{
|
||||
#ifdef WIN32
|
||||
fSearchHandle = FindFirstFileW((sPath+searchPattern)().c_wcs().c_str(), &fFileInfo);
|
||||
if (fSearchHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Path [" << (sPath+searchPattern)() << L"] does not exist";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
#else
|
||||
count = scandir(sPath().utf8().c_str(),&files,NULL,NULL);
|
||||
current_pos = 0;
|
||||
#endif
|
||||
fFirstRequest = true;
|
||||
}
|
||||
|
||||
os::CIterateDirectory::~CIterateDirectory()
|
||||
{
|
||||
#ifdef WIN32
|
||||
FindClose(fSearchHandle);
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::CIterateDirectory::NextFile(utf8string &fileName, CIterateDirectory::EFileAttribute &attrib)
|
||||
{
|
||||
#ifdef WIN32
|
||||
THROWIFFALSE(fSearchHandle != INVALID_HANDLE_VALUE, L"Invalid Handle Value");
|
||||
if (fFirstRequest)
|
||||
{
|
||||
fFirstRequest = false;
|
||||
}
|
||||
else if ( !FindNextFileW(fSearchHandle, &fFileInfo) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign(fFileInfo.cFileName);
|
||||
attrib = (fFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
return true;
|
||||
#else
|
||||
if(current_pos < count)
|
||||
{
|
||||
struct dirent* entry = files[current_pos];
|
||||
fileName.assign(VfsString(entry->d_name)());
|
||||
attrib = (entry->d_type == DT_DIR) ? CIterateDir::FA_DIRECTORY : CIterateDir::FA_FILE;
|
||||
current_pos++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::CreateRealDirecory(vfs::Path& sDir, bool bDoNotCreate)
|
||||
{
|
||||
#if WIN32
|
||||
if(bDoNotCreate)
|
||||
{
|
||||
bool bDirExists = false;
|
||||
WIN32_FIND_DATAW fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
|
||||
HANDLE hFile = FindFirstFileW( sDir().c_wcs().c_str(), &fd);
|
||||
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
FindClose(hFile);
|
||||
return bDirExists;
|
||||
}
|
||||
BOOL success;
|
||||
success = CreateDirectoryW(sDir().c_wcs().c_str(),NULL);
|
||||
if(success == 0)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
if(error == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::DeleteRealFile(vfs::Path &sDir)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (DeleteFileW( sDir().c_wcs().c_str() ) != FALSE);
|
||||
#else
|
||||
return (remove( sDir().utf8().c_str() ) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user