mirror of
https://github.com/1dot13/source.git
synced 2026-09-02 14:36:06 +02:00
**********************************************************
** Big Maps Projects code (incl. Multiplayer v1.5 ** ********************************************************** - Merged Big Maps Project code from BMP+MP trunk (Revision: 3340) o Complete SVN Revision history: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP - Before THIS merge, I made a branch of the existing 1.13 source o SVN Branch: https://81.169.133.124/source/ja2/branches/JA2_rev.3336/src - Removed old VS 6.0 and VS 2003 project and solutions files, because compilation is broken long time ago - I will add VS 2010 projects and solution file in the next few days git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3341 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+98
-179
@@ -1,213 +1,132 @@
|
||||
#include "vfs_dir_file.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
#include "../iteratedir.h"
|
||||
#include "../vfs_settings.h"
|
||||
#include "../os_functions.h"
|
||||
|
||||
extern bool g_VFS_NO_UNICODE;
|
||||
|
||||
vfs::Path vfs::CVFSFile::GetFullPath()
|
||||
vfs::CReadOnlyDirFile::CReadOnlyDirFile(vfs::Path const& filename, tLocation *directory)
|
||||
: vfs::CReadOnlyFile(filename), _location(directory)
|
||||
{
|
||||
if(_pLoc_)
|
||||
}
|
||||
|
||||
vfs::CReadOnlyDirFile::~CReadOnlyDirFile()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path vfs::CReadOnlyDirFile::getPath()
|
||||
{
|
||||
if(_location)
|
||||
{
|
||||
return _pLoc_->GetFullPath() + m_sFileName;
|
||||
return _location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_sFileName;
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CVFSFile::_getRealPath(vfs::Path& rPath)
|
||||
bool vfs::CReadOnlyDirFile::_getRealPath(vfs::Path& path)
|
||||
{
|
||||
if(_pLoc_)
|
||||
if(_location)
|
||||
{
|
||||
rPath = static_cast<IDirectory<CVFSFile::write_type>*>(_pLoc_)->GetRealPath() + m_sFileName;
|
||||
path = _location->getRealPath() + m_filename;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CVFSFile::Delete()
|
||||
vfs::FileAttributes vfs::CReadOnlyDirFile::getAttributes()
|
||||
{
|
||||
Close();
|
||||
vfs::FileAttributes _attribs = vfs::CReadOnlyFile::getAttributes();
|
||||
|
||||
vfs::UInt32 attr = _attribs.getAttrib();
|
||||
attr |= vfs::FileAttributes::ATTRIB_READONLY;
|
||||
|
||||
return vfs::FileAttributes(attr, vfs::FileAttributes::LT_READONLY_DIRECTORY);
|
||||
}
|
||||
|
||||
bool vfs::CReadOnlyDirFile::openRead()
|
||||
{
|
||||
vfs::Path filename;
|
||||
if(!_getRealPath(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _internalOpenRead(filename);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vfs::CDirFile::CDirFile(vfs::Path const& filename, tLocation *directory)
|
||||
: CFile(filename), _location(directory)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CDirFile::~CDirFile()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path vfs::CDirFile::getPath()
|
||||
{
|
||||
if(_location)
|
||||
{
|
||||
return _location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CDirFile::deleteFile()
|
||||
{
|
||||
this->close();
|
||||
vfs::Path fname;
|
||||
if(_pLoc_)
|
||||
if(_getRealPath(fname))
|
||||
{
|
||||
fname = static_cast<IDirectory<CVFSFile::write_type>*>(_pLoc_)->GetRealPath() + m_sFileName;
|
||||
return os::deleteRealFile(fname);
|
||||
}
|
||||
else
|
||||
{
|
||||
fname = m_sFileName;
|
||||
}
|
||||
return os::DeleteRealFile(fname);
|
||||
}
|
||||
|
||||
bool vfs::CVFSFile::OpenRead()
|
||||
{
|
||||
// std::cout << "[CVFSFile::OpenRead] open file <" << m_sFileName() << ">\n" ;
|
||||
if( !m_oFile.good() )
|
||||
{
|
||||
std::cout << "ERROR" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(m_bIsOpen_read)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
vfs::Path sFileName;
|
||||
if(_pLoc_)
|
||||
{
|
||||
sFileName = static_cast<IDirectory<CFile::write_type>*>(_pLoc_)->GetRealPath() + m_sFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
sFileName = m_sFileName;
|
||||
}
|
||||
// try to open
|
||||
Mode = std::ios::in|std::ios::binary;
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_read = m_oFile.is_open()) )
|
||||
{
|
||||
m_oFile.clear();
|
||||
return false;
|
||||
}
|
||||
return m_oFile.good();
|
||||
}
|
||||
|
||||
bool vfs::CVFSFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
{
|
||||
// std::cout << "[CVFSFile::OpenWrite] opening file <" << m_sFileName << "> .. ";
|
||||
if(!m_oFile.good())
|
||||
{
|
||||
// std::cout << "ERROR" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(m_bIsOpen_write)
|
||||
{
|
||||
// std::cout << "already open" << std::endl;
|
||||
return m_oFile.good();
|
||||
}
|
||||
vfs::Path sFileName;
|
||||
if(_pLoc_)
|
||||
{
|
||||
sFileName = static_cast<IDirectory<CFile::write_type>*>(_pLoc_)->GetRealPath() + m_sFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
sFileName = m_sFileName;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in|std::ios::out|std::ios::binary;
|
||||
if(bTruncate)
|
||||
{
|
||||
Mode |= std::ios::trunc;
|
||||
}
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_write = m_oFile.is_open()) )
|
||||
{
|
||||
m_oFile.clear();
|
||||
if(bCreateWhenNotExist)
|
||||
{
|
||||
// create file
|
||||
Mode = std::ios::out|std::ios::binary;
|
||||
if(bTruncate)
|
||||
{
|
||||
Mode |= std::ios::trunc;
|
||||
}
|
||||
#ifdef WIN32
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_write = m_oFile.is_open()) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_oFile.close();
|
||||
Mode |= std::ios::in;
|
||||
#ifdef WIN32
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_write = m_oFile.is_open()) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return m_oFile.good();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vfs::Path vfs::CVFSTextFile::GetFullPath()
|
||||
bool vfs::CDirFile::_getRealPath(vfs::Path& path)
|
||||
{
|
||||
if(_pLoc_)
|
||||
{
|
||||
return static_cast<IDirectory<CFile::write_type>*>(_pLoc_)->GetRealPath() + m_sFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_sFileName;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CVFSTextFile::OpenRead()
|
||||
{
|
||||
if( !m_oFile.good() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(m_bIsOpen_read)
|
||||
if(_location)
|
||||
{
|
||||
path = _location->getRealPath() + m_filename;
|
||||
return true;
|
||||
}
|
||||
vfs::Path sFileName;
|
||||
if(_pLoc_)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vfs::FileAttributes vfs::CDirFile::getAttributes()
|
||||
{
|
||||
vfs::FileAttributes _attribs = vfs::CFile::getAttributes();
|
||||
|
||||
return vfs::FileAttributes(_attribs.getAttrib(), vfs::FileAttributes::LT_DIRECTORY);
|
||||
}
|
||||
|
||||
bool vfs::CDirFile::openRead()
|
||||
{
|
||||
vfs::Path filename;
|
||||
if(!_getRealPath(filename))
|
||||
{
|
||||
sFileName = static_cast<IDirectory<CFile::write_type>*>(_pLoc_)->GetRealPath() + m_sFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
sFileName = m_sFileName;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in;
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_read = m_oFile.is_open()) )
|
||||
{
|
||||
m_oFile.clear();
|
||||
return false;
|
||||
}
|
||||
return m_oFile.good();
|
||||
return _internalOpenRead(filename);
|
||||
}
|
||||
|
||||
bool vfs::CDirFile::openWrite(bool createWhenNotExist, bool truncate)
|
||||
{
|
||||
vfs::Path filename;
|
||||
if(!_getRealPath(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _internalOpenWrite(filename, createWhenNotExist, truncate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+28
-21
@@ -6,41 +6,48 @@
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include "../Interface/vfs_location_aware_file_interface.h"
|
||||
#include "../Interface/vfs_location_interface.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class CVFSFile : public vfs::CFile, public vfs::ILocationAware<vfs::IReadable, vfs::IWriteable>
|
||||
class VFS_API CReadOnlyDirFile : public vfs::CReadOnlyFile
|
||||
{
|
||||
protected:
|
||||
typedef vfs::TDirectory<vfs::CReadOnlyDirFile::write_type> tLocation;
|
||||
public:
|
||||
CVFSFile(vfs::Path const& sFileName, vfs::IDirectory<vfs::CFile::write_type> *pDirectory)
|
||||
: vfs::CFile(sFileName), vfs::ILocationAware<vfs::IReadable, vfs::IWriteable>(pDirectory)
|
||||
{};
|
||||
virtual ~CVFSFile()
|
||||
{};
|
||||
CReadOnlyDirFile(vfs::Path const& filename, tLocation *directory);
|
||||
virtual ~CReadOnlyDirFile();
|
||||
|
||||
virtual vfs::Path GetFullPath();
|
||||
virtual bool Delete();
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual bool OpenRead();
|
||||
virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
|
||||
virtual vfs::Path getPath();
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& rPath);
|
||||
virtual bool openRead();
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& path);
|
||||
private:
|
||||
tLocation* _location;
|
||||
};
|
||||
|
||||
class CVFSTextFile : public vfs::CTextFile, public vfs::ILocationAware<vfs::CFile::read_type, vfs::CFile::write_type>
|
||||
class VFS_API CDirFile : public vfs::CFile
|
||||
{
|
||||
typedef vfs::TDirectory<vfs::CFile::write_type> tLocation;
|
||||
public:
|
||||
CVFSTextFile(vfs::Path const& sFileName, vfs::IDirectory<vfs::CFile::write_type> *pDirectory)
|
||||
: vfs::CTextFile(sFileName), vfs::ILocationAware<vfs::CFile::read_type, vfs::CFile::write_type>(pDirectory)
|
||||
{};
|
||||
virtual ~CVFSTextFile()
|
||||
{};
|
||||
CDirFile(vfs::Path const& filename, tLocation *directory);
|
||||
virtual ~CDirFile();
|
||||
|
||||
virtual vfs::Path GetFullPath();
|
||||
virtual bool OpenRead();
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual vfs::Path getPath();
|
||||
virtual bool deleteFile();
|
||||
|
||||
virtual bool openRead();
|
||||
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false);
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& path);
|
||||
private:
|
||||
tLocation* _location;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#endif // _VFS_DIR_FILE_H_
|
||||
|
||||
+313
-367
@@ -1,194 +1,289 @@
|
||||
#include "vfs_file.h"
|
||||
#include <cassert>
|
||||
#include "../vfs_debug.h"
|
||||
#include "../vfs_settings.h"
|
||||
#include "../os_functions.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern bool g_VFS_NO_UNICODE;
|
||||
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
|
||||
|
||||
vfs::CFile::CFile(vfs::Path const& sFileName)
|
||||
: vfs::IFileTemplate<vfs::IReadable,vfs::IWriteable>(sFileName), m_bIsOpen_read(false), m_bIsOpen_write(false)
|
||||
#ifdef _DEBUG
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_file.good(), ERROR_FILE(BuildString().add(L"invalid file object").add(m_file.eof() ? L" [EOF]" : L"").get()) );
|
||||
#else
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_file.good(), ERROR_FILE(BuildString().add(L"invalid file object").add(m_file.eof() ? L" [EOF]" : L"").get()) );
|
||||
#endif
|
||||
|
||||
static inline bool hasAttrib(vfs::UInt32 const& attrib, vfs::UInt32 Attribs)
|
||||
{
|
||||
return attrib == (attrib & Attribs);
|
||||
}
|
||||
|
||||
static inline void copyAttributes(vfs::UInt32 osFileAttributes, vfs::UInt32& vfsFileAttributes)
|
||||
{
|
||||
if(os::FileAttributes::ATTRIB_ARCHIVE == (os::FileAttributes::ATTRIB_ARCHIVE & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_ARCHIVE;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_COMPRESSED == (os::FileAttributes::ATTRIB_COMPRESSED & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_COMPRESSED;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_DIRECTORY == (os::FileAttributes::ATTRIB_DIRECTORY & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_DIRECTORY;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_HIDDEN == (os::FileAttributes::ATTRIB_HIDDEN & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_HIDDEN;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_NORMAL == (os::FileAttributes::ATTRIB_NORMAL & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_NORMAL;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_OFFLINE == (os::FileAttributes::ATTRIB_OFFLINE & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_OFFLINE;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_READONLY == (os::FileAttributes::ATTRIB_READONLY & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_READONLY;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_SYSTEM == (os::FileAttributes::ATTRIB_SYSTEM & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_SYSTEM;
|
||||
}
|
||||
if(os::FileAttributes::ATTRIB_TEMPORARY == (os::FileAttributes::ATTRIB_TEMPORARY & osFileAttributes))
|
||||
{
|
||||
vfsFileAttributes |= vfs::FileAttributes::ATTRIB_TEMPORARY;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _openFile(std::fstream& file, vfs::Path const& filename, std::ios::openmode mode)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
utf8string::str_t const& fname = filename.c_wcs();
|
||||
vfs::Settings::getUseUnicode() ?
|
||||
file.open( fname.c_str(), mode ) :
|
||||
file.open( utf8string::narrow(fname.c_str(),fname.length()).c_str(), mode );
|
||||
#else
|
||||
file.open(utf8string::as_utf8(filename()).c_str(), mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline std::ios::seekdir _seekDir(vfs::IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(seekDir == vfs::IBaseFile::SD_BEGIN)
|
||||
{
|
||||
return std::ios::beg;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_CURRENT)
|
||||
{
|
||||
return std::ios::cur;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_END)
|
||||
{
|
||||
return std::ios::end;
|
||||
}
|
||||
THROWEXCEPTION(BuildString().add(L"Unknown seek direction [").add(seekDir).add(L"]").get());
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TFile<WriteType>::TFile(vfs::Path const& filename)
|
||||
: tBaseClass(filename), m_isOpen_read(false)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TFile<WriteType>::~TFile()
|
||||
{
|
||||
m_file.clear();
|
||||
if(m_isOpen_read)
|
||||
{
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TFile<WriteType>::close()
|
||||
{
|
||||
m_file.clear();
|
||||
if( m_file.is_open() )
|
||||
{
|
||||
m_file.close();
|
||||
}
|
||||
m_isOpen_read = false;
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::FileAttributes vfs::TFile<WriteType>::getAttributes()
|
||||
{
|
||||
vfs::Path fullpath;
|
||||
THROWIFFALSE(this->_getRealPath(fullpath), ERROR_FILE(L""));
|
||||
|
||||
vfs::UInt32 osFileAttributes = 0;
|
||||
os::FileAttributes fa;
|
||||
THROWIFFALSE( fa.getFileAttributes(fullpath, osFileAttributes), ERROR_FILE(L"Could not read file Attributes") );
|
||||
|
||||
vfs::UInt32 _attribs = vfs::FileAttributes::ATTRIB_INVALID;
|
||||
copyAttributes(osFileAttributes, _attribs);
|
||||
|
||||
if(!this->implementsWritable())
|
||||
{
|
||||
_attribs &= ~vfs::FileAttributes::ATTRIB_NORMAL;
|
||||
_attribs |= vfs::FileAttributes::ATTRIB_READONLY;
|
||||
}
|
||||
|
||||
return vfs::FileAttributes(_attribs, vfs::FileAttributes::LT_NONE);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TFile<WriteType>::isOpenRead()
|
||||
{
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TFile<WriteType>::_internalOpenRead(vfs::Path const& path)
|
||||
{
|
||||
if( m_isOpen_read )
|
||||
return true;
|
||||
if( !m_file.good() )
|
||||
return false;
|
||||
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in|std::ios::binary;
|
||||
// try to open
|
||||
_openFile(m_file, path, Mode);
|
||||
m_isOpen_read = m_file.is_open() && m_file.good();
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TFile<WriteType>::openRead()
|
||||
{
|
||||
return _internalOpenRead(this->m_filename);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::size_t vfs::TFile<WriteType>::read(vfs::Byte* pData, vfs::size_t bytesToRead)
|
||||
{
|
||||
if(!m_file.eof())
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
|
||||
m_file.read(static_cast<char*>(pData), bytesToRead);
|
||||
std::streamsize bytesRead = m_file.gcount();
|
||||
|
||||
// don't treat EOF as error
|
||||
THROWIFFALSE( m_file.good() || m_file.eof(), ERROR_FILE(L"read error") );
|
||||
return (vfs::size_t)bytesRead;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::size_t vfs::TFile<WriteType>::getReadPosition()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
return (vfs::size_t)m_file.tellg();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TFile<WriteType>::setReadPosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
|
||||
m_file.seekg( (std::streamoff)positionInBytes );
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TFile<WriteType>::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
TRYCATCH_RETHROW( ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error"));
|
||||
m_file.seekg( offsetInBytes, ioSeekDir );
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
/********************************************************************************/
|
||||
/********************************************************************************/
|
||||
|
||||
|
||||
vfs::CFile::CFile(vfs::Path const& filename)
|
||||
: tBaseClass(filename), m_isOpen_write(false)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CFile::~CFile()
|
||||
{
|
||||
m_oFile.clear();
|
||||
if(m_bIsOpen_read || m_bIsOpen_write)
|
||||
m_file.clear();
|
||||
if(m_isOpen_read || m_isOpen_write)
|
||||
{
|
||||
this->Close();
|
||||
this->close();
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CFile::Delete()
|
||||
void vfs::CFile::close()
|
||||
{
|
||||
Close();
|
||||
if(remove(m_sFileName().utf8().c_str()) == 0)
|
||||
{
|
||||
tBaseClass::close();
|
||||
m_isOpen_write = false;
|
||||
}
|
||||
|
||||
bool vfs::CFile::deleteFile()
|
||||
{
|
||||
this->close();
|
||||
return os::deleteRealFile(m_filename);
|
||||
}
|
||||
|
||||
bool vfs::CFile::isOpenWrite()
|
||||
{
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CFile::_internalOpenWrite(vfs::Path const& path, bool createWhenNotExist, bool truncate)
|
||||
{
|
||||
if( m_isOpen_write )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CFile::Close()
|
||||
{
|
||||
m_oFile.clear();
|
||||
if( (m_bIsOpen_read || m_bIsOpen_write) && m_oFile.good() )
|
||||
{
|
||||
m_oFile.close();
|
||||
m_bIsOpen_read = false;
|
||||
m_bIsOpen_write = false;
|
||||
}
|
||||
return m_oFile.good();
|
||||
}
|
||||
|
||||
bool vfs::CFile::IsOpenRead()
|
||||
{
|
||||
return m_bIsOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CFile::OpenRead()
|
||||
{
|
||||
if(!m_oFile.good())
|
||||
{
|
||||
if( !m_file.good() )
|
||||
return false;
|
||||
}
|
||||
if(m_bIsOpen_read)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
// try to open
|
||||
Mode = std::ios::in|std::ios::binary;
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open( utf8string::narrow(fname.c_str(),fname.length()).c_str(), Mode ) :
|
||||
m_oFile.open( fname.c_str(), Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(), Mode);
|
||||
#endif
|
||||
m_bIsOpen_read = m_oFile.is_open() && m_oFile.good();
|
||||
return m_bIsOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CFile::Read(vfs::Byte* pData, vfs::UInt32 uiBytesToRead, vfs::UInt32& uiBytesRead)
|
||||
{
|
||||
|
||||
uiBytesRead = 0;
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_oFile.read(static_cast<char*>(pData),uiBytesToRead);
|
||||
uiBytesRead = m_oFile.gcount();
|
||||
return m_oFile.good();
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CFile::GetReadLocation()
|
||||
{
|
||||
return m_oFile.tellg();
|
||||
}
|
||||
bool vfs::CFile::SetReadLocation(vfs::UInt32 uiPositionInBytes)
|
||||
{
|
||||
if(m_oFile.good())
|
||||
{
|
||||
if(m_bIsOpen_read || this->OpenRead())
|
||||
{
|
||||
m_oFile.seekg(uiPositionInBytes);
|
||||
}
|
||||
}
|
||||
return m_oFile.good();
|
||||
}
|
||||
|
||||
bool vfs::CFile::SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir)
|
||||
{
|
||||
if(!m_bIsOpen_read && !OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::ios::seekdir ioSeekDir;
|
||||
if(eSeekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
ioSeekDir = std::ios::beg;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
ioSeekDir = std::ios::cur;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_END)
|
||||
{
|
||||
ioSeekDir = std::ios::end;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_oFile.good();
|
||||
}
|
||||
m_oFile.seekg(uiOffsetInBytes,ioSeekDir);
|
||||
return m_oFile.good();
|
||||
}
|
||||
|
||||
bool vfs::CFile::IsOpenWrite()
|
||||
{
|
||||
return m_bIsOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
{
|
||||
if(!m_oFile.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(m_bIsOpen_write)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in|std::ios::out|std::ios::binary;
|
||||
if(bTruncate)
|
||||
if(truncate)
|
||||
{
|
||||
Mode |= std::ios::trunc;
|
||||
}
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_write = m_oFile.is_open()) )
|
||||
_openFile(m_file, path, Mode);
|
||||
if( !(m_isOpen_write = m_file.is_open() && m_file.good()) )
|
||||
{
|
||||
m_oFile.clear();
|
||||
if(bCreateWhenNotExist)
|
||||
m_file.clear();
|
||||
if(createWhenNotExist)
|
||||
{
|
||||
// create file
|
||||
Mode = std::ios::out|std::ios::binary;
|
||||
if(bTruncate)
|
||||
if(truncate)
|
||||
{
|
||||
Mode |= std::ios::trunc;
|
||||
}
|
||||
//m_oFile.open(VfsString(sFileName).AsString().c_str(),Mode);
|
||||
#ifdef WIN32
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_write = m_oFile.is_open()) )
|
||||
_openFile(m_file, path, Mode);
|
||||
if( !(m_isOpen_write = m_file.is_open() && m_file.good()) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_oFile.close();
|
||||
m_file.close();
|
||||
Mode |= std::ios::in;
|
||||
#ifdef WIN32
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if( !(m_bIsOpen_write = m_oFile.is_open()) )
|
||||
_openFile(m_file, path, Mode);
|
||||
if( !(m_isOpen_write = m_file.is_open() && m_file.good()) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -198,237 +293,88 @@ bool vfs::CFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return m_oFile.good();
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CFile::Write(const vfs::Byte* pData, vfs::UInt32 uiBytesToWrite, vfs::UInt32& uiBytesWritten)
|
||||
bool vfs::CFile::openWrite(bool createWhenNotExist, bool truncate)
|
||||
{
|
||||
uiBytesWritten = 0;
|
||||
// expect file to be opened (if not, should i open it? with what parameters?)
|
||||
if(!m_bIsOpen_write && !this->OpenWrite(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::UInt64 start = m_oFile.tellp();
|
||||
if(!m_oFile.write(pData,uiBytesToWrite))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::UInt64 end = m_oFile.tellp();
|
||||
uiBytesWritten = end-start;
|
||||
if(uiBytesWritten != uiBytesToWrite)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_oFile.good();
|
||||
return _internalOpenWrite(m_filename, createWhenNotExist, truncate);
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CFile::write(const vfs::Byte* data, vfs::size_t bytesToWrite)
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write, ERROR_FILE(L"file not opened") );
|
||||
|
||||
std::streampos start = m_file.tellp();
|
||||
THROWIFFALSE( m_file.write(data, bytesToWrite), ERROR_FILE(L"write error") );
|
||||
std::streampos bytesWritten = m_file.tellp() - start;
|
||||
|
||||
IS_FILE_VALID();
|
||||
|
||||
return (vfs::size_t)bytesWritten;
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CFile::GetWriteLocation()
|
||||
vfs::size_t vfs::CFile::getWritePosition()
|
||||
{
|
||||
return m_oFile.tellp();
|
||||
}
|
||||
bool vfs::CFile::SetWriteLocation(vfs::Int32 uiPositionInBytes)
|
||||
{
|
||||
if(m_oFile.good())
|
||||
{
|
||||
if(!m_bIsOpen_write && !this->OpenWrite(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_oFile.seekp(uiPositionInBytes);
|
||||
}
|
||||
return m_oFile.good();
|
||||
IS_FILE_VALID();
|
||||
return (vfs::size_t)m_file.tellp();
|
||||
}
|
||||
|
||||
bool vfs::CFile::SetWriteLocation(Int32 uiOffsetInBytes, vfs::IBaseFile::ESeekDir eSeekDir)
|
||||
void vfs::CFile::setWritePosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
if(m_oFile.good())
|
||||
{
|
||||
if(!m_bIsOpen_write && !this->OpenWrite(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::ios::seekdir ioSeekDir;
|
||||
if(eSeekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
ioSeekDir = std::ios::beg;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
ioSeekDir = std::ios::cur;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_END)
|
||||
{
|
||||
ioSeekDir = std::ios::end;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_oFile.seekp(uiOffsetInBytes,ioSeekDir);
|
||||
}
|
||||
return m_oFile.good();
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write, ERROR_FILE(L"file not opened") );
|
||||
|
||||
m_file.seekp( (std::streamoff)positionInBytes );
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
bool vfs::CFile::GetFileSize(UInt32& uiFileSize)
|
||||
void vfs::CFile::setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
uiFileSize = 0;
|
||||
if(!m_oFile.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool closeAtExit = !m_bIsOpen_read;
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write, ERROR_FILE(L"file not opened") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
TRYCATCH_RETHROW( ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error") );
|
||||
m_file.seekp(offsetInBytes,ioSeekDir);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
//vfs::size_t vfs::CFile::getSize()
|
||||
template<typename T>
|
||||
vfs::size_t vfs::TFile<T>::getSize()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
|
||||
// if file was alredy opened, keep it open, otherwise close it
|
||||
bool closeAtExit = !m_isOpen_read;
|
||||
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"could not open file") )
|
||||
|
||||
// save the current position
|
||||
std::ios::pos_type current_position = m_oFile.tellg();
|
||||
std::streampos current_position = m_file.tellg();
|
||||
|
||||
// move to end of the file
|
||||
m_oFile.seekg(0,std::ios::end);
|
||||
std::ios::pos_type file_size = m_oFile.tellg();
|
||||
m_file.seekg(0,std::ios::end);
|
||||
std::streampos file_size = m_file.tellg();
|
||||
|
||||
// move to old position
|
||||
m_oFile.seekg(current_position,std::ios::beg);
|
||||
assert(current_position == m_oFile.tellg());
|
||||
uiFileSize = file_size;
|
||||
m_file.seekg(current_position,std::ios::beg);
|
||||
THROWIFFALSE(current_position == m_file.tellg(), ERROR_FILE(L"could not restore seek position"));
|
||||
|
||||
if(closeAtExit)
|
||||
{
|
||||
this->Close();
|
||||
this->close();
|
||||
}
|
||||
return m_oFile.good();
|
||||
IS_FILE_VALID();
|
||||
return (vfs::size_t)file_size;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
bool vfs::CTextFile::OpenRead()
|
||||
{
|
||||
if(m_bIsOpen_read)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::in;
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if(!(m_bIsOpen_read = m_oFile.is_open()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_bIsOpen_read && m_oFile.good();
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CTextFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
{
|
||||
if(m_oFile.good())
|
||||
{
|
||||
if(m_bIsOpen_write)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
std::ios::openmode Mode;
|
||||
Mode = std::ios::out|std::ios::app;
|
||||
#ifdef WIN32
|
||||
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if(!m_oFile.is_open())
|
||||
{
|
||||
m_oFile.clear();
|
||||
if(bCreateWhenNotExist)
|
||||
{
|
||||
// create file
|
||||
Mode = std::ios::out;
|
||||
Mode |= bTruncate ? std::ios::trunc : std::ios::app;
|
||||
#ifdef WIN32
|
||||
g_VFS_NO_UNICODE ?
|
||||
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||
m_oFile.open(fname.c_str(),Mode);
|
||||
#else
|
||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||
#endif
|
||||
if(!m_oFile.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bIsOpen_write = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_bIsOpen_write = true;
|
||||
}
|
||||
return m_oFile.good();
|
||||
}
|
||||
|
||||
bool vfs::CTextFile::ReadLine(std::string &sLine, UInt32 uiMaxNumChars)
|
||||
{
|
||||
if(!m_bIsOpen_read && !OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!m_oFile.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!m_oFile.eof())
|
||||
{
|
||||
char *text = new char[uiMaxNumChars+1];
|
||||
m_oFile.getline(text,uiMaxNumChars);
|
||||
sLine.assign(text);
|
||||
delete[] text;
|
||||
return m_oFile.good();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CTextFile::Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead)
|
||||
{
|
||||
if(!m_bIsOpen_read)
|
||||
{
|
||||
OpenRead();
|
||||
}
|
||||
if(!m_oFile.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!m_oFile.eof())
|
||||
{
|
||||
m_oFile.getline((char*)pData,uiBytesToRead);
|
||||
uiBytesRead = m_oFile.gcount();
|
||||
return m_oFile.good();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CTextFile::Write(const Byte* pData, UInt32 uiBytesToWrite, UInt32& uiBytesWritten)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool vfs::CTextFile::WriteLine(std::string const& sLine)
|
||||
{
|
||||
UInt32 uiWritten, uiToWrite=sLine.size();
|
||||
return CFile::Write(sLine.c_str(), uiToWrite ,uiWritten) && (uiWritten == uiToWrite);
|
||||
}
|
||||
|
||||
|
||||
template class vfs::TFile<vfs::IWriteType>;
|
||||
|
||||
|
||||
+47
-39
@@ -13,58 +13,66 @@ namespace vfs
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
class CFile : public vfs::IFileTemplate<IReadable,IWriteable>
|
||||
template<typename WriteType=vfs::IWriteType>
|
||||
class VFS_API TFile : public vfs::TFileTemplate<vfs::IReadable,WriteType>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,WriteType> tBaseClass;
|
||||
public :
|
||||
CFile(vfs::Path const& sFileName);
|
||||
TFile(vfs::Path const& filename);
|
||||
virtual ~TFile();
|
||||
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual void close();
|
||||
virtual vfs::size_t getSize();
|
||||
|
||||
virtual bool isOpenRead();
|
||||
virtual bool openRead();
|
||||
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead);
|
||||
|
||||
virtual vfs::size_t getReadPosition();
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
protected:
|
||||
bool _internalOpenRead(vfs::Path const& path);
|
||||
protected:
|
||||
bool m_isOpen_read;
|
||||
std::fstream m_file;
|
||||
};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
// implements the IWritable interface for TFile
|
||||
class VFS_API CFile : public vfs::TFile<vfs::IWritable>
|
||||
{
|
||||
typedef vfs::TFile<vfs::IWritable> tBaseClass;
|
||||
public :
|
||||
CFile(vfs::Path const& filename);
|
||||
virtual ~CFile();
|
||||
|
||||
virtual bool Close();
|
||||
virtual bool GetFileSize(UInt32& uiFileSize);
|
||||
virtual void close();
|
||||
|
||||
virtual bool IsOpenRead();
|
||||
virtual bool OpenRead();
|
||||
virtual bool Read(vfs::Byte* pData, vfs::UInt32 uiBytesToRead, vfs::UInt32& uiBytesRead);
|
||||
virtual bool isOpenWrite();
|
||||
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false);
|
||||
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite);
|
||||
|
||||
virtual vfs::UInt32 GetReadLocation();
|
||||
virtual bool SetReadLocation(UInt32 uiPositionInBytes);
|
||||
virtual bool SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir);
|
||||
virtual vfs::size_t getWritePosition();
|
||||
virtual void setWritePosition(vfs::size_t positionInBytes);
|
||||
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual bool IsOpenWrite();
|
||||
virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
|
||||
virtual bool Write(const vfs::Byte* pData, vfs::UInt32 uiBytesToWrite, vfs::UInt32& uiBytesWritten);
|
||||
|
||||
virtual vfs::UInt32 GetWriteLocation();
|
||||
virtual bool SetWriteLocation(Int32 uiPositionInBytes);
|
||||
virtual bool SetWriteLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir);
|
||||
|
||||
virtual bool Delete();
|
||||
virtual bool deleteFile();
|
||||
protected:
|
||||
std::fstream m_oFile;
|
||||
bool m_bIsOpen_read, m_bIsOpen_write;
|
||||
bool _internalOpenWrite(vfs::Path const& path, bool createWhenNotExist = false, bool truncate = false);
|
||||
protected:
|
||||
bool m_isOpen_write;
|
||||
};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
class CTextFile : public CFile
|
||||
{
|
||||
public:
|
||||
CTextFile(vfs::Path const& sFileName)
|
||||
: CFile(sFileName)
|
||||
{};
|
||||
virtual ~CTextFile()
|
||||
{};
|
||||
|
||||
virtual bool OpenRead();
|
||||
virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
|
||||
|
||||
virtual bool Read(Byte* pData, vfs::UInt32 uiBytesToRead, vfs::UInt32& uiBytesRead);
|
||||
virtual bool ReadLine(std::string &sLine, vfs::UInt32 uiMaxNumChars);
|
||||
|
||||
virtual bool Write(const vfs::Byte* pData, vfs::UInt32 uiBytesToWrite, vfs::UInt32& uiBytesWritten);
|
||||
virtual bool WriteLine(std::string const& sLine);
|
||||
};
|
||||
typedef vfs::TFile<vfs::IWriteType> CReadOnlyFile; // needs explicit template instantiation
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
+64
-55
@@ -1,11 +1,14 @@
|
||||
#include "vfs_lib_file.h"
|
||||
#include "../vfs.h"
|
||||
|
||||
|
||||
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
|
||||
|
||||
ObjBlockAllocator<vfs::CLibFile>* vfs::CLibFile::_lfile_pool = NULL;
|
||||
|
||||
vfs::CLibFile* vfs::CLibFile::Create(vfs::Path const& sFileName,
|
||||
vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType> *pLocation,
|
||||
ILibrary *pLibrary,
|
||||
vfs::CLibFile* vfs::CLibFile::create(vfs::Path const& filename,
|
||||
tLocation *location,
|
||||
ILibrary *library,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator)
|
||||
{
|
||||
#if 0
|
||||
@@ -21,22 +24,22 @@ vfs::CLibFile* vfs::CLibFile::Create(vfs::Path const& sFileName,
|
||||
if(!_lfile_pool)
|
||||
{
|
||||
_lfile_pool = new ObjBlockAllocator<vfs::CLibFile>();
|
||||
CFileAllocator::RegisterAllocator(_lfile_pool);
|
||||
CFileAllocator::registerAllocator(_lfile_pool);
|
||||
}
|
||||
pFile = _lfile_pool->New();
|
||||
}
|
||||
#endif
|
||||
pFile->m_sFileName = sFileName;
|
||||
pFile->_pLoc_ = pLocation;
|
||||
pFile->m_pLibrary = pLibrary;
|
||||
pFile->m_filename = filename;
|
||||
pFile->m_location = location;
|
||||
pFile->m_library = library;
|
||||
return pFile;
|
||||
}
|
||||
|
||||
vfs::CLibFile::CLibFile()
|
||||
: vfs::IFileTemplate<IReadable,IWriteType>(L""),
|
||||
vfs::ILocationAware<vfs::IReadable,vfs::IWriteType>(NULL),
|
||||
m_bIsOpen_read(false),
|
||||
m_pLibrary(NULL)
|
||||
: tBaseClass(L""),
|
||||
m_isOpen_read(false),
|
||||
m_library(NULL),
|
||||
m_location(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
@@ -44,88 +47,94 @@ vfs::CLibFile::~CLibFile()
|
||||
{
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::Close()
|
||||
void vfs::CLibFile::close()
|
||||
{
|
||||
if(m_bIsOpen_read)
|
||||
if(m_isOpen_read)
|
||||
{
|
||||
m_bIsOpen_read = !m_pLibrary->Close(this);
|
||||
return m_bIsOpen_read;
|
||||
m_library->close(this);
|
||||
m_isOpen_read = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Path vfs::CLibFile::GetFullPath()
|
||||
vfs::FileAttributes vfs::CLibFile::getAttributes()
|
||||
{
|
||||
if(_pLoc_)
|
||||
return vfs::FileAttributes(vfs::FileAttributes::ATTRIB_NORMAL | vfs::FileAttributes::ATTRIB_READONLY,
|
||||
vfs::FileAttributes::LT_LIBRARY);
|
||||
}
|
||||
|
||||
vfs::Path vfs::CLibFile::getPath()
|
||||
{
|
||||
if(m_location)
|
||||
{
|
||||
return _pLoc_->GetFullPath() + m_sFileName;
|
||||
return m_location->getPath() + m_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_sFileName;
|
||||
return m_filename;
|
||||
}
|
||||
}
|
||||
bool vfs::CLibFile::IsOpenRead()
|
||||
bool vfs::CLibFile::isOpenRead()
|
||||
{
|
||||
return m_bIsOpen_read;
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::OpenRead()
|
||||
bool vfs::CLibFile::openRead()
|
||||
{
|
||||
if(!m_bIsOpen_read)
|
||||
if(!m_isOpen_read)
|
||||
{
|
||||
if(!(m_bIsOpen_read = m_pLibrary->OpenRead(this)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TRYCATCH_RETHROW(m_isOpen_read = m_library->openRead(this), ERROR_FILE(L"read open error"));
|
||||
}
|
||||
return true;
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead)
|
||||
vfs::size_t vfs::CLibFile::read(vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
try
|
||||
{
|
||||
return false;
|
||||
return m_library->read(this, data, bytesToRead);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"read error"), &ex);
|
||||
}
|
||||
bool success = m_pLibrary->Read(this,pData,uiBytesToRead,uiBytesRead);
|
||||
return success;
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CLibFile::GetReadLocation()
|
||||
vfs::size_t vfs::CLibFile::getReadPosition()
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
try
|
||||
{
|
||||
return -1;
|
||||
return m_library->getReadPosition(this);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
|
||||
}
|
||||
return m_pLibrary->GetReadLocation(this);
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CLibFile::SetReadLocation(vfs::UInt32 uiPositionInBytes)
|
||||
void vfs::CLibFile::setReadPosition(vfs::size_t uiPositionInBytes)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool success = m_pLibrary->SetReadLocation(this,uiPositionInBytes);
|
||||
return success;
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
TRYCATCH_RETHROW(m_library->setReadPosition(this,uiPositionInBytes), ERROR_FILE(L"library error") );
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir)
|
||||
void vfs::CLibFile::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_pLibrary->SetReadLocation(this,uiOffsetInBytes,eSeekDir);
|
||||
THROWIFFALSE( m_isOpen_read, ERROR_FILE(L"file not opened") );
|
||||
TRYCATCH_RETHROW(m_library->setReadPosition(this, offsetInBytes, seekDir), ERROR_FILE(L"library error"));
|
||||
}
|
||||
|
||||
bool vfs::CLibFile::GetFileSize(vfs::UInt32& uiFileSize)
|
||||
vfs::size_t vfs::CLibFile::getSize()
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"could not open file") );
|
||||
try
|
||||
{
|
||||
return false;
|
||||
return m_library->getSize(this);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L"library error"), &ex);
|
||||
}
|
||||
return m_pLibrary->GetFileSize(this,uiFileSize);
|
||||
}
|
||||
|
||||
+22
-18
@@ -11,37 +11,41 @@ namespace vfs
|
||||
|
||||
class ILibrary;
|
||||
|
||||
class CLibFile : public vfs::IFileTemplate<vfs::IReadable,vfs::IWriteType>, public vfs::ILocationAware<vfs::IReadable,vfs::IWriteType>
|
||||
class CLibFile : public vfs::TFileTemplate<vfs::IReadable,vfs::IWriteType>
|
||||
{
|
||||
typedef vfs::IFileTemplate<vfs::IReadable,vfs::IWriteType> tBaseType;
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,vfs::IWriteType> tBaseClass;
|
||||
typedef vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType> tLocation;
|
||||
public:
|
||||
static CLibFile* Create(vfs::Path const& sFileName,
|
||||
vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType> *pLocation,
|
||||
ILibrary *pLibrary,
|
||||
CLibFile();
|
||||
static CLibFile* create(vfs::Path const& filename,
|
||||
tLocation *location,
|
||||
vfs::ILibrary *library,
|
||||
ObjBlockAllocator<CLibFile>* allocator = NULL);
|
||||
|
||||
// don't delete objects that YOU have not created with 'new'
|
||||
// dtor has to remain public to be usable at all
|
||||
virtual ~CLibFile();
|
||||
|
||||
virtual bool Close();
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual vfs::Path GetFullPath();
|
||||
virtual void close();
|
||||
|
||||
virtual bool IsOpenRead();
|
||||
virtual bool OpenRead();
|
||||
virtual bool Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead);
|
||||
virtual vfs::Path getPath();
|
||||
|
||||
virtual UInt32 GetReadLocation();
|
||||
virtual bool SetReadLocation(UInt32 uiPositionInBytes);
|
||||
virtual bool SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir);
|
||||
virtual bool isOpenRead();
|
||||
virtual bool openRead();
|
||||
virtual vfs::size_t read(vfs::Byte* pData, vfs::size_t bytesToRead);
|
||||
|
||||
virtual bool GetFileSize(UInt32& uiFileSize);
|
||||
virtual vfs::size_t getReadPosition();
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual vfs::size_t getSize();
|
||||
protected:
|
||||
bool m_bIsOpen_read;
|
||||
ILibrary* m_pLibrary;
|
||||
bool m_isOpen_read;
|
||||
ILibrary* m_library;
|
||||
tLocation* m_location;
|
||||
private:
|
||||
friend class std::vector<CLibFile>;
|
||||
CLibFile();
|
||||
static ObjBlockAllocator<CLibFile>* _lfile_pool;
|
||||
};
|
||||
|
||||
|
||||
+172
-156
@@ -3,220 +3,236 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
vfs::CMemoryFile::CMemoryFile()
|
||||
: vfs::IFileTemplate<vfs::IReadable,vfs::IWriteable>(vfs::Path()), m_bIsOpen_read(false), m_bIsOpen_write(false)
|
||||
#define ERROR_FILE(msg) BuildString().add(L"[").add(this->getPath()).add(L"] - ").add(msg).get()
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_buffer.good(), ERROR_FILE(L"invalid file object") );
|
||||
#else
|
||||
#define IS_FILE_VALID() THROWIFFALSE( m_buffer.good(), ERROR_FILE(L"invalid file object") );
|
||||
#endif
|
||||
|
||||
static inline std::ios::seekdir _seekDir(vfs::IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
m_ssBuffer.str("");
|
||||
if(seekDir == vfs::IBaseFile::SD_BEGIN)
|
||||
{
|
||||
return std::ios::beg;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_CURRENT)
|
||||
{
|
||||
return std::ios::cur;
|
||||
}
|
||||
else if(seekDir == vfs::IBaseFile::SD_END)
|
||||
{
|
||||
return std::ios::end;
|
||||
}
|
||||
THROWEXCEPTION(BuildString().add(L"Unknown seek direction [").add(seekDir).add(L"]").get());
|
||||
}
|
||||
|
||||
vfs::CMemoryFile::CMemoryFile(vfs::Path const& sFileName)
|
||||
: vfs::IFileTemplate<vfs::IReadable,vfs::IWriteable>(sFileName), m_bIsOpen_read(false), m_bIsOpen_write(false)
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
vfs::CMemoryFile::CMemoryFile()
|
||||
: tBaseClass(vfs::Path()), m_isOpen_read(false), m_isOpen_write(false)
|
||||
{
|
||||
m_ssBuffer.str("");
|
||||
m_buffer.str("");
|
||||
}
|
||||
|
||||
vfs::CMemoryFile::CMemoryFile(vfs::Path const& fileName)
|
||||
: tBaseClass(fileName), m_isOpen_read(false), m_isOpen_write(false)
|
||||
{
|
||||
m_buffer.str("");
|
||||
}
|
||||
|
||||
vfs::CMemoryFile::~CMemoryFile()
|
||||
{
|
||||
m_ssBuffer.str("");
|
||||
m_ssBuffer.clear();
|
||||
m_buffer.str("");
|
||||
m_buffer.clear();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::Close()
|
||||
vfs::FileAttributes vfs::CMemoryFile::getAttributes()
|
||||
{
|
||||
m_ssBuffer.clear();
|
||||
m_bIsOpen_read = false;
|
||||
m_bIsOpen_write = false;
|
||||
return m_ssBuffer.good();
|
||||
return vfs::FileAttributes(vfs::FileAttributes::ATTRIB_NORMAL, vfs::FileAttributes::LT_NONE);
|
||||
}
|
||||
bool vfs::CMemoryFile::GetFileSize(UInt32& uiFileSize)
|
||||
|
||||
void vfs::CMemoryFile::close()
|
||||
{
|
||||
uiFileSize = 0;
|
||||
if(!m_ssBuffer.good())
|
||||
m_buffer.clear();
|
||||
m_isOpen_read = false;
|
||||
m_isOpen_write = false;
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
vfs::size_t vfs::CMemoryFile::getSize()
|
||||
{
|
||||
IS_FILE_VALID();
|
||||
|
||||
std::streampos size = 0;
|
||||
if(!m_buffer.str().empty())
|
||||
{
|
||||
std::streampos current_position = m_buffer.tellg();
|
||||
m_buffer.seekg(0,std::ios::end);
|
||||
size = m_buffer.tellg();
|
||||
m_buffer.seekg(current_position,std::ios::beg);
|
||||
}
|
||||
|
||||
IS_FILE_VALID();
|
||||
return (vfs::size_t)size;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::isOpenRead()
|
||||
{
|
||||
return m_isOpen_read;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::openRead()
|
||||
{
|
||||
if(!m_buffer.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::ios::pos_type current_position = 0;
|
||||
if(!m_ssBuffer.str().empty())
|
||||
return m_isOpen_read = true;
|
||||
}
|
||||
vfs::size_t vfs::CMemoryFile::read(vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
if(!m_buffer.eof())
|
||||
{
|
||||
current_position = m_ssBuffer.tellg();
|
||||
m_ssBuffer.seekg(0,std::ios::end);
|
||||
uiFileSize = m_ssBuffer.tellg();
|
||||
m_ssBuffer.seekg(current_position,std::ios::beg);
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE(m_isOpen_read || this->openRead(), ERROR_FILE(L"open error"));
|
||||
|
||||
m_buffer.read(static_cast<Byte*>(data), bytesToRead);
|
||||
std::streamsize bytesRead = m_buffer.gcount();
|
||||
|
||||
THROWIFFALSE( m_buffer.good() || m_buffer.eof(), ERROR_FILE(L"read error") );
|
||||
return (vfs::size_t)bytesRead;
|
||||
}
|
||||
return m_ssBuffer.good();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::IsOpenRead()
|
||||
vfs::size_t vfs::CMemoryFile::getReadPosition()
|
||||
{
|
||||
return m_bIsOpen_read;
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE(m_isOpen_read || this->openRead(), ERROR_FILE(L"open error"));
|
||||
|
||||
return (vfs::size_t)m_buffer.tellg();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::OpenRead()
|
||||
void vfs::CMemoryFile::setReadPosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
m_bIsOpen_read = m_ssBuffer.good();
|
||||
return m_bIsOpen_read;
|
||||
}
|
||||
bool vfs::CMemoryFile::Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_ssBuffer.read(static_cast<Byte*>(pData),uiBytesToRead);
|
||||
uiBytesRead = m_ssBuffer.gcount();
|
||||
return m_ssBuffer.good();
|
||||
}
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"open error") );
|
||||
|
||||
vfs::UInt32 vfs::CMemoryFile::GetReadLocation()
|
||||
{
|
||||
if(!m_bIsOpen_read && this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_ssBuffer.tellg();
|
||||
}
|
||||
m_buffer.seekg((std::streamoff)positionInBytes);
|
||||
|
||||
bool vfs::CMemoryFile::SetReadLocation(UInt32 uiPositionInBytes)
|
||||
{
|
||||
if(!m_ssBuffer.good())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_ssBuffer.seekg(uiPositionInBytes);
|
||||
return m_ssBuffer.good();
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
bool vfs::CMemoryFile::SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir)
|
||||
void vfs::CMemoryFile::setReadPosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(!m_bIsOpen_read && !this->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_read || this->openRead(), ERROR_FILE(L"open error") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
if(eSeekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
ioSeekDir = std::ios::beg;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
ioSeekDir = std::ios::cur;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_END)
|
||||
{
|
||||
ioSeekDir = std::ios::end;
|
||||
}
|
||||
else
|
||||
{
|
||||
TRYCATCH_RETHROW(ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error"));
|
||||
m_buffer.seekg(offsetInBytes, ioSeekDir);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::isOpenWrite()
|
||||
{
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::openWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
{
|
||||
if( !m_buffer.good() )
|
||||
return false;
|
||||
}
|
||||
m_ssBuffer.seekg(uiOffsetInBytes,ioSeekDir);
|
||||
return m_ssBuffer.good();
|
||||
}
|
||||
if( m_isOpen_write )
|
||||
return true;
|
||||
|
||||
bool vfs::CMemoryFile::IsOpenWrite()
|
||||
{
|
||||
return m_bIsOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
||||
{
|
||||
if(bTruncate)
|
||||
{
|
||||
m_ssBuffer.str("");
|
||||
m_ssBuffer.clear();
|
||||
m_buffer.str("");
|
||||
m_buffer.clear();
|
||||
}
|
||||
m_bIsOpen_write = m_ssBuffer.good();
|
||||
return m_bIsOpen_write;
|
||||
m_isOpen_write = m_buffer.good();
|
||||
return m_isOpen_write;
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::Write(const Byte* pData, UInt32 uiBytesToWrite, UInt32& uiBytesWritten)
|
||||
vfs::size_t vfs::CMemoryFile::write(const vfs::Byte* data, vfs::size_t bytesToWrite)
|
||||
{
|
||||
if(!m_bIsOpen_write && !this->OpenWrite())
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
std::streampos start = 0;
|
||||
if(!m_buffer.str().empty())
|
||||
{
|
||||
return false;
|
||||
start = m_buffer.tellp();
|
||||
}
|
||||
vfs::UInt64 start = 0;
|
||||
if(!m_ssBuffer.str().empty())
|
||||
{
|
||||
start = m_ssBuffer.tellp();
|
||||
}
|
||||
m_ssBuffer.write(pData,uiBytesToWrite);
|
||||
vfs::UInt64 end = m_ssBuffer.tellp();
|
||||
uiBytesWritten = end-start;
|
||||
if(uiBytesWritten != uiBytesToWrite)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_ssBuffer.good();
|
||||
THROWIFFALSE( m_buffer.write(data, bytesToWrite), ERROR_FILE(L"write error") );
|
||||
std::streampos bytesWritten = m_buffer.tellp() - start;
|
||||
|
||||
IS_FILE_VALID();
|
||||
|
||||
return (vfs::size_t)bytesWritten;
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CMemoryFile::GetWriteLocation()
|
||||
vfs::size_t vfs::CMemoryFile::getWritePosition()
|
||||
{
|
||||
return m_ssBuffer.tellp();
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
return (vfs::size_t)m_buffer.tellp();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::SetWriteLocation(Int32 uiPositionInBytes)
|
||||
void vfs::CMemoryFile::setWritePosition(vfs::size_t positionInBytes)
|
||||
{
|
||||
if(!m_bIsOpen_write && !this->OpenWrite())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_ssBuffer.seekp(uiPositionInBytes);
|
||||
return m_ssBuffer.good();
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
m_buffer.seekp((std::streamoff)positionInBytes);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::SetWriteLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir)
|
||||
void vfs::CMemoryFile::setWritePosition(vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
if(!m_bIsOpen_write && !this->OpenWrite())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IS_FILE_VALID();
|
||||
THROWIFFALSE( m_isOpen_write || this->openWrite(), ERROR_FILE(L"open error") );
|
||||
|
||||
std::ios::seekdir ioSeekDir;
|
||||
if(eSeekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
ioSeekDir = std::ios::beg;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
ioSeekDir = std::ios::cur;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_END)
|
||||
{
|
||||
ioSeekDir = std::ios::end;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_ssBuffer.seekp(uiOffsetInBytes,ioSeekDir);
|
||||
return m_ssBuffer.good();
|
||||
TRYCATCH_RETHROW( ioSeekDir = _seekDir(seekDir), ERROR_FILE(L"seek error") );
|
||||
m_buffer.seekp(offsetInBytes, ioSeekDir);
|
||||
|
||||
IS_FILE_VALID();
|
||||
}
|
||||
|
||||
bool vfs::CMemoryFile::CopyToBuffer(vfs::tReadableFile& rFile)
|
||||
void vfs::CMemoryFile::copyToBuffer(vfs::tReadableFile& rFile)
|
||||
{
|
||||
bool needToClose = !rFile.IsOpenRead();
|
||||
vfs::COpenReadFile readfile(&rFile);
|
||||
if(!needToClose)
|
||||
try
|
||||
{
|
||||
readfile.release();
|
||||
}
|
||||
vfs::UInt32 uiSize,uiIO;
|
||||
|
||||
uiSize = rFile.GetFileSize();
|
||||
std::vector<Byte> vBuffer(uiSize);
|
||||
if( rFile.Read(&vBuffer[0],uiSize,uiIO) && (uiSize == uiIO) )
|
||||
{
|
||||
if( this->Write(&vBuffer[0],uiSize,uiIO) && (uiSize == uiIO) )
|
||||
bool needToClose = !rFile.isOpenRead();
|
||||
vfs::COpenReadFile readfile(&rFile);
|
||||
if(!needToClose)
|
||||
{
|
||||
return true;
|
||||
readfile.release();
|
||||
}
|
||||
|
||||
typedef std::vector<vfs::Byte> tByteVector;
|
||||
|
||||
vfs::size_t size = rFile.getSize();
|
||||
tByteVector vBuffer(size);
|
||||
|
||||
rFile.read(&vBuffer[0], size);
|
||||
this->write(&vBuffer[0], size);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(ERROR_FILE(L""), &ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CMemoryFile::Delete()
|
||||
bool vfs::CMemoryFile::deleteFile()
|
||||
{
|
||||
m_ssBuffer.clear();
|
||||
m_ssBuffer.str("");
|
||||
return m_ssBuffer.good();
|
||||
m_buffer.clear();
|
||||
m_buffer.str("");
|
||||
return m_buffer.good();
|
||||
}
|
||||
|
||||
+23
-20
@@ -6,39 +6,42 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CMemoryFile : public vfs::IFileTemplate<vfs::IReadable,vfs::IWriteable>
|
||||
class VFS_API CMemoryFile : public vfs::TFileTemplate<vfs::IReadable,vfs::IWritable>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,vfs::IWritable> tBaseClass;
|
||||
public :
|
||||
CMemoryFile();
|
||||
CMemoryFile(vfs::Path const& sFileName);
|
||||
CMemoryFile(vfs::Path const& filename);
|
||||
virtual ~CMemoryFile();
|
||||
|
||||
virtual bool Close();
|
||||
virtual bool GetFileSize(UInt32& uiFileSize);
|
||||
virtual vfs::FileAttributes getAttributes();
|
||||
|
||||
virtual bool IsOpenRead();
|
||||
virtual bool OpenRead();
|
||||
virtual bool Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead);
|
||||
virtual void close();
|
||||
virtual vfs::size_t getSize();
|
||||
|
||||
virtual UInt32 GetReadLocation();
|
||||
virtual bool SetReadLocation(UInt32 uiPositionInBytes);
|
||||
virtual bool SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir);
|
||||
virtual bool isOpenRead();
|
||||
virtual bool openRead();
|
||||
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead);
|
||||
|
||||
virtual bool IsOpenWrite();
|
||||
virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
|
||||
virtual bool Write(const Byte* pData, UInt32 uiBytesToWrite, UInt32& uiBytesWritten);
|
||||
virtual vfs::size_t getReadPosition();
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual UInt32 GetWriteLocation();
|
||||
virtual bool SetWriteLocation(Int32 uiPositionInBytes);
|
||||
virtual bool SetWriteLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir);
|
||||
virtual bool isOpenWrite();
|
||||
virtual bool openWrite(bool bCreateWhenNotExist = false, bool bTruncate = false);
|
||||
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite);
|
||||
|
||||
virtual bool Delete();
|
||||
virtual vfs::size_t getWritePosition();
|
||||
virtual void setWritePosition(vfs::size_t positionInBytes);
|
||||
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual bool deleteFile();
|
||||
|
||||
// convenience method
|
||||
bool CopyToBuffer(vfs::tReadableFile& rFile);
|
||||
void copyToBuffer(vfs::tReadableFile& rFile);
|
||||
protected:
|
||||
std::stringstream m_ssBuffer;
|
||||
bool m_bIsOpen_read, m_bIsOpen_write;
|
||||
std::stringstream m_buffer;
|
||||
bool m_isOpen_read, m_isOpen_write;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
@@ -1,21 +1,40 @@
|
||||
#ifndef _VFS_DIRECTORY_INTERFACE_H_
|
||||
#define _VFS_DIRECTORY_INTERFACE_H_
|
||||
|
||||
//#include "vfs_file_interface.h"
|
||||
#include "vfs_location_interface.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
/**
|
||||
* NOTE: declaration of 'IDirectory' is in file 'vfs_location_interface' because
|
||||
* of msvc and gcc incompatibilities
|
||||
*
|
||||
|
||||
template<class WriteType>
|
||||
class IDirectory : public IVFSLocation<vfs::IReadable, WriteType>
|
||||
class TDirectory : public vfs::TLocationTemplate<vfs::IReadable, WriteType>
|
||||
{
|
||||
public:
|
||||
typedef typename vfs::TLocationTemplate<vfs::IReadable, WriteType> tBaseClass;
|
||||
typedef typename tBaseClass::tFileType tFileType;
|
||||
typedef typename tBaseClass::tWriteType tWriteType;
|
||||
|
||||
*
|
||||
*/
|
||||
TDirectory(vfs::Path const& mountPoint, vfs::Path const& realPath)
|
||||
: tBaseClass(mountPoint), m_realPath(realPath)
|
||||
{};
|
||||
virtual ~TDirectory()
|
||||
{};
|
||||
|
||||
vfs::Path const& getRealPath()
|
||||
{
|
||||
return m_realPath;
|
||||
}
|
||||
|
||||
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false) = 0;
|
||||
virtual bool addFile(typename tBaseClass::tFileType* pFile, bool bDeleteOldFile=false) = 0;
|
||||
|
||||
virtual bool createSubDirectory(vfs::Path const& sSubDirPath) = 0;
|
||||
virtual bool deleteDirectory(vfs::Path const& sDirPath) = 0;
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName) = 0;
|
||||
protected:
|
||||
const vfs::Path m_realPath;
|
||||
private:
|
||||
void operator=(TDirectory<WriteType> const& t);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _VFS_DIRECTORY_INTERFACE_H_
|
||||
|
||||
+130
-122
@@ -2,13 +2,58 @@
|
||||
#define _VFS_FILE_INTERFACE_H_
|
||||
|
||||
#include "../vfs_types.h"
|
||||
#include "../vfs_path.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
/**
|
||||
* FileAttributes
|
||||
*/
|
||||
class FileAttributes
|
||||
{
|
||||
public:
|
||||
enum Attributes {
|
||||
ATTRIB_INVALID = 0,
|
||||
ATTRIB_ARCHIVE = 1,
|
||||
ATTRIB_DIRECTORY = 2,
|
||||
ATTRIB_HIDDEN = 4,
|
||||
ATTRIB_NORMAL = 8,
|
||||
ATTRIB_READONLY = 16,
|
||||
ATTRIB_SYSTEM = 32,
|
||||
ATTRIB_TEMPORARY = 64,
|
||||
ATTRIB_COMPRESSED = 128,
|
||||
ATTRIB_OFFLINE = 256,
|
||||
};
|
||||
enum LocationType {
|
||||
LT_NONE = 0,
|
||||
LT_LIBRARY = 1,
|
||||
LT_DIRECTORY = 2,
|
||||
LT_READONLY_DIRECTORY = 4,
|
||||
};
|
||||
public:
|
||||
FileAttributes();
|
||||
FileAttributes(vfs::UInt32 attribs, LocationType location);
|
||||
|
||||
vfs::UInt32 getAttrib() const;
|
||||
vfs::UInt32 getLocation() const;
|
||||
|
||||
bool isAttribSet(vfs::UInt32 attribs) const;
|
||||
bool isAttribNotSet(vfs::UInt32 attribs) const;
|
||||
|
||||
bool isLocation(vfs::UInt32 location) const;
|
||||
private:
|
||||
void operator=(vfs::FileAttributes const& attr);
|
||||
|
||||
const vfs::UInt32 _attribs;
|
||||
const vfs::UInt32 _location;
|
||||
};
|
||||
|
||||
/**
|
||||
* IBaseFile
|
||||
*/
|
||||
class IBaseFile
|
||||
class VFS_API IBaseFile
|
||||
{
|
||||
public:
|
||||
enum ESeekDir
|
||||
@@ -18,42 +63,23 @@ namespace vfs
|
||||
SD_END,
|
||||
};
|
||||
public:
|
||||
IBaseFile(vfs::Path const& sFileName)
|
||||
: m_sFileName(sFileName)
|
||||
{};
|
||||
virtual ~IBaseFile()
|
||||
{};
|
||||
IBaseFile(vfs::Path const& filename);
|
||||
virtual ~IBaseFile();
|
||||
|
||||
vfs::Path const& GetFileName()
|
||||
{
|
||||
return m_sFileName;
|
||||
};
|
||||
virtual vfs::Path GetFullPath()
|
||||
{
|
||||
return GetFileName();
|
||||
};
|
||||
virtual vfs::FileAttributes getAttributes() = 0;
|
||||
|
||||
virtual bool IsWriteable() = 0;
|
||||
virtual bool IsReadable() = 0;
|
||||
vfs::Path const& getName();
|
||||
virtual vfs::Path getPath();
|
||||
|
||||
virtual bool Close() = 0;
|
||||
virtual bool GetFileSize(UInt32& uiFileSize) = 0;
|
||||
UInt32 GetFileSize()
|
||||
{
|
||||
UInt32 size;
|
||||
if(GetFileSize(size))
|
||||
{
|
||||
return size;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
virtual bool implementsWritable() = 0;
|
||||
virtual bool implementsReadable() = 0;
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& rPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual void close() = 0;
|
||||
virtual vfs::size_t getSize() = 0;
|
||||
|
||||
virtual bool _getRealPath(vfs::Path& path);
|
||||
protected:
|
||||
vfs::Path m_sFileName;
|
||||
vfs::Path m_filename;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -63,34 +89,34 @@ namespace vfs
|
||||
class IReadable : public vfs::IReadType
|
||||
{
|
||||
public:
|
||||
virtual bool IsOpenRead() = 0;
|
||||
virtual bool OpenRead() = 0;
|
||||
virtual bool Read(Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead) = 0;
|
||||
virtual bool isOpenRead() = 0;
|
||||
virtual bool openRead() = 0;
|
||||
virtual vfs::size_t read(vfs::Byte* data, vfs::size_t bytesToRead) = 0;
|
||||
|
||||
virtual UInt32 GetReadLocation() = 0;
|
||||
virtual bool SetReadLocation(UInt32 uiPositionInBytes) = 0;
|
||||
virtual bool SetReadLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir) = 0;
|
||||
virtual vfs::size_t getReadPosition() = 0;
|
||||
virtual void setReadPosition(vfs::size_t positionInBytes) = 0;
|
||||
virtual void setReadPosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir) = 0;
|
||||
};
|
||||
//class NonReadable : public IReadType{};
|
||||
|
||||
/**
|
||||
* IWriteType , IWriteable
|
||||
* IWriteType , IWritable
|
||||
*/
|
||||
class IWriteType{};
|
||||
class IWriteable : public vfs::IWriteType
|
||||
class IWritable : public vfs::IWriteType
|
||||
{
|
||||
public:
|
||||
virtual bool IsOpenWrite() = 0;
|
||||
virtual bool OpenWrite(bool bCreateWhenNotExist = false, bool bTruncate = false) = 0;
|
||||
virtual bool Write(const Byte* pData, UInt32 uiBytesToWrite, UInt32& uiBytesWritten) = 0;
|
||||
virtual bool isOpenWrite() = 0;
|
||||
virtual bool openWrite(bool createWhenNotExist = false, bool truncate = false) = 0;
|
||||
virtual vfs::size_t write(const vfs::Byte* data, vfs::size_t bytesToWrite) = 0;
|
||||
|
||||
virtual UInt32 GetWriteLocation() = 0;
|
||||
virtual bool SetWriteLocation(Int32 uiPositionInBytes) = 0;
|
||||
virtual bool SetWriteLocation(Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir) = 0;
|
||||
virtual vfs::size_t getWritePosition() = 0;
|
||||
virtual void setWritePosition(vfs::size_t positionInBytes) = 0;
|
||||
virtual void setWritePosition(vfs::offset_t offsetInBytes, vfs::IBaseFile::ESeekDir seekDir) = 0;
|
||||
|
||||
virtual bool Delete() = 0;
|
||||
virtual bool deleteFile() = 0;
|
||||
};
|
||||
//class NonWriteable: public IWriteType{};
|
||||
//class NonWritable: public IWriteType{};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
@@ -99,127 +125,109 @@ namespace vfs
|
||||
* IFileTemplate
|
||||
*/
|
||||
template<typename ReadType=vfs::IReadType, typename WriteType=vfs::IWriteType>
|
||||
class IFileTemplate : public vfs::IBaseFile, public ReadType, public WriteType
|
||||
class VFS_API TFileTemplate : public vfs::IBaseFile, public ReadType, public WriteType
|
||||
{
|
||||
public:
|
||||
typedef ReadType read_type;
|
||||
typedef WriteType write_type;
|
||||
public:
|
||||
IFileTemplate(vfs::Path const& sFileName)
|
||||
: vfs::IBaseFile(sFileName), ReadType(), WriteType()
|
||||
{};
|
||||
virtual ~IFileTemplate()
|
||||
{};
|
||||
|
||||
virtual bool IsWriteable()
|
||||
typedef vfs::TFileTemplate<read_type,vfs::IWritable> write_file_type;
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,write_type> read_file_type;
|
||||
public:
|
||||
TFileTemplate(vfs::Path const& fileName)
|
||||
: vfs::IBaseFile(fileName), ReadType(), WriteType()
|
||||
{};
|
||||
virtual ~TFileTemplate()
|
||||
{};
|
||||
virtual bool implementsWritable()
|
||||
{
|
||||
return typeid(write_type) == typeid(vfs::IWriteable);
|
||||
return typeid(write_type) == typeid(vfs::IWritable);
|
||||
}
|
||||
virtual bool IsReadable()
|
||||
virtual bool implementsReadable()
|
||||
{
|
||||
return typeid(read_type) == typeid(vfs::IReadable);
|
||||
}
|
||||
virtual vfs::IFileTemplate<read_type,vfs::IWriteable>* GetWriteable()
|
||||
{
|
||||
//if(IsWriteable()) TODO: test how this affects compatibility
|
||||
{
|
||||
return reinterpret_cast<vfs::IFileTemplate<read_type,vfs::IWriteable>*>(this);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual vfs::IFileTemplate<vfs::IReadable,write_type>* GetReadable()
|
||||
{
|
||||
if(IsReadable())
|
||||
{
|
||||
return reinterpret_cast<vfs::IFileTemplate<vfs::IReadable,write_type>*>(this);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* IReadableFile
|
||||
* TReadableFile
|
||||
*/
|
||||
template<class WriteType=vfs::IWriteType>
|
||||
class IReadableFile : public vfs::IFileTemplate<IReadable,WriteType>
|
||||
class TReadableFile : public vfs::TFileTemplate<vfs::IReadable,WriteType>
|
||||
{
|
||||
typedef vfs::TFileTemplate<vfs::IReadable,WriteType> tBaseClass;
|
||||
public:
|
||||
template<typename T>
|
||||
static IReadableFile* Cast(T* t)
|
||||
typedef vfs::TReadableFile<WriteType> read_file_type;
|
||||
|
||||
/////////////////////////////////////////
|
||||
TReadableFile(vfs::Path const& sFilename)
|
||||
: tBaseClass(sFilename)
|
||||
{};
|
||||
virtual ~TReadableFile(){};
|
||||
|
||||
/////////////////////////////////////////
|
||||
read_file_type* operator=(vfs::IBaseFile const& t)
|
||||
{
|
||||
vfs::IBaseFile* bf = t;
|
||||
return Cast<IBaseFile>(bf);
|
||||
return read_file_type::cast(t);
|
||||
}
|
||||
template<>
|
||||
static IReadableFile* Cast<IBaseFile>(IBaseFile* bf)
|
||||
|
||||
/////////////////////////////////////////
|
||||
static read_file_type* cast(vfs::IBaseFile* bf)
|
||||
{
|
||||
if(bf && bf->IsReadable())
|
||||
if(bf && bf->implementsReadable())
|
||||
{
|
||||
return static_cast<IReadableFile*>(bf);
|
||||
return static_cast<read_file_type*>(bf);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
IReadableFile* operator=(T const& t)
|
||||
{
|
||||
return IReadableFile::Cast(t);
|
||||
}
|
||||
public:
|
||||
IReadableFile(vfs::Path const& sFileName)
|
||||
: vfs::IFileTemplate<vfs::IReadable,WriteType>(sFileName)
|
||||
{};
|
||||
virtual ~IReadableFile(){};
|
||||
protected:
|
||||
IReadableFile();
|
||||
TReadableFile();
|
||||
};
|
||||
|
||||
/**
|
||||
* IWriteableFile
|
||||
* TWritableFile
|
||||
*/
|
||||
template<class ReadType=IReadType>
|
||||
class IWriteableFile : public vfs::IFileTemplate<ReadType,vfs::IWriteable>
|
||||
template<class ReadType=vfs::IReadType>
|
||||
class TWritableFile : public vfs::TFileTemplate<ReadType,vfs::IWritable>
|
||||
{
|
||||
typedef vfs::TFileTemplate<ReadType,vfs::IWritable> tBaseClass;
|
||||
public:
|
||||
template<class T>
|
||||
static IWriteableFile* Cast(T* t)
|
||||
typedef vfs::TWritableFile<ReadType> write_file_type;
|
||||
|
||||
/////////////////////////////////////////
|
||||
TWritableFile(vfs::Path const& sFilename)
|
||||
: tBaseClass(sFilename)
|
||||
{};
|
||||
virtual ~TWritableFile(){};
|
||||
|
||||
/////////////////////////////////////////
|
||||
write_file_type& operator=(vfs::IBaseFile const& t)
|
||||
{
|
||||
vfs::IBaseFile* bf = t;
|
||||
return Cast<IBaseFile>(bf);
|
||||
return *write_file_type::cast(t);
|
||||
}
|
||||
template<>
|
||||
static IWriteableFile* Cast<IBaseFile>(IBaseFile* bf)
|
||||
|
||||
/////////////////////////////////////////
|
||||
static write_file_type* cast(IBaseFile* bf)
|
||||
{
|
||||
if(bf && bf->IsWriteable())
|
||||
if(bf && bf->implementsWritable())
|
||||
{
|
||||
return static_cast<IWriteableFile*>(bf);
|
||||
return static_cast<write_file_type*>(bf);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
template<class T>
|
||||
IWriteableFile& operator=(T const& t)
|
||||
{
|
||||
return *IWriteableFile::Cast(t);
|
||||
}
|
||||
public:
|
||||
IWriteableFile(vfs::Path const& sFileName)
|
||||
: vfs::IFileTemplate<ReadType,vfs::IWriteable>(sFileName)
|
||||
{};
|
||||
virtual ~IWriteableFile(){};
|
||||
protected:
|
||||
IWriteableFile();
|
||||
TWritableFile();
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
/**
|
||||
* typedef's
|
||||
*/
|
||||
typedef vfs::IReadableFile<vfs::IWriteType> tReadableFile;
|
||||
typedef vfs::IWriteableFile<vfs::IReadable> tWriteableFile;
|
||||
//typedef vfs::IWriteableFile<vfs::IReadType> tWriteableFile;
|
||||
|
||||
typedef vfs::TReadableFile<vfs::IWriteType> tReadableFile;
|
||||
typedef vfs::TWritableFile<vfs::IReadable> tWritableFile;
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#include "vfs_file_interface.h"
|
||||
#include "vfs_library_interface.h"
|
||||
|
||||
/**********************************************************************
|
||||
* vfs::FileAttributes
|
||||
*/
|
||||
vfs::FileAttributes::FileAttributes()
|
||||
: _attribs(ATTRIB_NORMAL), _location(LT_NONE)
|
||||
{
|
||||
};
|
||||
|
||||
vfs::FileAttributes::FileAttributes(vfs::UInt32 attribs, LocationType location)
|
||||
: _attribs(attribs), _location(location)
|
||||
{
|
||||
};
|
||||
|
||||
vfs::UInt32 vfs::FileAttributes::getAttrib() const
|
||||
{
|
||||
return _attribs;
|
||||
};
|
||||
|
||||
vfs::UInt32 vfs::FileAttributes::getLocation() const
|
||||
{
|
||||
return _location;
|
||||
};
|
||||
|
||||
bool vfs::FileAttributes::isAttribSet(vfs::UInt32 attribs) const
|
||||
{
|
||||
return attribs == (attribs & _attribs);
|
||||
};
|
||||
|
||||
bool vfs::FileAttributes::isAttribNotSet(vfs::UInt32 attribs) const
|
||||
{
|
||||
return 0 == (attribs & _attribs);
|
||||
};
|
||||
|
||||
bool vfs::FileAttributes::isLocation(vfs::UInt32 location) const
|
||||
{
|
||||
return location == (location & _location);
|
||||
};
|
||||
|
||||
/**********************************************************************
|
||||
* vfs::IBaseFile
|
||||
*/
|
||||
|
||||
vfs::IBaseFile::IBaseFile(vfs::Path const& filename)
|
||||
: m_filename(filename)
|
||||
{};
|
||||
|
||||
vfs::IBaseFile::~IBaseFile()
|
||||
{};
|
||||
|
||||
vfs::Path const& vfs::IBaseFile::getName()
|
||||
{
|
||||
return m_filename;
|
||||
};
|
||||
|
||||
vfs::Path vfs::IBaseFile::getPath()
|
||||
{
|
||||
return this->getName();
|
||||
};
|
||||
|
||||
|
||||
bool vfs::IBaseFile::_getRealPath(vfs::Path& path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* vfs::ILibrary
|
||||
*/
|
||||
|
||||
vfs::ILibrary::ILibrary(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile)
|
||||
: tBaseClass(mountPoint), m_ownLibFile(ownFile), m_libraryFile(libraryFile)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::ILibrary::~ILibrary()
|
||||
{
|
||||
if(m_libraryFile && m_ownLibFile)
|
||||
{
|
||||
m_libraryFile->close();
|
||||
delete m_libraryFile;
|
||||
m_libraryFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::Path const& vfs::ILibrary::getName()
|
||||
{
|
||||
return m_libraryFile->getName();
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -0,0 +1,65 @@
|
||||
#ifndef _VFS_ITERATOR_INTERFACE_H_
|
||||
#define _VFS_ITERATOR_INTERFACE_H_
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
template<typename T>
|
||||
class VFS_API TIterator
|
||||
{
|
||||
public:
|
||||
class IImplementation
|
||||
{
|
||||
friend class TIterator<T>;
|
||||
public:
|
||||
virtual ~IImplementation() {};
|
||||
virtual T* value() = 0;
|
||||
virtual void next() = 0;
|
||||
protected:
|
||||
virtual IImplementation* clone() = 0;
|
||||
};
|
||||
public:
|
||||
TIterator() : _obj(NULL), _iter_impl(NULL) {};
|
||||
TIterator(IImplementation* impl) : _obj(NULL), _iter_impl(impl)
|
||||
{
|
||||
if(_iter_impl)
|
||||
{
|
||||
_obj = _iter_impl->value();
|
||||
}
|
||||
}
|
||||
~TIterator()
|
||||
{
|
||||
if(_iter_impl) delete _iter_impl;
|
||||
};
|
||||
TIterator& operator=(TIterator const& t)
|
||||
{
|
||||
_obj = t._obj;
|
||||
_iter_impl = NULL;
|
||||
if(t._iter_impl)
|
||||
{
|
||||
_iter_impl = t._iter_impl->clone();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
//////////////////////////////
|
||||
T* value() { return _obj; };
|
||||
bool end() { return _obj == NULL; };
|
||||
void next()
|
||||
{
|
||||
if(_iter_impl)
|
||||
{
|
||||
_iter_impl->next();
|
||||
_obj = _iter_impl->value();
|
||||
if(!_obj)
|
||||
{
|
||||
delete _iter_impl;
|
||||
_iter_impl = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
T* _obj;
|
||||
IImplementation* _iter_impl;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _VFS_ITERATOR_INTERFACE_H_
|
||||
@@ -3,46 +3,32 @@
|
||||
|
||||
#include "vfs_location_interface.h"
|
||||
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class ILibrary : public vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType>
|
||||
class VFS_API ILibrary : public vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType>
|
||||
{
|
||||
typedef vfs::TLocationTemplate<vfs::IReadable,vfs::IWriteType> tBaseClass;
|
||||
public:
|
||||
ILibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false)
|
||||
: vfs::IVFSLocation<vfs::IReadable,vfs::IWriteType>(sMountPoint), m_pLibraryFile(pLibraryFile), m_bOwnLibFile(bOwnFile)
|
||||
{};
|
||||
virtual ~ILibrary()
|
||||
{
|
||||
if(m_pLibraryFile && m_bOwnLibFile)
|
||||
{
|
||||
m_pLibraryFile->Close();
|
||||
delete m_pLibraryFile;
|
||||
m_pLibraryFile = NULL;
|
||||
}
|
||||
};
|
||||
ILibrary(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile = false);
|
||||
virtual ~ILibrary();
|
||||
|
||||
virtual bool Init() = 0;
|
||||
virtual bool CloseLibrary() = 0;
|
||||
virtual bool init() = 0;
|
||||
virtual void closeLibrary() = 0;
|
||||
|
||||
virtual bool Close(tFileType *pFileHandle) = 0;
|
||||
virtual bool OpenRead(tFileType *pFileHandle) = 0;
|
||||
virtual bool Read(tFileType *pFileHandle, Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead) = 0;
|
||||
virtual void close(tFileType *fileHandle) = 0;
|
||||
virtual bool openRead(tFileType *fileHandle) = 0;
|
||||
virtual vfs::size_t read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead) = 0;
|
||||
|
||||
virtual UInt32 GetReadLocation(tFileType *pFileHandle) = 0;
|
||||
virtual bool SetReadLocation(tFileType *pFileHandle, UInt32 uiPositionInBytes) = 0;
|
||||
virtual bool SetReadLocation(tFileType *pFileHandle, Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir) = 0;
|
||||
virtual vfs::size_t getReadPosition(tFileType *fileHandle) = 0;
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes) = 0;
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir) = 0;
|
||||
|
||||
virtual bool GetFileSize(tFileType *pFileHandle, UInt32& uiFileSize) = 0;
|
||||
virtual vfs::size_t getSize(tFileType *pFileHandle) = 0;
|
||||
|
||||
vfs::Path const& GetLibName()
|
||||
{
|
||||
return m_pLibraryFile->GetFileName();
|
||||
}
|
||||
vfs::Path const& getName();
|
||||
protected:
|
||||
vfs::tReadableFile* m_pLibraryFile;
|
||||
bool m_bOwnLibFile;
|
||||
bool m_ownLibFile;
|
||||
vfs::tReadableFile* m_libraryFile;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -17,20 +17,20 @@ namespace vfs
|
||||
/**
|
||||
* ILocationAware
|
||||
*/
|
||||
template<typename ReadType, typename WriteType>
|
||||
class ILocationAware
|
||||
{
|
||||
public:
|
||||
typedef vfs::IVFSLocation<ReadType,WriteType> tLocationType;
|
||||
public:
|
||||
ILocationAware(vfs::IVFSLocation<ReadType,WriteType> *pLocation)
|
||||
: _pLoc_(pLocation)
|
||||
{};
|
||||
virtual ~ILocationAware()
|
||||
{};
|
||||
protected:
|
||||
tLocationType* _pLoc_;
|
||||
};
|
||||
//template<typename ReadType, typename WriteType>
|
||||
//class ILocationAware
|
||||
//{
|
||||
//public:
|
||||
// typedef vfs::IVFSLocation<ReadType,WriteType> tLocationType;
|
||||
//public:
|
||||
// ILocationAware(vfs::IVFSLocation<ReadType,WriteType> *pLocation)
|
||||
// : _pLoc_(pLocation)
|
||||
// {};
|
||||
// virtual ~ILocationAware()
|
||||
// {};
|
||||
//protected:
|
||||
// tLocationType* _pLoc_;
|
||||
//};
|
||||
|
||||
/******************************************************************/
|
||||
/******************************************************************/
|
||||
|
||||
@@ -4,231 +4,132 @@
|
||||
#include "../vfs_types.h"
|
||||
#include "../vfs_debug.h"
|
||||
#include "vfs_file_interface.h"
|
||||
#include "vfs_iterator_interface.h"
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class IBaseLocation
|
||||
class VFS_API IBaseLocation
|
||||
{
|
||||
public:
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
class IImplemetation
|
||||
{
|
||||
public:
|
||||
virtual ~IImplemetation() {};
|
||||
virtual vfs::IBaseFile* value() = 0;
|
||||
virtual void next() = 0;
|
||||
};
|
||||
public:
|
||||
Iterator() : _iter_impl(NULL), _file(NULL) {};
|
||||
Iterator(IImplemetation* impl) : _iter_impl(impl), _file(NULL)
|
||||
{
|
||||
THROWIFFALSE(_iter_impl, L"EXCEPTION");
|
||||
_file = _iter_impl->value();
|
||||
}
|
||||
~Iterator()
|
||||
{
|
||||
}
|
||||
//////////////////////////////
|
||||
vfs::IBaseFile* value()
|
||||
{
|
||||
return _file;
|
||||
};
|
||||
void next()
|
||||
{
|
||||
if(_iter_impl)
|
||||
{
|
||||
_iter_impl->next();
|
||||
_file = _iter_impl->value();
|
||||
if(!_file)
|
||||
{
|
||||
delete _iter_impl;
|
||||
_iter_impl = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool end()
|
||||
{
|
||||
return _file == NULL;
|
||||
}
|
||||
//////////////////////////////
|
||||
private:
|
||||
IImplemetation* _iter_impl;
|
||||
vfs::IBaseFile* _file;
|
||||
};
|
||||
public:
|
||||
typedef TIterator<vfs::IBaseFile> Iterator;
|
||||
|
||||
virtual ~IBaseLocation()
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
T* Cast()
|
||||
{
|
||||
return dynamic_cast<T*>(this);
|
||||
}
|
||||
virtual bool IsWriteable() = 0;
|
||||
virtual bool IsReadable() = 0;
|
||||
virtual bool implementsWritable() = 0;
|
||||
virtual bool implementsReadable() = 0;
|
||||
|
||||
virtual vfs::Path const& GetFullPath() = 0;
|
||||
virtual bool FileExists(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::Path const& getPath() = 0;
|
||||
virtual bool fileExists(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0;
|
||||
|
||||
virtual Iterator begin() = 0;
|
||||
virtual void GetSubDirList(std::list<vfs::Path>& rlSubDirs) = 0;
|
||||
virtual Iterator begin() = 0;
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* IVFSLocation
|
||||
* TVFSLocation
|
||||
*/
|
||||
//template<typename ReadType=vfs::IReadType, typename WriteType=vfs::IWriteType>
|
||||
template<typename ReadType, typename WriteType>
|
||||
class IVFSLocation : public IBaseLocation
|
||||
class VFS_API TLocationTemplate : public IBaseLocation
|
||||
{
|
||||
public:
|
||||
typedef vfs::IVFSLocation<ReadType,WriteType> tClassType;
|
||||
typedef vfs::IFileTemplate<ReadType,WriteType> tFileType;
|
||||
typedef vfs::TLocationTemplate<ReadType,WriteType> tLocationType;
|
||||
typedef vfs::TFileTemplate<ReadType,WriteType> tFileType;
|
||||
typedef ReadType tReadType;
|
||||
typedef WriteType tWriteType;
|
||||
typedef std::list<std::pair<tFileType*,vfs::Path> > tListFilesWithPath;
|
||||
public:
|
||||
IVFSLocation(vfs::Path const& sMountPoint)
|
||||
: m_sMountPoint(sMountPoint)
|
||||
TLocationTemplate(vfs::Path const& mountPoint)
|
||||
: m_mountPoint(mountPoint)
|
||||
{};
|
||||
virtual ~IVFSLocation()
|
||||
virtual ~TLocationTemplate()
|
||||
{};
|
||||
|
||||
// has to be virtual , or the types of the caller (not the real object) will be tested
|
||||
virtual bool IsWriteable()
|
||||
virtual bool implementsWritable()
|
||||
{
|
||||
return typeid(tWriteType) == typeid(vfs::IWriteable);
|
||||
return typeid(tWriteType) == typeid(vfs::IWritable);
|
||||
}
|
||||
virtual bool IsReadable()
|
||||
virtual bool implementsReadable()
|
||||
{
|
||||
return typeid(tReadType) == typeid(vfs::IReadable);
|
||||
}
|
||||
virtual IVFSLocation<IReadType,IWriteable>* GetWriteable()
|
||||
|
||||
vfs::Path const& getMountPoint()
|
||||
{
|
||||
//if(IsWriteable()) TODO: test how this affects compatibility
|
||||
{
|
||||
return reinterpret_cast<IVFSLocation<vfs::IReadType,vfs::IWriteable>*>(this);
|
||||
}
|
||||
return NULL;
|
||||
return m_mountPoint;
|
||||
}
|
||||
vfs::Path const& GetMountPoint()
|
||||
{
|
||||
return m_sMountPoint;
|
||||
};
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
* TLocationTemplate interface
|
||||
*/
|
||||
virtual vfs::Path const& GetFullPath()
|
||||
virtual vfs::Path const& getPath()
|
||||
{
|
||||
return m_sMountPoint;
|
||||
return m_mountPoint;
|
||||
}
|
||||
virtual bool FileExists(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName) = 0;
|
||||
virtual tFileType* GetFileTyped(vfs::Path const& rFileName) = 0;
|
||||
|
||||
virtual bool fileExists(vfs::Path const& sFileName) = 0;
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName) = 0;
|
||||
virtual tFileType* getFileTyped(vfs::Path const& rFileName) = 0;
|
||||
protected:
|
||||
vfs::Path m_sMountPoint;
|
||||
vfs::Path m_mountPoint;
|
||||
};
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
|
||||
template<typename WriteType=vfs::IWriteType>
|
||||
class IReadLocation : public IVFSLocation<IReadable,WriteType>
|
||||
class TReadLocation : public TLocationTemplate<IReadable,WriteType>
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static IReadLocation* Cast(T* t)
|
||||
typedef TReadLocation<WriteType> tLocationType;
|
||||
|
||||
static tLocationType* cast(vfs::IBaseLocation* bl)
|
||||
{
|
||||
// which file type does the to tested location contain
|
||||
typename T::tFileType* _F=NULL;
|
||||
// is it readable?
|
||||
vfs::IReadable *rf = _F;
|
||||
// is the write type compatible (probably redundant)
|
||||
WriteType *wf = _F;
|
||||
// it is readable and the write type fits
|
||||
return reinterpret_cast<IReadLocation*>(t);
|
||||
}
|
||||
template<>
|
||||
static IReadLocation* Cast<IBaseLocation>(IBaseLocation* bl)
|
||||
{
|
||||
return dynamic_cast<IReadLocation*>(bl);
|
||||
if(bl && bl->implementsReadable())
|
||||
{
|
||||
return static_cast<tLocationType*>(bl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
IReadLocation(vfs::Path const& sLocalPath)
|
||||
: vfs::IVFSLocation<IReadable,WriteType>(sLocalPath)
|
||||
TReadLocation(vfs::Path const& sLocalPath)
|
||||
: vfs::TLocationTemplate<IReadable,WriteType>(sLocalPath)
|
||||
{};
|
||||
virtual ~IReadLocation(){};
|
||||
virtual ~TReadLocation(){};
|
||||
};
|
||||
typedef IReadLocation<vfs::IWriteType> tReadLocation;
|
||||
|
||||
|
||||
template<typename ReadType=vfs::IReadType>
|
||||
class IWriteLocation : public vfs::IVFSLocation<ReadType,vfs::IWriteable>
|
||||
class TWriteLocation : public vfs::TLocationTemplate<ReadType,vfs::IWritable>
|
||||
{
|
||||
public:
|
||||
template<class T>
|
||||
static IWriteLocation* Cast(T* t)
|
||||
typedef TWriteLocation<ReadType> tLocationType;
|
||||
|
||||
static tLocationType* cast(vfs::IBaseLocation* bl)
|
||||
{
|
||||
// which file type does the to tested location contain
|
||||
typename T::tFileType* _F=NULL;
|
||||
// is it writeable?
|
||||
vfs::IWriteable *wf = _F;
|
||||
// is the read type compatible (probably redundant)
|
||||
ReadType *rf = _F;
|
||||
// is writeable and the read type fits
|
||||
return reinterpret_cast<IWriteLocation*>(t);
|
||||
}
|
||||
template<>
|
||||
static IWriteLocation* Cast<IBaseLocation>(IBaseLocation* bl)
|
||||
{
|
||||
return dynamic_cast<IWriteLocation*>(bl);
|
||||
if(bl && bl->implementsWritable())
|
||||
{
|
||||
return static_cast<tLocationType*>(bl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
IWriteLocation(vfs::Path const& sLocalPath)
|
||||
: vfs::IVFSLocation<ReadType,vfs::IWriteable>(sLocalPath)
|
||||
TWriteLocation(vfs::Path const& sLocalPath)
|
||||
: vfs::TLocationTemplate<ReadType,vfs::IWritable>(sLocalPath)
|
||||
{};
|
||||
virtual ~IWriteLocation(){};
|
||||
virtual ~TWriteLocation(){};
|
||||
};
|
||||
typedef IWriteLocation<vfs::IReadType> tWriteLocation;
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
|
||||
template<class WriteType>
|
||||
class IDirectory : public vfs::IVFSLocation<vfs::IReadable, WriteType>
|
||||
{
|
||||
typedef typename vfs::IVFSLocation<vfs::IReadable, WriteType> tBaseType;
|
||||
public:
|
||||
IDirectory(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: vfs::IVFSLocation<vfs::IReadable, WriteType>(sMountPoint), m_sRealPath(sRealPath)
|
||||
{};
|
||||
virtual ~IDirectory()
|
||||
{};
|
||||
|
||||
vfs::Path const& GetRealPath()
|
||||
{
|
||||
return m_sRealPath;
|
||||
}
|
||||
|
||||
virtual tBaseType::tFileType* AddFile(vfs::Path const& sFilename, bool bDeleteOldFile=false) = 0;
|
||||
virtual bool AddFile( typename vfs::IVFSLocation<vfs::IReadable, WriteType>::tFileType* pFile, bool bDeleteOldFile=false) = 0;
|
||||
|
||||
virtual bool CreateSubDirectory(vfs::Path const& sSubDirPath) = 0;
|
||||
virtual bool DeleteDirectory(vfs::Path const& sDirPath) = 0;
|
||||
virtual bool DeleteFileFromDirectory(vfs::Path const& sFileName) = 0;
|
||||
protected:
|
||||
const vfs::Path m_sRealPath;
|
||||
};
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
typedef TReadLocation<vfs::IWriteType> tReadLocation;
|
||||
typedef TWriteLocation<vfs::IReadType> tWriteLocation;
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
+124
-108
@@ -32,21 +32,21 @@ namespace szExt
|
||||
} CVfsFileInStream;
|
||||
|
||||
|
||||
static sz::SRes VfsFileInStream_Read(void *pp, void *buf, size_t *size)
|
||||
static sz::SRes VfsFileInStream_Read(void *pp, void *buf, ::size_t *size)
|
||||
{
|
||||
CVfsFileInStream *p = (CVfsFileInStream *)pp;
|
||||
vfs::UInt32 to_read = *size;
|
||||
vfs::UInt32 has_read = 0;
|
||||
::size_t to_read = *size;
|
||||
sz::SRes res;
|
||||
if(p->file.file->Read((vfs::Byte*)buf,to_read, has_read))
|
||||
try
|
||||
{
|
||||
*size = (::size_t)p->file.file->read((vfs::Byte*)buf,to_read);
|
||||
res = SZ_OK;
|
||||
}
|
||||
else
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
logException(ex);
|
||||
res = SZ_ERROR_READ;
|
||||
}
|
||||
*size = has_read;
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -67,17 +67,19 @@ namespace szExt
|
||||
eSD = vfs::IBaseFile::SD_END;
|
||||
break;
|
||||
default:
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
return SZ_ERROR_PARAM;
|
||||
}
|
||||
vfs::Int32 _pos = (vfs::Int32)(*pos); // only 32 bit
|
||||
vfs::offset_t _pos = (vfs::offset_t)(*pos);
|
||||
sz::SRes res;
|
||||
if(p->file.file->SetReadLocation(_pos,eSD))
|
||||
try
|
||||
{
|
||||
*pos = p->file.file->GetReadLocation();
|
||||
p->file.file->setReadPosition(_pos,eSD);
|
||||
*pos = p->file.file->getReadPosition();
|
||||
res = SZ_OK;
|
||||
}
|
||||
else
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
res = SZ_ERROR_READ;
|
||||
}
|
||||
return res;
|
||||
@@ -94,6 +96,20 @@ namespace szExt
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
vfs::CUncompressed7zLibrary::CUncompressed7zLibrary(
|
||||
tReadableFile *libraryFile,
|
||||
vfs::Path const& mountPoint,
|
||||
bool ownFile,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator)
|
||||
: vfs::CUncompressedLibraryBase(libraryFile, mountPoint, ownFile), _allocator(allocator)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressed7zLibrary::~CUncompressed7zLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#define k_Copy 0
|
||||
|
||||
sz::UInt64 GetSum(const sz::UInt64 *values, sz::UInt32 index)
|
||||
@@ -107,109 +123,109 @@ sz::UInt64 GetSum(const sz::UInt64 *values, sz::UInt32 index)
|
||||
return sum;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressed7zLibrary::Init()
|
||||
bool vfs::CUncompressed7zLibrary::init()
|
||||
{
|
||||
if(!m_pLibraryFile)
|
||||
if(!m_libraryFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
szExt::CVfsFileInStream archiveStream;
|
||||
sz::CLookToRead lookStream;
|
||||
sz::CSzArEx db;
|
||||
sz::SRes res;
|
||||
sz::ISzAlloc allocImp;
|
||||
sz::ISzAlloc allocTempImp;
|
||||
|
||||
if(!m_pLibraryFile->OpenRead())
|
||||
try
|
||||
{
|
||||
szExt::CVfsFileInStream archiveStream;
|
||||
sz::CLookToRead lookStream;
|
||||
sz::CSzArEx db;
|
||||
sz::SRes res;
|
||||
sz::ISzAlloc allocImp;
|
||||
sz::ISzAlloc allocTempImp;
|
||||
|
||||
vfs::COpenReadFile rfile(m_libraryFile);
|
||||
|
||||
archiveStream.file.file = m_libraryFile;
|
||||
|
||||
szExt::VfsFileInStream_CreateVTable(&archiveStream);
|
||||
sz::LookToRead_CreateVTable(&lookStream, False);
|
||||
|
||||
lookStream.realStream = &archiveStream.s;
|
||||
sz::LookToRead_Init(&lookStream);
|
||||
|
||||
allocImp.Alloc = sz::SzAlloc;
|
||||
allocImp.Free = sz::SzFree;
|
||||
|
||||
allocTempImp.Alloc = sz::SzAllocTemp;
|
||||
allocTempImp.Free = sz::SzFreeTemp;
|
||||
|
||||
sz::CrcGenerateTable();
|
||||
|
||||
sz::SzArEx_Init(&db);
|
||||
if( SZ_OK != (res = sz::SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp)) )
|
||||
{
|
||||
THROWEXCEPTION(BuildString().add(L"Could not open 7z archive [").add(m_libraryFile->getPath()).add(L"]").get());
|
||||
}
|
||||
|
||||
vfs::TDirectory<ILibrary::tWriteType>* pLD = NULL;
|
||||
vfs::Path oDir, oFile;
|
||||
vfs::Path oDirPath;
|
||||
|
||||
for(vfs::UInt32 i = 0; i < db.db.NumFiles; i++)
|
||||
{
|
||||
sz::CSzFileItem *f = db.db.Files + i;
|
||||
if (f->IsDir)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
vfs::Path sPath(f->Name);
|
||||
sPath.splitLast(oDir,oFile);
|
||||
oDirPath = m_mountPoint;
|
||||
if(!oDir.empty())
|
||||
{
|
||||
oDirPath += oDir;
|
||||
}
|
||||
|
||||
// determine offset and size
|
||||
sz::UInt32 folderIndex = db.FileIndexToFolderIndexMap[i];
|
||||
|
||||
sz::CSzFolder *folder = db.db.Folders + folderIndex;
|
||||
sz::UInt64 unpackSizeSpec = sz::SzFolder_GetUnpackSize(folder);
|
||||
size_t unpackSize = (size_t)unpackSizeSpec;
|
||||
sz::UInt64 startOffset = sz::SzArEx_GetFolderStreamPos(&db, folderIndex, 0);
|
||||
|
||||
//const sz::UInt64 *packSizes = db.db.PackSizes + db.FolderStartPackStreamIndex[folderIndex];
|
||||
|
||||
//CSzCoderInfo *coder = &folder->Coders[0];
|
||||
//if (coder->MethodID == k_Copy)
|
||||
//{
|
||||
// UInt32 si = 0;
|
||||
// UInt64 offset;
|
||||
// UInt64 inSize;
|
||||
// offset = GetSum(packSizes, si);
|
||||
// inSize = packSizes[si];
|
||||
//}
|
||||
|
||||
// get or create according directory object
|
||||
tDirCatalogue::iterator it = m_dirs.find(oDirPath);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
pLD = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
pLD = new vfs::CLibDirectory(oDir,oDirPath);
|
||||
m_dirs.insert(std::make_pair(oDirPath,pLD));
|
||||
}
|
||||
// create file
|
||||
vfs::CLibFile *pFile = vfs::CLibFile::create(oFile,pLD,this,_allocator);
|
||||
// add file to directory
|
||||
THROWIFFALSE( pLD->addFile(pFile), L"" );
|
||||
|
||||
// link file data struct to file object
|
||||
m_fileData.insert(std::make_pair(pFile,SFileData(unpackSize, (vfs::size_t)startOffset)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
return false;
|
||||
}
|
||||
archiveStream.file.file = m_pLibraryFile;
|
||||
|
||||
szExt::VfsFileInStream_CreateVTable(&archiveStream);
|
||||
sz::LookToRead_CreateVTable(&lookStream, False);
|
||||
|
||||
lookStream.realStream = &archiveStream.s;
|
||||
sz::LookToRead_Init(&lookStream);
|
||||
|
||||
allocImp.Alloc = sz::SzAlloc;
|
||||
allocImp.Free = sz::SzFree;
|
||||
|
||||
allocTempImp.Alloc = sz::SzAllocTemp;
|
||||
allocTempImp.Free = sz::SzFreeTemp;
|
||||
|
||||
sz::CrcGenerateTable();
|
||||
|
||||
sz::SzArEx_Init(&db);
|
||||
if( SZ_OK != (res = sz::SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp)) )
|
||||
{
|
||||
std::stringstream wss;
|
||||
wss << "Could not open 7z archive [" << m_pLibraryFile->GetFullPath()().utf8() << "]";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
|
||||
vfs::IDirectory<ILibrary::tWriteType>* pLD = NULL;
|
||||
vfs::Path oDir, oFile;
|
||||
vfs::Path oDirPath;
|
||||
|
||||
for(vfs::UInt32 i = 0; i < db.db.NumFiles; i++)
|
||||
{
|
||||
sz::CSzFileItem *f = db.db.Files + i;
|
||||
if (f->IsDir)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
vfs::Path sPath(f->Name);
|
||||
sPath.SplitLast(oDir,oFile);
|
||||
oDirPath = m_sMountPoint;
|
||||
if(!oDir.empty())
|
||||
{
|
||||
oDirPath += oDir;
|
||||
}
|
||||
|
||||
// determine offset and size
|
||||
sz::UInt32 folderIndex = db.FileIndexToFolderIndexMap[i];
|
||||
|
||||
sz::CSzFolder *folder = db.db.Folders + folderIndex;
|
||||
sz::UInt64 unpackSizeSpec = sz::SzFolder_GetUnpackSize(folder);
|
||||
size_t unpackSize = (size_t)unpackSizeSpec;
|
||||
sz::UInt64 startOffset = sz::SzArEx_GetFolderStreamPos(&db, folderIndex, 0);
|
||||
|
||||
const sz::UInt64 *packSizes = db.db.PackSizes + db.FolderStartPackStreamIndex[folderIndex];
|
||||
|
||||
//CSzCoderInfo *coder = &folder->Coders[0];
|
||||
//if (coder->MethodID == k_Copy)
|
||||
//{
|
||||
// UInt32 si = 0;
|
||||
// UInt64 offset;
|
||||
// UInt64 inSize;
|
||||
// offset = GetSum(packSizes, si);
|
||||
// inSize = packSizes[si];
|
||||
//}
|
||||
|
||||
// get or create according directory object
|
||||
tDirCatalogue::iterator it = m_catDirs.find(oDirPath);
|
||||
if(it != m_catDirs.end())
|
||||
{
|
||||
pLD = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
pLD = new CLibDirectory(oDir,oDirPath);
|
||||
m_catDirs.insert(std::make_pair(oDirPath,pLD));
|
||||
}
|
||||
// create file
|
||||
vfs::CLibFile *pFile = vfs::CLibFile::Create(oFile,pLD,this,_allocator);
|
||||
// add file to directory
|
||||
if(!pLD->AddFile(pFile))
|
||||
{
|
||||
// something is wrong
|
||||
m_pLibraryFile->Close();
|
||||
return false;
|
||||
}
|
||||
// link file data struct to file object
|
||||
m_mapLibData.insert(std::pair<tFileType*,sFileData>(pFile,sFileData(unpackSize, (UInt32)startOffset)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,13 @@ namespace vfs
|
||||
class CUncompressed7zLibrary : public vfs::CUncompressedLibraryBase
|
||||
{
|
||||
public:
|
||||
CUncompressed7zLibrary(tReadableFile *pLibraryFile,
|
||||
vfs::Path const& sMountPoint,
|
||||
bool bOwnFile = false,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator=NULL)
|
||||
: vfs::CUncompressedLibraryBase(pLibraryFile,sMountPoint,bOwnFile), _allocator(allocator)
|
||||
{};
|
||||
virtual ~CUncompressed7zLibrary()
|
||||
{};
|
||||
/**
|
||||
* ILibrary interface
|
||||
*/
|
||||
virtual bool Init();
|
||||
CUncompressed7zLibrary(tReadableFile *libraryFile,
|
||||
vfs::Path const& mountPoint,
|
||||
bool ownFile = false,
|
||||
ObjBlockAllocator<vfs::CLibFile>* allocator=NULL);
|
||||
virtual ~CUncompressed7zLibrary();
|
||||
|
||||
virtual bool init();
|
||||
private:
|
||||
ObjBlockAllocator<vfs::CLibFile>* _allocator;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//#define VFS_BASIC_TYPES
|
||||
#include <cstring>
|
||||
|
||||
#include "../vfs_types.h"
|
||||
|
||||
#include "vfs_create_7z_library.h"
|
||||
@@ -22,21 +23,21 @@ extern "C"
|
||||
/******************************************************************************************/
|
||||
namespace szExt
|
||||
{
|
||||
inline vfs::UInt32 WRITEBYTE(std::ostream& out, sz::Byte const& value)
|
||||
inline ::size_t WRITEBYTE(std::ostream& out, sz::Byte const& value)
|
||||
{
|
||||
out.write((char*)&value,sizeof(sz::Byte));
|
||||
return 1;
|
||||
}
|
||||
template<typename T>
|
||||
inline vfs::UInt32 WRITEALL(std::ostream& out, T const& value)
|
||||
inline ::size_t WRITEALL(std::ostream& out, T const& value)
|
||||
{
|
||||
out.write((char*)&value,sizeof(T));
|
||||
return sizeof(T);
|
||||
}
|
||||
template<typename T>
|
||||
inline vfs::UInt32 WRITEBUFFER(std::ostream& out, T* value, size_t num_elements)
|
||||
inline ::size_t WRITEBUFFER(std::ostream& out, T* value, ::size_t num_elements)
|
||||
{
|
||||
out.write((char*)value,sizeof(T) * num_elements);
|
||||
out.write((char*)value, num_elements*sizeof(T));
|
||||
return num_elements*sizeof(T);
|
||||
}
|
||||
|
||||
@@ -46,16 +47,16 @@ namespace szExt
|
||||
* - if the number is smaller than 128, use the extra byte to store the value
|
||||
*/
|
||||
template<typename T>
|
||||
inline vfs::UInt32 WRITE(std::ostream& out, T const& value)
|
||||
inline ::size_t WRITE(std::ostream& out, T const& value)
|
||||
{
|
||||
vfs::UInt32 count = 0;
|
||||
::size_t count = 0;
|
||||
sz::Byte data[8];
|
||||
sz::Byte firstByte = 0;
|
||||
sz::Byte* b = (sz::Byte*)&value;
|
||||
size_t SIZE = sizeof(T);
|
||||
::size_t SIZE = sizeof(T);
|
||||
b+= SIZE-1;
|
||||
vfs::Int32 i;
|
||||
for(i=SIZE-1; i>=0; --i)
|
||||
for(i = (vfs::Int32)(SIZE-1); i>=0; --i)
|
||||
{
|
||||
if( (*b & 0xFF) != 0)
|
||||
{
|
||||
@@ -107,7 +108,7 @@ vfs::CCreateUncompressed7zLibrary::~CCreateUncompressed7zLibrary()
|
||||
m_mapDirInfo.clear();
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
bool vfs::CCreateUncompressed7zLibrary::addFile(vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
@@ -121,13 +122,13 @@ bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not open File \"" << pFile->GetFullPath()() << L"\"";
|
||||
wss << L"Could not open File \"" << pFile->getPath()() << L"\"";
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
SFileInfo fi;
|
||||
vfs::Path filename = pFile->GetFullPath();
|
||||
fi.name = filename().c_wcs();
|
||||
fi.size = pFile->GetFileSize();
|
||||
vfs::Path filename = pFile->getPath();
|
||||
fi.name = filename.c_wcs();
|
||||
fi.size = pFile->getSize();
|
||||
if(m_lFileInfo.empty())
|
||||
{
|
||||
fi.offset = 0;
|
||||
@@ -138,23 +139,23 @@ bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
fi.offset = fic.offset + fic.size;
|
||||
}
|
||||
|
||||
std::vector<vfs::Byte> data(fi.size);
|
||||
UInt32 ui_read;
|
||||
pFile->Read(&data[0], fi.size, ui_read);
|
||||
fi.CRC = sz::CrcCalc(&data[0],fi.size);
|
||||
m_ssFileStream.write(&data[0],fi.size);
|
||||
typedef std::vector<vfs::Byte> tByteVector;
|
||||
tByteVector data( (tByteVector::size_type)fi.size );
|
||||
THROWIFFALSE(fi.size == pFile->read(&data[0], (vfs::size_t)fi.size), L"");
|
||||
fi.CRC = sz::CrcCalc(&data[0],(::size_t)fi.size);
|
||||
m_ssFileStream.write(&data[0],(std::streamsize)fi.size);
|
||||
|
||||
m_lFileInfo.push_back(fi);
|
||||
|
||||
vfs::Path path,dummy;
|
||||
filename.SplitLast(path,dummy);
|
||||
filename.splitLast(path,dummy);
|
||||
if(!path.empty())
|
||||
{
|
||||
tDirInfo::iterator it_find = m_mapDirInfo.find(path().c_wcs());
|
||||
tDirInfo::iterator it_find = m_mapDirInfo.find(path.c_wcs());
|
||||
if(it_find == m_mapDirInfo.end())
|
||||
{
|
||||
SFileInfo dir;
|
||||
dir.name = path().c_wcs();
|
||||
dir.name = path.c_wcs();
|
||||
dir.offset = 0;
|
||||
dir.size = 0;
|
||||
dir.time_creation = 0;
|
||||
@@ -166,12 +167,12 @@ bool vfs::CCreateUncompressed7zLibrary::AddFile(vfs::tReadableFile* pFile)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteLibrary(vfs::Path const& sLibName)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeLibrary(vfs::Path const& sLibName)
|
||||
{
|
||||
vfs::COpenWriteFile outfile(sLibName,true);
|
||||
return WriteLibrary(&outfile.file());
|
||||
return writeLibrary(&outfile.file());
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteLibrary(vfs::tWriteableFile* pFile)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeLibrary(vfs::tWritableFile* pFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
@@ -182,32 +183,30 @@ bool vfs::CCreateUncompressed7zLibrary::WriteLibrary(vfs::tWriteableFile* pFile)
|
||||
return false;
|
||||
}
|
||||
m_pLibFile = pFile;
|
||||
if(!m_pLibFile->IsOpenWrite() && !m_pLibFile->OpenWrite(true,true))
|
||||
if(!m_pLibFile->isOpenWrite() && !m_pLibFile->openWrite(true,true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//
|
||||
WriteNextHeader(m_ssInfoStream);
|
||||
writeNextHeader(m_ssInfoStream);
|
||||
//
|
||||
std::stringstream ssSigHeader;
|
||||
WriteSignatureHeader(ssSigHeader);
|
||||
writeSignatureHeader(ssSigHeader);
|
||||
//
|
||||
UInt32 written;
|
||||
m_pLibFile->write(ssSigHeader.str().c_str() , (vfs::size_t)ssSigHeader.str().length());
|
||||
//
|
||||
m_pLibFile->Write(ssSigHeader.str().c_str(),ssSigHeader.str().length(), written);
|
||||
m_pLibFile->write(m_ssFileStream.str().c_str() , (vfs::size_t)m_ssFileStream.str().length());
|
||||
//
|
||||
m_pLibFile->Write(m_ssFileStream.str().c_str(),m_ssFileStream.str().length(), written);
|
||||
//
|
||||
m_pLibFile->Write(m_ssInfoStream.str().c_str(),m_ssInfoStream.str().length(), written);
|
||||
m_pLibFile->write(m_ssInfoStream.str().c_str() , (vfs::size_t)m_ssInfoStream.str().length());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteSignatureHeader(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeSignatureHeader(std::ostream& out)
|
||||
{
|
||||
vfs::UInt32 count=0;
|
||||
::size_t count=0;
|
||||
|
||||
// #define k7zSignatureSize -> not in namespace sz
|
||||
count += szExt::WRITEBUFFER(out, sz::k7zSignature, k7zSignatureSize);
|
||||
@@ -221,7 +220,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteSignatureHeader(std::ostream& out)
|
||||
SFileInfo const& fi = m_lFileInfo.back();
|
||||
sz::UInt64 NextHeaderOffset = fi.offset + fi.size;
|
||||
sz::UInt64 NextHeaderSize = m_ssInfoStream.str().length()*sizeof(char);
|
||||
NextHeaderCRC = sz::CrcCalc(m_ssInfoStream.str().c_str(),(size_t)NextHeaderSize);
|
||||
NextHeaderCRC = sz::CrcCalc(m_ssInfoStream.str().c_str(),(::size_t)NextHeaderSize);
|
||||
|
||||
std::stringstream sstemp;
|
||||
count += szExt::WRITEALL(sstemp, (sz::UInt64)NextHeaderOffset );
|
||||
@@ -234,7 +233,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteSignatureHeader(std::ostream& out)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteNextHeader(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeNextHeader(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdHeader);
|
||||
|
||||
@@ -243,25 +242,25 @@ bool vfs::CCreateUncompressed7zLibrary::WriteNextHeader(std::ostream& out)
|
||||
// this->WriteAdditionalStreamsInfo(out)
|
||||
|
||||
//
|
||||
this->WriteMainStreamsInfo(out);
|
||||
this->writeMainStreamsInfo(out);
|
||||
|
||||
//
|
||||
this->WriteFilesInfo(out);
|
||||
this->writeFilesInfo(out);
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteMainStreamsInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeMainStreamsInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdMainStreamsInfo );
|
||||
|
||||
this->WritePackInfo(out);
|
||||
this->writePackInfo(out);
|
||||
|
||||
this->WriteUnPackInfo(out);
|
||||
this->writeUnPackInfo(out);
|
||||
|
||||
this->WriteSubStreamsInfo(out);
|
||||
this->writeSubStreamsInfo(out);
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
|
||||
@@ -269,7 +268,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteMainStreamsInfo(std::ostream& out)
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WritePackInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writePackInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdPackInfo );
|
||||
szExt::WRITE(out, (sz::UInt64)0 ); // data offset
|
||||
@@ -285,7 +284,7 @@ bool vfs::CCreateUncompressed7zLibrary::WritePackInfo(std::ostream& out)
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEnd );
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteUnPackInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeUnPackInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdUnpackInfo );
|
||||
|
||||
@@ -296,7 +295,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteUnPackInfo(std::ostream& out)
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
this->WriteFolder(out);
|
||||
this->writeFolder(out);
|
||||
}
|
||||
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdCodersUnpackSize );
|
||||
@@ -310,7 +309,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteUnPackInfo(std::ostream& out)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteSubStreamsInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeSubStreamsInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdSubStreamsInfo );
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdCRC );
|
||||
@@ -326,7 +325,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteSubStreamsInfo(std::ostream& out)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteFolder(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeFolder(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::UInt32)1 ); // NumCoders
|
||||
|
||||
@@ -336,7 +335,7 @@ bool vfs::CCreateUncompressed7zLibrary::WriteFolder(std::ostream& out)
|
||||
|
||||
return true;
|
||||
}
|
||||
bool vfs::CCreateUncompressed7zLibrary::WriteFilesInfo(std::ostream& out)
|
||||
bool vfs::CCreateUncompressed7zLibrary::writeFilesInfo(std::ostream& out)
|
||||
{
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdFilesInfo );
|
||||
|
||||
@@ -346,34 +345,34 @@ bool vfs::CCreateUncompressed7zLibrary::WriteFilesInfo(std::ostream& out)
|
||||
// empty stream -> pack info in bit-vector
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdEmptyStream );
|
||||
sz::UInt64 num_empty64 = num_files/8 + (num_files%8 == 0 ? 0 : 1);
|
||||
size_t num_empty = (size_t)num_empty64;
|
||||
::size_t num_empty = (::size_t)num_empty64;
|
||||
THROWIFFALSE(num_empty == num_empty64, L"WTF");
|
||||
|
||||
sz::Byte *empty_vector = new sz::Byte[num_empty];
|
||||
memset(empty_vector,0,num_empty);
|
||||
for(vfs::UInt32 e=m_lFileInfo.size(); e < num_files; ++e)
|
||||
memset(empty_vector,0,(::size_t)num_empty);
|
||||
for(::size_t e=m_lFileInfo.size(); e < num_files; ++e)
|
||||
{
|
||||
size_t index = e / 8;
|
||||
::size_t index = e / 8;
|
||||
empty_vector[index] |= 1 << (7 - e%8);
|
||||
}
|
||||
szExt::WRITE(out, (sz::UInt64)num_empty ); // size
|
||||
szExt::WRITEBUFFER(out, empty_vector, num_empty);
|
||||
szExt::WRITEBUFFER(out, empty_vector, (::size_t)num_empty);
|
||||
delete[] empty_vector;
|
||||
|
||||
// names
|
||||
szExt::WRITE(out, (sz::Byte)sz::k7zIdName );
|
||||
sz::UInt32 count = 0;
|
||||
::size_t count = 0;
|
||||
std::stringstream name_stream;
|
||||
count += szExt::WRITE(name_stream, (sz::Byte)0 ); // switch
|
||||
std::list<SFileInfo>::iterator fit = m_lFileInfo.begin();
|
||||
for(;fit != m_lFileInfo.end(); ++fit)
|
||||
{
|
||||
count += this->WriteFileName(name_stream, fit->name);
|
||||
count += (::size_t)this->writeFileName(name_stream, fit->name);
|
||||
}
|
||||
std::map<utf8string::str_t,SFileInfo>::iterator dit = m_mapDirInfo.begin();
|
||||
for(;dit != m_mapDirInfo.end(); ++dit)
|
||||
{
|
||||
count += this->WriteFileName(name_stream, dit->second.name);
|
||||
count += (::size_t)this->writeFileName(name_stream, dit->second.name);
|
||||
}
|
||||
szExt::WRITE(out, (sz::UInt64)count ); // size
|
||||
szExt::WRITEBUFFER(out, name_stream.str().c_str(), name_stream.str().length() );
|
||||
@@ -390,13 +389,13 @@ bool vfs::CCreateUncompressed7zLibrary::WriteFilesInfo(std::ostream& out)
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::UInt32 vfs::CCreateUncompressed7zLibrary::WriteFileName(std::ostream& out, utf8string const& filename)
|
||||
vfs::size_t vfs::CCreateUncompressed7zLibrary::writeFileName(std::ostream& out, utf8string const& filename)
|
||||
{
|
||||
vfs::UInt32 count = 0;
|
||||
::size_t count = 0;
|
||||
THROWIFFALSE(filename.length(), L"zero length name");
|
||||
count += szExt::WRITEBUFFER(out, &filename.c_wcs().at(0), filename.length());
|
||||
count += szExt::WRITEBUFFER(out, filename.c_str(), filename.length());
|
||||
count += szExt::WRITE(out, (sz::Byte)0);
|
||||
count += szExt::WRITE(out, (sz::Byte)0);
|
||||
return count;
|
||||
return (vfs::size_t)count;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _VFS_CREATE_7Z_LIBRARY_H_
|
||||
#define _VFS_CREATE_7Z_LIBRARY_H_
|
||||
|
||||
//#include "Interface/vfs_library_interface.h"
|
||||
//#include "Interface/vfs_directory_interface.h"
|
||||
#include "../Interface/vfs_file_interface.h"
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
@@ -10,30 +8,30 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CCreateUncompressed7zLibrary
|
||||
class VFS_API CCreateUncompressed7zLibrary
|
||||
{
|
||||
public:
|
||||
CCreateUncompressed7zLibrary();
|
||||
virtual ~CCreateUncompressed7zLibrary();
|
||||
|
||||
bool AddFile(vfs::tReadableFile* pFile);
|
||||
bool addFile(vfs::tReadableFile* pFile);
|
||||
|
||||
bool WriteLibrary(vfs::Path const& sLibName);
|
||||
bool WriteLibrary(vfs::tWriteableFile* pFile);
|
||||
bool writeLibrary(vfs::Path const& sLibName);
|
||||
bool writeLibrary(vfs::tWritableFile* pFile);
|
||||
protected:
|
||||
bool WriteSignatureHeader(std::ostream& out);
|
||||
bool WriteNextHeader(std::ostream& out);
|
||||
bool WriteMainStreamsInfo(std::ostream &out);
|
||||
bool WritePackInfo(std::ostream& out);
|
||||
bool WriteUnPackInfo(std::ostream& out);
|
||||
bool WriteSubStreamsInfo(std::ostream& out);
|
||||
bool WriteFolder(std::ostream& out);
|
||||
bool WriteFilesInfo(std::ostream& out);
|
||||
bool writeSignatureHeader(std::ostream& out);
|
||||
bool writeNextHeader(std::ostream& out);
|
||||
bool writeMainStreamsInfo(std::ostream &out);
|
||||
bool writePackInfo(std::ostream& out);
|
||||
bool writeUnPackInfo(std::ostream& out);
|
||||
bool writeSubStreamsInfo(std::ostream& out);
|
||||
bool writeFolder(std::ostream& out);
|
||||
bool writeFilesInfo(std::ostream& out);
|
||||
private:
|
||||
unsigned int WriteFileName(std::ostream& out, utf8string const& filename);
|
||||
vfs::size_t writeFileName(std::ostream& out, utf8string const& filename);
|
||||
|
||||
protected:
|
||||
vfs::tWriteableFile* m_pLibFile;
|
||||
vfs::tWritableFile* m_pLibFile;
|
||||
|
||||
struct SFileInfo
|
||||
{
|
||||
@@ -42,10 +40,10 @@ namespace vfs
|
||||
{};
|
||||
//////
|
||||
utf8string::str_t name;
|
||||
UInt32 CRC;
|
||||
UInt64 offset;
|
||||
UInt64 size;
|
||||
UInt64 time_creation,time_last_access,time_write;
|
||||
vfs::UInt32 CRC;
|
||||
vfs::UInt64 offset;
|
||||
vfs::UInt64 size;
|
||||
vfs::UInt64 time_creation,time_last_access,time_write;
|
||||
};
|
||||
typedef std::map<utf8string::str_t,SFileInfo> tDirInfo;
|
||||
|
||||
|
||||
+420
-328
@@ -1,131 +1,158 @@
|
||||
#include "vfs_directory_tree.h"
|
||||
#include "../File/vfs_dir_file.h"
|
||||
#include "../Interface/vfs_location_aware_file_interface.h"
|
||||
|
||||
#include "../iteratedir.h"
|
||||
#include "../os_functions.h"
|
||||
|
||||
#include <queue>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
const utf8string::str_t CONST_EXT_TXT = L".TXT";
|
||||
const utf8string::str_t CONST_EXT_LOG = L".LOG";
|
||||
const utf8string::str_t CONST_EXT_INI = L".INI";
|
||||
#define ERROR_FILE(msg) BuildString().add((msg)).add(L" : ").add(pFile->getPath()).get()
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CSubDir : public vfs::IDirectory<vfs::CDirectoryTree::tWriteType>
|
||||
template<typename WriteType>
|
||||
class TSubDir : public vfs::TDirectory<typename vfs::TDirectoryTree<WriteType>::tWriteType>
|
||||
{
|
||||
typedef vfs::TDirectory<typename vfs::TDirectoryTree<WriteType>::tWriteType> tBaseClass;
|
||||
typedef typename tBaseClass::tFileType tFileType;
|
||||
|
||||
typedef std::map<vfs::Path, tFileType*, vfs::Path::Less> tFileCatalogue;
|
||||
|
||||
class IterImpl : public tClassType::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
IterImpl(CSubDir& dir);
|
||||
virtual ~IterImpl();
|
||||
virtual tFileType* value();
|
||||
virtual void next();
|
||||
private:
|
||||
CSubDir& _dir;
|
||||
tFileCatalogue::iterator _iter;
|
||||
};
|
||||
public:
|
||||
CSubDir(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: vfs::IDirectory<vfs::CDirectoryTree::tWriteType>(sMountPoint,sRealPath)
|
||||
typedef vfs::IBaseLocation::Iterator Iterator;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
class IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
friend class TSubDir<WriteType>;
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
|
||||
IterImpl(TSubDir<WriteType>* dir): _dir(dir)
|
||||
{
|
||||
THROWIFFALSE(_dir, L"");
|
||||
_iter = _dir->m_mapFiles.begin();
|
||||
}
|
||||
public:
|
||||
IterImpl() : tBaseClass(), _dir(NULL)
|
||||
{};
|
||||
virtual ~IterImpl()
|
||||
{};
|
||||
|
||||
virtual tFileType* value()
|
||||
{
|
||||
if(_iter != _dir->m_mapFiles.end())
|
||||
{
|
||||
return _iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(_iter != _dir->m_mapFiles.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl();
|
||||
iter->_dir = _dir;
|
||||
iter->_iter = _iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
TSubDir<WriteType>* _dir;
|
||||
typename tFileCatalogue::iterator _iter;
|
||||
};
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
TSubDir(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: tBaseClass(sMountPoint,sRealPath)
|
||||
{};
|
||||
virtual ~CSubDir();
|
||||
|
||||
virtual bool FileExists(vfs::Path const& rFileName);
|
||||
virtual vfs::IBaseFile* GetFile(vfs::Path const& rFileName);
|
||||
virtual tFileType* GetFileTyped(vfs::Path const& rFileName);
|
||||
virtual ~TSubDir();
|
||||
|
||||
virtual bool fileExists(vfs::Path const& rFileName);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& rFileName);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& rFileName);
|
||||
|
||||
virtual tFileType* AddFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool AddFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool addFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
|
||||
virtual bool CreateSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool DeleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual bool DeleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
virtual bool createSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool deleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
|
||||
virtual void GetSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
virtual Iterator begin();
|
||||
virtual Iterator begin();
|
||||
private:
|
||||
tFileCatalogue m_mapFiles;
|
||||
};
|
||||
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWriteType>::tFileType* vfs::TSubDir<vfs::IWriteType>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile);
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWritable>::tFileType* vfs::TSubDir<vfs::IWritable>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile);
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteDirectory(vfs::Path const& sDirPath);
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteDirectory(vfs::Path const& sDirPath);
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteFileFromDirectory(vfs::Path const& rFileName);
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteFileFromDirectory(vfs::Path const& rFileName);
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
vfs::CSubDir::IterImpl::IterImpl(CSubDir& dir)
|
||||
: _dir(dir)
|
||||
{
|
||||
_iter = _dir.m_mapFiles.begin();
|
||||
}
|
||||
vfs::CSubDir::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
vfs::CSubDir::tFileType* vfs::CSubDir::IterImpl::value()
|
||||
{
|
||||
if(_iter != _dir.m_mapFiles.end())
|
||||
{
|
||||
return _iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void vfs::CSubDir::IterImpl::next()
|
||||
{
|
||||
if(_iter != _dir.m_mapFiles.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
/********************************************************/
|
||||
|
||||
vfs::CSubDir::~CSubDir()
|
||||
template<typename WriteType>
|
||||
vfs::TSubDir<WriteType>::~TSubDir()
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.begin();
|
||||
typename tFileCatalogue::iterator it = m_mapFiles.begin();
|
||||
for(; it != m_mapFiles.end(); ++it)
|
||||
{
|
||||
if(it->second)
|
||||
{
|
||||
it->second->Close();
|
||||
it->second->close();
|
||||
delete it->second;
|
||||
}
|
||||
}
|
||||
m_mapFiles.clear();
|
||||
}
|
||||
|
||||
bool vfs::CSubDir::FileExists(vfs::Path const& sFileName)
|
||||
template<typename WriteType>
|
||||
bool vfs::TSubDir<WriteType>::fileExists(vfs::Path const& sFileName)
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
typename tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
bool success = (it != m_mapFiles.end()) && (it->second != NULL);
|
||||
return success;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CSubDir::GetFile(vfs::Path const& sFileName)
|
||||
template<typename WriteType>
|
||||
vfs::IBaseFile* vfs::TSubDir<WriteType>::getFile(vfs::Path const& sFileName)
|
||||
{
|
||||
return GetFileTyped(sFileName);
|
||||
return getFileTyped(sFileName);
|
||||
}
|
||||
|
||||
vfs::CSubDir::tFileType* vfs::CSubDir::GetFileTyped(vfs::Path const& sFileName)
|
||||
template<typename WriteType>
|
||||
typename vfs::TSubDir<WriteType>::tFileType* vfs::TSubDir<WriteType>::getFileTyped(vfs::Path const& sFileName)
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
typename tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
if(it != m_mapFiles.end())
|
||||
{
|
||||
CSubDir::tFileType* file = it->second;
|
||||
return file;
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
vfs::CSubDir::tFileType* vfs::CSubDir::AddFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWriteType>::tFileType* vfs::TSubDir<vfs::IWriteType>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
#if 1
|
||||
tFileType* pFile = m_mapFiles[sFilename];
|
||||
#else
|
||||
CSubDir::tFileCatalogue::iterator it;
|
||||
tFileType* pFile = ((it=m_mapFiles.find(sFilename)) != m_mapFiles.end()) ? it->second : NULL;
|
||||
#endif
|
||||
if(pFile)
|
||||
{
|
||||
if(!bDeleteOldFile)
|
||||
@@ -135,47 +162,55 @@ vfs::CSubDir::tFileType* vfs::CSubDir::AddFile(vfs::Path const& sFilename, bool
|
||||
}
|
||||
delete pFile;
|
||||
}
|
||||
utf8string sExtension;
|
||||
sFilename.Extension(sExtension);
|
||||
if(sExtension == CONST_EXT_TXT || sExtension == CONST_EXT_LOG || sExtension == CONST_EXT_INI)
|
||||
{
|
||||
pFile = new vfs::CVFSTextFile(sFilename,this);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = new vfs::CVFSFile(sFilename,this);
|
||||
}
|
||||
#if 1
|
||||
pFile = new vfs::CReadOnlyDirFile(sFilename,this);
|
||||
m_mapFiles[sFilename] = pFile;
|
||||
#else
|
||||
m_mapFiles.insert(std::make_pair(sFilename,pFile));
|
||||
#endif
|
||||
|
||||
return pFile;
|
||||
}
|
||||
|
||||
bool vfs::CSubDir::AddFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
template<>
|
||||
vfs::TSubDir<vfs::IWritable>::tFileType* vfs::TSubDir<vfs::IWritable>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
tFileType* pFile = m_mapFiles[sFilename];
|
||||
if(pFile)
|
||||
{
|
||||
if(!bDeleteOldFile)
|
||||
{
|
||||
// not allowed to replace old file
|
||||
return NULL;
|
||||
}
|
||||
delete pFile;
|
||||
}
|
||||
pFile = new vfs::CDirFile(sFilename,this);
|
||||
m_mapFiles[sFilename] = pFile;
|
||||
|
||||
return pFile;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TSubDir<WriteType>::addFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
{
|
||||
if(!pFile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
tFileType * pOldFile = m_mapFiles[pFile->GetFileName()];
|
||||
tFileType* pOldFile = m_mapFiles[pFile->getName()];
|
||||
if( pOldFile && (pOldFile != pFile) )
|
||||
{
|
||||
if(bDeleteOldFile)
|
||||
{
|
||||
pOldFile->Close();
|
||||
pOldFile->close();
|
||||
delete pOldFile;
|
||||
}
|
||||
}
|
||||
m_mapFiles[pFile->GetFileName()] = pFile;
|
||||
m_mapFiles[pFile->getName()] = pFile;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CSubDir::DeleteDirectory(vfs::Path const& sDirPath)
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
if( !(m_sMountPoint == sDirPath) )
|
||||
if( !(this->m_mountPoint == sDirPath) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -185,12 +220,12 @@ bool vfs::CSubDir::DeleteDirectory(vfs::Path const& sDirPath)
|
||||
tFileType* pFile = it->second;
|
||||
if(pFile)
|
||||
{
|
||||
pFile->Close();
|
||||
if(!pFile->Delete())
|
||||
pFile->close();
|
||||
if(!pFile->deleteFile())
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not delete file \"" << pFile->GetFullPath()() << L"\"";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
wss << L"Could not delete file \"" << pFile->getPath()() << L"\"";
|
||||
THROWEXCEPTION( ERROR_FILE(L"Could not delete file") );
|
||||
}
|
||||
delete pFile;
|
||||
}
|
||||
@@ -199,7 +234,14 @@ bool vfs::CSubDir::DeleteDirectory(vfs::Path const& sDirPath)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CSubDir::DeleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWritable>::deleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.find(rFileName);
|
||||
if( it != m_mapFiles.end() )
|
||||
@@ -207,8 +249,8 @@ bool vfs::CSubDir::DeleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
tFileType* pFile = it->second;
|
||||
if(pFile)
|
||||
{
|
||||
pFile->Close();
|
||||
THROWIFFALSE(pFile->Delete(), L"Could not delete file");
|
||||
pFile->close();
|
||||
THROWIFFALSE(pFile->deleteFile(), ERROR_FILE(L"Could not delete file"));
|
||||
delete pFile;
|
||||
}
|
||||
m_mapFiles.erase(it);
|
||||
@@ -217,252 +259,68 @@ bool vfs::CSubDir::DeleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::CSubDir::CreateSubDirectory(vfs::Path const& sSubDirPath)
|
||||
template<>
|
||||
bool vfs::TSubDir<vfs::IWriteType>::deleteFileFromDirectory(vfs::Path const& rFileName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void vfs::CSubDir::GetSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
template<typename WriteType>
|
||||
bool vfs::TSubDir<WriteType>::createSubDirectory(vfs::Path const& sSubDirPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TSubDir<WriteType>::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CSubDir::Iterator vfs::CSubDir::begin()
|
||||
template<typename WriteType>
|
||||
typename vfs::TSubDir<WriteType>::Iterator vfs::TSubDir<WriteType>::begin()
|
||||
{
|
||||
Iterator it;
|
||||
{
|
||||
it = Iterator(new IterImpl(*this));
|
||||
}
|
||||
return it;
|
||||
return Iterator(new IterImpl(this));
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
vfs::CDirectoryTree::~CDirectoryTree()
|
||||
template<typename WriteType>
|
||||
class vfs::TDirectoryTree<WriteType>::IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
typedef vfs::TDirectoryTree<WriteType> tDirTree;
|
||||
public:
|
||||
IterImpl(tDirTree& tree);
|
||||
virtual ~IterImpl();
|
||||
|
||||
virtual typename tDirTree::tFileType* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
delete it->second;
|
||||
it->second = NULL;
|
||||
IterImpl* iter = new IterImpl(_tree);
|
||||
iter->_subdir_iter = _subdir_iter;
|
||||
iter->_file_iter = _file_iter;
|
||||
return iter;
|
||||
}
|
||||
m_catDirs.clear();
|
||||
}
|
||||
private:
|
||||
void operator=(typename vfs::TDirectoryTree<WriteType>::IterImpl const& tree);
|
||||
tDirTree& _tree;
|
||||
typename tDirTree::tDirCatalogue::iterator _subdir_iter;
|
||||
typename tDirTree::tLocationType::Iterator _file_iter;
|
||||
};
|
||||
|
||||
|
||||
bool vfs::CDirectoryTree::Init()
|
||||
{
|
||||
// contains local path
|
||||
typedef std::pair<vfs::Path,CSubDir*> tDirs;
|
||||
std::queue<tDirs> qSubDirs;
|
||||
qSubDirs.push(tDirs(vfs::Path(vfs::Const::EMPTY()),new CSubDir(m_sMountPoint,m_sRealPath)));
|
||||
|
||||
m_catDirs[m_sMountPoint] = qSubDirs.front().second;
|
||||
|
||||
utf8string sFilename;
|
||||
CSubDir *pCurrentDir;
|
||||
vfs::Path oCurDir;
|
||||
while(!qSubDirs.empty())
|
||||
{
|
||||
pCurrentDir = qSubDirs.front().second;
|
||||
oCurDir = m_sRealPath;
|
||||
if( !qSubDirs.front().first.empty())
|
||||
{
|
||||
oCurDir += qSubDirs.front().first;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
os::CIterateDirectory::EFileAttribute eFA;
|
||||
os::CIterateDirectory iterFS(oCurDir, vfs::Const::STAR());
|
||||
while ( iterFS.NextFile(sFilename, eFA) )
|
||||
{
|
||||
if (StrCmp::Equal(vfs::Const::DOT(),sFilename) || StrCmp::Equal(vfs::Const::DOTDOT(),sFilename) || StrCmp::Equal(vfs::Const::DOTSVN(),sFilename) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (eFA == os::CIterateDirectory::FA_DIRECTORY)
|
||||
{
|
||||
vfs::Path sLocal = qSubDirs.front().first + sFilename;
|
||||
|
||||
vfs::Path temp = m_sMountPoint+sLocal;
|
||||
CSubDir *pNewDir = new CSubDir(sLocal, m_sRealPath+sLocal);
|
||||
qSubDirs.push(tDirs(sLocal,pNewDir));
|
||||
m_catDirs[temp] = pNewDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
pCurrentDir->AddFile(vfs::Path(sFilename));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
// probably directory doesn't exist. abort or continue???
|
||||
// -> abort AND continue
|
||||
LogException(ex);
|
||||
return false;
|
||||
}
|
||||
qSubDirs.pop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::CDirectoryTree::tFileType* vfs::CDirectoryTree::AddFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFilename.SplitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
vfs::Path sTemp,sCreateDir,sLeft,sRight = sDir;
|
||||
while(sRight.SplitFirst(sLeft,sTemp))
|
||||
{
|
||||
sRight = sTemp;
|
||||
sCreateDir += sLeft;
|
||||
CreateSubDirectory(sCreateDir);
|
||||
}
|
||||
it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
vfs::CDirectoryTree::tFileType* file = it->second->AddFile(sFile,bDeleteOldFile);
|
||||
return file;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CDirectoryTree::AddFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
{
|
||||
// no files from outside
|
||||
// these files are not connected with the correct directory object
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CDirectoryTree::DeleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDirPath);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->DeleteDirectory(sDirPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CDirectoryTree::DeleteFileFromDirectory(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFileName.SplitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->DeleteFileFromDirectory(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
*/
|
||||
bool vfs::CDirectoryTree::FileExists(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir, sFile;
|
||||
sFileName.SplitLast(sDir, sFile);
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
bool success = it->second->FileExists(sFile);
|
||||
return success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CDirectoryTree::GetFile(vfs::Path const& sFileName)
|
||||
{
|
||||
return GetFileTyped(sFileName);
|
||||
}
|
||||
|
||||
vfs::CDirectoryTree::tFileType* vfs::CDirectoryTree::GetFileTyped(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir, sFile;
|
||||
sFileName.SplitLast(sDir, sFile);
|
||||
//tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return NULL;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
vfs::CDirectoryTree::tFileType* file = it->second->GetFileTyped(sFile);
|
||||
return file;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CDirectoryTree::CreateSubDirectory(vfs::Path const& sSubDirPath)
|
||||
{
|
||||
if(os::CreateRealDirecory( m_sRealPath + sSubDirPath ))
|
||||
{
|
||||
if( m_catDirs[sSubDirPath] == NULL)
|
||||
{
|
||||
CSubDir *pNewDir = new CSubDir(sSubDirPath, m_sRealPath + sSubDirPath);
|
||||
m_catDirs[sSubDirPath] = pNewDir;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void vfs::CDirectoryTree::GetSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
{
|
||||
rlSubDirs.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CDirectoryTree::Iterator vfs::CDirectoryTree::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(*this));
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
vfs::CDirectoryTree::IterImpl::IterImpl(CDirectoryTree& tree)
|
||||
: _tree(tree)
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::IterImpl::IterImpl(vfs::TDirectoryTree<WriteType>& tree)
|
||||
: tBaseClass(), _tree(tree)
|
||||
{
|
||||
_subdir_iter = _tree.m_catDirs.begin();
|
||||
if(_subdir_iter != _tree.m_catDirs.end())
|
||||
{
|
||||
CSubDir *sdir = dynamic_cast<CSubDir*>(_subdir_iter->second);
|
||||
CSubDir::Iterator it = sdir->begin();
|
||||
TSubDir<WriteType> *sdir = dynamic_cast<TSubDir<WriteType>*>(_subdir_iter->second);
|
||||
typename TSubDir<WriteType>::Iterator it = sdir->begin();
|
||||
_file_iter = it;
|
||||
if(_file_iter.end())
|
||||
{
|
||||
@@ -471,20 +329,23 @@ vfs::CDirectoryTree::IterImpl::IterImpl(CDirectoryTree& tree)
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CDirectoryTree::IterImpl::~IterImpl()
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CDirectoryTree::tFileType* vfs::CDirectoryTree::IterImpl::value()
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::tFileType* vfs::TDirectoryTree<WriteType>::IterImpl::value()
|
||||
{
|
||||
if(!_file_iter.end())
|
||||
{
|
||||
return static_cast<tFileType*>(_file_iter.value());
|
||||
return static_cast<vfs::TDirectoryTree<WriteType>::tFileType*>(_file_iter.value());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CDirectoryTree::IterImpl::next()
|
||||
template<typename WriteType>
|
||||
void vfs::TDirectoryTree<WriteType>::IterImpl::next()
|
||||
{
|
||||
if(!_file_iter.end())
|
||||
{
|
||||
@@ -509,5 +370,236 @@ void vfs::CDirectoryTree::IterImpl::next()
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::TDirectoryTree(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: tBaseClass(sMountPoint,sRealPath)
|
||||
{};
|
||||
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::TDirectoryTree<WriteType>::~TDirectoryTree()
|
||||
{
|
||||
typename tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
it->second = NULL;
|
||||
}
|
||||
m_catDirs.clear();
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::init()
|
||||
{
|
||||
// contains local path
|
||||
typedef vfs::TSubDir<WriteType> tSubDir;
|
||||
typedef std::pair<vfs::Path,tSubDir*> tDirs;
|
||||
std::queue<tDirs> qSubDirs;
|
||||
qSubDirs.push(tDirs(vfs::Path(vfs::Const::EMPTY()),new tSubDir(this->m_mountPoint, this->m_realPath)));
|
||||
|
||||
m_catDirs[this->m_mountPoint] = qSubDirs.front().second;
|
||||
|
||||
utf8string sFilename;
|
||||
tSubDir *pCurrentDir;
|
||||
vfs::Path oCurDir;
|
||||
while(!qSubDirs.empty())
|
||||
{
|
||||
pCurrentDir = qSubDirs.front().second;
|
||||
oCurDir = this->m_realPath;
|
||||
if( !qSubDirs.front().first.empty())
|
||||
{
|
||||
oCurDir += qSubDirs.front().first;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
os::CIterateDirectory::EFileAttribute eFA;
|
||||
os::CIterateDirectory iterFS(oCurDir, vfs::Const::STAR());
|
||||
while ( iterFS.nextFile(sFilename, eFA) )
|
||||
{
|
||||
if (StrCmp::Equal(vfs::Const::DOT(),sFilename) || StrCmp::Equal(vfs::Const::DOTDOT(),sFilename) || StrCmp::Equal(vfs::Const::DOTSVN(),sFilename) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (eFA == os::CIterateDirectory::FA_DIRECTORY)
|
||||
{
|
||||
vfs::Path sLocal = qSubDirs.front().first + sFilename;
|
||||
|
||||
vfs::Path temp = this->m_mountPoint+sLocal;
|
||||
tSubDir *pNewDir = new tSubDir(sLocal, this->m_realPath+sLocal);
|
||||
qSubDirs.push(tDirs(sLocal,pNewDir));
|
||||
m_catDirs[temp] = pNewDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
pCurrentDir->addFile(vfs::Path(sFilename));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
// probably directory doesn't exist. abort or continue???
|
||||
// -> abort AND continue
|
||||
logException(ex);
|
||||
return false;
|
||||
}
|
||||
qSubDirs.pop();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::tFileType* vfs::TDirectoryTree<WriteType>::addFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFilename.splitLast(sDir,sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
vfs::Path sTemp,sCreateDir,sLeft,sRight = sDir;
|
||||
while(!sRight.empty())
|
||||
{
|
||||
sRight.splitFirst(sLeft,sTemp);
|
||||
sRight = sTemp;
|
||||
sCreateDir += sLeft;
|
||||
this->createSubDirectory(sCreateDir);
|
||||
}
|
||||
it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->addFile(sFile,bDeleteOldFile);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::addFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
{
|
||||
// no files from outside
|
||||
// these files are not connected with the correct directory object
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::deleteDirectory(vfs::Path const& sDirPath)
|
||||
{
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDirPath);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->deleteDirectory(sDirPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::deleteFileFromDirectory(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFileName.splitLast(sDir,sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->deleteFileFromDirectory(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
*/
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::fileExists(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir, sFile;
|
||||
sFileName.splitLast(sDir, sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return false;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->fileExists(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
vfs::IBaseFile* vfs::TDirectoryTree<WriteType>::getFile(vfs::Path const& sFileName)
|
||||
{
|
||||
return getFileTyped(sFileName);
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::tFileType* vfs::TDirectoryTree<WriteType>::getFileTyped(vfs::Path const& sFileName)
|
||||
{
|
||||
vfs::Path sDir, sFile;
|
||||
sFileName.splitLast(sDir, sFile);
|
||||
typename tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it == m_catDirs.end())
|
||||
{
|
||||
// no such directory
|
||||
return NULL;
|
||||
}
|
||||
if(it->second)
|
||||
{
|
||||
return it->second->getFileTyped(sFile);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
bool vfs::TDirectoryTree<WriteType>::createSubDirectory(vfs::Path const& sSubDirPath)
|
||||
{
|
||||
if(os::createRealDirectory( this->m_realPath + sSubDirPath ))
|
||||
{
|
||||
if( m_catDirs[sSubDirPath] == NULL)
|
||||
{
|
||||
m_catDirs[sSubDirPath] = new vfs::TSubDir<WriteType>(sSubDirPath, this->m_realPath + sSubDirPath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
void vfs::TDirectoryTree<WriteType>::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
typename tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
{
|
||||
rlSubDirs.push_back(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename WriteType>
|
||||
typename vfs::TDirectoryTree<WriteType>::Iterator vfs::TDirectoryTree<WriteType>::begin()
|
||||
{
|
||||
return Iterator(new IterImpl(*this));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
template class vfs::TDirectoryTree<vfs::IWritable>; // explicit template class instantiation
|
||||
template class vfs::TDirectoryTree<vfs::IWriteType>; // explicit template class instantiation
|
||||
|
||||
|
||||
@@ -15,55 +15,48 @@ namespace vfs
|
||||
/**
|
||||
* IDirectory<read,write>
|
||||
*/
|
||||
class CDirectoryTree : public vfs::IDirectory<vfs::IWriteable>
|
||||
template<typename WriteType>
|
||||
class TDirectoryTree : public vfs::TDirectory<WriteType>
|
||||
{
|
||||
typedef std::map<vfs::Path, vfs::IDirectory<CDirectoryTree::tWriteType>*, vfs::Path::Less> tDirCatalogue;
|
||||
typedef std::map<vfs::Path, vfs::TDirectory<typename TDirectoryTree<WriteType>::tWriteType>*, vfs::Path::Less> tDirCatalogue;
|
||||
|
||||
class IterImpl : public tClassType::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
IterImpl(CDirectoryTree& tree);
|
||||
virtual ~IterImpl();
|
||||
virtual tFileType* value();
|
||||
virtual void next();
|
||||
private:
|
||||
CDirectoryTree& _tree;
|
||||
tDirCatalogue::iterator _subdir_iter;
|
||||
tClassType::Iterator _file_iter;
|
||||
};
|
||||
public:
|
||||
CDirectoryTree(vfs::Path const& sMountPoint, vfs::Path const& sRealPath)
|
||||
: vfs::IDirectory<vfs::IWriteable>(sMountPoint,sRealPath)
|
||||
{};
|
||||
virtual ~CDirectoryTree();
|
||||
class IterImpl;
|
||||
public:
|
||||
typedef vfs::TDirectory<WriteType> tBaseClass;
|
||||
typedef typename tBaseClass::tWriteType tWriteType;
|
||||
typedef typename tBaseClass::tFileType tFileType;
|
||||
|
||||
bool Init();
|
||||
typedef TIterator<vfs::IBaseFile> Iterator;
|
||||
TDirectoryTree(vfs::Path const& sMountPoint, vfs::Path const& sRealPath);
|
||||
virtual ~TDirectoryTree();
|
||||
|
||||
bool init();
|
||||
|
||||
/**
|
||||
* IDirectory interface
|
||||
* TDirectory interface
|
||||
*/
|
||||
virtual tFileType* AddFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool AddFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
virtual tFileType* addFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool addFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
|
||||
virtual bool CreateSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool DeleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual bool DeleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
virtual bool createSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool deleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
* TVFSLocation interface
|
||||
*/
|
||||
virtual bool FileExists(vfs::Path const& sFileName);
|
||||
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName);
|
||||
virtual tFileType* GetFileTyped(vfs::Path const& sFileName);
|
||||
virtual void GetSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
virtual bool fileExists(vfs::Path const& sFileName);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& sFileName);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& sFileName);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
virtual Iterator begin();
|
||||
protected:
|
||||
tDirCatalogue m_catDirs;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef TDirectoryTree<vfs::IWritable> CDirectoryTree;
|
||||
typedef TDirectoryTree<vfs::IWriteType> CReadOnlyDirectoryTree;
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
||||
+117
-90
@@ -1,104 +1,172 @@
|
||||
#include "vfs_lib_dir.h"
|
||||
#include "../Tools/Log.h"
|
||||
|
||||
class vfs::CLibDirectory::IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
public:
|
||||
IterImpl(CLibDirectory& lib);
|
||||
virtual ~IterImpl();
|
||||
virtual vfs::CLibDirectory::tFileType* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone();
|
||||
private:
|
||||
void operator=(vfs::CLibDirectory::IterImpl const& iter);
|
||||
|
||||
vfs::CLibDirectory& _lib;
|
||||
vfs::CLibDirectory::tFileCatalogue::iterator _iter;
|
||||
};
|
||||
|
||||
vfs::CLibDirectory::IterImpl::IterImpl(CLibDirectory& lib)
|
||||
: tBaseClass(), _lib(lib)
|
||||
{
|
||||
_iter = _lib.m_files.begin();
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::IterImpl::value()
|
||||
{
|
||||
if(_iter != _lib.m_files.end())
|
||||
{
|
||||
return _iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CLibDirectory::IterImpl::next()
|
||||
{
|
||||
if(_iter != _lib.m_files.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::IterImpl::tBaseClass* vfs::CLibDirectory::IterImpl::clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl(_lib);
|
||||
iter->_iter = _iter;
|
||||
return iter;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
vfs::CLibDirectory::CLibDirectory(vfs::Path const& sLocalPath, vfs::Path const& sRealPath)
|
||||
: tBaseClass(sLocalPath,sRealPath)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::~CLibDirectory()
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.begin();
|
||||
for(; it != m_mapFiles.end(); ++it)
|
||||
tFileCatalogue::iterator it = m_files.begin();
|
||||
for(; it != m_files.end(); ++it)
|
||||
{
|
||||
// don't delete objects here
|
||||
//delete it->second;
|
||||
}
|
||||
m_mapFiles.clear();
|
||||
m_files.clear();
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::AddFile(vfs::Path const& sFilename, bool bDeleteOldFile)
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::addFile(vfs::Path const& filename, bool deleteOldFile)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::AddFile(tFileType* pFile, bool bDeleteOldFile)
|
||||
bool vfs::CLibDirectory::addFile(tFileType* file, bool deleteOldFile)
|
||||
{
|
||||
if(!pFile)
|
||||
if(!file)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::Path const& sName = pFile->GetFileName();
|
||||
tFileType* pFileOld = m_mapFiles[sName];
|
||||
if(pFileOld && (pFileOld != pFile) )
|
||||
vfs::Path const& name = file->getName();
|
||||
tFileType* oldFile = m_files[name];
|
||||
if(oldFile && (oldFile != file) )
|
||||
{
|
||||
if(bDeleteOldFile)
|
||||
if(deleteOldFile)
|
||||
{
|
||||
delete pFileOld;
|
||||
m_mapFiles[sName] = pFile;
|
||||
delete oldFile;
|
||||
m_files[name] = file;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_mapFiles[sName] = pFile;
|
||||
m_files[name] = file;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::DeleteDirectory(vfs::Path const& sDirPath)
|
||||
bool vfs::CLibDirectory::deleteDirectory(vfs::Path const& dirPath)
|
||||
{
|
||||
if( !(m_sMountPoint == sDirPath) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(IsWriteable())
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.begin();
|
||||
for(; it != m_mapFiles.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_mapFiles.clear();
|
||||
return true;
|
||||
}
|
||||
//if( !(m_mountPoint == dirPath) )
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
//if(implementsWritable())
|
||||
//{
|
||||
// tFileCatalogue::iterator it = m_files.begin();
|
||||
// for(; it != m_files.end(); ++it)
|
||||
// {
|
||||
// //delete it->second;
|
||||
// }
|
||||
// m_files.clear();
|
||||
// return true;
|
||||
//}
|
||||
CLog log(L"errors.log");
|
||||
log << "called 'vfs::CLibDirectory::deleteDirectory' which doesn't implement the IWritable interface" << CLog::ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::DeleteFileFromDirectory(vfs::Path const& sFileName)
|
||||
bool vfs::CLibDirectory::deleteFileFromDirectory(vfs::Path const& filename)
|
||||
{
|
||||
if(IsWriteable())
|
||||
{
|
||||
tFileCatalogue::iterator it = m_mapFiles.find(sFileName);
|
||||
if(it != m_mapFiles.end())
|
||||
{
|
||||
delete it->second;
|
||||
m_mapFiles.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//if(implementsWritable())
|
||||
//{
|
||||
// tFileCatalogue::iterator it = m_files.find(filename);
|
||||
// if(it != m_files.end())
|
||||
// {
|
||||
// delete it->second;
|
||||
// m_files.erase(it);
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
CLog log(L"errors.log");
|
||||
log << "called 'vfs::CLibDirectory::deleteFileFromDirectory' which doesn't implement the IWritable interface" << CLog::ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::FileExists(vfs::Path const& sFileName)
|
||||
bool vfs::CLibDirectory::fileExists(vfs::Path const& filename)
|
||||
{
|
||||
bool success = (m_mapFiles[sFileName] != NULL);
|
||||
return success;
|
||||
return (m_files[filename] != NULL);
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CLibDirectory::GetFile(vfs::Path const& sFileName)
|
||||
vfs::IBaseFile* vfs::CLibDirectory::getFile(vfs::Path const& filename)
|
||||
{
|
||||
return GetFileTyped(sFileName);
|
||||
return getFileTyped(filename);
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::GetFileTyped(vfs::Path const& sFileName)
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::getFileTyped(vfs::Path const& filename)
|
||||
{
|
||||
CLibDirectory::tFileType* file = m_mapFiles[sFileName];
|
||||
return file;
|
||||
tFileCatalogue::iterator it = m_files.find(filename);
|
||||
if(it != m_files.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CLibDirectory::CreateSubDirectory(vfs::Path const& sSubDirPath)
|
||||
bool vfs::CLibDirectory::createSubDirectory(vfs::Path const& subDirPath)
|
||||
{
|
||||
// libraries are readonly
|
||||
return false;
|
||||
}
|
||||
|
||||
void vfs::CLibDirectory::GetSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
void vfs::CLibDirectory::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::Iterator vfs::CLibDirectory::begin()
|
||||
@@ -108,44 +176,3 @@ vfs::CLibDirectory::Iterator vfs::CLibDirectory::begin()
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
vfs::CLibDirectory::IterImpl::IterImpl(CLibDirectory& lib)
|
||||
: _lib(lib)
|
||||
{
|
||||
_iter = _lib.m_mapFiles.begin();
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CLibDirectory::tFileType* vfs::CLibDirectory::IterImpl::value()
|
||||
{
|
||||
if(_iter != _lib.m_mapFiles.end())
|
||||
{
|
||||
return _iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CLibDirectory::IterImpl::next()
|
||||
{
|
||||
if(_iter != _lib.m_mapFiles.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
static void tesst()
|
||||
{
|
||||
vfs::CLibDirectory *dir = new vfs::CLibDirectory(vfs::Path("test"), vfs::Path("test2"));
|
||||
vfs::CLibDirectory::Iterator it = dir->begin();
|
||||
while(!it.end())
|
||||
{
|
||||
vfs::CLibDirectory::tFileType* file = static_cast<vfs::CLibDirectory::tFileType*>(it.value());
|
||||
it.next();
|
||||
}
|
||||
}
|
||||
+16
-27
@@ -6,47 +6,36 @@
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class CLibDirectory : public vfs::IDirectory<vfs::IWriteType>
|
||||
class CLibDirectory : public vfs::TDirectory<vfs::IWriteType>
|
||||
{
|
||||
typedef vfs::TDirectory<vfs::IWriteType> tBaseClass;
|
||||
typedef std::map<vfs::Path, tFileType*, vfs::Path::Less> tFileCatalogue;
|
||||
|
||||
class IterImpl : public tClassType::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
IterImpl(CLibDirectory& lib);
|
||||
virtual ~IterImpl();
|
||||
virtual tFileType* value();
|
||||
virtual void next();
|
||||
private:
|
||||
CLibDirectory& _lib;
|
||||
tFileCatalogue::iterator _iter;
|
||||
};
|
||||
class IterImpl;
|
||||
public:
|
||||
CLibDirectory(vfs::Path const& sLocalPath, vfs::Path const& sRealPath)
|
||||
: vfs::IDirectory<vfs::IWriteType>(sLocalPath,sRealPath)
|
||||
{};
|
||||
CLibDirectory(vfs::Path const& sLocalPath, vfs::Path const& sRealPath);
|
||||
virtual ~CLibDirectory();
|
||||
|
||||
/**
|
||||
* IDirectory interface
|
||||
* TDirectory interface
|
||||
*/
|
||||
virtual tFileType* AddFile(vfs::Path const& sFilename, bool bDeleteOldFile=false);
|
||||
virtual bool AddFile(tFileType* pFile, bool bDeleteOldFile=false);
|
||||
virtual bool DeleteFileFromDirectory(vfs::Path const& sFileName);
|
||||
virtual bool CreateSubDirectory(vfs::Path const& sSubDirPath);
|
||||
virtual bool DeleteDirectory(vfs::Path const& sDirPath);
|
||||
virtual tFileType* addFile(vfs::Path const& filename, bool deleteOldFile=false);
|
||||
virtual bool addFile(tFileType* file, bool deleteOldFile=false);
|
||||
virtual bool deleteFileFromDirectory(vfs::Path const& filename);
|
||||
virtual bool createSubDirectory(vfs::Path const& subDirPath);
|
||||
virtual bool deleteDirectory(vfs::Path const& dirPath);
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
* TVFSLocation interface
|
||||
*/
|
||||
virtual bool FileExists(vfs::Path const& sFileName);
|
||||
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName);
|
||||
virtual tFileType* GetFileTyped(vfs::Path const& sFileName);
|
||||
virtual void GetSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
virtual bool fileExists(vfs::Path const& filename);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& filename);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& filename);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
virtual Iterator begin();
|
||||
protected:
|
||||
tFileCatalogue m_mapFiles;
|
||||
tFileCatalogue m_files;
|
||||
};
|
||||
|
||||
} // -end- namespace
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#include "vfs_slf_library.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
#include "vfs_lib_dir.h"
|
||||
#include "../vfs_config.h"
|
||||
#include "../Interface/vfs_directory_interface.h"
|
||||
#include "../File/vfs_lib_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace slf
|
||||
{
|
||||
@@ -50,35 +54,31 @@ namespace slf
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
vfs::CSLFLibrary::CSLFLibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile)
|
||||
: vfs::CUncompressedLibraryBase(pLibraryFile,sMountPoint,bOwnFile)
|
||||
{};
|
||||
|
||||
vfs::CSLFLibrary::~CSLFLibrary()
|
||||
{
|
||||
}
|
||||
|
||||
bool vfs::CSLFLibrary::Init()
|
||||
bool vfs::CSLFLibrary::init()
|
||||
{
|
||||
if(m_pLibraryFile)
|
||||
if(!m_libraryFile)
|
||||
{
|
||||
if(!m_pLibraryFile->OpenRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile rfile(m_libraryFile);
|
||||
|
||||
slf::LIBHEADER LibFileHeader;
|
||||
UInt32 uiNumBytesRead;
|
||||
if(!m_pLibraryFile->Read((Byte*)&LibFileHeader,sizeof( slf::LIBHEADER ), uiNumBytesRead))
|
||||
{
|
||||
m_pLibraryFile->Close();
|
||||
return false;
|
||||
}
|
||||
if( uiNumBytesRead != sizeof( slf::LIBHEADER ) )
|
||||
{
|
||||
//Error Reading the file database header.
|
||||
m_pLibraryFile->Close();
|
||||
return false;
|
||||
}
|
||||
vfs::size_t bytesRead = m_libraryFile->read((vfs::Byte*)&LibFileHeader, sizeof( slf::LIBHEADER ));
|
||||
THROWIFFALSE(bytesRead == sizeof( slf::LIBHEADER ), L"");
|
||||
|
||||
vfs::Path oLibPath;
|
||||
//if the library has a path
|
||||
if( strlen( LibFileHeader.sPathToLibrary ) != 0 )
|
||||
if( strlen( (char*)LibFileHeader.sPathToLibrary ) != 0 )
|
||||
{
|
||||
oLibPath = vfs::Path( LibFileHeader.sPathToLibrary );
|
||||
}
|
||||
@@ -87,70 +87,66 @@ bool vfs::CSLFLibrary::Init()
|
||||
//else the library name does not contain a path ( most likely either an error or it is the default path )
|
||||
oLibPath = vfs::Path( vfs::Const::EMPTY() );
|
||||
}
|
||||
if(m_sMountPoint.empty())
|
||||
if(m_mountPoint.empty())
|
||||
{
|
||||
m_sMountPoint = oLibPath;
|
||||
m_mountPoint = oLibPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sMountPoint += oLibPath;
|
||||
m_mountPoint += oLibPath;
|
||||
}
|
||||
|
||||
//place the file pointer at the begining of the file headers ( they are at the end of the file )
|
||||
m_pLibraryFile->SetReadLocation(-( LibFileHeader.iEntries * (Int32)sizeof(slf::DIRENTRY) ), vfs::IBaseFile::SD_END);
|
||||
m_libraryFile->setReadPosition(-( LibFileHeader.iEntries * (vfs::Int32)sizeof(slf::DIRENTRY) ), vfs::IBaseFile::SD_END);
|
||||
|
||||
//loop through the library and determine the number of files that are FILE_OK
|
||||
//ie. so we dont load the old or deleted files
|
||||
slf::DIRENTRY DirEntry;
|
||||
vfs::Path oDir, oFile;
|
||||
vfs::Path oDirPath;
|
||||
for(UInt32 uiLoop=0; uiLoop < (UInt32)LibFileHeader.iEntries; uiLoop++ )
|
||||
for(vfs::UInt32 uiLoop=0; uiLoop < (vfs::UInt32)LibFileHeader.iEntries; uiLoop++ )
|
||||
{
|
||||
//read in the file header
|
||||
if(!m_pLibraryFile->Read((Byte*)&DirEntry, sizeof( slf::DIRENTRY ), uiNumBytesRead))
|
||||
{
|
||||
m_pLibraryFile->Close();
|
||||
return false;
|
||||
}
|
||||
bytesRead = m_libraryFile->read((Byte*)&DirEntry, sizeof( slf::DIRENTRY ));
|
||||
THROWIFFALSE(bytesRead == sizeof( slf::DIRENTRY ), L"");
|
||||
|
||||
if( DirEntry.ubState == slf::FILE_OK )
|
||||
{
|
||||
vfs::Path sPath(utf8string::as_utf16(DirEntry.sFileName));
|
||||
sPath.SplitLast(oDir,oFile);
|
||||
oDirPath = m_sMountPoint;
|
||||
sPath.splitLast(oDir,oFile);
|
||||
oDirPath = m_mountPoint;
|
||||
if(!oDir.empty())
|
||||
{
|
||||
oDirPath += oDir;
|
||||
}
|
||||
|
||||
// get or create according directory object
|
||||
vfs::IDirectory<ILibrary::tWriteType>* pLD = NULL;
|
||||
tDirCatalogue::iterator it = m_catDirs.find(oDirPath);
|
||||
if(it != m_catDirs.end())
|
||||
vfs::TDirectory<ILibrary::tWriteType>* pLD = NULL;
|
||||
tDirCatalogue::iterator it = m_dirs.find(oDirPath);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
pLD = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
pLD = new vfs::CLibDirectory(oDirPath,oDirPath);
|
||||
m_catDirs.insert(std::make_pair(oDirPath,pLD));
|
||||
m_dirs.insert(std::make_pair(oDirPath,pLD));
|
||||
}
|
||||
// create file
|
||||
vfs::CLibFile *pFile = vfs::CLibFile::Create(oFile,pLD,this);
|
||||
vfs::CLibFile *pFile = vfs::CLibFile::create(oFile,pLD,this);
|
||||
// add file to directory
|
||||
if(!pLD->AddFile(pFile))
|
||||
{
|
||||
m_pLibraryFile->Close();
|
||||
return false;
|
||||
}
|
||||
THROWIFFALSE(pLD->addFile(pFile), L"");
|
||||
|
||||
// link file data struct to file object
|
||||
m_mapLibData.insert(std::make_pair(pFile,sFileData(DirEntry.uiLength, DirEntry.uiOffset)));
|
||||
m_fileData.insert(std::make_pair(pFile, SFileData(DirEntry.uiLength, DirEntry.uiOffset)));
|
||||
} // end if
|
||||
} // end for
|
||||
m_pLibraryFile->Close();
|
||||
return true;
|
||||
} // end if
|
||||
// no library file
|
||||
return false;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
logException(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
#ifndef _VFS_SLF_LIBRARY_H_
|
||||
#define _VFS_SLF_LIBRARY_H_
|
||||
|
||||
//#include "Interface/vfs_library_interface.h"
|
||||
//#include "Interface/vfs_directory_interface.h"
|
||||
#include "vfs_uncompressed_lib_base.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CSLFLibrary : public vfs::CUncompressedLibraryBase
|
||||
class VFS_API CSLFLibrary : public vfs::CUncompressedLibraryBase
|
||||
{
|
||||
public:
|
||||
CSLFLibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false)
|
||||
: vfs::CUncompressedLibraryBase(pLibraryFile,sMountPoint,bOwnFile)
|
||||
{};
|
||||
CSLFLibrary(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false);
|
||||
virtual ~CSLFLibrary();
|
||||
|
||||
/**
|
||||
* ILibrary interface
|
||||
*/
|
||||
virtual bool Init();
|
||||
virtual bool init();
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
@@ -1,100 +1,167 @@
|
||||
#include "vfs_uncompressed_lib_base.h"
|
||||
|
||||
/********************************************************************************************/
|
||||
vfs::CUncompressedLibraryBase::SFileData& vfs::CUncompressedLibraryBase::_fileDataFromHandle(tFileType* handle)
|
||||
{
|
||||
tFileData::iterator it = m_fileData.find(handle);
|
||||
if(it != m_fileData.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
THROWEXCEPTION(L"Invalid file handle");
|
||||
}
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
class vfs::CUncompressedLibraryBase::IterImpl : public vfs::IBaseLocation::Iterator::IImplementation
|
||||
{
|
||||
typedef vfs::IBaseLocation::Iterator::IImplementation tBaseClass;
|
||||
public:
|
||||
IterImpl(CUncompressedLibraryBase& lib);
|
||||
virtual ~IterImpl();
|
||||
virtual tFileType* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl(*_lib);
|
||||
iter->_iter = _iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CUncompressedLibraryBase* _lib;
|
||||
vfs::CUncompressedLibraryBase::tFileData::iterator _iter;
|
||||
};
|
||||
|
||||
|
||||
vfs::CUncompressedLibraryBase::IterImpl::IterImpl(vfs::CUncompressedLibraryBase &lib)
|
||||
: tBaseClass(), _lib(&lib)
|
||||
{
|
||||
_iter = _lib->m_fileData.begin();
|
||||
}
|
||||
vfs::CUncompressedLibraryBase::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::tFileType* vfs::CUncompressedLibraryBase::IterImpl::value()
|
||||
{
|
||||
if(_iter != _lib->m_fileData.end())
|
||||
{
|
||||
return _iter->first;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::IterImpl::next()
|
||||
{
|
||||
if(_iter != _lib->m_fileData.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/************************************************************************/
|
||||
|
||||
vfs::CUncompressedLibraryBase::CUncompressedLibraryBase(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile)
|
||||
: vfs::ILibrary(libraryFile,mountPoint,ownFile), m_numberOfOpenedFiles(0)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::~CUncompressedLibraryBase()
|
||||
{
|
||||
this->CloseLibrary();
|
||||
this->closeLibrary();
|
||||
// delete sub dirs from catalogue
|
||||
tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(; it != m_catDirs.end(); ++it)
|
||||
tDirCatalogue::iterator it = m_dirs.begin();
|
||||
for(; it != m_dirs.end(); ++it)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
// LibData is invalid
|
||||
// just clear it, since the file handles were deleted before
|
||||
m_mapLibData.clear();
|
||||
m_catDirs.clear();
|
||||
m_fileData.clear();
|
||||
m_dirs.clear();
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::CloseLibrary()
|
||||
void vfs::CUncompressedLibraryBase::closeLibrary()
|
||||
{
|
||||
bool success = true;
|
||||
tLibData::iterator it = m_mapLibData.begin();
|
||||
for(; it != m_mapLibData .end(); ++it)
|
||||
tFileData::iterator it = m_fileData.begin();
|
||||
for(; it != m_fileData .end(); ++it)
|
||||
{
|
||||
success &= it->first->Close();
|
||||
// what if closing of (at least) one file fails?? continue or not??
|
||||
// in the end, these are not real files!
|
||||
IGNOREEXCEPTION(it->first->close());
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::FileExists(vfs::Path const& sFileName)
|
||||
bool vfs::CUncompressedLibraryBase::fileExists(vfs::Path const& filename)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFileName.SplitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it != m_catDirs.end())
|
||||
filename.splitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_dirs.find(sDir);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
return it->second->FileExists(sFile);
|
||||
return it->second->fileExists(sFile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CUncompressedLibraryBase::GetFile(vfs::Path const& sFileName)
|
||||
vfs::IBaseFile* vfs::CUncompressedLibraryBase::getFile(vfs::Path const& filename)
|
||||
{
|
||||
return GetFileTyped(sFileName);
|
||||
return getFileTyped(filename);
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::tFileType* vfs::CUncompressedLibraryBase::GetFileTyped(vfs::Path const& sFileName)
|
||||
vfs::CUncompressedLibraryBase::tFileType* vfs::CUncompressedLibraryBase::getFileTyped(vfs::Path const& filename)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFileName.SplitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_catDirs.find(sDir);
|
||||
if(it != m_catDirs.end())
|
||||
filename.splitLast(sDir,sFile);
|
||||
tDirCatalogue::iterator it = m_dirs.find(sDir);
|
||||
if(it != m_dirs.end())
|
||||
{
|
||||
return it->second->GetFileTyped(sFile);
|
||||
return it->second->getFileTyped(sFile);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::Close(tFileType *pFileHandle)
|
||||
void vfs::CUncompressedLibraryBase::close(tFileType *fileHandle)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
try
|
||||
{
|
||||
// wrong file handle
|
||||
return false;
|
||||
}
|
||||
// reset read position
|
||||
// can't do this when opening file,
|
||||
// because you could try to open a file when it is already open and would so reset the read position
|
||||
it->second.uiCurrentReadPosition = 0;
|
||||
if(m_uiNumberOfOpenedFiles > 0)
|
||||
{
|
||||
m_uiNumberOfOpenedFiles--;
|
||||
if(m_uiNumberOfOpenedFiles == 0)
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
|
||||
// reset read position
|
||||
// can't do this when opening file,
|
||||
// because you could try to open a file when it is already open and would so reset the read position
|
||||
file._currentReadPosition = 0;
|
||||
if(m_numberOfOpenedFiles > 0)
|
||||
{
|
||||
m_pLibraryFile->Close();
|
||||
m_numberOfOpenedFiles--;
|
||||
if(m_numberOfOpenedFiles == 0)
|
||||
{
|
||||
m_libraryFile->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool vfs::CUncompressedLibraryBase::OpenRead(tFileType *pFileHandle)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
// wrong file handle
|
||||
return false;
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
m_uiNumberOfOpenedFiles++;
|
||||
if(m_uiNumberOfOpenedFiles == 1)
|
||||
}
|
||||
bool vfs::CUncompressedLibraryBase::openRead(tFileType *fileHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!m_pLibraryFile->IsOpenRead() && !m_pLibraryFile->OpenRead())
|
||||
_fileDataFromHandle(fileHandle);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
|
||||
m_numberOfOpenedFiles++;
|
||||
if(m_numberOfOpenedFiles == 1)
|
||||
{
|
||||
if(!m_libraryFile->isOpenRead() && !m_libraryFile->openRead())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -103,127 +170,116 @@ bool vfs::CUncompressedLibraryBase::OpenRead(tFileType *pFileHandle)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::Read(tFileType *pFileHandle, Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead)
|
||||
vfs::size_t vfs::CUncompressedLibraryBase::read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
try
|
||||
{
|
||||
// wrong file handle
|
||||
return false;
|
||||
}
|
||||
// if(m_pLibraryFile->IsOpen()) ... we could check it (*AGAIN*),
|
||||
// but the file implementation does it already,
|
||||
// and the user probably called 'OpenRead' too,
|
||||
// so why do it over and over again
|
||||
if( (it->second.uiCurrentReadPosition + uiBytesToRead) > it->second.uiFileSize )
|
||||
{
|
||||
// original implementation
|
||||
uiBytesRead = 0;
|
||||
return false;
|
||||
// or you could adjust the number of bytes to read
|
||||
uiBytesToRead = it->second.uiFileSize - it->second.uiCurrentReadPosition; // +-1 ???
|
||||
}
|
||||
// set lib-file's read-location to match location of virtual-file
|
||||
m_pLibraryFile->SetReadLocation(it->second.uiFileOffset + it->second.uiCurrentReadPosition,IBaseFile::SD_BEGIN);
|
||||
bool success = m_pLibraryFile->Read(pData,uiBytesToRead,uiBytesRead)
|
||||
&& (uiBytesToRead == uiBytesRead);
|
||||
if(success)
|
||||
{
|
||||
it->second.uiCurrentReadPosition += uiBytesRead;
|
||||
}
|
||||
// false if read operation failed
|
||||
return success;
|
||||
}
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
|
||||
vfs::UInt32 vfs::CUncompressedLibraryBase::GetReadLocation(tFileType *pFileHandle)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
{
|
||||
// wrong file handle
|
||||
return -1;
|
||||
}
|
||||
return it->second.uiCurrentReadPosition;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::SetReadLocation(tFileType *pFileHandle, vfs::UInt32 uiPositionInBytes)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
{
|
||||
// wrong file handle
|
||||
return false;
|
||||
}
|
||||
if( (uiPositionInBytes < 0) || (uiPositionInBytes >= (vfs::Int32)(it->second.uiFileSize)) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// uiCurrentReadPosition is offset to file-offset
|
||||
it->second.uiCurrentReadPosition = uiPositionInBytes;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::SetReadLocation(tFileType *pFileHandle, Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
{
|
||||
// wrong file handle
|
||||
return false;
|
||||
}
|
||||
if( abs(uiOffsetInBytes) > (Int32)(it->second.uiFileSize) )
|
||||
{
|
||||
// cannot be corrent in any case
|
||||
return false;
|
||||
}
|
||||
if(eSeekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
if(uiOffsetInBytes < 0)
|
||||
if( (file._currentReadPosition + bytesToRead) > file._fileSize )
|
||||
{
|
||||
return false;
|
||||
bytesToRead = file._fileSize - file._currentReadPosition;
|
||||
}
|
||||
it->second.uiCurrentReadPosition = uiOffsetInBytes;
|
||||
return true;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
vfs::Int32 temp = it->second.uiCurrentReadPosition + uiOffsetInBytes;
|
||||
if( (temp < 0) || (temp > (Int32)(it->second.uiFileSize)) )
|
||||
if(bytesToRead == 0)
|
||||
{
|
||||
return false;
|
||||
// eof
|
||||
return 0;
|
||||
}
|
||||
it->second.uiCurrentReadPosition = temp;
|
||||
return true;
|
||||
// set lib-file's read-location to match location of lib-file
|
||||
m_libraryFile->setReadPosition(file._fileOffset + file._currentReadPosition, IBaseFile::SD_BEGIN);
|
||||
|
||||
vfs::size_t bytesRead = m_libraryFile->read(data, bytesToRead);
|
||||
THROWIFFALSE( bytesToRead == bytesRead, L"Number of bytes doesn't match" );
|
||||
file._currentReadPosition += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
else if(eSeekDir == IBaseFile::SD_END)
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
if(uiOffsetInBytes > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
it->second.uiCurrentReadPosition = it->second.uiFileSize - uiOffsetInBytes;
|
||||
return true;
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CUncompressedLibraryBase::GetFileSize(tFileType *pFileHandle, UInt32& uiFileSize)
|
||||
vfs::size_t vfs::CUncompressedLibraryBase::getReadPosition(tFileType *fileHandle)
|
||||
{
|
||||
tLibData::iterator it = m_mapLibData.find(pFileHandle);
|
||||
if(it == m_mapLibData.end())
|
||||
try
|
||||
{
|
||||
// wrong file handle
|
||||
uiFileSize = 0;
|
||||
return false;
|
||||
return _fileDataFromHandle(fileHandle)._currentReadPosition;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
uiFileSize = it->second.uiFileSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::GetSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
void vfs::CUncompressedLibraryBase::setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes)
|
||||
{
|
||||
tDirCatalogue::iterator it = m_catDirs.begin();
|
||||
for(;it != m_catDirs.end(); ++it)
|
||||
try
|
||||
{
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
THROWIFFALSE( positionInBytes < file._fileSize, L"" );
|
||||
|
||||
// uiCurrentReadPosition is offset to file-offset
|
||||
file._currentReadPosition = positionInBytes;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
SFileData& file = _fileDataFromHandle(fileHandle);
|
||||
|
||||
vfs::size_t pos = (vfs::size_t) (offsetInBytes < 0 ? -offsetInBytes : offsetInBytes);
|
||||
THROWIFFALSE( pos < file._fileSize, L"" );
|
||||
|
||||
if(seekDir == IBaseFile::SD_BEGIN)
|
||||
{
|
||||
THROWIFFALSE(offsetInBytes >= 0, L"");
|
||||
file._currentReadPosition = offsetInBytes;
|
||||
}
|
||||
else if(seekDir == IBaseFile::SD_CURRENT)
|
||||
{
|
||||
vfs::offset_t pos = file._currentReadPosition + offsetInBytes;
|
||||
THROWIFFALSE( (pos >= 0) && (pos <= (vfs::offset_t)file._fileSize), L"" );
|
||||
|
||||
file._currentReadPosition = (vfs::size_t) pos;
|
||||
}
|
||||
else if(seekDir == IBaseFile::SD_END)
|
||||
{
|
||||
THROWIFFALSE(offsetInBytes <= 0, L"");
|
||||
file._currentReadPosition = file._fileSize + offsetInBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWEXCEPTION(L"Unknown seek direction");
|
||||
}
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
vfs::size_t vfs::CUncompressedLibraryBase::getSize(tFileType *fileHandle)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _fileDataFromHandle(fileHandle)._fileSize;
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::getSubDirList(std::list<vfs::Path>& rlSubDirs)
|
||||
{
|
||||
tDirCatalogue::iterator it = m_dirs.begin();
|
||||
for(;it != m_dirs.end(); ++it)
|
||||
{
|
||||
rlSubDirs.push_back(it->first);
|
||||
}
|
||||
@@ -234,34 +290,5 @@ vfs::CUncompressedLibraryBase::Iterator vfs::CUncompressedLibraryBase::begin()
|
||||
return Iterator(new IterImpl(*this));
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/************************************************************************/
|
||||
|
||||
vfs::CUncompressedLibraryBase::IterImpl::IterImpl(vfs::CUncompressedLibraryBase &lib)
|
||||
: _lib(&lib)
|
||||
{
|
||||
_iter = _lib->m_mapLibData.begin();
|
||||
}
|
||||
vfs::CUncompressedLibraryBase::IterImpl::~IterImpl()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CUncompressedLibraryBase::tFileType* vfs::CUncompressedLibraryBase::IterImpl::value()
|
||||
{
|
||||
if(_iter != _lib->m_mapLibData.end())
|
||||
{
|
||||
return _iter->first;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CUncompressedLibraryBase::IterImpl::next()
|
||||
{
|
||||
if(_iter != _lib->m_mapLibData.end())
|
||||
{
|
||||
_iter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,65 +8,55 @@
|
||||
namespace vfs
|
||||
{
|
||||
|
||||
class CUncompressedLibraryBase : public vfs::ILibrary
|
||||
class VFS_API CUncompressedLibraryBase : public vfs::ILibrary
|
||||
{
|
||||
protected:
|
||||
typedef std::map<vfs::Path, vfs::IDirectory<ILibrary::tWriteType>*, vfs::Path::Less> tDirCatalogue;
|
||||
struct sFileData
|
||||
typedef std::map<vfs::Path, vfs::TDirectory<vfs::ILibrary::tWriteType>*, vfs::Path::Less> tDirCatalogue;
|
||||
struct SFileData
|
||||
{
|
||||
sFileData(UInt32 const& fileSize, UInt32 const& fileOffset)
|
||||
: uiFileSize(fileSize), uiFileOffset(fileOffset), uiCurrentReadPosition(0)
|
||||
SFileData(vfs::size_t const& fileSize, vfs::size_t const& fileOffset)
|
||||
: _fileSize(fileSize), _fileOffset(fileOffset), _currentReadPosition(0)
|
||||
{};
|
||||
UInt32 uiFileSize,uiFileOffset,uiCurrentReadPosition;
|
||||
vfs::size_t _fileSize, _fileOffset, _currentReadPosition;
|
||||
};
|
||||
typedef std::map<tFileType*, sFileData> tLibData;
|
||||
typedef std::map<tFileType*, SFileData> tFileData;
|
||||
|
||||
class IterImpl : public tClassType::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
IterImpl(CUncompressedLibraryBase& lib);
|
||||
virtual ~IterImpl();
|
||||
virtual tFileType* value();
|
||||
virtual void next();
|
||||
private:
|
||||
CUncompressedLibraryBase* _lib;
|
||||
tLibData::iterator _iter;
|
||||
};
|
||||
class IterImpl;
|
||||
public:
|
||||
CUncompressedLibraryBase(tReadableFile *pLibraryFile, vfs::Path const& sMountPoint, bool bOwnFile = false)
|
||||
: vfs::ILibrary(pLibraryFile,sMountPoint,bOwnFile), m_uiNumberOfOpenedFiles(0)
|
||||
{};
|
||||
CUncompressedLibraryBase(vfs::tReadableFile *libraryFile, vfs::Path const& mountPoint, bool ownFile = false);
|
||||
virtual ~CUncompressedLibraryBase();
|
||||
|
||||
/**
|
||||
* IVFSLocation interface
|
||||
* TVFSLocation interface
|
||||
*/
|
||||
virtual bool FileExists(vfs::Path const& sFileName);
|
||||
virtual vfs::IBaseFile* GetFile(vfs::Path const& sFileName);
|
||||
virtual tFileType* GetFileTyped(vfs::Path const& sFileName);
|
||||
virtual void GetSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
virtual bool fileExists(vfs::Path const& filename);
|
||||
virtual vfs::IBaseFile* getFile(vfs::Path const& filename);
|
||||
virtual tFileType* getFileTyped(vfs::Path const& filename);
|
||||
virtual void getSubDirList(std::list<vfs::Path>& rlSubDirs);
|
||||
|
||||
/**
|
||||
* ILibrary interface
|
||||
*/
|
||||
virtual bool Init() = 0;
|
||||
virtual bool CloseLibrary();
|
||||
virtual bool init() = 0;
|
||||
virtual void closeLibrary();
|
||||
|
||||
virtual bool Close(tFileType *pFileHandle);
|
||||
virtual bool OpenRead(tFileType *pFileHandle);
|
||||
virtual bool Read(tFileType *pFileHandle, Byte* pData, UInt32 uiBytesToRead, UInt32& uiBytesRead);
|
||||
virtual void close(tFileType *fileHandle);
|
||||
virtual bool openRead(tFileType *fileHandle);
|
||||
virtual vfs::size_t read(tFileType *fileHandle, vfs::Byte* data, vfs::size_t bytesToRead);
|
||||
|
||||
virtual UInt32 GetReadLocation(tFileType *pFileHandle);
|
||||
virtual bool SetReadLocation(tFileType *pFileHandle, UInt32 uiPositionInBytes);
|
||||
virtual bool SetReadLocation(tFileType *pFileHandle, Int32 uiOffsetInBytes, IBaseFile::ESeekDir eSeekDir);
|
||||
virtual vfs::size_t getReadPosition(tFileType *fileHandle);
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::size_t positionInBytes);
|
||||
virtual void setReadPosition(tFileType *fileHandle, vfs::offset_t offsetInBytes, IBaseFile::ESeekDir seekDir);
|
||||
|
||||
virtual bool GetFileSize(tFileType *pFileHandle, UInt32& uiFileSize);
|
||||
virtual vfs::size_t getSize(tFileType *fileHandle);
|
||||
|
||||
virtual Iterator begin();
|
||||
virtual Iterator begin();
|
||||
protected:
|
||||
tDirCatalogue m_catDirs;
|
||||
tLibData m_mapLibData;
|
||||
UInt32 m_uiNumberOfOpenedFiles;
|
||||
tDirCatalogue m_dirs;
|
||||
tFileData m_fileData;
|
||||
vfs::UInt32 m_numberOfOpenedFiles;
|
||||
private:
|
||||
SFileData& _fileDataFromHandle(tFileType* handle);
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
|
||||
@@ -11,30 +11,30 @@ CHPTimer::~CHPTimer()
|
||||
{
|
||||
}
|
||||
|
||||
void CHPTimer::StartTimer()
|
||||
void CHPTimer::startTimer()
|
||||
{
|
||||
#ifdef WIN32
|
||||
QueryPerformanceCounter(&tick);
|
||||
#elif LINUX
|
||||
#elif __linux__
|
||||
gettimeofday(&t1,0);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void CHPTimer::StopTimer()
|
||||
void CHPTimer::stopTimer()
|
||||
{
|
||||
#ifdef WIN32
|
||||
QueryPerformanceCounter(&tick2);
|
||||
#elif LINUX
|
||||
#elif __linux__
|
||||
gettimeofday(&t2,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
double CHPTimer::GetElapsedTimeInSeconds()
|
||||
double CHPTimer::getElapsedTimeInSeconds()
|
||||
{
|
||||
#ifdef WIN32
|
||||
return (double)(tick2.QuadPart - tick.QuadPart)/(double)ticksPerSecond.QuadPart;
|
||||
#elif LINUX
|
||||
#elif __linux__
|
||||
return (double)(t2.tv_usec - t1.tv_usec)/1000000.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#elif LINUX
|
||||
#elif __linux__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
@@ -13,15 +13,15 @@ public:
|
||||
CHPTimer();
|
||||
~CHPTimer();
|
||||
|
||||
void StartTimer();
|
||||
void StopTimer();
|
||||
void startTimer();
|
||||
void stopTimer();
|
||||
|
||||
double GetElapsedTimeInSeconds();
|
||||
double getElapsedTimeInSeconds();
|
||||
protected:
|
||||
#ifdef WIN32
|
||||
LARGE_INTEGER ticksPerSecond;
|
||||
LARGE_INTEGER tick,tick2;
|
||||
#elif LINUX
|
||||
#elif __linux__
|
||||
timeval t1,t2;
|
||||
#endif
|
||||
};
|
||||
|
||||
+24
-25
@@ -5,25 +5,20 @@
|
||||
#include "../File/vfs_file.h"
|
||||
#include <sstream>
|
||||
|
||||
CProf* g_Profiler = NULL;
|
||||
|
||||
class CProfileStarter
|
||||
{
|
||||
public:
|
||||
CProfileStarter()
|
||||
{
|
||||
CProf::GetProf();
|
||||
CProf::getProf();
|
||||
}
|
||||
};
|
||||
static CProfileStarter starter;
|
||||
|
||||
CProf* CProf::GetProf()
|
||||
CProf& CProf::getProf()
|
||||
{
|
||||
if(!g_Profiler)
|
||||
{
|
||||
g_Profiler = new CProf();
|
||||
}
|
||||
return g_Profiler;
|
||||
static CProf* _prof = new CProf;
|
||||
return *_prof;
|
||||
}
|
||||
|
||||
CProf::CProf()
|
||||
@@ -32,7 +27,7 @@ CProf::CProf()
|
||||
_nextMarker = 0;
|
||||
}
|
||||
|
||||
void CProf::Clear()
|
||||
void CProf::clear()
|
||||
{
|
||||
for(unsigned int i = 0; i < _nextMarker; ++i)
|
||||
{
|
||||
@@ -46,27 +41,27 @@ void CProf::Clear()
|
||||
}
|
||||
|
||||
|
||||
CProf::tMarkerID CProf::RegisterMarker(const char *marker)
|
||||
CProf::tMarkerID CProf::registerMarker(const char *marker)
|
||||
{
|
||||
m_vMarker[_nextMarker].markername = marker;
|
||||
return _nextMarker++;
|
||||
}
|
||||
|
||||
void CProf::StartMarker(tMarkerID id)
|
||||
void CProf::startMarker(tMarkerID id)
|
||||
{
|
||||
m_vMarker[id].timer.StartTimer();
|
||||
m_vMarker[id].timer.startTimer();
|
||||
}
|
||||
|
||||
void CProf::StopMarker(tMarkerID id, bool success)
|
||||
void CProf::stopMarker(tMarkerID id, bool success)
|
||||
{
|
||||
m_vMarker[id].timer.StopTimer();
|
||||
m_vMarker[id].time += m_vMarker[id].timer.GetElapsedTimeInSeconds();
|
||||
m_vMarker[id].timer.stopTimer();
|
||||
m_vMarker[id].time += m_vMarker[id].timer.getElapsedTimeInSeconds();
|
||||
m_vMarker[id].call_count++;
|
||||
if(success) m_vMarker[id].success_count++;
|
||||
else m_vMarker[id].fail_count++;
|
||||
}
|
||||
|
||||
inline std::string MultChar(std::string::value_type c, unsigned int multiplicity)
|
||||
inline std::string multChar(std::string::value_type c, unsigned int multiplicity)
|
||||
{
|
||||
std::string s;
|
||||
s.resize(multiplicity);
|
||||
@@ -88,16 +83,16 @@ inline long double oneDigit(long double number)
|
||||
return (temp / 10.0);
|
||||
}
|
||||
|
||||
bool CProf::PrintProfilerState(vfs::Path const& file)
|
||||
bool CProf::printProfilerState(vfs::Path const& file)
|
||||
{
|
||||
vfs::CFile oFile(file);
|
||||
if(!oFile.OpenWrite(true,true))
|
||||
if(!oFile.openWrite(true,true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// get largest value
|
||||
long double max_time = 0;
|
||||
unsigned int max_prefix = 0;
|
||||
std::string::size_type max_prefix = 0;
|
||||
for(unsigned int i=0; i<m_vMarker.size(); ++i)
|
||||
{
|
||||
if(m_vMarker[i].time > max_time)
|
||||
@@ -122,7 +117,7 @@ bool CProf::PrintProfilerState(vfs::Path const& file)
|
||||
if(m_vMarker[i].markername.length() < WIDTH)
|
||||
{
|
||||
unsigned int space = WIDTH - m_vMarker[i].markername.length();
|
||||
line << m_vMarker[i].markername << MultChar(' ',space) << " | ";
|
||||
line << m_vMarker[i].markername << multChar(' ',space) << " | ";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -134,15 +129,19 @@ bool CProf::PrintProfilerState(vfs::Path const& file)
|
||||
ld_success = perCent(m_vMarker[i].success_count,m_vMarker[i].call_count);
|
||||
ld_failure = perCent(m_vMarker[i].fail_count,m_vMarker[i].call_count);
|
||||
line << "[" << oneDigit(ld_success) << "|" << oneDigit(ld_failure) << "] "
|
||||
<< MultChar('*', num_stars) << MultChar(' ', WIDTH - num_stars) << " | ";
|
||||
<< multChar('*', num_stars) << multChar(' ', WIDTH - num_stars) << " | ";
|
||||
}
|
||||
line << "C: " << m_vMarker[i].call_count << ", T: " << m_vMarker[i].time << std::endl;
|
||||
//line << std::endl;
|
||||
}
|
||||
vfs::UInt32 written;
|
||||
std::string useless_copy = line.str();
|
||||
oFile.Write(useless_copy.c_str(), useless_copy.length()*sizeof(std::string::value_type),written);
|
||||
oFile.Close();
|
||||
oFile.write(useless_copy.c_str(), (vfs::size_t)(useless_copy.length()*sizeof(std::string::value_type)));
|
||||
oFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DumpProfileState(vfs::Path const& path)
|
||||
{
|
||||
CProf::getProf().printProfilerState(path);
|
||||
}
|
||||
|
||||
|
||||
+35
-13
@@ -3,16 +3,17 @@
|
||||
|
||||
#include "HPTimer.h"
|
||||
#include "../vfs_types.h"
|
||||
#include "../vfs_path.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define DO_PROFILE 1
|
||||
#if DO_PROFILE
|
||||
#define REGISTERMARKER(id,name) static CProf::tMarkerID id = g_Profiler->RegisterMarker(name)
|
||||
#define STARTMARKER(id) (g_Profiler->StartMarker(id))
|
||||
#define STOPMARKER(id,success) (g_Profiler->StopMarker(id,success))
|
||||
#define REGISTERMARKER(id,name) static CProf::tMarkerID id = CProf::getProf().registerMarker(name)
|
||||
#define STARTMARKER(id) (CProf::getProf().startMarker(id))
|
||||
#define STOPMARKER(id,success) (CProf::getProf().stopMarker(id,success))
|
||||
|
||||
#define DUMPPROFILERSTATSTOFILE(file) if(g_Profiler){g_Profiler->PrintProfilerState(file);}
|
||||
#define DUMPPROFILERSTATSTOFILE(file) CProf::getProf().printProfilerState(file)
|
||||
#else
|
||||
#define REGISTERMARKER(id,name)
|
||||
#define STARTMARKER(id)
|
||||
@@ -22,20 +23,20 @@
|
||||
#endif
|
||||
|
||||
|
||||
class CProf
|
||||
class VFS_API CProf
|
||||
{
|
||||
public:
|
||||
typedef unsigned int tMarkerID;
|
||||
static CProf* GetProf();
|
||||
static CProf& getProf();
|
||||
|
||||
void Clear();
|
||||
void clear();
|
||||
|
||||
tMarkerID RegisterMarker(const char *marker);
|
||||
tMarkerID registerMarker(const char *marker);
|
||||
|
||||
void StartMarker(tMarkerID id);
|
||||
void StopMarker(tMarkerID id, bool success);
|
||||
void startMarker(tMarkerID id);
|
||||
void stopMarker(tMarkerID id, bool success);
|
||||
|
||||
bool PrintProfilerState(vfs::Path const& file);
|
||||
bool printProfilerState(vfs::Path const& file);
|
||||
private:
|
||||
CProf();
|
||||
|
||||
@@ -43,16 +44,37 @@ private:
|
||||
{
|
||||
MARKER() : call_count(0), success_count(0), fail_count(0), time(0.0) {};
|
||||
std::string markername;
|
||||
long double time;
|
||||
unsigned long call_count;
|
||||
unsigned long success_count;
|
||||
unsigned long fail_count;
|
||||
long double time;
|
||||
CHPTimer timer;
|
||||
};
|
||||
std::vector<MARKER> m_vMarker;
|
||||
unsigned int _nextMarker;
|
||||
};
|
||||
|
||||
extern CProf* g_Profiler;
|
||||
class ProfileMarker
|
||||
{
|
||||
public:
|
||||
ProfileMarker(CProf::tMarkerID id, bool default_exit=true)
|
||||
: _id(id), _exit_success(default_exit)
|
||||
{
|
||||
STARTMARKER(_id);
|
||||
}
|
||||
~ProfileMarker()
|
||||
{
|
||||
STOPMARKER(_id,_exit_success);
|
||||
}
|
||||
void exit(bool success)
|
||||
{
|
||||
_exit_success = success;
|
||||
}
|
||||
private:
|
||||
CProf::tMarkerID _id;
|
||||
bool _exit_success;
|
||||
};
|
||||
|
||||
VFS_API void DumpProfileState(vfs::Path const& path);
|
||||
|
||||
#endif // _PROF_H_
|
||||
|
||||
+234
-225
@@ -1,10 +1,11 @@
|
||||
#include "vfs_config.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
#include "vfs.h"
|
||||
#include "File/vfs_file.h"
|
||||
#include "File/vfs_memory_file.h"
|
||||
#include "vfs_file_raii.h"
|
||||
#include "iteratedir.h"
|
||||
#include "os_functions.h"
|
||||
|
||||
#include "Tools/Tools.h"
|
||||
#include "Tools/ParserTools.h"
|
||||
@@ -12,9 +13,13 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
bool CPropertyContainer::CSection::has(utf8string const& key)
|
||||
{
|
||||
return mapProps.find(key) != mapProps.end();
|
||||
}
|
||||
|
||||
bool CPropertyContainer::CSection::add(utf8string const& key, utf8string const& value)
|
||||
{
|
||||
@@ -40,7 +45,7 @@ bool CPropertyContainer::CSection::value(utf8string const& key, utf8string& valu
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void CPropertyContainer::CSection::Print(std::ostream& out, utf8string::str_t sPrefix)
|
||||
void CPropertyContainer::CSection::print(std::ostream& out, utf8string::str_t sPrefix)
|
||||
{
|
||||
tProps::iterator sit = mapProps.begin();
|
||||
for(; sit != mapProps.end(); ++sit)
|
||||
@@ -49,184 +54,178 @@ void CPropertyContainer::CSection::Print(std::ostream& out, utf8string::str_t sP
|
||||
}
|
||||
}
|
||||
|
||||
void CPropertyContainer::CSection::Clear()
|
||||
void CPropertyContainer::CSection::clear()
|
||||
{
|
||||
mapProps.clear();
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
void CPropertyContainer::ClearContainer()
|
||||
void CPropertyContainer::clearContainer()
|
||||
{
|
||||
tSections::iterator it = m_mapProps.begin();
|
||||
for(;it != m_mapProps.end(); ++it)
|
||||
{
|
||||
it->second.Clear();
|
||||
it->second.clear();
|
||||
}
|
||||
m_mapProps.clear();
|
||||
}
|
||||
|
||||
bool CPropertyContainer::ExtractSection(utf8string::str_t const& readStr, size_t startPos, utf8string::str_t& sSection)
|
||||
bool CPropertyContainer::extractSection(utf8string::str_t const& readStr, vfs::size_t startPos, utf8string::str_t& sSection)
|
||||
{
|
||||
// extract section name
|
||||
unsigned int close = readStr.find_first_of(L"]",startPos);
|
||||
if( close > 0 && close > startPos)
|
||||
vfs::size_t close = readStr.find_first_of(L"]", startPos);
|
||||
if( close != vfs::npos && close > startPos)
|
||||
{
|
||||
startPos += 1;
|
||||
sSection = vfs::TrimString(readStr,startPos,close-1);
|
||||
sSection = vfs::trimString(readStr,startPos,(vfs::size_t)(close-1));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CPropertyContainer::EOperation CPropertyContainer::ExtractKeyValue(utf8string::str_t const &readStr, size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue)
|
||||
CPropertyContainer::EOperation CPropertyContainer::extractKeyValue(utf8string::str_t const &readStr, vfs::size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue)
|
||||
{
|
||||
vfs::Int32 iEqual = readStr.find_first_of(L"+=",startPos);
|
||||
if(iEqual < 0)
|
||||
vfs::size_t iEqual = readStr.find_first_of(L"+=", startPos);
|
||||
if(iEqual == vfs::npos)
|
||||
{
|
||||
//std::cout << "WARNING : could not extract key-value pair : " << readStr << std::endl;
|
||||
return CPropertyContainer::Error;
|
||||
}
|
||||
// extract key
|
||||
sKey = vfs::TrimString(readStr,0,iEqual-1);
|
||||
sKey = vfs::trimString(readStr,0,iEqual-1);
|
||||
// extract value
|
||||
EOperation op = CPropertyContainer::Set;
|
||||
if( readStr.at(iEqual) == L'+' )
|
||||
{
|
||||
if( (vfs::UInt32)(iEqual+1) < readStr.size() && (readStr.at((vfs::UInt32)(iEqual+1)) == L'=') )
|
||||
if( (iEqual+1) < readStr.size() && (readStr.at(iEqual+1) == L'=') )
|
||||
{
|
||||
iEqual += 1;
|
||||
op = CPropertyContainer::Add;
|
||||
}
|
||||
}
|
||||
sValue = vfs::TrimString(readStr,iEqual+1,readStr.size());
|
||||
sValue = vfs::trimString(readStr,iEqual+1,readStr.size());
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
bool CPropertyContainer::InitFromIniFile(vfs::Path const& sFileName)
|
||||
bool CPropertyContainer::initFromIniFile(vfs::Path const& sFileName)
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
if(GetVFS()->FileExists(sFileName))
|
||||
if(getVFS()->fileExists(sFileName))
|
||||
{
|
||||
return InitFromIniFile(GetVFS()->GetRFile(sFileName));
|
||||
return initFromIniFile(getVFS()->getReadFile(sFileName));
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CTextFile(sFileName);
|
||||
if(pFile)
|
||||
{
|
||||
bool success = InitFromIniFile(vfs::tReadableFile::Cast(pFile));
|
||||
delete pFile;
|
||||
return success;
|
||||
}
|
||||
vfs::CFile file(sFileName);
|
||||
return initFromIniFile(vfs::tReadableFile::cast(&file));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::InitFromIniFile(vfs::tReadableFile *pFile)
|
||||
bool CPropertyContainer::initFromIniFile(vfs::tReadableFile *pFile)
|
||||
{
|
||||
if(pFile && pFile->OpenRead())
|
||||
if(!pFile)
|
||||
{
|
||||
vfs::COpenReadFile rfile(pFile);
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
int line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.GetLine(sBuffer))
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
int line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
// remove leading white spaces
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
if(iStart == std::string::npos)
|
||||
{
|
||||
// remove leading white spaces
|
||||
unsigned int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
if(iStart == std::string::npos)
|
||||
// only white space characters
|
||||
continue;
|
||||
}
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
case '[':
|
||||
{
|
||||
// only white space characters
|
||||
continue;
|
||||
}
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
case '!':
|
||||
case ';':
|
||||
case '#':
|
||||
// comment -> do nothing
|
||||
break;
|
||||
case '[':
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string u8s;
|
||||
try
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
if(this->extractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
m_mapProps[sCurrentSection];
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "WARNING : could not extract section name : " << sBuffer << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// probably key-value pair
|
||||
utf8string::str_t u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s);
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
EOperation op = this->extractKeyValue(u8s, 0, sKey, sValue);
|
||||
if(op != Error)
|
||||
{
|
||||
// add key-value pair to map
|
||||
if(m_mapProps.find(sCurrentSection) != m_mapProps.end())
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
if(this->ExtractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
m_mapProps[sCurrentSection];
|
||||
if(op == Set)
|
||||
{
|
||||
this->section(sCurrentSection).value(sKey) = sValue;
|
||||
}
|
||||
else if(op == Add)
|
||||
{
|
||||
this->section(sCurrentSection).add(sKey, sValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "WARNING : could not extract section name : " << sBuffer << std::endl;
|
||||
//std::cout << "ERROR : could not find section ["<<sCurrentSection << "]in container" << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// probably key-value pair
|
||||
utf8string u8s;
|
||||
try
|
||||
{
|
||||
utf8string::as_utf16(sBuffer.substr(iStart, sBuffer.length()-iStart), u8s.r_wcs());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
EOperation op = this->ExtractKeyValue(u8s.c_wcs(), 0, sKey, sValue);
|
||||
if(op != Error)
|
||||
{
|
||||
// add key-value pair to map
|
||||
if(m_mapProps.find(sCurrentSection) != m_mapProps.end())
|
||||
{
|
||||
if(op == Set)
|
||||
{
|
||||
Section(sCurrentSection).value(sKey) = sValue;
|
||||
}
|
||||
else if(op == Add)
|
||||
{
|
||||
Section(sCurrentSection).add(sKey, sValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "ERROR : could not find section ["<<sCurrentSection << "]in container" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
} // end if (empty)
|
||||
} // end while(!eof)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}; // end switch
|
||||
} // end if (empty)
|
||||
} // end while(!eof)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreateNew)
|
||||
static vfs::UByte utf8bom[3] = {0xef,0xbb,0xbf};
|
||||
|
||||
bool CPropertyContainer::writeToIniFile(vfs::Path const& sFilename, bool bCreateNew)
|
||||
{
|
||||
#ifdef WIN32
|
||||
const char ENDL[] = "\r\n";
|
||||
@@ -235,43 +234,43 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
#endif
|
||||
if(bCreateNew)
|
||||
{
|
||||
vfs::tWriteableFile* file;
|
||||
vfs::tWritableFile* file;
|
||||
bool delete_file = false;
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile wfile(sFileName,true,true);
|
||||
vfs::COpenWriteFile wfile(sFilename,true,true);
|
||||
file = &wfile.file();
|
||||
wfile.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
LogException(ex);
|
||||
logException(ex);
|
||||
// vfs not initialized?
|
||||
vfs::CFile* cfile = new vfs::CFile(sFileName);
|
||||
cfile->OpenWrite(true,true);
|
||||
file = vfs::tWriteableFile::Cast(cfile);
|
||||
vfs::CFile* cfile = new vfs::CFile(sFilename);
|
||||
cfile->openWrite(true,true);
|
||||
file = vfs::tWritableFile::cast(cfile);
|
||||
delete_file = true;
|
||||
}
|
||||
tSections::iterator sit = m_mapProps.begin();
|
||||
std::stringstream ss;
|
||||
std::string str;
|
||||
vfs::UInt32 written;
|
||||
ss << (char*)utf8bom;
|
||||
for(; sit != m_mapProps.end(); ++sit)
|
||||
{
|
||||
ss.str("");
|
||||
ss << "[" << sit->first.utf8() << "]" << ENDL;
|
||||
str = ss.str();
|
||||
file->Write(str.c_str(),str.length(),written);
|
||||
file->write(str.c_str(), str.length());
|
||||
|
||||
ss.clear();
|
||||
ss.str("");
|
||||
CSection& section = sit->second;
|
||||
section.Print(ss);
|
||||
section.print(ss);
|
||||
ss << ENDL;
|
||||
str = ss.str();
|
||||
file->Write(str.c_str(),str.length(),written);
|
||||
file->write(str.c_str(),str.length());
|
||||
}
|
||||
file->Close();
|
||||
file->close();
|
||||
if(delete_file)
|
||||
{
|
||||
delete file;
|
||||
@@ -283,18 +282,18 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
// try to open via VirtualFileSystem
|
||||
vfs::tReadableFile *pFile = NULL;
|
||||
vfs::CMemoryFile rfile;
|
||||
if(GetVFS()->FileExists(sFileName))
|
||||
if(getVFS()->fileExists(sFilename))
|
||||
{
|
||||
pFile = GetVFS()->GetRFile(sFileName);
|
||||
rfile.CopyToBuffer(*pFile);
|
||||
pFile = getVFS()->getReadFile(sFilename);
|
||||
rfile.copyToBuffer(*pFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sFileName);
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sFilename);
|
||||
if(pFile)
|
||||
{
|
||||
rfile.CopyToBuffer(*vfs::tReadableFile::Cast(pFile));
|
||||
rfile.copyToBuffer(*vfs::tReadableFile::cast(pFile));
|
||||
delete pFile;
|
||||
}
|
||||
}
|
||||
@@ -302,7 +301,6 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
|
||||
std::string sBuffer;
|
||||
utf8string::str_t sCurrentSection;
|
||||
vfs::UInt32 written;
|
||||
|
||||
std::set<utf8string> setKeys;
|
||||
std::set<utf8string> setSections;
|
||||
@@ -312,15 +310,16 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
setSections.insert(sit->first);
|
||||
}
|
||||
|
||||
CReadLine rl(*vfs::tReadableFile::Cast(&rfile));
|
||||
CReadLine rl(*vfs::tReadableFile::cast(&rfile));
|
||||
outbuffer << (char*)(utf8bom);
|
||||
vfs::UInt32 line_counter = 0;
|
||||
while(rl.GetLine(sBuffer))
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
@@ -339,12 +338,12 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t oldSection = sCurrentSection;
|
||||
if(this->ExtractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
if(this->extractSection(u8s.c_wcs(), 0, sCurrentSection))
|
||||
{
|
||||
if(setSections.find(sCurrentSection) == setSections.end())
|
||||
{
|
||||
@@ -388,12 +387,12 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Conversion error in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Conversion error in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
utf8string::str_t sKey, sValue;
|
||||
if(this->ExtractKeyValue(u8s.c_wcs(), 0, sKey, sValue))
|
||||
if(this->extractKeyValue(u8s.c_wcs(), 0, sKey, sValue))
|
||||
{
|
||||
if(setKeys.find(sKey) != setKeys.end())
|
||||
{
|
||||
@@ -437,57 +436,67 @@ bool CPropertyContainer::WriteToIniFile(vfs::Path const& sFileName, bool bCreate
|
||||
{
|
||||
outbuffer << ENDL << "[" << utf8string::as_utf8(*it) << "]" << ENDL;
|
||||
std::stringstream ss;
|
||||
m_mapProps[*it].Print(outbuffer);
|
||||
m_mapProps[*it].print(outbuffer);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile wfile(sFileName,true,true);
|
||||
wfile.file().Write(outbuffer.str().c_str(),outbuffer.str().length(),written);
|
||||
vfs::COpenWriteFile wfile(sFilename,true,true);
|
||||
wfile.file().write(outbuffer.str().c_str(),(vfs::size_t)outbuffer.str().length());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
LogException(ex);
|
||||
vfs::CFile file(sFileName);
|
||||
if(file.OpenWrite(true,true))
|
||||
logException(ex);
|
||||
vfs::CFile file(sFilename);
|
||||
if(file.openWrite(true,true))
|
||||
{
|
||||
file.Write(outbuffer.str().c_str(),outbuffer.str().length(),written);
|
||||
file.Close();
|
||||
file.write(outbuffer.str().c_str(),(vfs::size_t)outbuffer.str().length());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CPropertyContainer::PrintProperties()
|
||||
void CPropertyContainer::printProperties()
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.begin();
|
||||
for(;pit != m_mapProps.end(); ++pit)
|
||||
{
|
||||
std::cout << "[" << pit->first.utf8() << "]\n";
|
||||
pit->second.Print(std::cout, L" ");
|
||||
pit->second.print(std::cout, L" ");
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
CPropertyContainer::CSection& CPropertyContainer::Section(utf8string const& sSection)
|
||||
|
||||
CPropertyContainer::CSection& CPropertyContainer::section(utf8string const& sSection)
|
||||
{
|
||||
return m_mapProps[sSection];
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue)
|
||||
bool CPropertyContainer::getValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue)
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.find(vfs::TrimString(sSection,0,sSection.length()));
|
||||
tSections::iterator pit = m_mapProps.find(vfs::trimString(sSection,0,(vfs::size_t)sSection.length()));
|
||||
if( pit != m_mapProps.end() )
|
||||
{
|
||||
return pit->second.value( vfs::TrimString(sKey,0,sKey.length()), sValue );
|
||||
return pit->second.value( vfs::trimString(sKey,0,(vfs::size_t)sKey.length()), sValue );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8string const& CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue)
|
||||
bool CPropertyContainer::hasProperty(utf8string const& sSection, utf8string const& sKey)
|
||||
{
|
||||
tSections::iterator pit = m_mapProps.find(vfs::trimString(sSection,0,(vfs::size_t)sSection.length()));
|
||||
if( pit != m_mapProps.end() )
|
||||
{
|
||||
return pit->second.has(vfs::trimString(sKey,0,sKey.length()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8string const& CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue)
|
||||
{
|
||||
CPropertyContainer::tSections::iterator sit = m_mapProps.find(sSection);
|
||||
if(sit != m_mapProps.end())
|
||||
@@ -501,9 +510,9 @@ utf8string const& CPropertyContainer::GetStringProperty(utf8string const& sSecti
|
||||
return sDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue)
|
||||
bool CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue)
|
||||
{
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -511,34 +520,34 @@ bool CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8strin
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::UInt32 len, utf8string const& sDefaultValue)
|
||||
bool CPropertyContainer::getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::size_t len, utf8string const& sDefaultValue)
|
||||
{
|
||||
utf8string s;
|
||||
if(GetValueForKey(sSection,sKey,s))
|
||||
if(getValueForKey(sSection,sKey,s))
|
||||
{
|
||||
vfs::UInt32 l = std::min<vfs::UInt32>(s.length(), len-1);
|
||||
wcsncpy(sValue,s.c_wcs().c_str(), l);
|
||||
vfs::size_t l = std::min<vfs::size_t>(s.length(), len-1);
|
||||
wcsncpy(sValue,s.c_str(), l);
|
||||
sValue[l] = 0;
|
||||
return true;
|
||||
}
|
||||
vfs::UInt32 l = std::min<vfs::UInt32>(sDefaultValue.length(), len-1);
|
||||
wcsncpy(sValue,sDefaultValue.c_wcs().c_str(), l);
|
||||
vfs::size_t l = std::min<vfs::size_t>(sDefaultValue.length(), len-1);
|
||||
wcsncpy(sValue,sDefaultValue.c_str(), l);
|
||||
sValue[l] = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Int64 CPropertyContainer::GetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue)
|
||||
vfs::Int64 CPropertyContainer::getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue)
|
||||
{
|
||||
return std::min<vfs::Int64>(iMaxValue, std::max<vfs::Int64>(iMinValue, GetIntProperty(sSection, sKey, iDefaultValue)));
|
||||
return std::min<vfs::Int64>(iMaxValue, std::max<vfs::Int64>(iMinValue, this->getIntProperty(sSection, sKey, iDefaultValue)));
|
||||
}
|
||||
|
||||
vfs::Int64 CPropertyContainer::GetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue)
|
||||
vfs::Int64 CPropertyContainer::getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::Int64 iRetVal;
|
||||
if(ConvertTo<vfs::Int64>(sValue,iRetVal))
|
||||
if(convertTo<vfs::Int64>(sValue,iRetVal))
|
||||
{
|
||||
return iRetVal;
|
||||
}
|
||||
@@ -546,18 +555,18 @@ vfs::Int64 CPropertyContainer::GetIntProperty(utf8string const& sSection, utf8st
|
||||
return iDefaultValue;
|
||||
}
|
||||
|
||||
vfs::UInt64 CPropertyContainer::GetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue)
|
||||
vfs::UInt64 CPropertyContainer::getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue)
|
||||
{
|
||||
return std::min<vfs::UInt64>(iMaxValue, std::max<vfs::UInt64>(iMinValue, GetIntProperty(sSection, sKey, iDefaultValue)));
|
||||
return std::min<vfs::UInt64>(iMaxValue, std::max<vfs::UInt64>(iMinValue, this->getIntProperty(sSection, sKey, iDefaultValue)));
|
||||
}
|
||||
|
||||
vfs::UInt64 CPropertyContainer::GetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue)
|
||||
vfs::UInt64 CPropertyContainer::getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
vfs::UInt64 iRetVal;
|
||||
if(ConvertTo<vfs::UInt64>(sValue,iRetVal))
|
||||
if(convertTo<vfs::UInt64>(sValue,iRetVal))
|
||||
{
|
||||
return iRetVal;
|
||||
}
|
||||
@@ -565,18 +574,18 @@ vfs::UInt64 CPropertyContainer::GetUIntProperty(utf8string const& sSection, utf8
|
||||
return iDefaultValue;
|
||||
}
|
||||
|
||||
double CPropertyContainer::GetFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue)
|
||||
double CPropertyContainer::getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue)
|
||||
{
|
||||
return std::min<double>(fMaxValue, std::max<double>(fMinValue, GetFloatProperty(sSection, sKey, fDefaultValue)));
|
||||
return std::min<double>(fMaxValue, std::max<double>(fMinValue, this->getFloatProperty(sSection, sKey, fDefaultValue)));
|
||||
}
|
||||
|
||||
double CPropertyContainer::GetFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue)
|
||||
double CPropertyContainer::getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
double fRetVal;
|
||||
if(ConvertTo<double>(sValue,fRetVal))
|
||||
if(convertTo<double>(sValue,fRetVal))
|
||||
{
|
||||
return fRetVal;
|
||||
}
|
||||
@@ -584,17 +593,17 @@ double CPropertyContainer::GetFloatProperty(utf8string const& sSection, utf8stri
|
||||
return fDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue)
|
||||
bool CPropertyContainer::getBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
int iRetVal;
|
||||
if( StrCmp::Equal(sValue,L"true") || ( ConvertTo<vfs::Int32>(sValue,iRetVal) && (iRetVal != 0) ) )
|
||||
vfs::Int32 iRetVal;
|
||||
if( StrCmp::Equal(sValue,L"true") || ( convertTo<>(sValue,iRetVal) && (iRetVal != 0) ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( StrCmp::Equal(sValue,"false") || ( ConvertTo<vfs::Int32>(sValue,iRetVal) && (iRetVal == 0) ) )
|
||||
else if( StrCmp::Equal(sValue,"false") || ( convertTo<>(sValue,iRetVal) && (iRetVal == 0) ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -603,33 +612,33 @@ bool CPropertyContainer::GetBoolProperty(utf8string const& sSection, utf8string
|
||||
return bDefaultValue;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue)
|
||||
bool CPropertyContainer::getStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
lValueList.push_back(vfs::TrimString(entry,0,entry.length()));
|
||||
lValueList.push_back(vfs::trimString(entry,0,entry.length()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue)
|
||||
bool CPropertyContainer::getIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::Int64 iRetVal;
|
||||
if(ConvertTo<vfs::Int64>(entry,iRetVal))
|
||||
if(convertTo<vfs::Int64>(entry,iRetVal))
|
||||
{
|
||||
lValueList.push_back(iRetVal);
|
||||
}
|
||||
@@ -643,17 +652,17 @@ bool CPropertyContainer::GetIntListProperty(utf8string const& sSection, utf8stri
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue)
|
||||
bool CPropertyContainer::getUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
vfs::UInt64 iRetVal;
|
||||
if(ConvertTo<vfs::UInt64>(entry,iRetVal))
|
||||
if(convertTo<vfs::UInt64>(entry,iRetVal))
|
||||
{
|
||||
lValueList.push_back(iRetVal);
|
||||
}
|
||||
@@ -666,17 +675,17 @@ bool CPropertyContainer::GetUIntListProperty(utf8string const& sSection, utf8str
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CPropertyContainer::GetFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue)
|
||||
bool CPropertyContainer::getFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
double fRetVal;
|
||||
if(ConvertTo<double>(entry,fRetVal))
|
||||
if(convertTo<double>(entry,fRetVal))
|
||||
{
|
||||
lValueList.push_back(fRetVal);
|
||||
}
|
||||
@@ -690,21 +699,21 @@ bool CPropertyContainer::GetFloatListProperty(utf8string const& sSection, utf8st
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CPropertyContainer::GetBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue)
|
||||
bool CPropertyContainer::getBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue)
|
||||
{
|
||||
utf8string sValue;
|
||||
if(GetValueForKey(sSection,sKey,sValue))
|
||||
if(getValueForKey(sSection,sKey,sValue))
|
||||
{
|
||||
utf8string entry;
|
||||
CSplitStringList splitter(sValue);
|
||||
while(splitter.NextListEntry(entry))
|
||||
while(splitter.nextListEntry(entry))
|
||||
{
|
||||
int iRetVal;
|
||||
if( StrCmp::Equal(entry,L"true") || ( ConvertTo<vfs::Int32>(entry,iRetVal) && (iRetVal != 0) ) )
|
||||
vfs::Int32 iRetVal;
|
||||
if( StrCmp::Equal(entry,L"true") || ( convertTo<>(entry,iRetVal) && (iRetVal != 0) ) )
|
||||
{
|
||||
lValueList.push_back(true);
|
||||
}
|
||||
else if( StrCmp::Equal(entry,L"false") || ( ConvertTo<vfs::Int32>(entry,iRetVal) && (iRetVal == 0) ) )
|
||||
else if( StrCmp::Equal(entry,L"false") || ( convertTo<>(entry,iRetVal) && (iRetVal == 0) ) )
|
||||
{
|
||||
lValueList.push_back(false);
|
||||
}
|
||||
@@ -718,46 +727,46 @@ bool CPropertyContainer::GetBoolListProperty(utf8string const& sSection, utf8str
|
||||
return false;
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue)
|
||||
void CPropertyContainer::setStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = sValue;
|
||||
this->section(sSection).value(sKey) = sValue;
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue)
|
||||
void CPropertyContainer::setIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,vfs::Int64>(iValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,vfs::Int64>(iValue);
|
||||
}
|
||||
void CPropertyContainer::SetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue)
|
||||
void CPropertyContainer::setUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,vfs::UInt64>(iValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,vfs::UInt64>(iValue);
|
||||
}
|
||||
void CPropertyContainer::SetFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue)
|
||||
void CPropertyContainer::setFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,double>(fValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,double>(fValue);
|
||||
}
|
||||
void CPropertyContainer::SetBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue)
|
||||
void CPropertyContainer::setBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToString<wchar_t,bool>(bValue);
|
||||
this->section(sSection).value(sKey) = toString<wchar_t,bool>(bValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue)
|
||||
void CPropertyContainer::setStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<utf8string>(slValue);
|
||||
this->section(sSection).value(sKey) = toStringList<utf8string>(slValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue)
|
||||
void CPropertyContainer::setIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<vfs::Int64>(ilValue);
|
||||
this->section(sSection).value(sKey) = toStringList<vfs::Int64>(ilValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue)
|
||||
void CPropertyContainer::setFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<double>(flValue);
|
||||
this->section(sSection).value(sKey) = toStringList<double>(flValue);
|
||||
}
|
||||
|
||||
void CPropertyContainer::SetBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue)
|
||||
void CPropertyContainer::setBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue)
|
||||
{
|
||||
Section(sSection).value(sKey) = ToStringList<bool>(blValue);
|
||||
this->section(sSection).value(sKey) = toStringList<bool>(blValue);
|
||||
}
|
||||
|
||||
/**************************************************************************************************/
|
||||
|
||||
+46
-44
@@ -9,7 +9,7 @@
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
class CPropertyContainer
|
||||
class VFS_API CPropertyContainer
|
||||
{
|
||||
public:
|
||||
class TagMap
|
||||
@@ -17,11 +17,11 @@ public:
|
||||
typedef std::map<utf8string,utf8string> tTagMap;
|
||||
public:
|
||||
TagMap();
|
||||
utf8string const& Container(utf8string::char_t* container = NULL);
|
||||
utf8string const& Section(utf8string::char_t* section = NULL);
|
||||
utf8string const& SectionID(utf8string::char_t* section_id = NULL);
|
||||
utf8string const& Key(utf8string::char_t* key = NULL);
|
||||
utf8string const& KeyID(utf8string::char_t* key_id = NULL);
|
||||
utf8string const& container(utf8string::char_t* container = NULL);
|
||||
utf8string const& section(utf8string::char_t* section = NULL);
|
||||
utf8string const& sectionID(utf8string::char_t* section_id = NULL);
|
||||
utf8string const& key(utf8string::char_t* key = NULL);
|
||||
utf8string const& keyID(utf8string::char_t* key_id = NULL);
|
||||
private:
|
||||
tTagMap _map;
|
||||
};
|
||||
@@ -29,77 +29,79 @@ public:
|
||||
CPropertyContainer(){};
|
||||
~CPropertyContainer(){};
|
||||
|
||||
void ClearContainer();
|
||||
void clearContainer();
|
||||
|
||||
bool InitFromIniFile(vfs::Path const& sFileName);
|
||||
bool InitFromIniFile(vfs::tReadableFile *pFile);
|
||||
bool WriteToIniFile(vfs::Path const& sFileName, bool bCreateNew = false);
|
||||
bool initFromIniFile(vfs::Path const& sFileName);
|
||||
bool initFromIniFile(vfs::tReadableFile *pFile);
|
||||
bool writeToIniFile(vfs::Path const& sFileName, bool bCreateNew = false);
|
||||
|
||||
bool InitFromXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
|
||||
bool WriteToXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
|
||||
bool initFromXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
|
||||
bool writeToXMLFile(vfs::Path const& sFileName, TagMap& tagmap);
|
||||
|
||||
void PrintProperties();
|
||||
void printProperties();
|
||||
|
||||
bool hasProperty(utf8string const& sSection, utf8string const& sKey);
|
||||
//
|
||||
utf8string const& GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue=L"");
|
||||
bool GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue=L"");
|
||||
bool GetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::UInt32 len, utf8string const& sDefaultValue=L"");
|
||||
utf8string const& getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sDefaultValue=L"");
|
||||
bool getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string& sValue, utf8string const& sDefaultValue=L"");
|
||||
bool getStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string::char_t* sValue, vfs::size_t len, utf8string const& sDefaultValue=L"");
|
||||
//
|
||||
vfs::Int64 GetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue);
|
||||
vfs::Int64 GetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue);
|
||||
vfs::Int64 getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue);
|
||||
vfs::Int64 getIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 iDefaultValue, vfs::Int64 iMinValue, vfs::Int64 iMaxValue);
|
||||
//
|
||||
vfs::UInt64 GetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue);
|
||||
vfs::UInt64 GetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue);
|
||||
vfs::UInt64 getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue);
|
||||
vfs::UInt64 getUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 iDefaultValue, vfs::UInt64 iMinValue, vfs::UInt64 iMaxValue);
|
||||
//
|
||||
double GetFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue);
|
||||
double GetFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue);
|
||||
double getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue);
|
||||
double getFloatProperty(utf8string const& sSection, utf8string const& sKey, double fDefaultValue, double fMinValue, double fMaxValue);
|
||||
//
|
||||
bool GetBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue);
|
||||
bool getBoolProperty(utf8string const& sSection, utf8string const& sKey, bool bDefaultValue);
|
||||
//
|
||||
bool GetStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue);
|
||||
bool GetIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue);
|
||||
bool GetUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue);
|
||||
bool GetFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue);
|
||||
bool GetBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue);
|
||||
bool getStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> &lValueList, utf8string sDefaultValue);
|
||||
bool getIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> &lValueList, vfs::Int64 iDefaultValue);
|
||||
bool getUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> &lValueList, vfs::UInt64 iDefaultValue);
|
||||
bool getFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> &lValueList, double fDefaultValue);
|
||||
bool getBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> &lValueList, bool bDefaultValue);
|
||||
//
|
||||
void SetStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue);
|
||||
void setStringProperty(utf8string const& sSection, utf8string const& sKey, utf8string const& sValue);
|
||||
//
|
||||
void SetIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue);
|
||||
void SetUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue);
|
||||
void SetFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue);
|
||||
void SetBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue);
|
||||
void setIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::Int64 const& iValue);
|
||||
void setUIntProperty(utf8string const& sSection, utf8string const& sKey, vfs::UInt64 const& iValue);
|
||||
void setFloatProperty(utf8string const& sSection, utf8string const& sKey, double const& fValue);
|
||||
void setBoolProperty(utf8string const& sSection, utf8string const& sKey, bool const& bValue);
|
||||
//
|
||||
void SetStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue);
|
||||
void SetIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue);
|
||||
void SetUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> const& ilValue);
|
||||
void SetFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue);
|
||||
void SetBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue);
|
||||
void setStringListProperty(utf8string const& sSection, utf8string const& sKey, std::list<utf8string> const& slValue);
|
||||
void setIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::Int64> const& ilValue);
|
||||
void setUIntListProperty(utf8string const& sSection, utf8string const& sKey, std::list<vfs::UInt64> const& ilValue);
|
||||
void setFloatListProperty(utf8string const& sSection, utf8string const& sKey, std::list<double> const& flValue);
|
||||
void setBoolListProperty(utf8string const& sSection, utf8string const& sKey, std::list<bool> const& blValue);
|
||||
private:
|
||||
enum EOperation
|
||||
{
|
||||
Error, Set, Add,
|
||||
};
|
||||
bool ExtractSection(utf8string::str_t const& readStr, size_t startPos, utf8string::str_t& sSection);
|
||||
EOperation ExtractKeyValue(utf8string::str_t const &readStr, size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue);
|
||||
bool extractSection(utf8string::str_t const& readStr, vfs::size_t startPos, utf8string::str_t& sSection);
|
||||
EOperation extractKeyValue(utf8string::str_t const &readStr, vfs::size_t startPos, utf8string::str_t& sKey, utf8string::str_t& sValue);
|
||||
private:
|
||||
class CSection
|
||||
{
|
||||
friend class CPropertyContainer;
|
||||
typedef std::map<utf8string,utf8string, utf8string::Less> tProps;
|
||||
public:
|
||||
bool has(utf8string const& key);
|
||||
bool add(utf8string const& key, utf8string const& value);
|
||||
bool value(utf8string const& key, utf8string& value);
|
||||
utf8string& value(utf8string const& key);
|
||||
void Print(std::ostream& out, utf8string::str_t sPrefix = L"");
|
||||
void Clear();
|
||||
void print(std::ostream& out, utf8string::str_t sPrefix = L"");
|
||||
void clear();
|
||||
private:
|
||||
tProps mapProps;
|
||||
};
|
||||
typedef std::map<utf8string, CSection, utf8string::Less> tSections;
|
||||
|
||||
bool GetValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue);
|
||||
bool getValueForKey(utf8string const& sSection, utf8string const& sKey, utf8string &sValue);
|
||||
|
||||
CSection& Section(utf8string const& sSection);
|
||||
CSection& section(utf8string const& sSection);
|
||||
|
||||
tSections m_mapProps;
|
||||
};
|
||||
|
||||
+59
-36
@@ -1,9 +1,10 @@
|
||||
#include "Log.h"
|
||||
#include <cstring>
|
||||
|
||||
#ifdef WIN32
|
||||
const char CLog::endl[] = "\r\n";
|
||||
const char CLog::ENDL[] = "\r\n";
|
||||
#else
|
||||
const char CLog::endl[] = "\n";
|
||||
const char CLog::ENDL[] = "\n";
|
||||
#endif
|
||||
|
||||
std::list<CLog*>& CLog::_logs()
|
||||
@@ -12,12 +13,12 @@ std::list<CLog*>& CLog::_logs()
|
||||
return logs;
|
||||
}
|
||||
|
||||
CLog* CLog::Create(vfs::Path fileName, bool append, EFlushMode flushMode)
|
||||
CLog* CLog::create(vfs::Path const& fileName, bool append, EFlushMode flushMode)
|
||||
{
|
||||
_logs().push_back(new CLog(fileName, append, flushMode));
|
||||
return _logs().back();
|
||||
}
|
||||
void CLog::FlushFinally()
|
||||
void CLog::flushFinally()
|
||||
{
|
||||
std::list<CLog*>::iterator it = _logs().begin();
|
||||
for(; it != _logs().end(); ++it)
|
||||
@@ -27,18 +28,30 @@ void CLog::FlushFinally()
|
||||
_logs().clear();
|
||||
}
|
||||
|
||||
void CLog::FlushAll()
|
||||
void CLog::flushAll()
|
||||
{
|
||||
std::list<CLog*>::iterator it = _logs().begin();
|
||||
for(; it != _logs().end(); ++it)
|
||||
{
|
||||
(*it)->Flush();
|
||||
(*it)->flush();
|
||||
(*it)->_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
utf8string CLog::_shared_id_str;
|
||||
|
||||
CLog::CLog(vfs::Path fileName, bool append, EFlushMode flushMode)
|
||||
utf8string const& CLog::getSharedString()
|
||||
{
|
||||
return _shared_id_str;
|
||||
}
|
||||
|
||||
void CLog::setSharedString(utf8string const& str)
|
||||
{
|
||||
_shared_id_str = str;
|
||||
}
|
||||
|
||||
|
||||
CLog::CLog(vfs::Path const& fileName, bool append, EFlushMode flushMode)
|
||||
: _filename(fileName), _file(NULL), _own_file(false),
|
||||
_first_write(true), _flush_mode(flushMode), _append(append),
|
||||
_buffer_size(0), _buffer_test_size(512)
|
||||
@@ -55,35 +68,35 @@ CLog::~CLog()
|
||||
|
||||
CLog& CLog::operator<<(unsigned int const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(unsigned short const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(unsigned char const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(int const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(short const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(char const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(float const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
CLog& CLog::operator<<(double const& t)
|
||||
{
|
||||
return PushNumber(t);
|
||||
return pushNumber(t);
|
||||
}
|
||||
|
||||
CLog& CLog::operator<<(const char* t)
|
||||
@@ -125,20 +138,20 @@ CLog& CLog::operator<<(utf8string const& t)
|
||||
return *this;
|
||||
}
|
||||
|
||||
CLog& CLog::Endl()
|
||||
CLog& CLog::endl()
|
||||
{
|
||||
_buffer << CLog::endl;
|
||||
_buffer_size += sizeof(CLog::endl)-1;
|
||||
_buffer << CLog::ENDL;
|
||||
_buffer_size += sizeof(CLog::ENDL)-1;
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CLog::SetAppend(bool append)
|
||||
void CLog::setAppend(bool append)
|
||||
{
|
||||
_append = append;
|
||||
}
|
||||
|
||||
void CLog::SetBufferSize(vfs::UInt32 bufferSize)
|
||||
void CLog::setBufferSize(vfs::UInt32 bufferSize)
|
||||
{
|
||||
_buffer_test_size = bufferSize;
|
||||
}
|
||||
@@ -149,14 +162,14 @@ void CLog::_test_flush(bool force)
|
||||
(_flush_mode == FLUSH_BUFFER && _buffer_size > _buffer_test_size) ||
|
||||
(/*_flush_mode == FLUSH_ON_DELETE &&*/ force == true) )
|
||||
{
|
||||
Flush();
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
#include <ctime>
|
||||
void CLog::Flush()
|
||||
void CLog::flush()
|
||||
{
|
||||
vfs::UInt32 buflen = _buffer.str().length();
|
||||
::size_t buflen = _buffer.str().length();
|
||||
if(buflen == 0)
|
||||
{
|
||||
return;
|
||||
@@ -172,21 +185,26 @@ void CLog::Flush()
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
LogException(ex);
|
||||
// write file anyway
|
||||
_file = vfs::tWriteableFile::Cast(new vfs::CFile(_filename));
|
||||
_file->OpenWrite(true,!_append);
|
||||
_own_file = true;
|
||||
try
|
||||
{
|
||||
logException(ex);
|
||||
// write file anyway
|
||||
_file = vfs::tWritableFile::cast(new vfs::CFile(_filename));
|
||||
_file->openWrite(true,!_append);
|
||||
_own_file = true;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vfs::COpenWriteFile wfile(_file);
|
||||
if(_append)
|
||||
{
|
||||
wfile.file().SetWriteLocation(0,vfs::IBaseFile::SD_END);
|
||||
wfile.file().setWritePosition(0,vfs::IBaseFile::SD_END);
|
||||
}
|
||||
|
||||
vfs::UInt32 io;
|
||||
if(_first_write)
|
||||
{
|
||||
time_t rawtime;
|
||||
@@ -194,21 +212,26 @@ void CLog::Flush()
|
||||
std::string datetime(ctime(&rawtime));
|
||||
std::string s_out;
|
||||
|
||||
vfs::UInt32 wloc = wfile.file().GetWriteLocation();
|
||||
vfs::size_t wloc = wfile.file().getWritePosition();
|
||||
if(wloc > 0)
|
||||
{
|
||||
s_out = CLog::endl;
|
||||
s_out = CLog::ENDL;
|
||||
}
|
||||
s_out += " *** ";
|
||||
s_out += datetime.substr(0,datetime.length()-1);
|
||||
s_out += " *** ";
|
||||
s_out += CLog::endl;
|
||||
s_out += CLog::endl;
|
||||
wfile.file().Write(s_out.c_str(), s_out.length(), io);
|
||||
s_out += CLog::ENDL;
|
||||
s_out += "[ ";
|
||||
s_out += _shared_id_str.utf8();
|
||||
s_out += " ]";
|
||||
s_out += CLog::ENDL;
|
||||
s_out += CLog::ENDL;
|
||||
|
||||
wfile.file().write(s_out.c_str(), s_out.length());
|
||||
_first_write = false;
|
||||
}
|
||||
|
||||
wfile.file().Write(_buffer.str().c_str(), buflen, io);
|
||||
wfile.file().write(_buffer.str().c_str(), buflen);
|
||||
_buffer.str("");
|
||||
_buffer.clear();
|
||||
_buffer_size = 0;
|
||||
|
||||
+18
-15
@@ -7,8 +7,7 @@
|
||||
#include "../File/vfs_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
//class CMemoryFile;
|
||||
class CLog
|
||||
class VFS_API CLog
|
||||
{
|
||||
public:
|
||||
enum EFlushMode
|
||||
@@ -19,12 +18,15 @@ public:
|
||||
};
|
||||
public:
|
||||
|
||||
CLog(vfs::Path fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
CLog(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
~CLog();
|
||||
|
||||
static CLog* Create(vfs::Path fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
static void FlushAll();
|
||||
static void FlushFinally();
|
||||
static CLog* create(vfs::Path const& fileName, bool append = false, EFlushMode flushMode = FLUSH_ON_DELETE);
|
||||
static void flushAll();
|
||||
static void flushFinally();
|
||||
|
||||
static utf8string const& getSharedString();
|
||||
static void setSharedString(utf8string const& str);
|
||||
|
||||
CLog& operator<<(unsigned int const& t);
|
||||
CLog& operator<<(unsigned short const& t);
|
||||
@@ -41,35 +43,36 @@ public:
|
||||
CLog& operator<<(std::wstring const& t);
|
||||
CLog& operator<<(utf8string const& t);
|
||||
|
||||
CLog& Endl();
|
||||
static const char endl[];
|
||||
CLog& endl();
|
||||
static const char ENDL[];
|
||||
|
||||
void SetAppend(bool append = true);
|
||||
void SetBufferSize(vfs::UInt32 bufferSize);
|
||||
void setAppend(bool append = true);
|
||||
void setBufferSize(vfs::UInt32 bufferSize);
|
||||
|
||||
void Flush();
|
||||
void flush();
|
||||
private:
|
||||
void _test_flush(bool force=false);
|
||||
|
||||
template<typename T_>
|
||||
CLog& PushNumber(T_ const& t)
|
||||
CLog& pushNumber(T_ const& t)
|
||||
{
|
||||
_buffer << ToString<char>(t);
|
||||
_buffer << toString<char>(t);
|
||||
_buffer_size += sizeof(T_);
|
||||
_test_flush();
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
vfs::Path _filename;
|
||||
vfs::tWriteableFile* _file;
|
||||
vfs::tWritableFile* _file;
|
||||
bool _own_file;
|
||||
bool _first_write;
|
||||
EFlushMode _flush_mode;
|
||||
bool _append;
|
||||
vfs::UInt32 _buffer_size, _buffer_test_size;
|
||||
::size_t _buffer_size, _buffer_test_size;
|
||||
std::stringstream _buffer;
|
||||
private:
|
||||
static std::list<CLog*>& _logs();
|
||||
static utf8string _shared_id_str;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+94
-70
@@ -4,6 +4,8 @@
|
||||
#include "../File/vfs_file.h"
|
||||
#include "../vfs_file_raii.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
@@ -11,41 +13,63 @@ CReadLine::CReadLine(vfs::tReadableFile& rFile)
|
||||
: _file(rFile), _buffer_pos(0), _eof(false)
|
||||
{
|
||||
memset(_buffer,0,sizeof(_buffer));
|
||||
FillBuffer();
|
||||
|
||||
vfs::COpenReadFile rfile(&_file);
|
||||
_bytes_left = rfile.file().getSize();
|
||||
fillBuffer();
|
||||
vfs::UByte utf8bom[3] = {0xef,0xbb,0xbf};
|
||||
if(memcmp(utf8bom, &_buffer[0],3) == 0)
|
||||
{
|
||||
_buffer_pos += 3;
|
||||
}
|
||||
rfile.release();
|
||||
};
|
||||
|
||||
bool CReadLine::FillBuffer()
|
||||
CReadLine::~CReadLine()
|
||||
{
|
||||
if(!_eof)
|
||||
if(_file.isOpenRead())
|
||||
{
|
||||
// reading can be done byte-wise or line-wise.
|
||||
// we have no control over this here, so we have to account for both cases.
|
||||
|
||||
vfs::UInt32 read = 0;
|
||||
// fill the buffer from the start, BUFFER_SIZE charactes at max (_buffer has BUFFER_SIZE+1 elements)
|
||||
_eof = !_file.Read(&_buffer[0],BUFFER_SIZE,read);
|
||||
// if read() fails, it means that we are at the end of the file,
|
||||
// but we probably have read a couple of valid bytes, so we need to do one last 'correct' run
|
||||
|
||||
// bite-wise read files usually terminate a line with \n (or \r\n on WIN32)
|
||||
// line-wise read files just returns 0-terminated string
|
||||
|
||||
// always terminate the string with 0
|
||||
_buffer[read] = 0;
|
||||
|
||||
_buffer_pos = 0;
|
||||
_buffer_last = read;
|
||||
return true;
|
||||
_file.close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CReadLine::FromBuffer(std::string& line)
|
||||
bool CReadLine::fillBuffer()
|
||||
{
|
||||
if(_eof)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vfs::size_t bytesRead = BUFFER_SIZE < _bytes_left ? BUFFER_SIZE : _bytes_left;
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile rfile(&_file);
|
||||
|
||||
// fill the buffer from the start, BUFFER_SIZE charactes at max (_buffer has BUFFER_SIZE+1 elements)
|
||||
THROWIFFALSE(bytesRead == _file.read(&_buffer[0], bytesRead), L"");
|
||||
rfile.release();
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
RETHROWEXCEPTION(L"", &ex);
|
||||
}
|
||||
|
||||
_bytes_left -= bytesRead;
|
||||
_eof = (_bytes_left == 0);
|
||||
|
||||
|
||||
// bite-wise read files usually terminate a line with \n (or \r\n on WIN32)
|
||||
// line-wise read files just returns 0-terminated string
|
||||
|
||||
// always terminate the string with 0
|
||||
_buffer[bytesRead] = 0;
|
||||
|
||||
_buffer_pos = 0;
|
||||
_buffer_last = bytesRead;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CReadLine::fromBuffer(std::string& line)
|
||||
{
|
||||
bool done = false;
|
||||
while(!done)
|
||||
@@ -54,7 +78,7 @@ bool CReadLine::FromBuffer(std::string& line)
|
||||
{
|
||||
// start where we left last time
|
||||
vfs::Byte *temp = &_buffer[_buffer_pos];
|
||||
vfs::UInt32 start_pos = _buffer_pos;
|
||||
vfs::size_t start_pos = _buffer_pos;
|
||||
// go until we hit 0. since our buffer is always 0 terminated, the second test should be redundant.
|
||||
while(*temp && (_buffer_pos < _buffer_last))
|
||||
{
|
||||
@@ -87,7 +111,7 @@ bool CReadLine::FromBuffer(std::string& line)
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !FillBuffer();
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
else if(*temp == '\n' || *temp == 0)
|
||||
@@ -99,47 +123,47 @@ bool CReadLine::FromBuffer(std::string& line)
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !FillBuffer();
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
done = !FillBuffer();
|
||||
done = !fillBuffer();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CReadLine::GetLine(std::string& line)
|
||||
bool CReadLine::getLine(std::string& line)
|
||||
{
|
||||
line.clear();
|
||||
return FromBuffer(line);
|
||||
return fromBuffer(line);
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/*************************************************************************************/
|
||||
|
||||
CSplitStringList::CSplitStringList(utf8string const& sList)
|
||||
: m_sList(sList), iCurrent(0),iNext(0)
|
||||
: m_list(sList), current(0), next(0)
|
||||
{};
|
||||
|
||||
CSplitStringList::~CSplitStringList()
|
||||
{};
|
||||
|
||||
bool CSplitStringList::NextListEntry(utf8string &sEntry)
|
||||
bool CSplitStringList::nextListEntry(utf8string &sEntry)
|
||||
{
|
||||
if(iNext >= 0)
|
||||
if(next != utf8string::str_t::npos)
|
||||
{
|
||||
iNext = m_sList.c_wcs().find_first_of(L",",iCurrent+1);
|
||||
if(iNext > iCurrent)
|
||||
next = m_list.c_wcs().find_first_of(L",", current+1);
|
||||
if(next != utf8string::str_t::npos)
|
||||
{
|
||||
sEntry.r_wcs().assign(vfs::TrimString(m_sList,iCurrent,iNext-1).c_wcs());
|
||||
iCurrent = iNext+1;
|
||||
sEntry.r_wcs().assign(vfs::trimString(m_list,current,next-1).c_wcs());
|
||||
current = next+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// last or only entry
|
||||
sEntry.r_wcs().assign(vfs::TrimString(m_sList,iCurrent,m_sList.length()).c_wcs());
|
||||
sEntry.r_wcs().assign(vfs::trimString(m_list,current,m_list.length()).c_wcs());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -154,20 +178,20 @@ CTransferRules::CTransferRules()
|
||||
{};
|
||||
|
||||
|
||||
bool CTransferRules::InitFromTxtFile(vfs::Path const& sPath)
|
||||
bool CTransferRules::initFromTxtFile(vfs::Path const& sPath)
|
||||
{
|
||||
// try to open via VirtualFileSystem
|
||||
if(GetVFS()->FileExists(sPath))
|
||||
if(getVFS()->fileExists(sPath))
|
||||
{
|
||||
return InitFromTxtFile(GetVFS()->GetRFile(sPath));
|
||||
return initFromTxtFile(getVFS()->getReadFile(sPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
// file doesn't exist or VFS not initialized yet
|
||||
vfs::IBaseFile* pFile = new vfs::CTextFile(sPath);
|
||||
vfs::IBaseFile* pFile = new vfs::CFile(sPath);
|
||||
if(pFile)
|
||||
{
|
||||
bool success = InitFromTxtFile(vfs::tReadableFile::Cast(pFile));
|
||||
bool success = initFromTxtFile(vfs::tReadableFile::cast(pFile));
|
||||
delete pFile;
|
||||
return success;
|
||||
}
|
||||
@@ -175,22 +199,22 @@ bool CTransferRules::InitFromTxtFile(vfs::Path const& sPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
bool CTransferRules::initFromTxtFile(vfs::tReadableFile* pFile)
|
||||
{
|
||||
if(pFile && pFile->OpenRead())
|
||||
if(pFile && pFile->openRead())
|
||||
{
|
||||
vfs::COpenReadFile rfile(pFile);
|
||||
std::string sBuffer;
|
||||
vfs::UInt32 line_counter = 0;
|
||||
CReadLine rl(*pFile);
|
||||
while(rl.GetLine(sBuffer))
|
||||
while(rl.getLine(sBuffer))
|
||||
{
|
||||
line_counter++;
|
||||
// very simple parsing : key = value
|
||||
if(!sBuffer.empty())
|
||||
{
|
||||
// remove leading white spaces
|
||||
int iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
::size_t iStart = sBuffer.find_first_not_of(" \t",0);
|
||||
char first = sBuffer.at(iStart);
|
||||
switch(first)
|
||||
{
|
||||
@@ -200,7 +224,7 @@ bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
// comment -> do nothing
|
||||
break;
|
||||
default:
|
||||
int iEnd = sBuffer.find_first_of(" \t", iStart);
|
||||
::size_t iEnd = sBuffer.find_first_of(" \t", iStart);
|
||||
if(iEnd != std::string::npos)
|
||||
{
|
||||
SRule rule;
|
||||
@@ -218,18 +242,18 @@ bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
std::wstring trybuffer = L"Invalid UTF-8 character in string";
|
||||
IGNOREEXCEPTION( trybuffer = utf8string(sBuffer).c_wcs() ); /* just make sure we don't break off when string conversion fails */
|
||||
std::wstringstream wss;
|
||||
wss << L"Unknown action in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Unknown action in file \"" << pFile->getPath().c_wcs()
|
||||
<< L", line " << line_counter << " : " << utf8string(sBuffer).c_wcs();
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
try
|
||||
{
|
||||
rule.pattern = vfs::Path(vfs::TrimString(sBuffer, iEnd, sBuffer.length()));
|
||||
rule.pattern = vfs::Path(vfs::trimString(sBuffer, iEnd, sBuffer.length()));
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not convert string, invalid utf8 encoding in file \"" << pFile->GetFullPath()().c_wcs()
|
||||
wss << L"Could not convert string, invalid utf8 encoding in file \"" << pFile->getPath().c_wcs()
|
||||
<< L"\", line " << line_counter;
|
||||
RETHROWEXCEPTION(wss.str().c_str(),&ex);
|
||||
}
|
||||
@@ -244,22 +268,22 @@ bool CTransferRules::InitFromTxtFile(vfs::tReadableFile* pFile)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CTransferRules::SetDefaultAction(CTransferRules::EAction act)
|
||||
void CTransferRules::setDefaultAction(CTransferRules::EAction act)
|
||||
{
|
||||
m_eDefaultAction = act;
|
||||
}
|
||||
|
||||
CTransferRules::EAction CTransferRules::GetDefaultAction()
|
||||
CTransferRules::EAction CTransferRules::getDefaultAction()
|
||||
{
|
||||
return m_eDefaultAction;
|
||||
}
|
||||
|
||||
CTransferRules::EAction CTransferRules::ApplyRule(utf8string const& sStr)
|
||||
CTransferRules::EAction CTransferRules::applyRule(utf8string const& sStr)
|
||||
{
|
||||
tPatternList::iterator sit = m_listRules.begin();
|
||||
for(; sit != m_listRules.end(); ++sit)
|
||||
{
|
||||
if(MatchPattern(sit->pattern(), sStr))
|
||||
if(matchPattern(sit->pattern(), sStr))
|
||||
{
|
||||
return sit->action;
|
||||
}
|
||||
@@ -275,7 +299,7 @@ CTransferRules::EAction CTransferRules::ApplyRule(utf8string const& sStr)
|
||||
typedef vfs::UInt16 UINT16;
|
||||
extern UINT16 gsKeyTranslationTable[1024];
|
||||
|
||||
CodePageReader::EMode CodePageReader::ExtractMode(std::string const &readStr, size_t startPos)
|
||||
CodePageReader::EMode CodePageReader::extractMode(std::string const &readStr, size_t startPos)
|
||||
{
|
||||
vfs::Int32 iEqual = readStr.find_first_of("=",startPos);
|
||||
if(iEqual < 0)
|
||||
@@ -283,14 +307,14 @@ CodePageReader::EMode CodePageReader::ExtractMode(std::string const &readStr, si
|
||||
return Error;
|
||||
}
|
||||
// extract keyword
|
||||
std::string key = vfs::TrimString(readStr,0,iEqual-1);
|
||||
std::string key = vfs::trimString(readStr,0,iEqual-1);
|
||||
if(!StrCmp::Equal(key, "mode"))
|
||||
{
|
||||
return Error;
|
||||
}
|
||||
// extract mode
|
||||
EMode mode = Error;
|
||||
std::string sMode = vfs::TrimString(readStr,iEqual+1,readStr.size());
|
||||
std::string sMode = vfs::trimString(readStr,iEqual+1,readStr.size());
|
||||
if(StrCmp::Equal(sMode, "normal"))
|
||||
{
|
||||
mode = Normal;
|
||||
@@ -310,7 +334,7 @@ CodePageReader::EMode CodePageReader::ExtractMode(std::string const &readStr, si
|
||||
return mode;
|
||||
}
|
||||
|
||||
bool CodePageReader::ExtractCode(std::string const& str, int iStart, vfs::UInt32& rInsertPoint, utf8string::str_t& u8s)
|
||||
bool CodePageReader::extractCode(std::string const& str, int iStart, vfs::UInt32& rInsertPoint, utf8string::str_t& u8s)
|
||||
{
|
||||
vfs::Int32 iEqual = str.find_first_of("=",iStart);
|
||||
if(iEqual < 0)
|
||||
@@ -341,9 +365,9 @@ bool CodePageReader::ExtractCode(std::string const& str, int iStart, vfs::UInt32
|
||||
return true;
|
||||
}
|
||||
|
||||
void CodePageReader::ReadCodePage(vfs::Path const& codepagefile)
|
||||
void CodePageReader::readCodePage(vfs::Path const& codepagefile)
|
||||
{
|
||||
if(!GetVFS()->FileExists(codepagefile))
|
||||
if(!GetVFS()->fileExists(codepagefile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -416,7 +440,7 @@ namespace charSet
|
||||
static std::map<ECharSet,std::set<wchar_t> > _sets;
|
||||
};
|
||||
|
||||
inline bool TestSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
inline bool testSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
{
|
||||
if(char_set & es)
|
||||
{
|
||||
@@ -426,20 +450,20 @@ inline bool TestSet(int char_set, charSet::ECharSet es, wchar_t wc)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool charSet::IsFromSet(char wc, unsigned int char_set)
|
||||
bool charSet::isFromSet(char wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::isFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::isFromSet(int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::IsFromSet(int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
bool charSet::IsFromSet(unsigned int wc, unsigned int char_set)
|
||||
bool charSet::isFromSet(unsigned int wc, unsigned int char_set)
|
||||
{
|
||||
return charSet::IsFromSet((wchar_t)wc, char_set);
|
||||
}
|
||||
|
||||
bool charSet::IsFromSet(wchar_t wc, unsigned int char_set)
|
||||
bool charSet::isFromSet(wchar_t wc, unsigned int char_set)
|
||||
{
|
||||
bool inSet = false;
|
||||
if( inSet |= TestSet(char_set, charSet::CS_SPACE, wc)) return true;
|
||||
@@ -452,7 +476,7 @@ bool charSet::IsFromSet(wchar_t wc, unsigned int char_set)
|
||||
return false;
|
||||
}
|
||||
|
||||
void charSet::AddToCharSet(ECharSet eset, std::wstring cset)
|
||||
void charSet::addToCharSet(ECharSet eset, std::wstring cset)
|
||||
{
|
||||
std::set<wchar_t>& wcset = charSet::_sets[eset];
|
||||
for(unsigned int i = 0; i < cset.length(); ++i)
|
||||
@@ -461,7 +485,7 @@ void charSet::AddToCharSet(ECharSet eset, std::wstring cset)
|
||||
}
|
||||
}
|
||||
|
||||
void charSet::InitializeCharSets()
|
||||
void charSet::initializeCharSets()
|
||||
{
|
||||
charSet::AddToCharSet(charSet::CS_SPACE, L" ");
|
||||
charSet::AddToCharSet(charSet::CS_ALPHA_LC, L"abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
+20
-14
@@ -8,22 +8,26 @@
|
||||
|
||||
/**************************************************************/
|
||||
/**************************************************************/
|
||||
const vfs::UInt32 BUFFER_SIZE = 1024;
|
||||
const vfs::size_t BUFFER_SIZE = 1024;
|
||||
|
||||
class CReadLine
|
||||
{
|
||||
public:
|
||||
CReadLine(vfs::tReadableFile& rFile);
|
||||
~CReadLine();
|
||||
|
||||
bool FillBuffer();
|
||||
bool FromBuffer(std::string& line);
|
||||
bool GetLine(std::string& line);
|
||||
bool fillBuffer();
|
||||
bool fromBuffer(std::string& line);
|
||||
bool getLine(std::string& line);
|
||||
private:
|
||||
vfs::Byte _buffer[BUFFER_SIZE+1];
|
||||
vfs::tReadableFile& _file;
|
||||
vfs::UInt32 _buffer_pos;
|
||||
vfs::UInt32 _buffer_last;
|
||||
vfs::size_t _bytes_left;
|
||||
vfs::size_t _buffer_pos;
|
||||
vfs::size_t _buffer_last;
|
||||
bool _eof;
|
||||
|
||||
void operator=(CReadLine const& rl);
|
||||
};
|
||||
|
||||
/**************************************************************/
|
||||
@@ -35,10 +39,12 @@ public:
|
||||
CSplitStringList(utf8string const& sList);
|
||||
~CSplitStringList();
|
||||
|
||||
bool NextListEntry(utf8string &sEntry);
|
||||
bool nextListEntry(utf8string &sEntry);
|
||||
private:
|
||||
const utf8string m_sList;
|
||||
int iCurrent,iNext;
|
||||
const utf8string m_list;
|
||||
utf8string::size_t current,next;
|
||||
|
||||
void operator=(CSplitStringList const& strlist);
|
||||
};
|
||||
|
||||
|
||||
@@ -56,13 +62,13 @@ public:
|
||||
public:
|
||||
CTransferRules();
|
||||
|
||||
bool InitFromTxtFile(vfs::Path const& sPath);
|
||||
bool InitFromTxtFile(vfs::tReadableFile* pFile);
|
||||
bool initFromTxtFile(vfs::Path const& sPath);
|
||||
bool initFromTxtFile(vfs::tReadableFile* pFile);
|
||||
|
||||
void SetDefaultAction(EAction act);
|
||||
EAction GetDefaultAction();
|
||||
void setDefaultAction(EAction act);
|
||||
EAction getDefaultAction();
|
||||
|
||||
EAction ApplyRule(utf8string const& sStr);
|
||||
EAction applyRule(utf8string const& sStr);
|
||||
private:
|
||||
struct SRule
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#include "Tools.h"
|
||||
|
||||
template<>
|
||||
utf8string ToStringList<utf8string>(std::list<utf8string> const& rValList)
|
||||
utf8string toStringList<utf8string>(std::list<utf8string> const& rValList)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
std::list<utf8string>::const_iterator cit = rValList.begin();
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
#include <list>
|
||||
|
||||
template<typename CharType, typename ValueType>
|
||||
std::basic_string<CharType> ToString(ValueType const& rVal)
|
||||
std::basic_string<CharType> toString(ValueType const& rVal)
|
||||
{
|
||||
std::basic_stringstream<CharType> tss;
|
||||
if( !(tss << rVal))
|
||||
@@ -16,7 +16,7 @@ std::basic_string<CharType> ToString(ValueType const& rVal)
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
bool ConvertTo(utf8string const& sStr, T_ &rVal)
|
||||
bool convertTo(utf8string const& sStr, T_ &rVal)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
ss.str(sStr.c_wcs());
|
||||
@@ -28,7 +28,7 @@ bool ConvertTo(utf8string const& sStr, T_ &rVal)
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
utf8string ToStringList(std::list<T_> const& rValList)
|
||||
utf8string toStringList(std::list<T_> const& rValList)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
typename std::list<T_>::const_iterator cit = rValList.begin();
|
||||
@@ -49,6 +49,6 @@ utf8string ToStringList(std::list<T_> const& rValList)
|
||||
}
|
||||
|
||||
template<>
|
||||
utf8string ToStringList<utf8string>(std::list<utf8string> const& rValList);
|
||||
utf8string toStringList<utf8string>(std::list<utf8string> const& rValList);
|
||||
|
||||
#endif // _TOOLS_H_
|
||||
|
||||
-345
@@ -1,345 +0,0 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="VFS"
|
||||
ProjectGUID="{C63466D6-49B5-4C54-AA0D-864F6171FD9B}"
|
||||
RootNamespace="Utils"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="FALSE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="MapEditorD|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="MapEditor|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="FALSE">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="FALSE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="TRUE"
|
||||
DebugInformationFormat="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Interface">
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_directory_interface.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_file_interface.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_library_interface.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_location_aware_file_interface.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_location_interface.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Location">
|
||||
<File
|
||||
RelativePath=".\Location\vfs_7z_library.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_7z_library.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_create_7z_library.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_create_7z_library.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_directory_tree.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_directory_tree.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_lib_dir.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_lib_dir.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_slf_library.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_slf_library.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_uncompressed_lib_base.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Location\vfs_uncompressed_lib_base.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="File">
|
||||
<File
|
||||
RelativePath=".\File\vfs_dir_file.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_dir_file.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_file.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_file.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_lib_file.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_lib_file.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_memory_file.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\File\vfs_memory_file.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Profiler">
|
||||
<File
|
||||
RelativePath=".\Profiler\HPTimer.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Profiler\HPTimer.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Profiler\Prof.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Profiler\Prof.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\iteratedir.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\iteratedir.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PropertyContainer.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\PropertyContainer.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stringicmp.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_debug.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_debug.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_file_raii.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_file_raii.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_init.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_init.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_profile.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_profile.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_types.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_types.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vfile.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vfile.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vloc.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_vloc.h">
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
+124
-7
@@ -20,7 +20,6 @@
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops;..\ja2_VS2008Debug.vsprops"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
@@ -41,7 +40,8 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VFS_STATIC"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@@ -105,7 +105,8 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
@@ -168,7 +169,8 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VFS_STATIC"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@@ -232,7 +234,8 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
@@ -269,6 +272,72 @@
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release_WithDebugInfo|Win32"
|
||||
OutputDirectory="$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
@@ -284,6 +353,14 @@
|
||||
RelativePath=".\Interface\vfs_file_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_interface_members.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_iterator_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_library_interface.h"
|
||||
>
|
||||
@@ -433,12 +510,32 @@
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="utfcpp"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\checked.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\core.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\unchecked.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\iteratedir.cpp"
|
||||
RelativePath=".\os_functions.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\iteratedir.h"
|
||||
RelativePath=".\os_functions.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -465,6 +562,10 @@
|
||||
RelativePath=".\vfs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_config.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_debug.cpp"
|
||||
>
|
||||
@@ -489,6 +590,14 @@
|
||||
RelativePath=".\vfs_init.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_path.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_path.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_profile.cpp"
|
||||
>
|
||||
@@ -497,6 +606,14 @@
|
||||
RelativePath=".\vfs_profile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_settings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_settings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_types.cpp"
|
||||
>
|
||||
|
||||
+123
-10
@@ -21,7 +21,6 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops;..\ja2_VS2008Debug.vsprops"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
@@ -42,7 +41,8 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VFS_STATIC"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@@ -83,7 +83,6 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
@@ -106,7 +105,8 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
@@ -148,7 +148,6 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops;..\ja2_VS2008Debug.vsprops"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
@@ -169,7 +168,8 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;VFS_STATIC"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@@ -210,7 +210,6 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
@@ -233,7 +232,8 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
@@ -270,6 +270,71 @@
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release_WithDebugInfo|Win32"
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
EnableIntrinsicFunctions="true"
|
||||
AdditionalIncludeDirectories="..\ext\7z;..\ext\utf8\source"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;VFS_STATIC"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="false"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
SuppressStartupBanner="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
@@ -285,6 +350,14 @@
|
||||
RelativePath=".\Interface\vfs_file_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_interface_members.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_iterator_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Interface\vfs_library_interface.h"
|
||||
>
|
||||
@@ -434,12 +507,32 @@
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="utfcpp"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\checked.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\core.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8\unchecked.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\ext\utf8\source\utf8.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\iteratedir.cpp"
|
||||
RelativePath=".\os_functions.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\iteratedir.h"
|
||||
RelativePath=".\os_functions.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
@@ -466,6 +559,10 @@
|
||||
RelativePath=".\vfs.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_config.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_debug.cpp"
|
||||
>
|
||||
@@ -490,6 +587,14 @@
|
||||
RelativePath=".\vfs_init.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_path.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_path.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_profile.cpp"
|
||||
>
|
||||
@@ -498,6 +603,14 @@
|
||||
RelativePath=".\vfs_profile.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_settings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_settings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\vfs_types.cpp"
|
||||
>
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
#include "os_functions.h"
|
||||
#include "vfs_debug.h"
|
||||
#include <sstream>
|
||||
#include "Tools/Log.h"
|
||||
#include "utf8string.h"
|
||||
#include "vfs_settings.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 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
std::string s;
|
||||
utf8string::narrow((sPath+searchPattern).c_wcs(), s);
|
||||
fSearchHandle = FindFirstFileA(s.c_str(), &fFileInfoA);
|
||||
}
|
||||
else
|
||||
{
|
||||
fSearchHandle = FindFirstFileW((sPath+searchPattern).c_wcs().c_str(), &fFileInfoW);
|
||||
}
|
||||
if (fSearchHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
std::wstringstream wss;
|
||||
wss << L"Error accessing path [" << (sPath+searchPattern)() << L"], error code : " << error;
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
#else
|
||||
count = scandir(utf8string::as_utf8(sPath()).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(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
if( !FindNextFileA(fSearchHandle, &fFileInfoA) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign( utf8string::widen( fFileInfoA.cFileName, strlen(fFileInfoA.cFileName) ) );
|
||||
attrib = (fFileInfoA.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !FindNextFileW(fSearchHandle, &fFileInfoW) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
fileName.r_wcs().assign(fFileInfoW.cFileName);
|
||||
attrib = (fFileInfoW.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
if(current_pos < count)
|
||||
{
|
||||
struct dirent* entry = files[current_pos];
|
||||
fileName = utf8string(entry->d_name);
|
||||
attrib = (entry->d_type == DT_DIR) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
|
||||
current_pos++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::createRealDirectory(vfs::Path const& sDir, bool bDoNotCreate)
|
||||
{
|
||||
#if WIN32
|
||||
if(bDoNotCreate)
|
||||
{
|
||||
bool bDirExists = false;
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
WIN32_FIND_DATAA fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAA));
|
||||
|
||||
std::string s;
|
||||
utf8string::narrow(sDir.c_wcs(), s);
|
||||
|
||||
HANDLE hFile = FindFirstFileA( s.c_str(), &fd);
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CLog log(L"errors.log", true);
|
||||
log << L"Directory [" << sDir() << L"] does not exist : " << (int)error << CLog::ENDL;
|
||||
}
|
||||
|
||||
// WANNE - MP: This should fix the missing sync folder event if it exists (by Frostregen)
|
||||
bDirExists = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
|
||||
//bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
FindClose(hFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
WIN32_FIND_DATAW fd;
|
||||
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
|
||||
HANDLE hFile = FindFirstFileW( sDir.c_str(), &fd);
|
||||
if(hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CLog log(L"errors.log", true);
|
||||
log << L"Directory [" << sDir() << L"] does not exist : " << (int)error << CLog::ENDL;
|
||||
}
|
||||
|
||||
// WANNE - MP: This should fix the missing sync folder event if it exists (by Frostregen)
|
||||
bDirExists = (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) > 0;
|
||||
//bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
||||
|
||||
FindClose(hFile);
|
||||
}
|
||||
return bDirExists;
|
||||
}
|
||||
BOOL success;
|
||||
utf8string::str_t const& str = sDir.c_wcs();
|
||||
success = vfs::Settings::getUseUnicode() ?
|
||||
CreateDirectoryW(sDir.c_str(),NULL) :
|
||||
CreateDirectoryA( utf8string::narrow( str.c_str(), str.length() ).c_str(), NULL );
|
||||
if(success == 0)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
if(error == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CLog log(L"errors.log", true);
|
||||
log << L"Could not create directory [" << sDir() << L"] : " << (int)error << CLog::ENDL;
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool os::FileAttributes::getFileAttributes(vfs::Path const& sDir, vfs::UInt32& uiAttribs)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD attribs = vfs::Settings::getUseUnicode() ?
|
||||
GetFileAttributesW(sDir.c_str()) :
|
||||
GetFileAttributesA(utf8string::narrow(sDir.c_str(), sDir.length()).c_str());
|
||||
|
||||
if(attribs == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
DWORD error = GetLastError();
|
||||
CLog log(L"errors.log");
|
||||
log << L"Invalid File Attributes : " << (int)error << CLog::ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(vfs::UInt32 attribMask = 0x80000000; attribMask > 0; attribMask >>= 1)
|
||||
{
|
||||
switch(attribs & attribMask)
|
||||
{
|
||||
case FILE_ATTRIBUTE_ARCHIVE:
|
||||
uiAttribs |= ATTRIB_ARCHIVE;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_DIRECTORY:
|
||||
uiAttribs |= ATTRIB_DIRECTORY;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_HIDDEN:
|
||||
uiAttribs |= ATTRIB_HIDDEN;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_NORMAL:
|
||||
uiAttribs |= ATTRIB_NORMAL;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_READONLY:
|
||||
uiAttribs |= ATTRIB_READONLY;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_SYSTEM:
|
||||
uiAttribs |= ATTRIB_SYSTEM;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_TEMPORARY:
|
||||
uiAttribs |= ATTRIB_TEMPORARY;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_COMPRESSED:
|
||||
uiAttribs |= ATTRIB_COMPRESSED;
|
||||
break;
|
||||
case FILE_ATTRIBUTE_OFFLINE:
|
||||
uiAttribs |= ATTRIB_OFFLINE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool os::deleteRealFile(vfs::Path const& sDir)
|
||||
{
|
||||
#ifdef WIN32
|
||||
BOOL del = vfs::Settings::getUseUnicode() ?
|
||||
DeleteFileW( sDir.c_str() ) :
|
||||
DeleteFileA( utf8string::narrow(sDir.c_str(), sDir.length()).c_str() );
|
||||
return (del != FALSE);
|
||||
#else
|
||||
return (remove( utf8string::as_utf8(sDir()).c_str() ) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void os::getExecutablePath(vfs::Path& sDir, vfs::Path& sFile)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD error;
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
char path[256];
|
||||
if( 0 != (error = ::GetModuleFileNameA(NULL, path, 256)) )
|
||||
{
|
||||
vfs::Path(utf8string::widen(path,256)).splitLast(sDir, sFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t path[256];
|
||||
if( 0 != (error = ::GetModuleFileNameW(NULL, path, 256)) )
|
||||
{
|
||||
vfs::Path(path).splitLast(sDir, sFile);
|
||||
}
|
||||
}
|
||||
if(error == 0)
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
THROWEXCEPTION( BuildString().add(L"Could not get current directory [").add(
|
||||
(!vfs::Settings::getUseUnicode()) ? L"[no unicode]" : L"[unicode]").add(L"], error code : ").add(code).get());
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void os::getCurrentDirectory(vfs::Path& sPath)
|
||||
{
|
||||
#ifdef WIN32
|
||||
DWORD error;
|
||||
vfs::Path path;
|
||||
if( !vfs::Settings::getUseUnicode() )
|
||||
{
|
||||
char path[256];
|
||||
if( 0 != (error = ::GetCurrentDirectoryA(256, path)) )
|
||||
{
|
||||
sPath = vfs::Path(utf8string::widen(path,256));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t path[256];
|
||||
if( 0 != (error = ::GetCurrentDirectoryW(256, path)) )
|
||||
{
|
||||
sPath = vfs::Path(path);
|
||||
}
|
||||
}
|
||||
if(error == 0)
|
||||
{
|
||||
DWORD code = GetLastError();
|
||||
THROWEXCEPTION(BuildString().add(L"Could not get current directory [").add(
|
||||
(!vfs::Settings::getUseUnicode()) ? L"[no unicode]" : L"[unicode]").add(L"], error code : ").add(code).get());
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
void os::setCurrectDirectory(vfs::Path const& sPath)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if(!vfs::Settings::getUseUnicode())
|
||||
{
|
||||
std::string str;
|
||||
utf8string::narrow( sPath.c_wcs(), str );
|
||||
THROWIFFALSE( ::SetCurrentDirectoryA( str.c_str() ) == TRUE,
|
||||
BuildString().add(L"Could not set current directory [no unicode] : ").add(sPath).get() );
|
||||
}
|
||||
else
|
||||
{
|
||||
THROWIFFALSE( ::SetCurrentDirectoryW( sPath.c_str() ) == TRUE,
|
||||
BuildString().add(L"Could not set current directory [unicode] : ").add(sPath).get() );
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#ifndef _OS_FUNCTIONS_H_
|
||||
#define _OS_FUNCTIONS_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/dir.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "vfs_config.h"
|
||||
#include "vfs_types.h"
|
||||
#include "vfs_path.h"
|
||||
|
||||
namespace os
|
||||
{
|
||||
|
||||
class CIterateDirectory
|
||||
{
|
||||
public:
|
||||
enum EFileAttribute
|
||||
{
|
||||
FA_DIRECTORY,
|
||||
FA_FILE
|
||||
};
|
||||
public:
|
||||
CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern);
|
||||
~CIterateDirectory();
|
||||
|
||||
bool nextFile(utf8string &fileName, CIterateDirectory::EFileAttribute &attrib);
|
||||
private:
|
||||
#ifdef WIN32
|
||||
HANDLE fSearchHandle;
|
||||
union
|
||||
{
|
||||
WIN32_FIND_DATAA fFileInfoA;
|
||||
WIN32_FIND_DATAW fFileInfoW;
|
||||
};
|
||||
#else
|
||||
struct direct **files;
|
||||
int count, current_pos;
|
||||
#endif
|
||||
bool fFirstRequest;
|
||||
};
|
||||
|
||||
class FileAttributes
|
||||
{
|
||||
public:
|
||||
enum Attributes
|
||||
{
|
||||
ATTRIB_INVALID = 0,
|
||||
ATTRIB_ARCHIVE = 1,
|
||||
ATTRIB_DIRECTORY = 2,
|
||||
ATTRIB_HIDDEN = 4,
|
||||
ATTRIB_NORMAL = 8,
|
||||
ATTRIB_READONLY = 16,
|
||||
ATTRIB_SYSTEM = 32,
|
||||
ATTRIB_TEMPORARY = 64,
|
||||
ATTRIB_COMPRESSED = 128,
|
||||
ATTRIB_OFFLINE = 256,
|
||||
};
|
||||
bool getFileAttributes(vfs::Path const& sDir, vfs::UInt32& uiAttribs);
|
||||
};
|
||||
|
||||
|
||||
VFS_API bool createRealDirectory(vfs::Path const& sDir, bool bDoNotCreate=false);
|
||||
|
||||
bool deleteRealFile(vfs::Path const& sDir);
|
||||
|
||||
VFS_API void getExecutablePath(vfs::Path& sDir, vfs::Path& sFile);
|
||||
VFS_API void getCurrentDirectory(vfs::Path& sDir);
|
||||
VFS_API void setCurrectDirectory(vfs::Path const& sPath);
|
||||
|
||||
}; // end namespace
|
||||
|
||||
#endif // _OS_FUNCTIONS_H_
|
||||
|
||||
+69
-114
@@ -1,13 +1,12 @@
|
||||
#include "utf8string.h"
|
||||
#include "utf8.h"
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "vfs_debug.h"
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool g_VFS_NO_UNICODE = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
namespace _StrCmp
|
||||
{
|
||||
////////////////////////////////////////////////////////////////
|
||||
@@ -68,55 +67,29 @@ namespace _StrCmp
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool utf8string::lessCase(utf8string const& s1, utf8string const& s2)
|
||||
bool utf8string::lessCase(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
const utf8string::char_t *p1 = s1._str.c_str();
|
||||
const utf8string::char_t *p2 = s2._str.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::LessCase(p1,p2);
|
||||
_StrCmp::AdvanceCase(s1,s2);
|
||||
return _StrCmp::LessCase(s1,s2);
|
||||
|
||||
}
|
||||
|
||||
bool utf8string::less(utf8string const& s1, utf8string const& s2)
|
||||
bool utf8string::less(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
const utf8string::char_t *p1 = s1._str.c_str();
|
||||
const utf8string::char_t *p2 = s2._str.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Less(p1,p2);
|
||||
|
||||
_StrCmp::Advance(s1,s2);
|
||||
return _StrCmp::Less(s1,s2);
|
||||
}
|
||||
|
||||
bool utf8string::equalCase(utf8string const& s1, const utf8string& s2)
|
||||
bool utf8string::equalCase(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
const utf8string::char_t *p1 = s1._str.c_str();
|
||||
const utf8string::char_t *p2 = s2._str.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
|
||||
}
|
||||
bool utf8string::equalCase(utf8string const& s1, const utf8string::str_t& s2)
|
||||
{
|
||||
const utf8string::char_t *p1 = s1._str.c_str();
|
||||
const utf8string::char_t *p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
|
||||
}
|
||||
bool utf8string::equalCase(utf8string const& s1, const utf8string::char_t* s2)
|
||||
{
|
||||
const utf8string::char_t *p1 = s1._str.c_str();
|
||||
_StrCmp::AdvanceCase(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
|
||||
_StrCmp::AdvanceCase(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
|
||||
bool utf8string::equal(utf8string const& s1, utf8string const& s2)
|
||||
bool utf8string::equal(const utf8string::char_t* s1, const utf8string::char_t* s2)
|
||||
{
|
||||
const utf8string::char_t *p1 = s1._str.c_str();
|
||||
const utf8string::char_t *p2 = s2._str.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
|
||||
_StrCmp::Advance(s1,s2);
|
||||
return _StrCmp::Equal(s1,s2);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@@ -155,20 +128,20 @@ void utf8string::as_utf16(std::string const& str, utf8string::str_t &str16)
|
||||
{
|
||||
try
|
||||
{
|
||||
int d = utf8::distance(str.begin(), str.end());
|
||||
::size_t d = utf8::distance(str.begin(), str.end());
|
||||
str16.resize(d);
|
||||
utf8::utf8to16(str.begin(), str.end(), &str16[0]);
|
||||
}
|
||||
catch(utf8::invalid_utf8& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
utf8::uint8_t c = ex.utf8_octet();
|
||||
wss << L"Invalid UTF8 character '" << (wchar_t)c << L"'=" << (unsigned char)c;
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
THROWEXCEPTION(BuildString().add(L"Invalid UTF8 character '").add((wchar_t)c).add(L"'=").add((unsigned char)c).get());
|
||||
}
|
||||
catch(utf8::not_enough_room &ex)
|
||||
{
|
||||
THROWEXCEPTION(L"Incomplete UTF8 string");
|
||||
std::wstring err;
|
||||
IGNOREEXCEPTION(utf8string::as_utf16(ex.what(),err));
|
||||
THROWEXCEPTION(BuildString().add(L"Incomplete UTF8 string [").add(err).add(L"]").get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,23 +153,27 @@ utf8string::str_t utf8string::as_utf16(const char* str)
|
||||
}
|
||||
void utf8string::as_utf16(const char* str, utf8string::str_t &str16)
|
||||
{
|
||||
if(str == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
int len = strlen(str);
|
||||
int d = utf8::distance(str,str+len);
|
||||
::size_t len = strlen(str);
|
||||
::size_t d = utf8::distance(str,str+len);
|
||||
str16.resize(d);
|
||||
utf8::utf8to16(str, str+len, &str16[0]);
|
||||
}
|
||||
catch(utf8::invalid_utf8& ex)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
utf8::uint8_t c = ex.utf8_octet();
|
||||
wss << L"Invalid UTF8 character '" << (wchar_t)c << L"'=" << (unsigned char)c;
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
THROWEXCEPTION(BuildString().add(L"Invalid UTF8 character '").add((wchar_t)c).add(L"'=").add((unsigned char)c).get());
|
||||
}
|
||||
catch(utf8::not_enough_room &ex)
|
||||
{
|
||||
THROWEXCEPTION(L"Incomplete UTF8 string");
|
||||
std::wstring err;
|
||||
IGNOREEXCEPTION(utf8string::as_utf16(ex.what(), err));
|
||||
THROWEXCEPTION(BuildString().add(L"Incomplete UTF8 string [").add(err).add(L"]").get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +183,7 @@ std::string utf8string::as_utf8(utf8string const& str)
|
||||
}
|
||||
std::string utf8string::as_utf8(std::wstring const& str)
|
||||
{
|
||||
if(str.length() == 0)
|
||||
if(str.empty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
@@ -215,27 +192,29 @@ std::string utf8string::as_utf8(std::wstring const& str)
|
||||
utf8::utf16to8(str.begin(), str.end(), std::back_inserter(s));
|
||||
#else
|
||||
static std::vector<char> buffer;
|
||||
buffer.resize(std::max<int>(buffer.size(), str.length()*3));
|
||||
buffer.resize(std::max< ::size_t>(buffer.size(), str.length()*3));
|
||||
char* end = utf8::utf16to8(str.begin(), str.end(), &buffer[0]);
|
||||
std::string s(&buffer[0],end);
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
// if 'strlen' is 0, length is determined automatically
|
||||
std::string utf8string::as_utf8(const wchar_t* str, unsigned int strlength)
|
||||
// if 'strlength' is 0, length is determined automatically
|
||||
std::string utf8string::as_utf8(const wchar_t* str, utf8string::size_t strlength)
|
||||
{
|
||||
std::string s;
|
||||
size_t len = strlength;
|
||||
if(len == 0)
|
||||
if(str != NULL)
|
||||
{
|
||||
len = wcslen(str);
|
||||
::size_t len = strlength;
|
||||
if(len == 0)
|
||||
{
|
||||
len = wcslen(str);
|
||||
}
|
||||
if(len != 0)
|
||||
{
|
||||
utf8::utf16to8(str,str+len,std::back_inserter(s));
|
||||
}
|
||||
}
|
||||
if(len == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
utf8::utf16to8(str,str+len,std::back_inserter(s));
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -245,21 +224,21 @@ std::string utf8string::as_utf8(std::string const& str)
|
||||
return str;
|
||||
}
|
||||
|
||||
size_t utf8string::narrow(std::wstring const& src, std::string& dst)
|
||||
utf8string::size_t utf8string::narrow(std::wstring const& src, std::string& dst)
|
||||
{
|
||||
size_t len = utf8string::narrow(src.c_str(),src.length(),NULL,0);
|
||||
utf8string::size_t len = utf8string::narrow(src.c_str(),src.length(),NULL,0);
|
||||
dst.resize(len);
|
||||
return utf8string::narrow(src.c_str(),src.length(),&dst[0],len);
|
||||
}
|
||||
std::string utf8string::narrow(wchar_t const* str, size_t length)
|
||||
std::string utf8string::narrow(wchar_t const* str, utf8string::size_t length)
|
||||
{
|
||||
size_t len = utf8string::narrow(str,length,NULL,0);
|
||||
utf8string::size_t len = utf8string::narrow(str,length,NULL,0);
|
||||
std::string s;
|
||||
s.resize(len);
|
||||
utf8string::narrow(str,length,&s[0],len);
|
||||
return s;
|
||||
}
|
||||
size_t utf8string::narrow(wchar_t const* src_str, size_t src_len, char* dst_str, size_t dst_len)
|
||||
utf8string::size_t utf8string::narrow(wchar_t const* src_str, utf8string::size_t src_len, char* dst_str, utf8string::size_t dst_len)
|
||||
{
|
||||
if(src_str && src_len>0)
|
||||
{
|
||||
@@ -267,26 +246,26 @@ size_t utf8string::narrow(wchar_t const* src_str, size_t src_len, char* dst_str,
|
||||
{
|
||||
return wcstombs(NULL, src_str, src_len);
|
||||
}
|
||||
return wcstombs(dst_str, src_str, std::min<size_t>(src_len,dst_len));
|
||||
return wcstombs(dst_str, src_str, std::min<utf8string::size_t>(src_len,dst_len));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
std::wstring utf8string::widen(char const* str, size_t length)
|
||||
std::wstring utf8string::widen(char const* str, utf8string::size_t length)
|
||||
{
|
||||
size_t len = utf8string::widen(str,length,NULL,0);
|
||||
utf8string::size_t len = utf8string::widen(str,length,NULL,0);
|
||||
std::wstring ws;
|
||||
ws.resize(len);
|
||||
utf8string::widen(str,length,&ws[0],len);
|
||||
return ws;
|
||||
}
|
||||
size_t utf8string::widen(std::string const& src, std::wstring& dst)
|
||||
utf8string::size_t utf8string::widen(std::string const& src, std::wstring& dst)
|
||||
{
|
||||
size_t len = utf8string::widen(src.c_str(),src.length(),NULL,0);
|
||||
utf8string::size_t len = utf8string::widen(src.c_str(),src.length(),NULL,0);
|
||||
dst.resize(len);
|
||||
return utf8string::widen(src.c_str(),src.length(),&dst[0],len);
|
||||
}
|
||||
size_t utf8string::widen(char const* src_str, size_t src_len, wchar_t* dst_str, size_t dst_len)
|
||||
utf8string::size_t utf8string::widen(char const* src_str, size_t src_len, wchar_t* dst_str, size_t dst_len)
|
||||
{
|
||||
if(src_str && src_len>0)
|
||||
{
|
||||
@@ -300,24 +279,6 @@ size_t utf8string::widen(char const* src_str, size_t src_len, wchar_t* dst_str,
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// get string methods
|
||||
////////////////////////////////////////////////////////////////////
|
||||
std::string utf8string::utf8() const
|
||||
{
|
||||
return as_utf8(_str);
|
||||
}
|
||||
|
||||
std::wstring const& utf8string::c_wcs() const
|
||||
{
|
||||
return _str;
|
||||
}
|
||||
|
||||
std::wstring& utf8string::r_wcs()
|
||||
{
|
||||
return _str;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool utf8string::empty() const
|
||||
{
|
||||
@@ -347,30 +308,24 @@ bool operator<(utf8string const& s1, utf8string const& s2)
|
||||
|
||||
std::wstringstream& operator<<(std::wstringstream& out, utf8string const& str)
|
||||
{
|
||||
out.write(str.c_wcs().c_str(), str.length());
|
||||
out.write(str.c_str(), (std::streamsize)str.length());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::wstringstream& operator<<(std::wstringstream& out, utf8string::str_t const& str)
|
||||
{
|
||||
out.write(str.c_str(), str.length());
|
||||
out.write(str.c_str(), (std::streamsize)str.length());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::wstringstream& operator<<(std::wstringstream& out, const utf8string::char_t* str)
|
||||
{
|
||||
out.write(str, wcslen(str));
|
||||
out.write(str, (std::streamsize)wcslen(str));
|
||||
return out;
|
||||
}
|
||||
|
||||
/*****************************************************************************************/
|
||||
/*****************************************************************************************/
|
||||
class StrAccess
|
||||
{
|
||||
public:
|
||||
StrAccess(utf8string const& s) : str(s._str) {};
|
||||
std::wstring const& str;
|
||||
};
|
||||
|
||||
// case IN-sensitive
|
||||
bool StrCmp::Equal(const char* s1, const char* s2)
|
||||
@@ -425,14 +380,14 @@ bool StrCmp::Equal(const wchar_t* s1, std::wstring const& s2)
|
||||
//
|
||||
bool StrCmp::Equal(utf8string const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = StrAccess(s1).str.c_str();
|
||||
const wchar_t* p2 = StrAccess(s2).str.c_str();
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(utf8string const& s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p1 = StrAccess(s1).str.c_str();
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
@@ -440,19 +395,19 @@ bool StrCmp::Equal(utf8string const& s1, std::wstring const& s2)
|
||||
bool StrCmp::Equal(std::wstring const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = StrAccess(s2).str.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::Equal(utf8string const& s1, const wchar_t* s2)
|
||||
{
|
||||
const wchar_t* p1 = StrAccess(s1).str.c_str();
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
_StrCmp::Advance(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::Equal(const wchar_t* s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p2 = StrAccess(s2).str.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::Advance(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
@@ -509,14 +464,14 @@ bool StrCmp::EqualCase(const wchar_t* s1, std::wstring const& s2)
|
||||
//
|
||||
bool StrCmp::EqualCase(utf8string const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = StrAccess(s1).str.c_str();
|
||||
const wchar_t* p2 = StrAccess(s2).str.c_str();
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(utf8string const& s1, std::wstring const& s2)
|
||||
{
|
||||
const wchar_t* p1 = StrAccess(s1).str.c_str();
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
@@ -524,19 +479,19 @@ bool StrCmp::EqualCase(utf8string const& s1, std::wstring const& s2)
|
||||
bool StrCmp::EqualCase(std::wstring const& s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
const wchar_t* p2 = StrAccess(s2).str.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(p1,p2);
|
||||
return _StrCmp::Equal(p1,p2);
|
||||
}
|
||||
bool StrCmp::EqualCase(utf8string const& s1, const wchar_t* s2)
|
||||
{
|
||||
const wchar_t* p1 = StrAccess(s1).str.c_str();
|
||||
const wchar_t* p1 = s1.c_str();
|
||||
_StrCmp::AdvanceCase(p1,s2);
|
||||
return _StrCmp::Equal(p1,s2);
|
||||
}
|
||||
bool StrCmp::EqualCase(const wchar_t* s1, utf8string const& s2)
|
||||
{
|
||||
const wchar_t* p2 = StrAccess(s2).str.c_str();
|
||||
const wchar_t* p2 = s2.c_str();
|
||||
_StrCmp::AdvanceCase(s1,p2);
|
||||
return _StrCmp::Equal(s1,p2);
|
||||
}
|
||||
|
||||
+59
-58
@@ -1,37 +1,34 @@
|
||||
#ifndef _UTF8STRING_H_
|
||||
#define _UTF8STRING_H_
|
||||
|
||||
#include "vfs_config.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
// simple UTF8 wrapper, uses utf8 implementation from http://utfcpp.sourceforge.net/
|
||||
class utf8string
|
||||
class VFS_API utf8string
|
||||
{
|
||||
friend bool operator<(utf8string const& s1, utf8string const& s2);
|
||||
friend class StrAccess;
|
||||
public:
|
||||
typedef std::wstring str_t;
|
||||
typedef std::wstring::value_type char_t;
|
||||
typedef std::wstring::value_type* ptr_t;
|
||||
typedef std::wstring str_t;
|
||||
typedef str_t::value_type char_t;
|
||||
typedef str_t::value_type* ptr_t;
|
||||
|
||||
typedef std::wstring::size_type size_t;
|
||||
typedef str_t::size_type size_t;
|
||||
////////////////////////////////////////////////////////////////////
|
||||
static bool less(utf8string const& s1, const utf8string& s2);
|
||||
static bool equal(utf8string const& s1, const utf8string& s2);
|
||||
static bool equal(utf8string const& s1, const utf8string::str_t& s2);
|
||||
static bool equal(utf8string const& s1, const utf8string::char_t* s2);
|
||||
static bool less(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
static bool equal(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
// case sensitive
|
||||
static bool lessCase(utf8string const& s1, utf8string const& s2);
|
||||
static bool equalCase(utf8string const& s1, const utf8string& s2);
|
||||
static bool equalCase(utf8string const& s1, const utf8string::str_t& s2);
|
||||
static bool equalCase(utf8string const& s1, const utf8string::char_t* s2);
|
||||
static bool lessCase(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
static bool equalCase(const utf8string::char_t* s1, const utf8string::char_t* s2);
|
||||
|
||||
template<bool (*funName)(utf8string const& s1, utf8string const& s2)>
|
||||
template<bool (*funName)(const utf8string::char_t* s1, const utf8string::char_t* s2)>
|
||||
class Op{
|
||||
public:
|
||||
bool operator()(utf8string const& s1, utf8string const& s2) const
|
||||
bool operator()(const utf8string& s1, const utf8string& s2) const
|
||||
{
|
||||
return funName(s1,s2);
|
||||
return funName(s1.c_str(),s2.c_str());
|
||||
}
|
||||
};
|
||||
typedef Op<utf8string::less> Less;
|
||||
@@ -54,79 +51,83 @@ public:
|
||||
static std::string as_utf8(utf8string const& str);
|
||||
static std::string as_utf8(std::wstring const& str);
|
||||
// if 'strlen' is 0, length is determined automatically
|
||||
static std::string as_utf8(const wchar_t* str, unsigned int strlength=0);
|
||||
static std::string as_utf8(const wchar_t* str, utf8string::size_t strlength=0);
|
||||
//
|
||||
static std::string narrow(wchar_t const* str, size_t length);
|
||||
static size_t narrow(wchar_t const* src_str, size_t src_len, char* dst_str, size_t dst_len);
|
||||
static size_t narrow(std::wstring const& src, std::string& dst);
|
||||
static std::string narrow(wchar_t const* str, utf8string::size_t length);
|
||||
static utf8string::size_t narrow(wchar_t const* src_str, utf8string::size_t src_len, char* dst_str, utf8string::size_t dst_len);
|
||||
static utf8string::size_t narrow(std::wstring const& src, std::string& dst);
|
||||
//
|
||||
static std::wstring widen(char const* str, size_t length);
|
||||
static size_t widen(char const* src_str, size_t src_len, wchar_t* dst_str, size_t dst_len);
|
||||
static size_t widen(std::string const& src, std::wstring& dst);
|
||||
static std::wstring widen(char const* str, utf8string::size_t length);
|
||||
static utf8string::size_t widen(char const* src_str, utf8string::size_t src_len, wchar_t* dst_str, utf8string::size_t dst_len);
|
||||
static utf8string::size_t widen(std::string const& src, std::wstring& dst);
|
||||
|
||||
// convenience method, for the case it should be used in generic code (overloading)
|
||||
static std::string as_utf8(std::string const& str);
|
||||
static std::string as_utf8(std::string const& str);
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// convert string to UTF8 encoding
|
||||
inline std::string utf8() const;
|
||||
inline std::string utf8() const { return as_utf8(_str); }
|
||||
|
||||
// returns const reference to copy or compare string
|
||||
inline std::wstring const& c_wcs() const;
|
||||
inline std::wstring const& c_wcs() const { return _str; }
|
||||
|
||||
inline const wchar_t* c_str() const { return _str.c_str(); }
|
||||
|
||||
// returns reference to modify string
|
||||
std::wstring& r_wcs();
|
||||
inline std::wstring& r_wcs() { return _str; }
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool empty() const;
|
||||
inline utf8string::size_t length() const;
|
||||
utf8string::size_t length() const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
utf8string operator+(utf8string const& str);
|
||||
utf8string operator+=(utf8string const& str);
|
||||
private:
|
||||
std::wstring _str;
|
||||
str_t _str;
|
||||
};
|
||||
|
||||
bool operator<(utf8string const& s1, utf8string const& s2);
|
||||
std::wstringstream& operator<<(std::wstringstream& out, utf8string const& str);
|
||||
std::wstringstream& operator<<(std::wstringstream& out, utf8string::str_t const& str);
|
||||
std::wstringstream& operator<<(std::wstringstream& out, const utf8string::char_t* str);
|
||||
VFS_API std::wstringstream& operator<<(std::wstringstream& out, utf8string const& str);
|
||||
VFS_API std::wstringstream& operator<<(std::wstringstream& out, utf8string::str_t const& str);
|
||||
VFS_API std::wstringstream& operator<<(std::wstringstream& out, const utf8string::char_t* str);
|
||||
|
||||
// explicit compare
|
||||
namespace StrCmp
|
||||
{
|
||||
// case IN-sensitive
|
||||
bool Equal(const char* s1, const char* s2);
|
||||
bool Equal(std::string const& s1, std::string const& s2);
|
||||
bool Equal(std::string const& s1, const char* s2);
|
||||
bool Equal(const char* s1, std::string const& s2);
|
||||
VFS_API bool Equal(const char* s1, const char* s2);
|
||||
VFS_API bool Equal(std::string const& s1, std::string const& s2);
|
||||
VFS_API bool Equal(std::string const& s1, const char* s2);
|
||||
VFS_API bool Equal(const char* s1, std::string const& s2);
|
||||
//
|
||||
bool Equal(const wchar_t* s1, const wchar_t* s2);
|
||||
bool Equal(std::wstring const& s1, std::wstring const& s2);
|
||||
bool Equal(std::wstring const& s1, const wchar_t* s2);
|
||||
bool Equal(const wchar_t* s1, std::wstring const& s2);
|
||||
VFS_API bool Equal(const wchar_t* s1, const wchar_t* s2);
|
||||
VFS_API bool Equal(std::wstring const& s1, std::wstring const& s2);
|
||||
VFS_API bool Equal(std::wstring const& s1, const wchar_t* s2);
|
||||
VFS_API bool Equal(const wchar_t* s1, std::wstring const& s2);
|
||||
//
|
||||
bool Equal(utf8string const& s1, utf8string const& s2);
|
||||
bool Equal(utf8string const& s1, std::wstring const& s2);
|
||||
bool Equal(std::wstring const& s1, utf8string const& s2);
|
||||
bool Equal(utf8string const& s1, const wchar_t* s2);
|
||||
bool Equal(const wchar_t* s1, utf8string const& s2);
|
||||
VFS_API bool Equal(utf8string const& s1, utf8string const& s2);
|
||||
VFS_API bool Equal(utf8string const& s1, std::wstring const& s2);
|
||||
VFS_API bool Equal(std::wstring const& s1, utf8string const& s2);
|
||||
VFS_API bool Equal(utf8string const& s1, const wchar_t* s2);
|
||||
VFS_API bool Equal(const wchar_t* s1, utf8string const& s2);
|
||||
// case Sensitive
|
||||
bool EqualCase(const char* s1, const char* s2);
|
||||
bool EqualCase(std::string const& s1, std::string const& s2);
|
||||
bool EqualCase(std::string const& s1, const char* s2);
|
||||
bool EqualCase(const char* s1, std::string const& s2);
|
||||
VFS_API bool EqualCase(const char* s1, const char* s2);
|
||||
VFS_API bool EqualCase(std::string const& s1, std::string const& s2);
|
||||
VFS_API bool EqualCase(std::string const& s1, const char* s2);
|
||||
VFS_API bool EqualCase(const char* s1, std::string const& s2);
|
||||
//
|
||||
bool EqualCase(const wchar_t* s1, const wchar_t* s2);
|
||||
bool EqualCase(std::wstring const& s1, std::wstring const& s2);
|
||||
bool EqualCase(std::wstring const& s1, const wchar_t* s2);
|
||||
bool EqualCase(const wchar_t* s1, std::wstring const& s2);
|
||||
VFS_API bool EqualCase(const wchar_t* s1, const wchar_t* s2);
|
||||
VFS_API bool EqualCase(std::wstring const& s1, std::wstring const& s2);
|
||||
VFS_API bool EqualCase(std::wstring const& s1, const wchar_t* s2);
|
||||
VFS_API bool EqualCase(const wchar_t* s1, std::wstring const& s2);
|
||||
//
|
||||
bool EqualCase(utf8string const& s1, utf8string const& s2);
|
||||
bool EqualCase(utf8string const& s1, std::wstring const& s2);
|
||||
bool EqualCase(std::wstring const& s1, utf8string const& s2);
|
||||
bool EqualCase(utf8string const& s1, const wchar_t* s2);
|
||||
bool EqualCase(const wchar_t* s1, utf8string const& s2);
|
||||
VFS_API bool EqualCase(utf8string const& s1, utf8string const& s2);
|
||||
VFS_API bool EqualCase(utf8string const& s1, std::wstring const& s2);
|
||||
VFS_API bool EqualCase(std::wstring const& s1, utf8string const& s2);
|
||||
VFS_API bool EqualCase(utf8string const& s1, const wchar_t* s2);
|
||||
VFS_API bool EqualCase(const wchar_t* s1, utf8string const& s2);
|
||||
}
|
||||
|
||||
#endif // _UTF8STRING_H_
|
||||
|
||||
+178
-161
@@ -1,6 +1,7 @@
|
||||
#include "vfs_types.h"
|
||||
#include "vfs.h"
|
||||
|
||||
#include "Interface/vfs_directory_interface.h"
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "File/vfs_file.h"
|
||||
#include "File/vfs_dir_file.h"
|
||||
@@ -15,11 +16,11 @@
|
||||
|
||||
std::vector<BasicAllocator*> CFileAllocator::_valloc;
|
||||
|
||||
void CFileAllocator::RegisterAllocator(BasicAllocator* allocator)
|
||||
void CFileAllocator::registerAllocator(BasicAllocator* allocator)
|
||||
{
|
||||
_valloc.push_back(allocator);
|
||||
}
|
||||
void CFileAllocator::Clear()
|
||||
void CFileAllocator::clear()
|
||||
{
|
||||
std::vector<BasicAllocator*>::iterator it = _valloc.begin();
|
||||
for(; it != _valloc.end(); ++it)
|
||||
@@ -34,26 +35,51 @@ void CFileAllocator::Clear()
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
vfs::CVirtualFileSystem::CRegularIterator::CRegularIterator(vfs::CVirtualFileSystem& rVFS)
|
||||
: vfs::CVirtualFileSystem::Iterator::IImplemetation(), m_rVFS(rVFS)
|
||||
class vfs::CVirtualFileSystem::CRegularIterator : public vfs::CVirtualFileSystem::Iterator::IImplementation
|
||||
{
|
||||
_vloc_iter = m_rVFS.m_mapFS.begin();
|
||||
if(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
friend class vfs::CVirtualFileSystem;
|
||||
typedef vfs::CVirtualFileSystem::Iterator::IImplementation tBaseClass;
|
||||
|
||||
CRegularIterator(vfs::CVirtualFileSystem* pVFS);
|
||||
public:
|
||||
CRegularIterator() : tBaseClass(), m_VFS(NULL)
|
||||
{};
|
||||
virtual ~CRegularIterator()
|
||||
{};
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
CRegularIterator* iter = new CRegularIterator();
|
||||
iter->m_VFS = m_VFS;
|
||||
iter->_vloc_iter = _vloc_iter;
|
||||
iter->_vfile_iter = _vfile_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CVirtualFileSystem* m_VFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
vfs::CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
|
||||
vfs::CVirtualFileSystem::CRegularIterator::CRegularIterator(vfs::CVirtualFileSystem* pVFS)
|
||||
: tBaseClass(), m_VFS(pVFS)
|
||||
{
|
||||
_vloc_iter = m_VFS->m_mapFS.begin();
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::CRegularIterator::~CRegularIterator()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::CRegularIterator::value()
|
||||
{
|
||||
bool bExclusiveVLoc = false;
|
||||
if(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
bExclusiveVLoc = _vloc_iter->second->GetIsExclusive();
|
||||
bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
}
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
@@ -62,11 +88,11 @@ vfs::tReadableFile* vfs::CVirtualFileSystem::CRegularIterator::value()
|
||||
{
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
return vfs::tReadableFile::Cast(pVFile->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE));
|
||||
return vfs::tReadableFile::cast(pVFile->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return vfs::tReadableFile::Cast(pVFile->File(vfs::CVirtualFile::SF_TOP));
|
||||
return vfs::tReadableFile::cast(pVFile->file(vfs::CVirtualFile::SF_TOP));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,10 +106,10 @@ void vfs::CVirtualFileSystem::CRegularIterator::next()
|
||||
}
|
||||
while(_vfile_iter.end())
|
||||
{
|
||||
if(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vloc_iter++;
|
||||
if(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
}
|
||||
@@ -95,12 +121,46 @@ void vfs::CVirtualFileSystem::CRegularIterator::next()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem& rVFS)
|
||||
: vfs::CVirtualFileSystem::Iterator::IImplemetation(), m_rVFS(rVFS)
|
||||
class vfs::CVirtualFileSystem::CMatchingIterator : public vfs::CVirtualFileSystem::Iterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualFileSystem;
|
||||
typedef vfs::CVirtualFileSystem::Iterator::IImplementation tBaseClass;
|
||||
|
||||
CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem* pVFS);
|
||||
public:
|
||||
CMatchingIterator() : tBaseClass(), m_VFS(NULL)
|
||||
{};
|
||||
virtual ~CMatchingIterator()
|
||||
{};
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
CMatchingIterator* iter = new CMatchingIterator();
|
||||
iter->m_sLocPattern = m_sLocPattern;
|
||||
iter->m_sFilePattern = m_sFilePattern;
|
||||
iter->m_VFS = m_VFS;
|
||||
iter->_vloc_iter = _vloc_iter;
|
||||
iter->_vfile_iter = _vfile_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
bool nextLocationMatch();
|
||||
bool nextFileMatch();
|
||||
private:
|
||||
vfs::Path m_sLocPattern, m_sFilePattern;
|
||||
vfs::CVirtualFileSystem* m_VFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
vfs::CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
|
||||
vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem* pVFS)
|
||||
: tBaseClass(), m_VFS(pVFS)
|
||||
{
|
||||
if(sPattern() == vfs::Const::STAR())
|
||||
{
|
||||
@@ -109,31 +169,31 @@ vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& s
|
||||
}
|
||||
else
|
||||
{
|
||||
sPattern.SplitLast(m_sLocPattern,m_sFilePattern);
|
||||
sPattern.splitLast(m_sLocPattern,m_sFilePattern);
|
||||
}
|
||||
|
||||
_vloc_iter = m_rVFS.m_mapFS.begin();
|
||||
while(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
_vloc_iter = m_VFS->m_mapFS.begin();
|
||||
while(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
if( MatchPattern(m_sLocPattern(),_vloc_iter->second->Path()) )
|
||||
if( matchPattern(m_sLocPattern(),_vloc_iter->second->cPath()) )
|
||||
{
|
||||
bool bExclusiveVLoc = _vloc_iter->second->GetIsExclusive();
|
||||
bool bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
while(!_vfile_iter.end())
|
||||
{
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_TOP);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
if(pFile)
|
||||
{
|
||||
vfs::Path const& filename = pFile->GetFileName();
|
||||
if( MatchPattern(m_sFilePattern(),filename()) )
|
||||
vfs::Path const& filename = pFile->getName();
|
||||
if( matchPattern(m_sFilePattern(),filename()) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -145,16 +205,12 @@ vfs::CVirtualFileSystem::CMatchingIterator::CMatchingIterator(vfs::Path const& s
|
||||
}
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::CMatchingIterator::~CMatchingIterator()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::CMatchingIterator::value()
|
||||
{
|
||||
bool bExclusiveVLoc = false;
|
||||
if( _vloc_iter != m_rVFS.m_mapFS.end() )
|
||||
if( _vloc_iter != m_VFS->m_mapFS.end() )
|
||||
{
|
||||
bExclusiveVLoc = _vloc_iter->second->GetIsExclusive();
|
||||
bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
}
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
@@ -164,13 +220,13 @@ vfs::tReadableFile* vfs::CVirtualFileSystem::CMatchingIterator::value()
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_TOP);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
return vfs::tReadableFile::Cast(pFile);
|
||||
return vfs::tReadableFile::cast(pFile);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -178,12 +234,12 @@ vfs::tReadableFile* vfs::CVirtualFileSystem::CMatchingIterator::value()
|
||||
|
||||
bool vfs::CVirtualFileSystem::CMatchingIterator::nextLocationMatch()
|
||||
{
|
||||
while(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
while(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
_vloc_iter++;
|
||||
if(_vloc_iter != m_rVFS.m_mapFS.end())
|
||||
if(_vloc_iter != m_VFS->m_mapFS.end())
|
||||
{
|
||||
if(MatchPattern(m_sLocPattern(),_vloc_iter->second->Path()))
|
||||
if(matchPattern(m_sLocPattern(),_vloc_iter->second->cPath()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -194,9 +250,9 @@ bool vfs::CVirtualFileSystem::CMatchingIterator::nextLocationMatch()
|
||||
bool vfs::CVirtualFileSystem::CMatchingIterator::nextFileMatch()
|
||||
{
|
||||
bool bExclusiveVLoc = false;
|
||||
if( _vloc_iter != m_rVFS.m_mapFS.end() )
|
||||
if( _vloc_iter != m_VFS->m_mapFS.end() )
|
||||
{
|
||||
bExclusiveVLoc = _vloc_iter->second->GetIsExclusive();
|
||||
bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
}
|
||||
while(!_vfile_iter.end())
|
||||
{
|
||||
@@ -206,16 +262,16 @@ bool vfs::CVirtualFileSystem::CMatchingIterator::nextFileMatch()
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_TOP);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
if(pFile)
|
||||
{
|
||||
vfs::Path const& filename = pFile->GetFileName();
|
||||
if(MatchPattern(m_sFilePattern(),filename()))
|
||||
vfs::Path const& filename = pFile->getName();
|
||||
if(matchPattern(m_sFilePattern(),filename()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -236,17 +292,17 @@ void vfs::CVirtualFileSystem::CMatchingIterator::next()
|
||||
_vfile_iter = _vloc_iter->second->iterate();
|
||||
if(!_vfile_iter.end())
|
||||
{
|
||||
bool bExclusiveVLoc = _vloc_iter->second->GetIsExclusive();
|
||||
bool bExclusiveVLoc = _vloc_iter->second->getIsExclusive();
|
||||
vfs::IBaseFile* pFile = NULL;
|
||||
if(bExclusiveVLoc)
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
pFile = _vfile_iter.value()->File(vfs::CVirtualFile::SF_TOP);
|
||||
pFile = _vfile_iter.value()->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
if(pFile && MatchPattern(m_sFilePattern(),pFile->GetFileName()()))
|
||||
if(pFile && matchPattern(m_sFilePattern(),pFile->getName()()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -261,54 +317,14 @@ void vfs::CVirtualFileSystem::CMatchingIterator::next()
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator::Iterator()
|
||||
: _iter_impl(NULL), _file(NULL)
|
||||
{};
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator::Iterator(vfs::CVirtualFileSystem::Iterator::IImplemetation* impl)
|
||||
: _iter_impl(impl), _file(NULL)
|
||||
vfs::CVirtualFileSystem* getVFS()
|
||||
{
|
||||
THROWIFFALSE(_iter_impl, L"EXCEPTION");
|
||||
_file = _iter_impl->value();
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator::~Iterator()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::Iterator::value()
|
||||
{
|
||||
return _file;
|
||||
};
|
||||
void vfs::CVirtualFileSystem::Iterator::next()
|
||||
{
|
||||
if(_iter_impl)
|
||||
{
|
||||
_iter_impl->next();
|
||||
_file = _iter_impl->value();
|
||||
if(!_file)
|
||||
{
|
||||
delete _iter_impl;
|
||||
_iter_impl = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool vfs::CVirtualFileSystem::Iterator::end()
|
||||
{
|
||||
return _file == NULL;
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
vfs::CVirtualFileSystem* GetVFS()
|
||||
{
|
||||
return vfs::CVirtualFileSystem::GetVFS();
|
||||
return vfs::CVirtualFileSystem::getVFS();
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem* vfs::CVirtualFileSystem::m_pSingleton = NULL;
|
||||
|
||||
vfs::CVirtualFileSystem* vfs::CVirtualFileSystem::GetVFS()
|
||||
vfs::CVirtualFileSystem* vfs::CVirtualFileSystem::getVFS()
|
||||
{
|
||||
if(!m_pSingleton)
|
||||
{
|
||||
@@ -317,7 +333,7 @@ vfs::CVirtualFileSystem* vfs::CVirtualFileSystem::GetVFS()
|
||||
return m_pSingleton;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFileSystem::ShutdownVFS()
|
||||
void vfs::CVirtualFileSystem::shutdownVFS()
|
||||
{
|
||||
if(m_pSingleton)
|
||||
{
|
||||
@@ -341,98 +357,98 @@ vfs::CVirtualFileSystem::~CVirtualFileSystem()
|
||||
m_mapFS.clear();
|
||||
}
|
||||
|
||||
vfs::CProfileStack* vfs::CVirtualFileSystem::GetProfileStack()
|
||||
vfs::CProfileStack* vfs::CVirtualFileSystem::getProfileStack()
|
||||
{
|
||||
return &m_oProfileStack;
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator vfs::CVirtualFileSystem::begin()
|
||||
{
|
||||
return Iterator(new vfs::CVirtualFileSystem::CRegularIterator(*this));
|
||||
return Iterator(new vfs::CVirtualFileSystem::CRegularIterator(this));
|
||||
}
|
||||
|
||||
vfs::CVirtualFileSystem::Iterator vfs::CVirtualFileSystem::begin(vfs::Path const& sPattern)
|
||||
{
|
||||
return Iterator(new vfs::CVirtualFileSystem::CMatchingIterator(sPattern,*this));
|
||||
return Iterator(new vfs::CVirtualFileSystem::CMatchingIterator(sPattern,this));
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::AddLocation(vfs::IBaseLocation* pLocation, utf8string const& sProfileName, bool bIsWriteable)
|
||||
bool vfs::CVirtualFileSystem::addLocation(vfs::IBaseLocation* pLocation, utf8string const& sProfileName, bool bIsWritable)
|
||||
{
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.GetProfile(sProfileName);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.getProfile(sProfileName);
|
||||
if(!pProf)
|
||||
{
|
||||
pProf = new vfs::CVirtualProfile(sProfileName, bIsWriteable);
|
||||
m_oProfileStack.PushProfile(pProf);
|
||||
pProf = new vfs::CVirtualProfile(sProfileName, bIsWritable);
|
||||
m_oProfileStack.pushProfile(pProf);
|
||||
}
|
||||
pProf->AddLocation(pLocation);
|
||||
pProf->addLocation(pLocation);
|
||||
|
||||
std::list<vfs::Path> lSubDirs;
|
||||
pLocation->GetSubDirList(lSubDirs);
|
||||
pLocation->getSubDirList(lSubDirs);
|
||||
std::list<vfs::Path>::const_iterator sd_cit = lSubDirs.begin();
|
||||
for(;sd_cit != lSubDirs.end(); ++sd_cit)
|
||||
{
|
||||
this->GetVirtualLocation(*sd_cit, true);
|
||||
this->getVirtualLocation(*sd_cit, true);
|
||||
}
|
||||
|
||||
vfs::IBaseLocation::Iterator it = pLocation->begin();
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
vfs::IBaseFile *pFile = it.value();
|
||||
vfs::Path const& sPath = pFile->GetFullPath();
|
||||
vfs::Path const& sPath = pFile->getPath();
|
||||
vfs::Path dir,file;
|
||||
sPath.SplitLast(dir,file);
|
||||
sPath.splitLast(dir,file);
|
||||
|
||||
CVirtualLocation* pLoc = this->GetVirtualLocation(dir,true);
|
||||
pLoc->AddFile(pFile,sProfileName);
|
||||
CVirtualLocation* pLoc = this->getVirtualLocation(dir,true);
|
||||
pLoc->addFile(pFile,sProfileName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::GetRFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::getReadFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
return vfs::tReadableFile::Cast(this->GetFile(rLocalFilePath,eSF));
|
||||
return vfs::tReadableFile::cast(this->getFile(rLocalFilePath,eSF));
|
||||
}
|
||||
|
||||
vfs::tWriteableFile* vfs::CVirtualFileSystem::GetWFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
vfs::tWritableFile* vfs::CVirtualFileSystem::getWriteFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
return vfs::tWriteableFile::Cast(this->GetFile(rLocalFilePath,eSF));
|
||||
return vfs::tWritableFile::cast(this->getFile(rLocalFilePath,eSF));
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFileSystem::GetFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
vfs::IBaseFile* vfs::CVirtualFileSystem::getFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
rLocalFilePath.SplitLast(sDir,sFile);
|
||||
rLocalFilePath.splitLast(sDir,sFile);
|
||||
|
||||
vfs::CVirtualLocation* pVLoc = this->GetVirtualLocation(sDir);
|
||||
vfs::CVirtualLocation* pVLoc = this->getVirtualLocation(sDir);
|
||||
if(pVLoc)
|
||||
{
|
||||
vfs::CVirtualFile *pVFile = pVLoc->GetVFile(sFile);
|
||||
vfs::CVirtualFile *pVFile = pVLoc->getVirtualFile(sFile);
|
||||
if(pVFile)
|
||||
{
|
||||
if(pVLoc->GetIsExclusive())
|
||||
if(pVLoc->getIsExclusive())
|
||||
{
|
||||
return pVFile->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
return pVFile->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
return pVFile->File(eSF);
|
||||
return pVFile->file(eSF);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::GetRFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
vfs::tReadableFile* vfs::CVirtualFileSystem::getReadFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
{
|
||||
return vfs::tReadableFile::Cast(this->GetFile(rLocalFilePath, sProfileName));
|
||||
return vfs::tReadableFile::cast(this->getFile(rLocalFilePath, sProfileName));
|
||||
}
|
||||
|
||||
vfs::tWriteableFile* vfs::CVirtualFileSystem::GetWFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
vfs::tWritableFile* vfs::CVirtualFileSystem::getWriteFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
{
|
||||
return vfs::tWriteableFile::Cast(this->GetFile(rLocalFilePath, sProfileName));
|
||||
return vfs::tWritableFile::cast(this->getFile(rLocalFilePath, sProfileName));
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFileSystem::GetFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
vfs::IBaseFile* vfs::CVirtualFileSystem::getFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
rLocalFilePath.SplitLast(sDir,sFile);
|
||||
rLocalFilePath.splitLast(sDir,sFile);
|
||||
|
||||
tVFS::iterator it_loc = m_mapFS.find(sDir);
|
||||
if(it_loc == m_mapFS.end())
|
||||
@@ -442,22 +458,22 @@ vfs::IBaseFile* vfs::CVirtualFileSystem::GetFile(vfs::Path const& rLocalFilePath
|
||||
vfs::CVirtualLocation* pVLoc = it_loc->second;
|
||||
if(pVLoc)
|
||||
{
|
||||
return pVLoc->GetFile(sFile,sProfileName);
|
||||
return pVLoc->getFile(sFile,sProfileName);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::FileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName)
|
||||
bool vfs::CVirtualFileSystem::fileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName)
|
||||
{
|
||||
return GetFile(rLocalFilePath, sProfileName) != NULL;
|
||||
return this->getFile(rLocalFilePath, sProfileName) != NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::FileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
bool vfs::CVirtualFileSystem::fileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
return GetFile(rLocalFilePath, eSF) != NULL;
|
||||
return this->getFile(rLocalFilePath, eSF) != NULL;
|
||||
}
|
||||
|
||||
vfs::CVirtualLocation* vfs::CVirtualFileSystem::GetVirtualLocation(vfs::Path const& sPath, bool bCreate)
|
||||
vfs::CVirtualLocation* vfs::CVirtualFileSystem::getVirtualLocation(vfs::Path const& sPath, bool bCreate)
|
||||
{
|
||||
tVFS::iterator it = m_mapFS.find(sPath);
|
||||
if(it == m_mapFS.end())
|
||||
@@ -473,7 +489,7 @@ vfs::CVirtualLocation* vfs::CVirtualFileSystem::GetVirtualLocation(vfs::Path con
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::RemoveDirectoryFromFS(vfs::Path const& sDir)
|
||||
bool vfs::CVirtualFileSystem::removeDirectoryFromFS(vfs::Path const& sDir)
|
||||
{
|
||||
vfs::Path pattern = sDir + "*";
|
||||
std::list<vfs::Path> files;
|
||||
@@ -481,80 +497,81 @@ bool vfs::CVirtualFileSystem::RemoveDirectoryFromFS(vfs::Path const& sDir)
|
||||
Iterator it = this->begin(pattern);
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
if(it.value()->IsWriteable())
|
||||
if(it.value()->implementsWritable())
|
||||
{
|
||||
files.push_back(it.value()->GetFullPath());
|
||||
files.push_back(it.value()->getPath());
|
||||
}
|
||||
}
|
||||
bool success = true;
|
||||
std::list<vfs::Path>::iterator fit = files.begin();
|
||||
for(; fit != files.end(); ++fit)
|
||||
{
|
||||
success &= this->RemoveFileFromFS(*fit);
|
||||
success &= this->removeFileFromFS(*fit);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::RemoveFileFromFS(vfs::Path const& sFilePath)
|
||||
bool vfs::CVirtualFileSystem::removeFileFromFS(vfs::Path const& sFilePath)
|
||||
{
|
||||
vfs::Path sPath,sFile;
|
||||
sFilePath.SplitLast(sPath,sFile);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.GetWriteProfile();
|
||||
sFilePath.splitLast(sPath,sFile);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
|
||||
if(pProf)
|
||||
{
|
||||
vfs::IBaseLocation *pBL = pProf->GetLocation(sPath);
|
||||
if(pBL && pBL->IsWriteable())
|
||||
vfs::IBaseLocation *pBL = pProf->getLocation(sPath);
|
||||
if(pBL && pBL->implementsWritable())
|
||||
{
|
||||
vfs::IDirectory<vfs::IWriteable> *pDir = pBL->Cast<vfs::IDirectory<vfs::IWriteable> >();
|
||||
vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pBL);
|
||||
if(pDir)
|
||||
{
|
||||
bool bSuccess = false;
|
||||
// remove file from virtual structures first
|
||||
vfs::IBaseFile* file = pDir->GetFile(sFilePath);
|
||||
vfs::IBaseFile* file = pDir->getFile(sFilePath);
|
||||
if(file)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sFilePath.SplitLast(sDir,sFile);
|
||||
vfs::CVirtualLocation *pVLoc = this->GetVirtualLocation(sDir);
|
||||
sFilePath.splitLast(sDir,sFile);
|
||||
vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sDir);
|
||||
if(pVLoc)
|
||||
{
|
||||
bSuccess = pVLoc->RemoveFile(file);
|
||||
bSuccess = pVLoc->removeFile(file);
|
||||
}
|
||||
}
|
||||
// delete actual file
|
||||
return bSuccess && pDir->DeleteFileFromDirectory(sFilePath);
|
||||
return bSuccess && pDir->deleteFileFromDirectory(sFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualFileSystem::CreateNewFile(vfs::Path const& sFileName)
|
||||
bool vfs::CVirtualFileSystem::createNewFile(vfs::Path const& sFilename)
|
||||
{
|
||||
vfs::Path sPath,sFile;
|
||||
sFileName.SplitLast(sPath,sFile);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.GetWriteProfile();
|
||||
sFilename.splitLast(sPath,sFile);
|
||||
vfs::CVirtualProfile *pProf = m_oProfileStack.getWriteProfile();
|
||||
if(pProf)
|
||||
{
|
||||
bool bIsExclusive = false;
|
||||
bool bNewLocation = false;
|
||||
vfs::IBaseLocation *pProfLoc = pProf->GetLocation(sPath);
|
||||
vfs::IBaseLocation *pProfLoc = pProf->getLocation(sPath);
|
||||
if(!pProfLoc)
|
||||
{
|
||||
// try to find closest match
|
||||
vfs::Path sTemp, sCreateDir, sRight, sLeft = sPath;
|
||||
while(!pProfLoc && sLeft.SplitLast(sTemp,sRight))
|
||||
while(!pProfLoc && !sLeft.empty())
|
||||
{
|
||||
sLeft.splitLast(sTemp,sRight);
|
||||
sLeft = sTemp;
|
||||
sCreateDir = sRight + sCreateDir;
|
||||
pProfLoc = pProf->GetLocation(sLeft);
|
||||
pProfLoc = pProf->getLocation(sLeft);
|
||||
}
|
||||
// see if the closest match is exclusive
|
||||
// if yes, then the the new path is a subdirectory and has to be exclusive too
|
||||
vfs::CVirtualLocation *pVLoc = this->GetVirtualLocation(sLeft,true);
|
||||
vfs::CVirtualLocation *pVLoc = this->getVirtualLocation(sLeft,true);
|
||||
if(pVLoc)
|
||||
{
|
||||
bIsExclusive = pVLoc->GetIsExclusive();
|
||||
bIsExclusive = pVLoc->getIsExclusive();
|
||||
}
|
||||
//else
|
||||
//{
|
||||
@@ -562,23 +579,23 @@ bool vfs::CVirtualFileSystem::CreateNewFile(vfs::Path const& sFileName)
|
||||
//}
|
||||
bNewLocation = true;
|
||||
}
|
||||
if(pProfLoc && pProfLoc->IsWriteable())
|
||||
if(pProfLoc && pProfLoc->implementsWritable())
|
||||
{
|
||||
// create file and add to location
|
||||
vfs::IDirectory<vfs::IWriteable> *pDir = pProfLoc->Cast<vfs::IDirectory<vfs::IWriteable> >();
|
||||
vfs::IBaseFile* pFile = pDir->AddFile(sFileName);
|
||||
vfs::TDirectory<vfs::IWritable> *pDir = dynamic_cast<vfs::TDirectory<vfs::IWritable>*>(pProfLoc);
|
||||
vfs::IBaseFile* pFile = pDir->addFile(sFilename);
|
||||
if(bNewLocation)
|
||||
{
|
||||
pProf->AddLocation(pProfLoc);
|
||||
pProf->addLocation(pProfLoc);
|
||||
}
|
||||
if(pFile)
|
||||
{
|
||||
CVirtualLocation* pLoc = this->GetVirtualLocation(sPath,true);
|
||||
CVirtualLocation* pLoc = this->getVirtualLocation(sPath,true);
|
||||
if(bIsExclusive)
|
||||
{
|
||||
pLoc->SetIsExclusive(bIsExclusive);
|
||||
pLoc->setIsExclusive(bIsExclusive);
|
||||
}
|
||||
pLoc->AddFile(pFile,pProf->Name);
|
||||
pLoc->addFile(pFile,pProf->cName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "Interface/vfs_location_interface.h"
|
||||
#include "Interface/vfs_iterator_interface.h"
|
||||
#include "vfs_vloc.h"
|
||||
#include "vfs_vfile.h"
|
||||
#include "vfs_types.h"
|
||||
#include <map>
|
||||
|
||||
#define USE_VFS
|
||||
|
||||
|
||||
class CFileAllocator
|
||||
{
|
||||
public:
|
||||
static void RegisterAllocator(BasicAllocator* allocator);
|
||||
static void registerAllocator(BasicAllocator* allocator);
|
||||
|
||||
static void Clear();
|
||||
static void clear();
|
||||
private:
|
||||
static std::vector<BasicAllocator*> _valloc;
|
||||
};
|
||||
@@ -25,103 +23,47 @@ namespace vfs
|
||||
{
|
||||
class CProfileStack;
|
||||
|
||||
class CVirtualFileSystem
|
||||
class VFS_API CVirtualFileSystem
|
||||
{
|
||||
typedef std::map<vfs::Path,CVirtualLocation*,vfs::Path::Less> tVFS;
|
||||
|
||||
class CRegularIterator;
|
||||
class CMatchingIterator;
|
||||
public:
|
||||
/*****************************************************/
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
//////////////////////////////
|
||||
class IImplemetation
|
||||
{
|
||||
public:
|
||||
virtual ~IImplemetation() {};
|
||||
virtual vfs::tReadableFile* value() = 0;
|
||||
virtual void next() = 0;
|
||||
};
|
||||
//////////////////////////////
|
||||
private:
|
||||
friend class CVirtualFileSystem;
|
||||
Iterator(IImplemetation* impl);
|
||||
public:
|
||||
Iterator();
|
||||
~Iterator();
|
||||
typedef TIterator<vfs::tReadableFile> Iterator;
|
||||
|
||||
vfs::tReadableFile* value();
|
||||
void next();
|
||||
bool end();
|
||||
private:
|
||||
IImplemetation* _iter_impl;
|
||||
vfs::tReadableFile* _file;
|
||||
};
|
||||
/*****************************************************/
|
||||
class CRegularIterator : public vfs::CVirtualFileSystem::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
CRegularIterator(vfs::CVirtualFileSystem& rVFS);
|
||||
virtual ~CRegularIterator();
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
private:
|
||||
vfs::CVirtualFileSystem& m_rVFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
/*****************************************************/
|
||||
class CMatchingIterator : public vfs::CVirtualFileSystem::Iterator::IImplemetation
|
||||
{
|
||||
public:
|
||||
CMatchingIterator(vfs::Path const& sPattern, vfs::CVirtualFileSystem& rVFS);
|
||||
virtual ~CMatchingIterator();
|
||||
|
||||
virtual vfs::tReadableFile* value();
|
||||
virtual void next();
|
||||
private:
|
||||
bool nextLocationMatch();
|
||||
bool nextFileMatch();
|
||||
private:
|
||||
vfs::Path m_sLocPattern, m_sFilePattern;
|
||||
vfs::CVirtualFileSystem& m_rVFS;
|
||||
vfs::CVirtualFileSystem::tVFS::iterator _vloc_iter;
|
||||
CVirtualLocation::Iterator _vfile_iter;
|
||||
};
|
||||
/*****************************************************/
|
||||
public:
|
||||
~CVirtualFileSystem();
|
||||
|
||||
static CVirtualFileSystem* GetVFS();
|
||||
static void ShutdownVFS();
|
||||
static CVirtualFileSystem* getVFS();
|
||||
static void shutdownVFS();
|
||||
|
||||
CProfileStack* GetProfileStack();
|
||||
vfs::CProfileStack* getProfileStack();
|
||||
|
||||
vfs::CVirtualLocation* GetVirtualLocation(vfs::Path const& sPath, bool bCreate = false);
|
||||
bool AddLocation(vfs::IBaseLocation* pLocation,
|
||||
vfs::CVirtualLocation* getVirtualLocation(vfs::Path const& sPath, bool bCreate = false);
|
||||
bool addLocation(vfs::IBaseLocation* pLocation,
|
||||
utf8string const& sProfileName,
|
||||
bool bIsWriteable = false);
|
||||
bool bIsWritable = false);
|
||||
|
||||
bool FileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
bool FileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName);
|
||||
bool fileExists(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
bool fileExists(vfs::Path const& rLocalFilePath, std::string const& sProfileName);
|
||||
|
||||
vfs::IBaseFile* GetFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::IBaseFile* GetFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
vfs::IBaseFile* getFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::IBaseFile* getFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
vfs::tReadableFile* GetRFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tReadableFile* GetRFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
vfs::tReadableFile* getReadFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tReadableFile* getReadFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
vfs::tWriteableFile* GetWFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tWriteableFile* GetWFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
vfs::tWritableFile* getWriteFile(vfs::Path const& rLocalFilePath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP );
|
||||
vfs::tWritableFile* getWriteFile(vfs::Path const& rLocalFilePath, utf8string const& sProfileName);
|
||||
|
||||
bool RemoveFileFromFS(vfs::Path const& sFilePath);
|
||||
bool RemoveDirectoryFromFS(vfs::Path const& sDir);
|
||||
bool CreateNewFile(vfs::Path const& sFileName);
|
||||
bool removeFileFromFS(vfs::Path const& sFilePath);
|
||||
bool removeDirectoryFromFS(vfs::Path const& sDir);
|
||||
bool createNewFile(vfs::Path const& sFileName);
|
||||
|
||||
Iterator begin();
|
||||
Iterator begin(vfs::Path const& sPattern);
|
||||
private:
|
||||
CProfileStack m_oProfileStack;
|
||||
vfs::CProfileStack m_oProfileStack;
|
||||
tVFS m_mapFS;
|
||||
private:
|
||||
CVirtualFileSystem();
|
||||
@@ -130,6 +72,6 @@ namespace vfs
|
||||
|
||||
} // end namespace
|
||||
|
||||
vfs::CVirtualFileSystem* GetVFS();
|
||||
VFS_API vfs::CVirtualFileSystem* getVFS();
|
||||
|
||||
#endif // _VFS_H_
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef _VFS_CONFIG_H_
|
||||
#define _VFS_CONFIG_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef _MSC_VER
|
||||
#ifndef PRINT_DLL_INTERFACE_WARNING
|
||||
#pragma warning ( disable : 4251 )
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// VFS_STATIC overrides VFS_EXPORT
|
||||
#ifdef VFS_STATIC
|
||||
#define VFS_API
|
||||
#endif
|
||||
|
||||
#ifndef VFS_STATIC
|
||||
#ifdef VFS_EXPORT
|
||||
#define VFS_API __declspec(dllexport)
|
||||
#else
|
||||
#define VFS_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define VFS_API
|
||||
#endif
|
||||
|
||||
#endif // _VFS_CONFIG_H_
|
||||
+59
-25
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "utf8string.h"
|
||||
#include "vfs_file_raii.h"
|
||||
#include "FILE/vfs_file.h"
|
||||
#include "File/vfs_file.h"
|
||||
|
||||
#include "Tools/Log.h"
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <ctime>
|
||||
|
||||
CBasicException::CBasicException(const wchar_t* text, const char* function, int line, const char* file, CBasicException* ex)
|
||||
: std::exception(utf8string::as_utf8(text).c_str())
|
||||
: std::exception() //(utf8string::as_utf8(text).c_str())
|
||||
{
|
||||
if(ex)
|
||||
{
|
||||
@@ -35,7 +35,7 @@ CBasicException::CBasicException(const wchar_t* text, const char* function, int
|
||||
};
|
||||
|
||||
CBasicException::CBasicException(utf8string const& text, utf8string const& function, int line, const char* file, CBasicException* ex)
|
||||
: std::exception(text.utf8().c_str())
|
||||
: std::exception() //(text.utf8().c_str())
|
||||
{
|
||||
if(ex)
|
||||
{
|
||||
@@ -59,19 +59,41 @@ CBasicException::CBasicException(utf8string const& text, utf8string const& funct
|
||||
m_CallStack.push_back(en);
|
||||
};
|
||||
|
||||
utf8string CBasicException::GetLastEntryString() const
|
||||
CBasicException::~CBasicException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
utf8string CBasicException::getLastEntryString() const
|
||||
{
|
||||
if(!m_CallStack.empty())
|
||||
{
|
||||
CALLSTACK::const_reverse_iterator rit = m_CallStack.rbegin();
|
||||
std::wstringstream ss;
|
||||
ss << rit->file.c_wcs() << L" (l. " << rit->line<< ") : [" << rit->function.c_wcs() << L"] - " << rit->message.c_wcs();
|
||||
return ss.str();
|
||||
std::wstringstream wss;
|
||||
wss << rit->file.c_wcs()
|
||||
<< L" (l. "
|
||||
<< rit->line
|
||||
<< ") : ["
|
||||
<< rit->function.c_wcs()
|
||||
<< L"] - "
|
||||
<< rit->message.c_wcs();
|
||||
return wss.str();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
utf8string CBasicException::GetExceptionString() const
|
||||
const char* CBasicException::what() const throw()
|
||||
{
|
||||
static std::string msg;
|
||||
if(!m_CallStack.empty())
|
||||
{
|
||||
//msg = m_CallStack.front().message.utf8();
|
||||
msg = this->getExceptionString().utf8();
|
||||
}
|
||||
return msg.c_str();
|
||||
}
|
||||
|
||||
|
||||
utf8string CBasicException::getExceptionString() const
|
||||
{
|
||||
if(!m_CallStack.empty())
|
||||
{
|
||||
@@ -83,43 +105,41 @@ utf8string CBasicException::GetExceptionString() const
|
||||
wss << L"File : " << rit->file << L"\r\n";
|
||||
wss << L"Line : " << rit->line << L"\r\n";
|
||||
wss << L"Location : " << rit->function << L"\r\n\r\n";
|
||||
wss << L" " << rit->message << L"\r\n\r\n";
|
||||
wss << L" " << rit->message << L"\r\n";
|
||||
}
|
||||
return wss.str();
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
|
||||
void CBasicException::WriteFile(vfs::Path const& sPath)
|
||||
void CBasicException::writeFile(vfs::Path const& sPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
vfs::COpenWriteFile oFile(sPath,true,true);
|
||||
utf8string s = this->GetExceptionString();
|
||||
vfs::UInt32 written;
|
||||
oFile.file().Write(s.utf8().c_str(),s.length(),written);
|
||||
oFile.file().Close();
|
||||
utf8string s = this->getExceptionString();
|
||||
oFile.file().write(s.utf8().c_str(), s.length());
|
||||
oFile.file().close();
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
CBasicException ex2(L"Could not write exception file into VFS",
|
||||
_FUNCTION_FORMAT_,__LINE__,__FILE__, &ex);
|
||||
CBasicException out("Writing exception to disc failed : is there no writeable profile?",
|
||||
CBasicException out("Writing exception to disc failed : is there no writable profile?",
|
||||
_FUNCTION_FORMAT_,__LINE__,__FILE__, this);
|
||||
|
||||
out.m_CallStack.insert(out.m_CallStack.begin(),ex.m_CallStack.begin(),ex.m_CallStack.end());
|
||||
|
||||
vfs::Path sDir,sFile;
|
||||
sPath.SplitLast(sDir,sFile);
|
||||
sPath.splitLast(sDir,sFile);
|
||||
vfs::CFile oFile(sFile);
|
||||
|
||||
try
|
||||
{
|
||||
// can also fail, but there is only so much we can do
|
||||
vfs::COpenWriteFile file( vfs::tWriteableFile::Cast(&oFile) );
|
||||
utf8string s = out.GetExceptionString();
|
||||
vfs::UInt32 written;
|
||||
file.file().Write(s.utf8().c_str(),s.length(),written);
|
||||
vfs::COpenWriteFile file( vfs::tWritableFile::cast(&oFile) );
|
||||
utf8string s = out.getExceptionString();
|
||||
file.file().write(s.utf8().c_str(), s.length());
|
||||
}
|
||||
catch(CBasicException &fex)
|
||||
{
|
||||
@@ -128,18 +148,32 @@ void CBasicException::WriteFile(vfs::Path const& sPath)
|
||||
}
|
||||
}
|
||||
|
||||
void LogException(CBasicException const& ex)
|
||||
void logException(CBasicException const& ex)
|
||||
{
|
||||
static CLog& exlog = *CLog::Create(L"game_exceptions.log");
|
||||
static bool is_logging = false;
|
||||
if(is_logging)
|
||||
{
|
||||
// drop message
|
||||
return;
|
||||
}
|
||||
//////////////////
|
||||
is_logging = true;
|
||||
//////////////////
|
||||
|
||||
static CLog& exlog = *CLog::create(L"game_exceptions.log", false, CLog::FLUSH_IMMEDIATELY);
|
||||
try
|
||||
{
|
||||
exlog << ">>>>>>>>>>>>>>>>>>>>>" << CLog::endl;
|
||||
exlog << ex.GetExceptionString();
|
||||
exlog << "<<<<<<<<<<<<<<<<<<<<<" << CLog::endl << CLog::endl;
|
||||
exlog << ">>>>>>>>>>>>>>>>>>>>>" << CLog::ENDL;
|
||||
exlog << ex.getExceptionString();
|
||||
exlog << "<<<<<<<<<<<<<<<<<<<<<" << CLog::ENDL << CLog::ENDL;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// don't throw at all
|
||||
}
|
||||
|
||||
//////////////////
|
||||
is_logging = false;
|
||||
//////////////////
|
||||
}
|
||||
|
||||
|
||||
+15
-6
@@ -2,18 +2,27 @@
|
||||
#define _VFS_DEBUG_H_
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "vfs_path.h"
|
||||
#include <list>
|
||||
|
||||
class CBasicException : public std::exception
|
||||
#ifdef _MSC_VER
|
||||
class VFS_API std::exception;
|
||||
#endif
|
||||
|
||||
class VFS_API CBasicException : public std::exception
|
||||
{
|
||||
public:
|
||||
CBasicException(const wchar_t* text, const char* function, int line, const char* file, CBasicException* ex=NULL);
|
||||
CBasicException(utf8string const& text, utf8string const& function, int line, const char* file, CBasicException* ex=NULL);
|
||||
|
||||
utf8string GetLastEntryString() const;
|
||||
utf8string GetExceptionString() const;
|
||||
virtual ~CBasicException() throw();
|
||||
|
||||
void WriteFile(vfs::Path const& sPath);
|
||||
virtual const char* what() const throw();
|
||||
|
||||
utf8string getLastEntryString() const;
|
||||
utf8string getExceptionString() const;
|
||||
|
||||
void writeFile(vfs::Path const& sPath);
|
||||
|
||||
struct SEntry
|
||||
{
|
||||
@@ -32,7 +41,7 @@ public:
|
||||
utf8string _time;
|
||||
};
|
||||
|
||||
void LogException(CBasicException const& ex);
|
||||
void logException(CBasicException const& ex);
|
||||
|
||||
#ifdef WIN32
|
||||
#define _FUNCTION_FORMAT_ __FUNCTION__
|
||||
@@ -55,7 +64,7 @@ void LogException(CBasicException const& ex);
|
||||
#define IGNOREEXCEPTION(expr) \
|
||||
{ \
|
||||
try{ (expr); } \
|
||||
catch(CBasicException& ex){ LogException(ex); } \
|
||||
catch(CBasicException& ex){ logException(ex); } \
|
||||
}
|
||||
|
||||
#endif // _VFS_DEBUG_H_
|
||||
|
||||
+38
-38
@@ -7,11 +7,17 @@
|
||||
|
||||
vfs::COpenReadFile::COpenReadFile(vfs::Path const& sPath, vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
vfs::IBaseFile *pFile = GetVFS()->GetFile(sPath,eSF);
|
||||
THROWIFFALSE(pFile, (L"file \"" + sPath().c_wcs() + L"\" does not exist").c_str());
|
||||
m_pFile = vfs::tReadableFile::Cast(pFile);
|
||||
THROWIFFALSE(m_pFile, L"not readable");
|
||||
THROWIFFALSE(m_pFile->OpenRead(), L"open read failed");
|
||||
vfs::IBaseFile *pFile = getVFS()->getFile(sPath,eSF);
|
||||
THROWIFFALSE(pFile,
|
||||
BuildString().add(L"file \"").add(sPath).add(L"\" does not exist").get());
|
||||
|
||||
m_pFile = vfs::tReadableFile::cast(pFile);
|
||||
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" is not readable").get());
|
||||
|
||||
THROWIFFALSE(m_pFile->openRead(),
|
||||
BuildString().add(L"Could not open file : ").add(m_pFile->getPath()).get());
|
||||
}
|
||||
|
||||
vfs::COpenReadFile::COpenReadFile(vfs::tReadableFile *pFile)
|
||||
@@ -19,8 +25,11 @@ vfs::COpenReadFile::COpenReadFile(vfs::tReadableFile *pFile)
|
||||
try
|
||||
{
|
||||
m_pFile = pFile;
|
||||
THROWIFFALSE(m_pFile, L"no file");
|
||||
THROWIFFALSE(m_pFile->OpenRead(), L"not open");
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"Invalid file object").get());
|
||||
|
||||
THROWIFFALSE(m_pFile->openRead(),
|
||||
BuildString().add(L"Could not open file : ").add(pFile->getPath()).get());
|
||||
}
|
||||
catch(CBasicException &ex)
|
||||
{
|
||||
@@ -31,7 +40,7 @@ vfs::COpenReadFile::~COpenReadFile()
|
||||
{
|
||||
if(m_pFile)
|
||||
{
|
||||
m_pFile->Close();
|
||||
m_pFile->close();
|
||||
m_pFile = NULL;
|
||||
}
|
||||
}
|
||||
@@ -53,47 +62,38 @@ vfs::COpenWriteFile::COpenWriteFile(vfs::Path const& sPath,
|
||||
bool bTruncate,
|
||||
vfs::CVirtualFile::ESearchFile eSF)
|
||||
{
|
||||
vfs::IBaseFile *pFile = GetVFS()->GetFile(sPath,eSF);
|
||||
vfs::IBaseFile *pFile = getVFS()->getFile(sPath,eSF);
|
||||
if(!pFile && bCreate)
|
||||
{
|
||||
if(GetVFS()->CreateNewFile(sPath))
|
||||
if(getVFS()->createNewFile(sPath))
|
||||
{
|
||||
pFile = GetVFS()->GetFile(sPath,eSF);
|
||||
pFile = getVFS()->getFile(sPath,eSF);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not create VFS file \"" << sPath().c_wcs() << L"\"";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
THROWEXCEPTION(BuildString().add(L"Could not create VFS file \"").add(sPath).add(L"\"").get());
|
||||
}
|
||||
}
|
||||
if(!pFile)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"File \"" << sPath().c_wcs() << L"\" not found";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
m_pFile = vfs::tWriteableFile::Cast(pFile);
|
||||
if(!m_pFile)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"File \"" << sPath().c_wcs() << L"\" exists, but is not writeable";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
if(!m_pFile->OpenWrite(bCreate,bTruncate))
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"File \"" << sPath().c_wcs() << L"\" could not be opened for writing";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
THROWIFFALSE(pFile,
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" not found").get());
|
||||
|
||||
m_pFile = vfs::tWritableFile::cast(pFile);
|
||||
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" exists, but is not writable").get());
|
||||
|
||||
THROWIFFALSE(m_pFile->openWrite(bCreate,bTruncate),
|
||||
BuildString().add(L"File \"").add(sPath).add(L"\" could not be opened for writing").get());
|
||||
}
|
||||
vfs::COpenWriteFile::COpenWriteFile(vfs::tWriteableFile *pFile)
|
||||
vfs::COpenWriteFile::COpenWriteFile(vfs::tWritableFile *pFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_pFile = pFile;
|
||||
THROWIFFALSE(m_pFile, L"no file");
|
||||
THROWIFFALSE(m_pFile->OpenWrite(true,false), (L"File not open : " + m_pFile->GetFullPath()().c_wcs()).c_str());
|
||||
THROWIFFALSE(m_pFile,
|
||||
BuildString().add(L"Invalid file object").get());
|
||||
THROWIFFALSE(m_pFile->openWrite(true,false),
|
||||
BuildString().add(L"Could not open file : ").add(m_pFile->getPath()).get());
|
||||
}
|
||||
catch(CBasicException& ex)
|
||||
{
|
||||
@@ -104,12 +104,12 @@ vfs::COpenWriteFile::~COpenWriteFile()
|
||||
{
|
||||
if(m_pFile)
|
||||
{
|
||||
m_pFile->Close();
|
||||
m_pFile->close();
|
||||
m_pFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
vfs::tWriteableFile& vfs::COpenWriteFile::file()
|
||||
vfs::tWritableFile& vfs::COpenWriteFile::file()
|
||||
{
|
||||
return *m_pFile;
|
||||
}
|
||||
|
||||
+6
-6
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class COpenReadFile
|
||||
class VFS_API COpenReadFile
|
||||
{
|
||||
public:
|
||||
COpenReadFile(vfs::Path const& sPath, vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_TOP);
|
||||
@@ -19,20 +19,20 @@ namespace vfs
|
||||
vfs::tReadableFile* m_pFile;
|
||||
};
|
||||
|
||||
class COpenWriteFile
|
||||
class VFS_API COpenWriteFile
|
||||
{
|
||||
public:
|
||||
COpenWriteFile( vfs::Path const& sPath,
|
||||
bool bCreate = false,
|
||||
bool bTruncate = false,
|
||||
vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
COpenWriteFile(vfs::tWriteableFile *pFile);
|
||||
vfs::CVirtualFile::ESearchFile eSF = vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
COpenWriteFile(vfs::tWritableFile *pFile);
|
||||
~COpenWriteFile();
|
||||
|
||||
vfs::tWriteableFile& file();
|
||||
vfs::tWritableFile& file();
|
||||
void release();
|
||||
private:
|
||||
vfs::tWriteableFile* m_pFile;
|
||||
vfs::tWritableFile* m_pFile;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
+82
-73
@@ -1,3 +1,4 @@
|
||||
#include "vfs_settings.h"
|
||||
#include "vfs_init.h"
|
||||
#include "vfs.h"
|
||||
#include "File/vfs_file.h"
|
||||
@@ -17,39 +18,39 @@
|
||||
#define LOG(x)
|
||||
#endif
|
||||
|
||||
extern bool g_VFS_NO_UNICODE;
|
||||
|
||||
/********************************************************************/
|
||||
/********************************************************************/
|
||||
|
||||
bool InitVirtualFileSystem(vfs::Path const& vfs_ini)
|
||||
bool initVirtualFileSystem(vfs::Path const& vfs_ini)
|
||||
{
|
||||
std::list<vfs::Path> li;
|
||||
li.push_back(vfs_ini);
|
||||
return InitVirtualFileSystem(li);
|
||||
return initVirtualFileSystem(li);
|
||||
}
|
||||
bool InitVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list)
|
||||
bool initVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list)
|
||||
{
|
||||
CPropertyContainer oVFSProps;
|
||||
std::list<vfs::Path>::const_iterator clit = vfs_ini_list.begin();
|
||||
for(; clit != vfs_ini_list.end(); ++clit)
|
||||
{
|
||||
oVFSProps.InitFromIniFile(*clit);
|
||||
oVFSProps.initFromIniFile(*clit);
|
||||
}
|
||||
return InitVirtualFileSystem(oVFSProps);
|
||||
return initVirtualFileSystem(oVFSProps);
|
||||
}
|
||||
bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
bool initVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
{
|
||||
LOG(CLog _LOG(vfs::Path(L"vfs_init.log")));
|
||||
|
||||
vfs::CVirtualFileSystem *pVirtFileSys = GetVFS();
|
||||
vfs::CVirtualFileSystem *pVirtFileSys = getVFS();
|
||||
|
||||
LOG(_LOG << "Initializing Virtual File System" << CLog::endl);
|
||||
LOG(_LOG << "Initializing Virtual File System" << CLog::ENDL);
|
||||
|
||||
if(g_VFS_NO_UNICODE){ LOG(_LOG.Endl() << "UNICODE disabled" << CLog::endl); }
|
||||
if(!vfs::Settings::getUseUnicode()){ LOG(_LOG.endl() << "UNICODE disabled" << CLog::ENDL); }
|
||||
|
||||
LOG(_LOG.Endl() << "reading profiles .. ");
|
||||
LOG(_LOG.endl() << "reading profiles .. ");
|
||||
std::list<utf8string> lProfiles, lLocSections;
|
||||
oVFSProps.GetStringListProperty(L"vfs_config",L"PROFILES",lProfiles,L"");
|
||||
oVFSProps.getStringListProperty(L"vfs_config",L"PROFILES",lProfiles,L"");
|
||||
if(lProfiles.empty())
|
||||
{
|
||||
LOG(_LOG << " ERROR");
|
||||
@@ -59,38 +60,38 @@ bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
{
|
||||
LOG(_LOG << " OK");
|
||||
}
|
||||
LOG(_LOG.Endl() << " profiles to read : ");
|
||||
LOG(_LOG.endl() << " profiles to read : ");
|
||||
std::list<utf8string>::const_iterator cit_profiles = lProfiles.begin();
|
||||
for(; cit_profiles != lProfiles.end(); ++cit_profiles)
|
||||
{
|
||||
LOG(_LOG << (*cit_profiles) << ", ");
|
||||
}
|
||||
LOG(_LOG.Endl());
|
||||
LOG(_LOG.endl());
|
||||
|
||||
std::list<utf8string>::const_iterator prof_cit = lProfiles.begin();
|
||||
for(; prof_cit != lProfiles.end(); ++prof_cit)
|
||||
{
|
||||
LOG(_LOG.Endl() << " reading profile [");
|
||||
LOG(_LOG.endl() << " reading profile [");
|
||||
utf8string sProfSection = utf8string("PROFILE_") + utf8string(*prof_cit);
|
||||
utf8string sProfName = oVFSProps.GetStringProperty(sProfSection,L"NAME",L"");
|
||||
utf8string sProfName = oVFSProps.getStringProperty(sProfSection,L"NAME",L"");
|
||||
LOG(_LOG << sProfName << "] .. ");
|
||||
|
||||
vfs::Path profileRoot = oVFSProps.GetStringProperty(sProfSection,L"PROFILE_ROOT",L"");
|
||||
vfs::Path profileRoot = oVFSProps.getStringProperty(sProfSection,L"PROFILE_ROOT",L"");
|
||||
|
||||
lLocSections.clear();
|
||||
oVFSProps.GetStringListProperty(sProfSection,L"LOCATIONS",lLocSections,L"");
|
||||
oVFSProps.getStringListProperty(sProfSection,L"LOCATIONS",lLocSections,L"");
|
||||
|
||||
LOG(_LOG << "OK");
|
||||
LOG(_LOG.Endl() << " locations to read : ");
|
||||
LOG(_LOG.endl() << " locations to read : ");
|
||||
std::list<utf8string>::const_iterator cit_locations = lLocSections.begin();
|
||||
for(; cit_locations != lLocSections.end(); ++cit_locations)
|
||||
{
|
||||
LOG(_LOG << (*cit_locations) << ", ");
|
||||
}
|
||||
LOG(_LOG.Endl().Endl());
|
||||
LOG(_LOG.endl().endl());
|
||||
|
||||
std::list<utf8string>::iterator loc_it = lLocSections.begin();
|
||||
bool bIsWriteable = oVFSProps.GetBoolProperty(sProfSection,L"WRITE",false);
|
||||
bool bIsWritable = oVFSProps.getBoolProperty(sProfSection,L"WRITE",false);
|
||||
for(; loc_it != lLocSections.end(); ++loc_it)
|
||||
{
|
||||
LOG(_LOG << " reading location [ ");
|
||||
@@ -98,10 +99,10 @@ bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
vfs::Path sLocPath, sLocMountPoint;
|
||||
utf8string sLocType;
|
||||
|
||||
sLocPath = oVFSProps.GetStringProperty(sLocSection,"PATH","");
|
||||
sLocMountPoint = oVFSProps.GetStringProperty(sLocSection,L"MOUNT_POINT",L"");
|
||||
sLocType = oVFSProps.GetStringProperty(sLocSection,L"TYPE",L"NOT_FOUND");
|
||||
bool bOptional = oVFSProps.GetBoolProperty(sLocSection,L"OPTIONAL",false);
|
||||
sLocPath = oVFSProps.getStringProperty(sLocSection,"PATH","");
|
||||
sLocMountPoint = oVFSProps.getStringProperty(sLocSection,L"MOUNT_POINT",L"");
|
||||
sLocType = oVFSProps.getStringProperty(sLocSection,L"TYPE",L"NOT_FOUND");
|
||||
bool bOptional = oVFSProps.getBoolProperty(sLocSection,L"OPTIONAL",false);
|
||||
if(StrCmp::Equal(sLocType,L"LIBRARY"))
|
||||
{
|
||||
LOG(_LOG << sLocType << " | " << (*loc_it) << " ] .. ");
|
||||
@@ -109,20 +110,20 @@ bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
bool bOwnFile = false;
|
||||
if(!sLocPath.empty())
|
||||
{
|
||||
pLibFile = vfs::tReadableFile::Cast( new vfs::CFile(profileRoot + sLocPath) );
|
||||
pLibFile = vfs::tReadableFile::cast( new vfs::CFile(profileRoot + sLocPath) );
|
||||
bOwnFile = true;
|
||||
}
|
||||
if(!pLibFile)
|
||||
{
|
||||
sLocPath = oVFSProps.GetStringProperty(sLocSection,L"VFS_PATH",L"");
|
||||
sLocPath = oVFSProps.getStringProperty(sLocSection,L"VFS_PATH",L"");
|
||||
if(!sLocPath.empty())
|
||||
{
|
||||
pLibFile = pVirtFileSys->GetRFile(profileRoot + sLocPath);
|
||||
pLibFile = pVirtFileSys->getReadFile(profileRoot + sLocPath);
|
||||
}
|
||||
}
|
||||
if(pLibFile)
|
||||
{
|
||||
utf8string full_str = pLibFile->GetFileName()();
|
||||
utf8string full_str = pLibFile->getName()();
|
||||
utf8string ext = full_str.c_wcs().substr(full_str.length()-3,3);
|
||||
vfs::ILibrary *pLib = NULL;
|
||||
if(StrCmp::Equal(ext,L"slf"))
|
||||
@@ -135,58 +136,68 @@ bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::endl);
|
||||
utf8string::str_t s = L"File [" + utf8string(sLocPath()).c_wcs() + L"] in not an SLF or 7z library";
|
||||
THROWEXCEPTION(s.c_str());
|
||||
return false;
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
THROWEXCEPTION(BuildString().add(L"File [").add(sLocPath).add(L"] in not an SLF or 7z library").get());
|
||||
}
|
||||
if(!pLib->Init())
|
||||
if(!pLib->init())
|
||||
{
|
||||
if(!bOptional)
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::endl);
|
||||
//std::cout << "ERROR : library initialization failed [ " << full_str << " ]" << std::endl;
|
||||
std::wstring s = L"Could not initialize library [ " + sLocPath().c_wcs()
|
||||
+ L" ] in : profile [ " + utf8string(sProfName).c_wcs()
|
||||
+ L" ], location [ " + (*loc_it).c_wcs()
|
||||
+ L" ], path [ " + (profileRoot + sLocPath)().c_wcs() + L" ]";
|
||||
THROWEXCEPTION(s.c_str());
|
||||
return false;
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
BuildString bs;
|
||||
bs.add(L"Could not initialize library [").add(sLocPath).add(L" ]").add(
|
||||
L" in : profile [ ").add(sProfName).add(L" ],").add(
|
||||
L" location [ ").add((*loc_it)).add(L" ],").add(
|
||||
L" path [ ").add((profileRoot + sLocPath)).add(L" ]");
|
||||
THROWEXCEPTION(bs.get());
|
||||
}
|
||||
LOG(_LOG << "optional library ignored" << CLog::endl);
|
||||
LOG(_LOG << "optional library ignored" << CLog::ENDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "OK" << CLog::endl);
|
||||
LOG(_LOG << "OK" << CLog::ENDL);
|
||||
}
|
||||
pVirtFileSys->AddLocation(vfs::tReadLocation::Cast(pLib), sProfName, bIsWriteable);
|
||||
pVirtFileSys->addLocation(vfs::tReadLocation::cast(pLib), sProfName, bIsWritable);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::endl);
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
THROWEXCEPTION(L"File not found");
|
||||
}
|
||||
}
|
||||
else if(StrCmp::Equal(sLocType,L"DIRECTORY"))
|
||||
{
|
||||
LOG(_LOG << sLocType << " | " << (*loc_it) << " ] .. ");
|
||||
vfs::CDirectoryTree *pDirTree = new vfs::CDirectoryTree(sLocMountPoint,profileRoot + sLocPath);
|
||||
if(!pDirTree->Init())
|
||||
vfs::IBaseLocation *pDirLocation = NULL;
|
||||
bool init_success = false;
|
||||
if(bIsWritable)
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::endl);
|
||||
std::wstring s = L"Could not initialize directory [\"" + sLocPath().c_wcs()
|
||||
+ L"\"] in : profile [\"" + utf8string(sProfName).c_wcs()
|
||||
+ L"\"], location [\"" + (*loc_it).c_wcs()
|
||||
+ L"\"], path [\"" + (profileRoot + sLocPath)().c_wcs() + L"\"]";
|
||||
THROWEXCEPTION(s.c_str());
|
||||
return false;
|
||||
vfs::CDirectoryTree *pDirTree = new vfs::CDirectoryTree(sLocMountPoint,profileRoot + sLocPath);
|
||||
init_success = pDirTree->init();
|
||||
pDirLocation = pDirTree;
|
||||
}
|
||||
pVirtFileSys->AddLocation(vfs::tReadLocation::Cast(pDirTree),sProfName,bIsWriteable);
|
||||
LOG(_LOG << "OK" << CLog::endl);
|
||||
else
|
||||
{
|
||||
vfs::CReadOnlyDirectoryTree *pDirTree = new vfs::CReadOnlyDirectoryTree(sLocMountPoint,profileRoot + sLocPath);
|
||||
init_success = pDirTree->init();
|
||||
pDirLocation = pDirTree;
|
||||
}
|
||||
if(!init_success)
|
||||
{
|
||||
LOG(_LOG << "ERROR" << CLog::ENDL);
|
||||
BuildString bs;
|
||||
bs.add(L"Could not initialize directory [\"").add(sLocPath).add(L"\"]").add(
|
||||
L" in : profile [\"").add(sProfName).add(L"\"],").add(
|
||||
L" location [\"").add((*loc_it)).add(L"\"],").add(
|
||||
L" path [\"").add(profileRoot + sLocPath).add(L"\"]");
|
||||
THROWEXCEPTION(bs.get());
|
||||
}
|
||||
pVirtFileSys->addLocation(pDirLocation,sProfName,bIsWritable);
|
||||
LOG(_LOG << "OK" << CLog::ENDL);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(_LOG << "]" << CLog::endl);
|
||||
LOG(_LOG << "]" << CLog::ENDL);
|
||||
}
|
||||
//else if( sLocType == "NOT_FOUND")
|
||||
//{
|
||||
@@ -195,35 +206,33 @@ bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
||||
// THROWEXCEPTION(wss.str().c_str());
|
||||
//}
|
||||
}
|
||||
if(bIsWriteable)
|
||||
if(bIsWritable)
|
||||
{
|
||||
vfs::CProfileStack *pPS = pVirtFileSys->GetProfileStack();
|
||||
vfs::CVirtualProfile *pProf = pPS->GetProfile(sProfName);
|
||||
vfs::CProfileStack *pPS = pVirtFileSys->getProfileStack();
|
||||
vfs::CVirtualProfile *pProf = pPS->getProfile(sProfName);
|
||||
if(!pProf)
|
||||
{
|
||||
pProf = new vfs::CVirtualProfile(sProfName,true);
|
||||
pPS->PushProfile(pProf);
|
||||
pPS->pushProfile(pProf);
|
||||
}
|
||||
else if(!pProf->Writeable)
|
||||
else if(!pProf->cWritable)
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Profile [" << sProfName << L"] is supposed to be writeable!";
|
||||
wss << L"Profile [" << sProfName << L"] is supposed to be writable!";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
InitWriteProfile(*pProf, profileRoot);
|
||||
initWriteProfile(*pProf, profileRoot);
|
||||
}
|
||||
}
|
||||
LOG(_LOG.Endl() << "VFS successfully initialized" << CLog::endl);
|
||||
|
||||
LOG(_LOG.endl() << "VFS successfully initialized" << CLog::ENDL);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool InitWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot)
|
||||
bool initWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot)
|
||||
{
|
||||
typedef vfs::IDirectory<vfs::IWriteable> tWDir;
|
||||
typedef vfs::TDirectory<vfs::IWritable> tWDir;
|
||||
tWDir *pDir = NULL;
|
||||
vfs::CDirectoryTree *pDirTree = NULL;
|
||||
vfs::IBaseLocation *pLoc = rProf.GetLocation(vfs::Path(vfs::Const::EMPTY()));
|
||||
vfs::IBaseLocation *pLoc = rProf.getLocation(vfs::Path(vfs::Const::EMPTY()));
|
||||
if(pLoc)
|
||||
{
|
||||
pDir = dynamic_cast<tWDir*>(pLoc);
|
||||
@@ -232,11 +241,11 @@ bool InitWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot)
|
||||
{
|
||||
vfs::CDirectoryTree *pDirTree = NULL;
|
||||
pDirTree = new vfs::CDirectoryTree(vfs::Path(vfs::Const::EMPTY()),profileRoot);
|
||||
if(!pDirTree->Init())
|
||||
if(!pDirTree->init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
GetVFS()->AddLocation(pDirTree,rProf.Name,true);
|
||||
getVFS()->addLocation(pDirTree,rProf.cName,true);
|
||||
pDir = pDirTree;
|
||||
}
|
||||
return pDir != NULL;
|
||||
|
||||
+4
-4
@@ -5,9 +5,9 @@
|
||||
#include "vfs_profile.h"
|
||||
#include "PropertyContainer.h"
|
||||
|
||||
bool InitWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot);
|
||||
bool InitVirtualFileSystem(vfs::Path const& vfs_ini);
|
||||
bool InitVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list);
|
||||
bool InitVirtualFileSystem(CPropertyContainer& props);
|
||||
VFS_API bool initWriteProfile(vfs::CVirtualProfile &rProf, vfs::Path const& profileRoot);
|
||||
VFS_API bool initVirtualFileSystem(vfs::Path const& vfs_ini);
|
||||
VFS_API bool initVirtualFileSystem(std::list<vfs::Path> const& vfs_ini_list);
|
||||
VFS_API bool initVirtualFileSystem(CPropertyContainer& props);
|
||||
|
||||
#endif // _VFS_INIT_H_
|
||||
|
||||
@@ -0,0 +1,500 @@
|
||||
#include "vfs_path.h"
|
||||
#include "vfs_debug.h"
|
||||
#include "vfs_settings.h"
|
||||
|
||||
static void unifySeparators(utf8string::str_t &sPath)
|
||||
{
|
||||
utf8string::char_t &raw = sPath[0];
|
||||
utf8string::ptr_t raw_ptr = &raw;
|
||||
while(*raw_ptr != 0)
|
||||
{
|
||||
if(*raw_ptr == '\\' || *raw_ptr == '/')
|
||||
{
|
||||
*raw_ptr = vfs::Const::SEPARATOR_CHAR();
|
||||
}
|
||||
raw_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call after unifying separators
|
||||
*/
|
||||
static vfs::UInt32 removeSeparators(utf8string::str_t &str)
|
||||
{
|
||||
vfs::UInt32 sepcount = 0;
|
||||
vfs::Int32 numsep = 0;
|
||||
::size_t put_pos = 0;
|
||||
::size_t len = str.length();
|
||||
utf8string::char_t& raw = str[0];
|
||||
utf8string::ptr_t old_ptr = &raw;
|
||||
utf8string::ptr_t new_ptr = &raw;
|
||||
utf8string::ptr_t last_ptr = &raw;
|
||||
while(*old_ptr != 0)
|
||||
{
|
||||
if(*old_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
numsep++;
|
||||
if(numsep == 1)
|
||||
{
|
||||
sepcount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have normal text (again)
|
||||
numsep = 0;
|
||||
}
|
||||
if(numsep <= 1)
|
||||
{
|
||||
*new_ptr = *old_ptr;
|
||||
last_ptr = new_ptr++;
|
||||
put_pos++;
|
||||
}
|
||||
old_ptr++;
|
||||
}
|
||||
if(*last_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
put_pos--;
|
||||
if(sepcount>0)
|
||||
{
|
||||
sepcount--;
|
||||
}
|
||||
}
|
||||
if(put_pos < len)
|
||||
{
|
||||
str.erase(put_pos);
|
||||
}
|
||||
return sepcount;
|
||||
}
|
||||
|
||||
static void removeLastSeparator(utf8string::str_t &str)
|
||||
{
|
||||
if( *str.rbegin() == vfs::Const::SEPARATOR_CHAR() )
|
||||
{
|
||||
str.erase( str.length()-1);
|
||||
}
|
||||
}
|
||||
|
||||
static void removeDots(utf8string::str_t &str, vfs::UInt32 number_of_separators)
|
||||
{
|
||||
utf8string::char_t& raw = str[0];
|
||||
utf8string::ptr_t old_ptr = &raw;
|
||||
utf8string::ptr_t new_ptr = &raw;
|
||||
utf8string::size_t LENGTH = str.length();
|
||||
bool dirty = false;
|
||||
|
||||
// see if we start with ./ (not . as this might be a hidden files on unix systems)
|
||||
if( (LENGTH > 1) && (*old_ptr == vfs::Const::DOT_CHAR()) && (*(old_ptr+1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
old_ptr += 2;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
std::vector<utf8string::ptr_t> sub_strings;
|
||||
sub_strings.resize(number_of_separators);
|
||||
int pos=0;
|
||||
|
||||
if(*old_ptr != 0 && *old_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
// in-place : just move along
|
||||
new_ptr++;
|
||||
old_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_ptr++ = *old_ptr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
sub_strings[pos++] = new_ptr;
|
||||
|
||||
while(*old_ptr != 0)
|
||||
{
|
||||
if(*old_ptr != vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
new_ptr++;
|
||||
old_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_ptr++ = *old_ptr++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
*new_ptr++ = *old_ptr++;
|
||||
sub_strings[pos++] = new_ptr;
|
||||
|
||||
if((&raw+3) < old_ptr)
|
||||
{
|
||||
if( (*(old_ptr-4) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-3) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 1)
|
||||
{
|
||||
new_ptr = sub_strings[pos-3];
|
||||
pos -= 2;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
else if((*(old_ptr-3) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 0)
|
||||
{
|
||||
new_ptr = sub_strings[pos-2];
|
||||
pos -= 1;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((&raw+2) < old_ptr)
|
||||
{
|
||||
if( (*(old_ptr-3) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 0)
|
||||
{
|
||||
new_ptr = sub_strings[pos-2];
|
||||
pos -= 1;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::size_t ttt = (new_ptr - &raw);
|
||||
if(ttt < LENGTH)
|
||||
{
|
||||
str.erase(ttt);
|
||||
}
|
||||
}
|
||||
|
||||
static void getFirstLastSeparator(const utf8string::char_t* sPath, vfs::size_t &iFirst, vfs::size_t &iLast)
|
||||
{
|
||||
const utf8string::char_t* ptr = sPath;
|
||||
vfs::size_t pos = 0;
|
||||
while(*ptr != 0)
|
||||
{
|
||||
if(*ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(iFirst == vfs::npos)
|
||||
{
|
||||
iFirst = pos;
|
||||
}
|
||||
iLast = pos;
|
||||
}
|
||||
pos++;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
bool vfs::Path::Less::operator ()(vfs::Path const& s1, vfs::Path const& s2) const
|
||||
{
|
||||
return utf8string::less(s1._path.c_str(), s2._path.c_str());
|
||||
}
|
||||
bool vfs::Path::Equal::operator ()(vfs::Path const& s1, vfs::Path const& s2) const
|
||||
{
|
||||
return utf8string::equal(s1._path.c_str(), s2._path.c_str());
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
vfs::Path::Path()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path::Path(utf8string const& sPath)
|
||||
: _path(sPath.c_wcs())
|
||||
{
|
||||
doCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(const char* sPath)
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
utf8string::as_utf16(sPath,_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
utf8string::widen(std::string(sPath),_path);
|
||||
}
|
||||
doCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(std::string const& sPath)
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
utf8string::as_utf16(sPath,_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
utf8string::widen(sPath,_path);
|
||||
}
|
||||
doCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(const wchar_t* sPath)
|
||||
: _path(sPath)
|
||||
{
|
||||
doCheck();
|
||||
}
|
||||
|
||||
const utf8string::char_t* vfs::Path::c_str() const
|
||||
{
|
||||
return _path.c_str();
|
||||
}
|
||||
|
||||
const utf8string::str_t& vfs::Path::c_wcs() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
const utf8string::str_t& vfs::Path::operator()() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
std::string vfs::Path::to_string() const
|
||||
{
|
||||
if(vfs::Settings::getUseUnicode())
|
||||
{
|
||||
return utf8string::as_utf8(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string s;
|
||||
utf8string::narrow(_path,s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::Path::empty() const
|
||||
{
|
||||
// is there a case where a non-empty string can become empty after a check?
|
||||
// if it is so then i don't care
|
||||
return _path.empty();
|
||||
}
|
||||
utf8string::size_t vfs::Path::length() const
|
||||
{
|
||||
return _path.length();
|
||||
}
|
||||
|
||||
|
||||
void vfs::Path::doCheck()
|
||||
{
|
||||
if(!_path.empty())
|
||||
{
|
||||
unifySeparators(_path);
|
||||
|
||||
vfs::UInt32 number_of_separators = removeSeparators(_path);
|
||||
|
||||
if(number_of_separators>0)
|
||||
{
|
||||
removeDots(_path,number_of_separators+1);
|
||||
getFirstLastSeparator(_path.c_str(),_sep.first,_sep.last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pathSplitLast(utf8string::str_t const& path,
|
||||
utf8string::str_t &head,
|
||||
utf8string::str_t &last,
|
||||
vfs::size_t const& sep_first,
|
||||
vfs::size_t const& sep_last)
|
||||
{
|
||||
if(path.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(&head == &path || &last == &path)
|
||||
{
|
||||
THROWEXCEPTION(L"cannot use output parameters that are equal to 'this'");
|
||||
}
|
||||
#if 1
|
||||
// use results from "GetFirstLastSeparator(..)"
|
||||
if(sep_last != vfs::npos)
|
||||
{
|
||||
head.assign(path.substr(0,sep_last));
|
||||
last.assign(path.substr(sep_last+1, path.length()-sep_last-1));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
utf8string::size_t position = path.length();
|
||||
while(--position != vfs::npos)
|
||||
{
|
||||
utf8string::char_t const& c = path.at(position);
|
||||
if(c == '\\' || c == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(position != vfs::npos)
|
||||
{
|
||||
head.assign(path.substr(0,position++));
|
||||
last.assign(path.substr(position,path.length()-position));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
head.assign(vfs::Const::EMPTY());
|
||||
last.assign(path);
|
||||
}
|
||||
|
||||
|
||||
void vfs::Path::splitLast(vfs::Path &rsHead, vfs::Path &rsLast) const
|
||||
{
|
||||
|
||||
pathSplitLast(_path, rsHead._path, rsLast._path, _sep.first, _sep.last);
|
||||
getFirstLastSeparator(rsHead.c_str(), rsHead._sep.first, rsHead._sep.last);
|
||||
getFirstLastSeparator(rsLast.c_str(), rsLast._sep.first, rsLast._sep.last);
|
||||
// no need to check, as the original path is already checked
|
||||
//rPath.DoCheck();
|
||||
//rFile.DoCheck();
|
||||
}
|
||||
|
||||
static void pathSplitFirst(utf8string::str_t const& path,
|
||||
utf8string::str_t &first,
|
||||
utf8string::str_t &tail,
|
||||
vfs::size_t const& sep_first,
|
||||
vfs::size_t const& sep_last)
|
||||
{
|
||||
if(path.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(&first == &path || &tail == &path)
|
||||
{
|
||||
THROWEXCEPTION(L"cannot use output parameters that are equal to 'this'");
|
||||
}
|
||||
|
||||
#if 1
|
||||
// use results from "GetFirstLastSeparator(..)"
|
||||
if(sep_first != vfs::npos)
|
||||
{
|
||||
first.assign(path.substr(0,sep_first));
|
||||
tail.assign(path.substr(sep_first+1, path.length()-sep_first-1));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
utf8string::size_t position = 0;
|
||||
while(position < path.length())
|
||||
{
|
||||
utf8string::char_t const& c = path.at(position);
|
||||
if(c == '\\' || c == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
if(position < path.length())
|
||||
{
|
||||
first.assign(path.substr(0,position++));
|
||||
tail.assign(path.substr(position,path.length()-position));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
first.assign(path);
|
||||
tail.assign(vfs::Const::EMPTY());
|
||||
}
|
||||
|
||||
void vfs::Path::splitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const
|
||||
{
|
||||
pathSplitFirst(_path, rsFirst._path, rsTail._path, _sep.first, _sep.last);
|
||||
getFirstLastSeparator(rsFirst.c_str(), rsFirst._sep.first, rsFirst._sep.last);
|
||||
getFirstLastSeparator(rsTail.c_str(), rsTail._sep.first, rsTail._sep.last);
|
||||
// no need to check, as the original path is already checked
|
||||
//rPath.doCheck();
|
||||
//rFile.doCheck();
|
||||
}
|
||||
|
||||
bool vfs::Path::extension(utf8string &sExt) const
|
||||
{
|
||||
if(_path.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
utf8string::size_t SIZE = _path.length();
|
||||
if(_path.at(SIZE-1) == L'.')
|
||||
{
|
||||
// not an extension
|
||||
return false;
|
||||
}
|
||||
for(utf8string::size_t i=SIZE-2; i > 0; i--)
|
||||
{
|
||||
if(_path.at(i) == L'.')
|
||||
{
|
||||
sExt.r_wcs().assign(&_path.at(i+1),SIZE-i-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
vfs::Path& vfs::Path::operator+=(utf8string const& p)
|
||||
{
|
||||
return *this += vfs::Path(p);
|
||||
}
|
||||
|
||||
vfs::Path& vfs::Path::operator+=(vfs::Path const& p)
|
||||
{
|
||||
if(_path.empty())
|
||||
{
|
||||
_path = p._path;
|
||||
}
|
||||
else if(!p.empty())
|
||||
{
|
||||
_path += vfs::Const::SEPARATOR();
|
||||
_path += p._path;
|
||||
getFirstLastSeparator(_path.c_str(),_sep.first,_sep.last);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2)
|
||||
{
|
||||
vfs::Path newpath = p1;
|
||||
newpath += p2;
|
||||
return newpath;
|
||||
}
|
||||
|
||||
bool vfs::Path::operator==(vfs::Path const& p2)
|
||||
{
|
||||
return utf8string::equal(_path.c_str(), p2._path.c_str());
|
||||
}
|
||||
|
||||
bool operator==(vfs::Path const& p1, vfs::Path const& p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2.c_str());
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, utf8string const& p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, utf8string::str_t const& p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, const utf8string::char_t* p2)
|
||||
{
|
||||
return StrCmp::Equal(p1.c_str(), p2);
|
||||
}
|
||||
|
||||
template<>
|
||||
BuildString& BuildString::add<vfs::Path>(vfs::Path const& value)
|
||||
{
|
||||
this->add(value.c_str());
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#ifndef _VFS_PATH_H_
|
||||
#define _VFS_PATH_H_
|
||||
|
||||
#include "vfs_config.h"
|
||||
#include "vfs_types.h"
|
||||
#include "utf8string.h"
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class VFS_API Path
|
||||
{
|
||||
friend class PathAccess;
|
||||
public:
|
||||
class Less{
|
||||
public:
|
||||
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
|
||||
};
|
||||
class Equal{
|
||||
public:
|
||||
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
|
||||
};
|
||||
public:
|
||||
Path();
|
||||
Path(const char* sPath);
|
||||
Path(std::string const& sPath);
|
||||
Path(const wchar_t* sPath);
|
||||
Path(utf8string const& sPath);
|
||||
|
||||
const utf8string::char_t* c_str() const;
|
||||
const utf8string::str_t& c_wcs() const;
|
||||
const utf8string::str_t& operator()() const;
|
||||
|
||||
std::string to_string() const;
|
||||
|
||||
Path& operator+=(Path const& p);
|
||||
Path& operator+=(utf8string const& p);
|
||||
|
||||
bool empty() const;
|
||||
|
||||
utf8string::size_t length() const;
|
||||
|
||||
void doCheck();
|
||||
|
||||
void splitLast(vfs::Path &rsHead, vfs::Path &rsLast) const;
|
||||
void splitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const;
|
||||
|
||||
bool extension(utf8string &sExt) const;
|
||||
|
||||
bool operator==(vfs::Path const& p2);
|
||||
private:
|
||||
utf8string::str_t _path;
|
||||
struct SeparatorPosition
|
||||
{
|
||||
SeparatorPosition() : first(vfs::npos), last(vfs::npos) {}
|
||||
vfs::size_t first, last;
|
||||
} _sep;
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
BuildString& BuildString::add<vfs::Path>(vfs::Path const& value);
|
||||
|
||||
|
||||
// add only valid Path objects
|
||||
vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2);
|
||||
|
||||
// compare path to string (that can be an invalid path)
|
||||
bool operator==(vfs::Path const& p1, vfs::Path const& p2);
|
||||
// use with care as these string can be different from the internal representation although they seem to be equal
|
||||
bool operator==(vfs::Path const& p1, utf8string const& p2);
|
||||
bool operator==(vfs::Path const& p1, utf8string::str_t const& p2);
|
||||
bool operator==(vfs::Path const& p1, const utf8string::char_t* p2);
|
||||
|
||||
#endif // _VFS_PATH_H_
|
||||
|
||||
+211
-104
@@ -7,47 +7,144 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
vfs::CVirtualProfile::Iterator::Iterator(vfs::CVirtualProfile& rProf)
|
||||
: m_pProf(&rProf)
|
||||
|
||||
class vfs::CVirtualProfile::IterImpl : public vfs::CVirtualProfile::Iterator::IImplementation
|
||||
{
|
||||
// only unique locations
|
||||
_loc_iter = m_pProf->m_setLocations.begin();
|
||||
}
|
||||
friend class vfs::CVirtualProfile;
|
||||
typedef vfs::CVirtualProfile::Iterator::IImplementation tBaseClass;
|
||||
|
||||
vfs::CVirtualProfile::Iterator::Iterator()
|
||||
: m_pProf(NULL)
|
||||
{}
|
||||
|
||||
vfs::CVirtualProfile::Iterator::~Iterator()
|
||||
{}
|
||||
|
||||
vfs::IBaseLocation* vfs::CVirtualProfile::Iterator::value() const
|
||||
{
|
||||
if(_loc_iter != m_pProf->m_setLocations.end())
|
||||
IterImpl(CVirtualProfile* profile) : tBaseClass(), m_profile(profile)
|
||||
{
|
||||
return *_loc_iter;
|
||||
THROWIFFALSE(profile, L"");
|
||||
// only unique locations
|
||||
_loc_iter = m_profile->m_setLocations.begin();
|
||||
}
|
||||
THROWEXCEPTION(L"End of map");
|
||||
public:
|
||||
IterImpl() : tBaseClass(), m_profile(NULL)
|
||||
{};
|
||||
virtual ~IterImpl()
|
||||
{};
|
||||
//////
|
||||
virtual vfs::IBaseLocation* value()
|
||||
{
|
||||
if(_loc_iter != m_profile->m_setLocations.end())
|
||||
{
|
||||
return *_loc_iter;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(_loc_iter != m_profile->m_setLocations.end())
|
||||
{
|
||||
_loc_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl();
|
||||
iter->m_profile = m_profile;
|
||||
iter->_loc_iter = _loc_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CVirtualProfile* m_profile;
|
||||
vfs::CVirtualProfile::tUniqueLoc::iterator _loc_iter;
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
class vfs::CVirtualProfile::FileIterImpl : public vfs::CVirtualProfile::FileIterator::IImplementation
|
||||
{
|
||||
friend class vfs::CVirtualProfile;
|
||||
typedef vfs::CVirtualProfile::FileIterator::IImplementation tBaseClass;
|
||||
FileIterImpl(vfs::Path const& sPattern, CVirtualProfile* profile);
|
||||
|
||||
public:
|
||||
FileIterImpl() : tBaseClass(), m_profile(NULL)
|
||||
{};
|
||||
virtual ~FileIterImpl()
|
||||
{};
|
||||
/////
|
||||
virtual vfs::IBaseFile* value()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
virtual void next();
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
FileIterImpl* iter2 = new FileIterImpl();
|
||||
iter2->m_pattern = m_pattern;
|
||||
iter2->m_profile = m_profile;
|
||||
iter2->iter = iter;
|
||||
iter2->fiter = fiter;
|
||||
iter2->file = file;
|
||||
return iter2;
|
||||
}
|
||||
private:
|
||||
vfs::Path m_pattern;
|
||||
vfs::CVirtualProfile* m_profile;
|
||||
vfs::CVirtualProfile::Iterator iter;
|
||||
vfs::IBaseLocation::Iterator fiter;
|
||||
vfs::IBaseFile* file;
|
||||
};
|
||||
|
||||
vfs::CVirtualProfile::FileIterImpl::FileIterImpl(vfs::Path const& sPattern, CVirtualProfile* profile)
|
||||
: tBaseClass(), m_pattern(sPattern), m_profile(profile)
|
||||
{
|
||||
THROWIFFALSE(profile, L"");
|
||||
iter = m_profile->begin();
|
||||
while(!iter.end())
|
||||
{
|
||||
fiter = iter.value()->begin();
|
||||
while(!fiter.end())
|
||||
{
|
||||
file = fiter.value();
|
||||
if( matchPattern(m_pattern(), file->getPath()()) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
fiter.next();
|
||||
}
|
||||
iter.next();
|
||||
}
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
void vfs::CVirtualProfile::Iterator::next()
|
||||
void vfs::CVirtualProfile::FileIterImpl::next()
|
||||
{
|
||||
if(_loc_iter != m_pProf->m_setLocations.end())
|
||||
if(!fiter.end())
|
||||
{
|
||||
_loc_iter++;
|
||||
fiter.next();
|
||||
}
|
||||
// silently ignore error
|
||||
}
|
||||
bool vfs::CVirtualProfile::Iterator::end() const
|
||||
{
|
||||
return _loc_iter == m_pProf->m_setLocations.end();
|
||||
while(!iter.end())
|
||||
{
|
||||
while(!fiter.end())
|
||||
{
|
||||
file = fiter.value();
|
||||
if( matchPattern(m_pattern(), file->getPath()()) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
fiter.next();
|
||||
}
|
||||
iter.next();
|
||||
if(!iter.end())
|
||||
{
|
||||
fiter = iter.value()->begin();
|
||||
}
|
||||
}
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
vfs::CVirtualProfile::CVirtualProfile(utf8string const& sProfileName, bool bWriteable)
|
||||
: Name(sProfileName), Writeable(bWriteable)
|
||||
vfs::CVirtualProfile::CVirtualProfile(utf8string const& sProfileName, bool bWritable)
|
||||
: cName(sProfileName), cWritable(bWritable)
|
||||
{};
|
||||
|
||||
vfs::CVirtualProfile::~CVirtualProfile()
|
||||
@@ -56,7 +153,7 @@ vfs::CVirtualProfile::~CVirtualProfile()
|
||||
for(; it != m_setLocations.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
(*it) = NULL;
|
||||
//(*it) = NULL;
|
||||
}
|
||||
m_setLocations.clear();
|
||||
m_mapLocations.clear();
|
||||
@@ -64,16 +161,21 @@ vfs::CVirtualProfile::~CVirtualProfile()
|
||||
|
||||
vfs::CVirtualProfile::Iterator vfs::CVirtualProfile::begin()
|
||||
{
|
||||
return Iterator(*this);
|
||||
return Iterator(new IterImpl(this));
|
||||
}
|
||||
|
||||
void vfs::CVirtualProfile::AddLocation(vfs::IBaseLocation* pLoc)
|
||||
|
||||
vfs::CVirtualProfile::FileIterator vfs::CVirtualProfile::files(vfs::Path const& sPattern)
|
||||
{
|
||||
return FileIterator( new FileIterImpl(sPattern, this));
|
||||
}
|
||||
|
||||
void vfs::CVirtualProfile::addLocation(vfs::IBaseLocation* pLoc)
|
||||
{
|
||||
if(pLoc)
|
||||
{
|
||||
m_setLocations.insert(pLoc);
|
||||
std::list<vfs::Path> lDirs;
|
||||
pLoc->GetSubDirList(lDirs);
|
||||
pLoc->getSubDirList(lDirs);
|
||||
std::list<vfs::Path>::const_iterator cit = lDirs.begin();
|
||||
for(;cit != lDirs.end(); ++cit)
|
||||
{
|
||||
@@ -82,7 +184,7 @@ void vfs::CVirtualProfile::AddLocation(vfs::IBaseLocation* pLoc)
|
||||
{
|
||||
m_mapLocations[*cit] = pLoc;
|
||||
}
|
||||
else if(pNewLoc = pLoc)
|
||||
else if(pNewLoc == pLoc)
|
||||
{
|
||||
// seems to be an update. do nothing
|
||||
}
|
||||
@@ -94,7 +196,7 @@ void vfs::CVirtualProfile::AddLocation(vfs::IBaseLocation* pLoc)
|
||||
}
|
||||
}
|
||||
|
||||
vfs::IBaseLocation* vfs::CVirtualProfile::GetLocation(vfs::Path const& sPath) const
|
||||
vfs::IBaseLocation* vfs::CVirtualProfile::getLocation(vfs::Path const& sPath) const
|
||||
{
|
||||
tLocations::const_iterator it = m_mapLocations.find(sPath);
|
||||
if(it != m_mapLocations.end())
|
||||
@@ -104,14 +206,14 @@ vfs::IBaseLocation* vfs::CVirtualProfile::GetLocation(vfs::Path const& sPath) co
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualProfile::GetFile(vfs::Path const& sPath) const
|
||||
vfs::IBaseFile* vfs::CVirtualProfile::getFile(vfs::Path const& sPath) const
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
sPath.SplitLast(sDir,sFile);
|
||||
sPath.splitLast(sDir,sFile);
|
||||
tLocations::const_iterator it = m_mapLocations.find(sDir);
|
||||
if(it != m_mapLocations.end())
|
||||
{
|
||||
return it->second->GetFile(sPath);
|
||||
return it->second->getFile(sPath);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -120,41 +222,50 @@ vfs::IBaseFile* vfs::CVirtualProfile::GetFile(vfs::Path const& sPath) const
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
vfs::CProfileStack::Iterator::Iterator(CProfileStack& rPStack)
|
||||
: m_pPStack(&rPStack)
|
||||
class vfs::CProfileStack::IterImpl : public vfs::CProfileStack::Iterator::IImplementation
|
||||
{
|
||||
_prof_iter = m_pPStack->m_lProfiles.begin();
|
||||
friend class CProfileStack;
|
||||
typedef CProfileStack::Iterator::IImplementation tBaseClass;
|
||||
|
||||
IterImpl(CProfileStack* pPStack) : tBaseClass(), m_pPStack(pPStack)
|
||||
{
|
||||
THROWIFFALSE(m_pPStack, L"");
|
||||
_prof_iter = m_pPStack->m_profiles.begin();
|
||||
}
|
||||
public:
|
||||
IterImpl() : tBaseClass(), m_pPStack(NULL)
|
||||
{};
|
||||
~IterImpl()
|
||||
{};
|
||||
//////
|
||||
virtual vfs::CVirtualProfile* value()
|
||||
{
|
||||
if(_prof_iter != m_pPStack->m_profiles.end())
|
||||
{
|
||||
return *_prof_iter;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
virtual void next()
|
||||
{
|
||||
if(_prof_iter != m_pPStack->m_profiles.end())
|
||||
{
|
||||
_prof_iter++;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
IterImpl* iter = new IterImpl();
|
||||
iter->m_pPStack = m_pPStack;
|
||||
iter->_prof_iter = _prof_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CProfileStack* m_pPStack;
|
||||
std::list<vfs::CVirtualProfile*>::iterator _prof_iter;
|
||||
};
|
||||
|
||||
vfs::CProfileStack::Iterator::Iterator()
|
||||
: m_pPStack(NULL)
|
||||
{};
|
||||
|
||||
vfs::CProfileStack::Iterator::~Iterator()
|
||||
{};
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::Iterator::value() const
|
||||
{
|
||||
if(_prof_iter != m_pPStack->m_lProfiles.end())
|
||||
{
|
||||
return *_prof_iter;
|
||||
}
|
||||
THROWEXCEPTION(L"end of container");
|
||||
}
|
||||
|
||||
void vfs::CProfileStack::Iterator::next()
|
||||
{
|
||||
if(_prof_iter != m_pPStack->m_lProfiles.end())
|
||||
{
|
||||
_prof_iter++;
|
||||
}
|
||||
// silently ignore that we already are at the end of the list
|
||||
}
|
||||
bool vfs::CProfileStack::Iterator::end() const
|
||||
{
|
||||
return _prof_iter == m_pPStack->m_lProfiles.end();
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
vfs::CProfileStack::CProfileStack()
|
||||
@@ -163,21 +274,21 @@ vfs::CProfileStack::CProfileStack()
|
||||
|
||||
vfs::CProfileStack::~CProfileStack()
|
||||
{
|
||||
std::list<CVirtualProfile*>::iterator it = m_lProfiles.begin();
|
||||
for(; it != m_lProfiles.end(); ++it)
|
||||
std::list<CVirtualProfile*>::iterator it = m_profiles.begin();
|
||||
for(; it != m_profiles.end(); ++it)
|
||||
{
|
||||
delete (*it);
|
||||
(*it) = NULL;
|
||||
}
|
||||
m_lProfiles.clear();
|
||||
m_profiles.clear();
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::GetProfile(utf8string const& sName) const
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::getProfile(utf8string const& sName) const
|
||||
{
|
||||
std::list<CVirtualProfile*>::const_iterator it = m_lProfiles.begin();
|
||||
for(;it != m_lProfiles.end(); ++it)
|
||||
std::list<CVirtualProfile*>::const_iterator it = m_profiles.begin();
|
||||
for(;it != m_profiles.end(); ++it)
|
||||
{
|
||||
if( StrCmp::EqualCase((*it)->Name, sName) )
|
||||
if( StrCmp::EqualCase((*it)->cName, sName) )
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
@@ -185,12 +296,12 @@ vfs::CVirtualProfile* vfs::CProfileStack::GetProfile(utf8string const& sName) co
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::GetWriteProfile()
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::getWriteProfile()
|
||||
{
|
||||
std::list<CVirtualProfile*>::const_iterator it = m_lProfiles.begin();
|
||||
for(;it != m_lProfiles.end(); ++it)
|
||||
std::list<vfs::CVirtualProfile*>::const_iterator it = m_profiles.begin();
|
||||
for(;it != m_profiles.end(); ++it)
|
||||
{
|
||||
if((*it)->Writeable)
|
||||
if((*it)->cWritable)
|
||||
{
|
||||
return *it;
|
||||
}
|
||||
@@ -198,25 +309,24 @@ vfs::CVirtualProfile* vfs::CProfileStack::GetWriteProfile()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::TopProfile() const
|
||||
vfs::CVirtualProfile* vfs::CProfileStack::topProfile() const
|
||||
{
|
||||
if(!m_lProfiles.empty())
|
||||
if(!m_profiles.empty())
|
||||
{
|
||||
return m_lProfiles.front();
|
||||
return m_profiles.front();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CProfileStack::PopProfile()
|
||||
bool vfs::CProfileStack::popProfile()
|
||||
{
|
||||
// there might be some files in this profile that are referenced in a CLog object
|
||||
// we need to it to release the file
|
||||
CLog::FlushAll();
|
||||
CLog::flushAll();
|
||||
// an observer pattern would probably be the better solution,
|
||||
// but for now lets do it this way
|
||||
|
||||
bool bSuccess = true;
|
||||
vfs::CVirtualProfile* prof = this->TopProfile();
|
||||
vfs::CVirtualProfile* prof = this->topProfile();
|
||||
if(prof)
|
||||
{
|
||||
vfs::CVirtualProfile::Iterator loc_it = prof->begin();
|
||||
@@ -230,17 +340,17 @@ bool vfs::CProfileStack::PopProfile()
|
||||
vfs::Path sDir, sFile;
|
||||
if(file)
|
||||
{
|
||||
file->GetFullPath().SplitLast(sDir,sFile);
|
||||
vfs::CVirtualLocation* vloc = GetVFS()->GetVirtualLocation(sDir);
|
||||
file->getPath().splitLast(sDir,sFile);
|
||||
vfs::CVirtualLocation* vloc = getVFS()->getVirtualLocation(sDir);
|
||||
if(vloc)
|
||||
{
|
||||
if( !(bSuccess &= vloc->RemoveFile(file)) )
|
||||
if( !vloc->removeFile(file) )
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"Could not remove file ["
|
||||
<< file->GetFullPath()()
|
||||
<< file->getPath()()
|
||||
<< L"] in Profile ["
|
||||
<< prof->Name << L"]";
|
||||
<< prof->cName << L"]";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
@@ -254,26 +364,23 @@ bool vfs::CProfileStack::PopProfile()
|
||||
else
|
||||
{
|
||||
std::wstringstream wss;
|
||||
wss << L"File is NULL during iteration over files in location [" << loc->GetFullPath()() << L"]";
|
||||
wss << L"File is NULL during iteration over files in location [" << loc->getPath()() << L"]";
|
||||
THROWEXCEPTION(wss.str().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(bSuccess)
|
||||
{
|
||||
// delete only when nothing went wrong
|
||||
this->m_lProfiles.pop_front();
|
||||
delete prof;
|
||||
}
|
||||
// delete only when nothing went wrong
|
||||
this->m_profiles.pop_front();
|
||||
delete prof;
|
||||
}
|
||||
return bSuccess;
|
||||
return true;
|
||||
}
|
||||
|
||||
void vfs::CProfileStack::PushProfile(CVirtualProfile* pProfile)
|
||||
void vfs::CProfileStack::pushProfile(CVirtualProfile* pProfile)
|
||||
{
|
||||
if(!GetProfile(pProfile->Name))
|
||||
if(!getProfile(pProfile->cName))
|
||||
{
|
||||
m_lProfiles.push_front(pProfile);
|
||||
m_profiles.push_front(pProfile);
|
||||
return;
|
||||
}
|
||||
THROWEXCEPTION(L"A profile with this name already exists");
|
||||
@@ -281,6 +388,6 @@ void vfs::CProfileStack::PushProfile(CVirtualProfile* pProfile)
|
||||
|
||||
vfs::CProfileStack::Iterator vfs::CProfileStack::begin()
|
||||
{
|
||||
return Iterator(*this);
|
||||
return Iterator(new IterImpl(this));
|
||||
}
|
||||
|
||||
|
||||
+25
-54
@@ -8,86 +8,57 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class CVirtualProfile
|
||||
class VFS_API CVirtualProfile
|
||||
{
|
||||
typedef std::map<vfs::Path,vfs::IBaseLocation*, vfs::Path::Less> tLocations;
|
||||
typedef std::set<vfs::IBaseLocation*> tUniqueLoc;
|
||||
|
||||
class IterImpl;
|
||||
class FileIterImpl;
|
||||
public:
|
||||
//////////////////////////////////////////////
|
||||
class Iterator
|
||||
{
|
||||
friend class CVirtualProfile;
|
||||
private:
|
||||
Iterator(CVirtualProfile& rProf);
|
||||
public:
|
||||
Iterator();
|
||||
~Iterator();
|
||||
//////
|
||||
vfs::IBaseLocation* value() const;
|
||||
void next();
|
||||
bool end() const;
|
||||
private:
|
||||
CVirtualProfile* m_pProf;
|
||||
tUniqueLoc::iterator _loc_iter;
|
||||
};
|
||||
//////////////////////////////////////////////
|
||||
friend class Iterator;
|
||||
public:
|
||||
CVirtualProfile(utf8string const& sProfileName, bool bWriteable = false);
|
||||
typedef TIterator<vfs::IBaseLocation> Iterator;
|
||||
typedef TIterator<vfs::IBaseFile> FileIterator;
|
||||
|
||||
CVirtualProfile(utf8string const& sProfileName, bool bWritable = false);
|
||||
~CVirtualProfile();
|
||||
|
||||
const utf8string Name;
|
||||
const bool Writeable;
|
||||
const utf8string cName;
|
||||
const bool cWritable;
|
||||
|
||||
Iterator begin();
|
||||
FileIterator files(vfs::Path const& sPattern);
|
||||
|
||||
void AddLocation(vfs::IBaseLocation* pLoc);
|
||||
vfs::IBaseLocation* GetLocation(vfs::Path const& sPath) const;
|
||||
vfs::IBaseFile* GetFile(vfs::Path const& sPath) const;
|
||||
void addLocation(vfs::IBaseLocation* pLoc);
|
||||
vfs::IBaseLocation* getLocation(vfs::Path const& sPath) const;
|
||||
vfs::IBaseFile* getFile(vfs::Path const& sPath) const;
|
||||
private:
|
||||
void operator=(vfs::CVirtualProfile const& vprof);
|
||||
tLocations m_mapLocations;
|
||||
tUniqueLoc m_setLocations;
|
||||
};
|
||||
|
||||
class CProfileStack
|
||||
class VFS_API CProfileStack
|
||||
{
|
||||
class IterImpl;
|
||||
public:
|
||||
//////////////////////////////////////////////
|
||||
class Iterator
|
||||
{
|
||||
friend class CProfileStack;
|
||||
private:
|
||||
Iterator(CProfileStack& rPStack);
|
||||
public:
|
||||
Iterator();
|
||||
~Iterator();
|
||||
//////
|
||||
CVirtualProfile* value() const;
|
||||
void next();
|
||||
bool end() const;
|
||||
private:
|
||||
CProfileStack* m_pPStack;
|
||||
std::list<CVirtualProfile*>::iterator _prof_iter;
|
||||
};
|
||||
//////////////////////////////////////////////
|
||||
friend class Iterator;
|
||||
public:
|
||||
typedef vfs::TIterator<CVirtualProfile> Iterator;
|
||||
|
||||
CProfileStack();
|
||||
~CProfileStack();
|
||||
|
||||
CVirtualProfile* GetWriteProfile();
|
||||
CVirtualProfile* GetProfile(utf8string const& sName) const;
|
||||
CVirtualProfile* getWriteProfile();
|
||||
CVirtualProfile* getProfile(utf8string const& sName) const;
|
||||
|
||||
CVirtualProfile* TopProfile() const;
|
||||
CVirtualProfile* topProfile() const;
|
||||
/**
|
||||
* All files from the top profile will be removed from the VFS and the profile object will be deleted.
|
||||
*/
|
||||
bool PopProfile();
|
||||
void PushProfile(CVirtualProfile* pProfile);
|
||||
bool popProfile();
|
||||
void pushProfile(CVirtualProfile* pProfile);
|
||||
|
||||
Iterator begin();
|
||||
private:
|
||||
std::list<CVirtualProfile*> m_lProfiles;
|
||||
std::list<vfs::CVirtualProfile*> m_profiles;
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "vfs_settings.h"
|
||||
|
||||
static bool s_UseUnicode = true;
|
||||
|
||||
void vfs::Settings::setUseUnicode(bool useUnicode)
|
||||
{
|
||||
s_UseUnicode = useUnicode;
|
||||
}
|
||||
|
||||
bool vfs::Settings::getUseUnicode()
|
||||
{
|
||||
return s_UseUnicode;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef _VFS_SETTIGNS_H_
|
||||
#define _VFS_SETTIGNS_H_
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
class Settings
|
||||
{
|
||||
public:
|
||||
static void setUseUnicode(bool useUnicode);
|
||||
static bool getUseUnicode();
|
||||
};
|
||||
}
|
||||
|
||||
#endif // _VFS_SETTIGNS_H_
|
||||
+31
-465
@@ -5,507 +5,73 @@
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
std::string vfs::TrimString<std::string>(std::string const& sStr, vfs::Int32 iMinPos, vfs::Int32 iMaxPos)
|
||||
namespace vfs
|
||||
{
|
||||
if(iMinPos >= iMaxPos || iMaxPos < 0)
|
||||
const vfs::size_t npos = vfs::size_t(-1);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
std::string vfs::trimString<std::string>(std::string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
||||
{
|
||||
if(iMinPos >= iMaxPos || iMaxPos == vfs::npos)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
vfs::Int32 iStart,iEnd;
|
||||
iStart = sStr.find_first_not_of(" \t\r\n",iMinPos);
|
||||
iEnd = sStr.find_last_not_of(" \t\r\n",iMaxPos);
|
||||
if( (iStart >= 0) && (iEnd >= 0) )
|
||||
::size_t iStart,iEnd;
|
||||
iStart = sStr.find_first_not_of(" \t\r\n",(::size_t)iMinPos);
|
||||
iEnd = sStr.find_last_not_of(" \t\r\n",(::size_t)iMaxPos);
|
||||
if( (iStart != std::string::npos) && (iEnd != std::string::npos) )
|
||||
{
|
||||
return sStr.substr(iStart,iEnd-iStart+1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
template<>
|
||||
std::wstring vfs::TrimString<std::wstring>(std::wstring const& sStr, vfs::Int32 iMinPos, vfs::Int32 iMaxPos)
|
||||
std::wstring vfs::trimString<std::wstring>(std::wstring const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
||||
{
|
||||
if(iMinPos >= iMaxPos || iMaxPos < 0)
|
||||
if(iMinPos >= iMaxPos || iMaxPos == vfs::npos)
|
||||
{
|
||||
return L"";
|
||||
}
|
||||
vfs::Int32 iStart,iEnd;
|
||||
iStart = sStr.find_first_not_of(L" \t\r\n",iMinPos);
|
||||
iEnd = sStr.find_last_not_of(L" \t\r\n",iMaxPos);
|
||||
if( (iStart >= 0) && (iEnd >= 0) )
|
||||
::size_t iStart,iEnd;
|
||||
iStart = sStr.find_first_not_of(L" \t\r\n",(::size_t)iMinPos);
|
||||
iEnd = sStr.find_last_not_of(L" \t\r\n",(::size_t)iMaxPos);
|
||||
if( (iStart != std::wstring::npos) && (iEnd != std::wstring::npos) )
|
||||
{
|
||||
return sStr.substr(iStart,iEnd-iStart+1);
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
template<>
|
||||
utf8string vfs::TrimString<utf8string>(utf8string const& sStr, vfs::Int32 iMinPos, vfs::Int32 iMaxPos)
|
||||
utf8string vfs::trimString<utf8string>(utf8string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos)
|
||||
{
|
||||
return vfs::TrimString(sStr.c_wcs(), iMinPos, iMaxPos);
|
||||
return vfs::trimString(sStr.c_wcs(), iMinPos, iMaxPos);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline static void UnifySeparators(utf8string::str_t &sPath)
|
||||
template<>
|
||||
BuildString& BuildString::add<utf8string>(utf8string const& value)
|
||||
{
|
||||
utf8string::char_t &raw = sPath[0];
|
||||
utf8string::ptr_t raw_ptr = &raw;
|
||||
while(*raw_ptr != 0)
|
||||
{
|
||||
if(*raw_ptr == '\\' || *raw_ptr == '/')
|
||||
{
|
||||
*raw_ptr = vfs::Const::SEPARATOR_CHAR();
|
||||
}
|
||||
raw_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call after unifying separators
|
||||
*/
|
||||
inline unsigned int RemoveSeparators(utf8string::str_t &str)
|
||||
{
|
||||
vfs::UInt32 sepcount = 0;
|
||||
vfs::Int32 numsep = 0;
|
||||
size_t put_pos = 0;
|
||||
size_t len = str.length();
|
||||
utf8string::char_t& raw = str[0];
|
||||
utf8string::ptr_t old_ptr = &raw;
|
||||
utf8string::ptr_t new_ptr = &raw;
|
||||
utf8string::ptr_t last_ptr = &raw;
|
||||
while(*old_ptr != 0)
|
||||
{
|
||||
if(*old_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
numsep++;
|
||||
if(numsep == 1)
|
||||
{
|
||||
sepcount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have normal text (again)
|
||||
numsep = 0;
|
||||
}
|
||||
if(numsep <= 1)
|
||||
{
|
||||
*new_ptr = *old_ptr;
|
||||
last_ptr = new_ptr++;
|
||||
put_pos++;
|
||||
}
|
||||
old_ptr++;
|
||||
}
|
||||
if(*last_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
put_pos--;
|
||||
if(sepcount>0)
|
||||
{
|
||||
sepcount--;
|
||||
}
|
||||
}
|
||||
if(put_pos < len)
|
||||
{
|
||||
str.erase(put_pos);
|
||||
}
|
||||
return sepcount;
|
||||
}
|
||||
|
||||
inline void RemoveLastSeparator(utf8string::str_t &str)
|
||||
{
|
||||
if( *str.rbegin() == vfs::Const::SEPARATOR_CHAR() )
|
||||
{
|
||||
str.erase( str.length()-1);
|
||||
}
|
||||
}
|
||||
|
||||
inline void RemoveDots(utf8string::str_t &str, vfs::UInt32 number_of_separators)
|
||||
{
|
||||
utf8string::char_t& raw = str[0];
|
||||
utf8string::ptr_t old_ptr = &raw;
|
||||
utf8string::ptr_t new_ptr = &raw;
|
||||
utf8string::size_t new_pos = 0;
|
||||
utf8string::size_t LENGTH = str.length();
|
||||
bool dirty = false;
|
||||
|
||||
// see if we start with ./ (not . as this might be a hidden files on unix systems)
|
||||
if( (LENGTH > 1) && (*old_ptr == vfs::Const::DOT_CHAR()) && (*(old_ptr+1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
old_ptr += 2;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
std::vector<utf8string::ptr_t> sub_strings;
|
||||
sub_strings.resize(number_of_separators);
|
||||
int pos=0;
|
||||
|
||||
if(*old_ptr != 0 && *old_ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
// in-place : just move along
|
||||
new_ptr++;
|
||||
old_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_ptr++ = *old_ptr++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
sub_strings[pos++] = new_ptr;
|
||||
|
||||
size_t current_position = 0;
|
||||
while(*old_ptr != 0)
|
||||
{
|
||||
if(*old_ptr != vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(!dirty)
|
||||
{
|
||||
new_ptr++;
|
||||
old_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
*new_ptr++ = *old_ptr++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
*new_ptr++ = *old_ptr++;
|
||||
sub_strings[pos++] = new_ptr;
|
||||
|
||||
if((&raw+3) < old_ptr)
|
||||
{
|
||||
if( (*(old_ptr-4) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-3) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 1)
|
||||
{
|
||||
new_ptr = sub_strings[pos-3];
|
||||
pos -= 2;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
else if((*(old_ptr-3) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 0)
|
||||
{
|
||||
new_ptr = sub_strings[pos-2];
|
||||
pos -= 1;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((&raw+2) < old_ptr)
|
||||
{
|
||||
if( (*(old_ptr-3) == vfs::Const::SEPARATOR_CHAR()) &&
|
||||
(*(old_ptr-2) == vfs::Const::DOT_CHAR()) &&
|
||||
(*(old_ptr-1) == vfs::Const::SEPARATOR_CHAR()) )
|
||||
{
|
||||
if(pos > 0)
|
||||
{
|
||||
new_ptr = sub_strings[pos-2];
|
||||
pos -= 1;
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int ttt = (new_ptr - &raw);
|
||||
if(ttt < LENGTH)
|
||||
{
|
||||
str.erase(ttt);
|
||||
}
|
||||
}
|
||||
|
||||
void GetFirstLastSeparator(utf8string::str_t &sPath, vfs::Int32 &iFirst, vfs::Int32 &iLast)
|
||||
{
|
||||
utf8string::char_t& raw = sPath[0];
|
||||
utf8string::ptr_t ptr = &raw;
|
||||
utf8string::size_t pos = 0;
|
||||
while(*ptr != 0)
|
||||
{
|
||||
if(*ptr == vfs::Const::SEPARATOR_CHAR())
|
||||
{
|
||||
if(iFirst < 0)
|
||||
{
|
||||
iFirst = pos;
|
||||
}
|
||||
iLast = pos;
|
||||
}
|
||||
pos++;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
bool vfs::Path::Less::operator ()(vfs::Path const& s1, vfs::Path const& s2) const
|
||||
{
|
||||
return utf8string::less(s1._path,s2._path);
|
||||
}
|
||||
bool vfs::Path::Equal::operator ()(vfs::Path const& s1, vfs::Path const& s2) const
|
||||
{
|
||||
return utf8string::equal(s1._path,s2._path);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
vfs::Path::Path(utf8string const& sPath)
|
||||
: _path(sPath), _first(-1), _last(-1)
|
||||
{
|
||||
DoCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(const char* sPath)
|
||||
: _path(sPath), _first(-1), _last(-1)
|
||||
{
|
||||
DoCheck();
|
||||
}
|
||||
|
||||
vfs::Path::Path(const wchar_t* sPath)
|
||||
: _path(sPath), _first(-1), _last(-1)
|
||||
{
|
||||
DoCheck();
|
||||
}
|
||||
|
||||
bool vfs::Path::empty() const
|
||||
{
|
||||
// is there a case where a non-empty string can become empty after a check?
|
||||
// if it is so then i don't care
|
||||
return _path.empty();
|
||||
}
|
||||
utf8string::size_t vfs::Path::length() const
|
||||
{
|
||||
return _path.length();
|
||||
}
|
||||
|
||||
|
||||
void vfs::Path::DoCheck()
|
||||
{
|
||||
if(!_path.empty())
|
||||
{
|
||||
UnifySeparators(_path.r_wcs());
|
||||
|
||||
vfs::UInt32 number_of_separators = RemoveSeparators(_path.r_wcs());
|
||||
|
||||
if(number_of_separators>0)
|
||||
{
|
||||
RemoveDots(_path.r_wcs(),number_of_separators+1);
|
||||
GetFirstLastSeparator(_path.r_wcs(),_first,_last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const utf8string& vfs::Path::operator()() const
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
bool vfs::Path::SplitLast(vfs::Path &rsHead, vfs::Path &rsLast) const
|
||||
{
|
||||
bool success = SplitLast(rsHead._path, rsLast._path);
|
||||
// no need to check, as the original path is already checked
|
||||
//rPath.DoCheck();
|
||||
//rFile.DoCheck();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool vfs::Path::SplitLast(utf8string &rsHead, utf8string &rsLast) const
|
||||
{
|
||||
utf8string::str_t& rHead = rsHead.r_wcs();
|
||||
utf8string::str_t& rLast = rsLast.r_wcs();
|
||||
if(&rHead == &_path.c_wcs() || &rLast == &_path.c_wcs())
|
||||
{
|
||||
THROWEXCEPTION(L"cannot use output parameters that are equal to 'this'");
|
||||
}
|
||||
if(_path.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
utf8string::size_t LENGTH = _path.length();
|
||||
|
||||
#if 1
|
||||
// use results from "GetFirstLastSeparator(..)"
|
||||
if(_last >= 0)
|
||||
{
|
||||
rHead.assign(_path.c_wcs().substr(0,_last));
|
||||
rLast.assign(_path.c_wcs().substr(_last+1,LENGTH-_last-1));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
vfs::Int32 position = LENGTH;
|
||||
while(--position >= 0)
|
||||
{
|
||||
utf8string::char_t const& c = _path.c_wcs()[position];
|
||||
if(c == '\\' || c == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(position >= 0)
|
||||
{
|
||||
rHead.assign(_path.c_wcs().substr(0,position));
|
||||
rLast.assign(_path.c_wcs().substr(position+1,LENGTH-position-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
rHead.assign(vfs::Const::EMPTY());
|
||||
rLast.assign(_path.c_wcs());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vfs::Path::SplitFirst(vfs::Path &rsFirst, vfs::Path &rsTail) const
|
||||
{
|
||||
bool success = SplitFirst(rsFirst._path, rsTail._path);
|
||||
// no need to check, as the original path is already checked
|
||||
//rPath.DoCheck();
|
||||
//rFile.DoCheck();
|
||||
return success;
|
||||
}
|
||||
bool vfs::Path::SplitFirst(utf8string &rsFirst, utf8string &rsTail) const
|
||||
{
|
||||
utf8string::str_t& rFirst = rsFirst.r_wcs();
|
||||
utf8string::str_t& rTail = rsTail.r_wcs();
|
||||
|
||||
if(_path.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(&rFirst == &_path.c_wcs() || &rTail == &_path.c_wcs())
|
||||
{
|
||||
THROWEXCEPTION(L"cannot use output parameters that are equal to this");
|
||||
}
|
||||
|
||||
utf8string::size_t LENGTH = _path.length();
|
||||
|
||||
#if 1
|
||||
// use results from "GetFirstLastSeparator(..)"
|
||||
if(_first >= 0)
|
||||
{
|
||||
rFirst.assign(_path.c_wcs().substr(0,_first));
|
||||
rTail.assign(_path.c_wcs().substr(_first+1,LENGTH-_first-1));
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
vfs::UInt32 position = 0;
|
||||
while(position++ < LENGTH)
|
||||
{
|
||||
utf8string::char_t const& c = _path.c_wcs()[position];
|
||||
if(c == '\\' || c == '/')
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(position < LENGTH)
|
||||
{
|
||||
rFirst.assign(_path.c_wcs().substr(0,position));
|
||||
rTail.assign(_path.c_wcs().substr(position+1,LENGTH-position-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
rFirst.assign(_path.c_wcs());
|
||||
rTail.assign(vfs::Const::EMPTY());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool vfs::Path::Extension(utf8string &sExt) const
|
||||
{
|
||||
utf8string::size_t SIZE = _path.length();
|
||||
if(_path.c_wcs().at(SIZE-1) == L'.')
|
||||
{
|
||||
// not an extension
|
||||
return false;
|
||||
}
|
||||
for(vfs::UInt32 i=SIZE-2; i > 0; i--)
|
||||
{
|
||||
if(_path.c_wcs().at(i) == L'.')
|
||||
{
|
||||
sExt.r_wcs().assign(&_path.c_wcs().at(i+1),SIZE-i-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
vfs::Path& vfs::Path::operator+=(vfs::Path const& p)
|
||||
{
|
||||
if(_path.empty())
|
||||
{
|
||||
_path = p._path;
|
||||
}
|
||||
else if(!p.empty())
|
||||
{
|
||||
utf8string::str_t& s =_path.r_wcs();
|
||||
s += vfs::Const::SEPARATOR();
|
||||
s += p._path.c_wcs();
|
||||
GetFirstLastSeparator(s,_first,_last);
|
||||
}
|
||||
this->add(value.c_str());
|
||||
return *this;
|
||||
}
|
||||
|
||||
vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2)
|
||||
{
|
||||
vfs::Path newpath = p1;
|
||||
newpath += p2;
|
||||
return newpath;
|
||||
}
|
||||
|
||||
bool vfs::Path::operator==(vfs::Path const& p2)
|
||||
{
|
||||
return utf8string::equal(_path, p2._path);
|
||||
}
|
||||
|
||||
|
||||
class PathAccess
|
||||
{
|
||||
public:
|
||||
PathAccess(vfs::Path const& p) : str(p._path) {};
|
||||
utf8string const& str;
|
||||
};
|
||||
|
||||
bool operator==(vfs::Path const& p1, vfs::Path const& p2)
|
||||
{
|
||||
return StrCmp::Equal(PathAccess(p1).str, PathAccess(p2).str);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, utf8string const& p2)
|
||||
{
|
||||
return StrCmp::Equal(PathAccess(p1).str, p2);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, utf8string::str_t const& p2)
|
||||
{
|
||||
return StrCmp::Equal(PathAccess(p1).str, p2);
|
||||
}
|
||||
bool operator==(vfs::Path const& p1, const utf8string::char_t* p2)
|
||||
{
|
||||
return StrCmp::Equal(PathAccess(p1).str, p2);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* try to recursively match the pattern
|
||||
*/
|
||||
bool MatchPattern(utf8string const& sPattern, utf8string const& sStr)
|
||||
bool matchPattern(utf8string const& sPattern, utf8string const& sStr)
|
||||
{
|
||||
return MatchPattern(sPattern,sStr.c_wcs());
|
||||
return matchPattern(sPattern,sStr.c_wcs());
|
||||
}
|
||||
|
||||
bool MatchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
||||
bool matchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
||||
{
|
||||
utf8string::str_t const& pat = sPattern.c_wcs();
|
||||
|
||||
@@ -522,7 +88,7 @@ bool MatchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
||||
return true;
|
||||
}
|
||||
utf8string::char_t atpos1 = pat.at(1);
|
||||
utf8string::size_t match = -1;
|
||||
utf8string::size_t match = utf8string::size_t(-1);
|
||||
do
|
||||
{
|
||||
match = sStr.find_first_of(atpos1,match+1);
|
||||
@@ -530,7 +96,7 @@ bool MatchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} while(!MatchPattern( pat.substr(1,pat.length()-1), sStr.substr(match,sStr.length()-match) ));
|
||||
} while(!matchPattern( pat.substr(1,pat.length()-1), sStr.substr(match,sStr.length()-match) ));
|
||||
return true;
|
||||
}
|
||||
else // if(star > 0)
|
||||
@@ -540,7 +106,7 @@ bool MatchPattern(utf8string const& sPattern, utf8string::str_t const& sStr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return MatchPattern( pat.substr(star,pat.length()-star), sStr.substr(star,sStr.length()-star) );
|
||||
return matchPattern( pat.substr(star,pat.length()-star), sStr.substr(star,sStr.length()-star) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+55
-68
@@ -8,17 +8,36 @@
|
||||
|
||||
namespace vfs
|
||||
{
|
||||
typedef unsigned long UInt64;
|
||||
typedef unsigned int UInt32;
|
||||
typedef unsigned short UInt16;
|
||||
typedef unsigned char UInt8;
|
||||
typedef unsigned char UByte;
|
||||
#ifdef WIN32
|
||||
typedef unsigned __int64 UInt64;
|
||||
typedef unsigned __int32 UInt32;
|
||||
typedef unsigned __int16 UInt16;
|
||||
typedef unsigned __int8 UInt8;
|
||||
typedef unsigned __int8 UByte;
|
||||
|
||||
typedef long Int64;
|
||||
typedef int Int32;
|
||||
typedef short Int16;
|
||||
typedef char Int8;
|
||||
typedef char Byte;
|
||||
typedef __int64 Int64;
|
||||
typedef __int32 Int32;
|
||||
typedef __int16 Int16;
|
||||
typedef __int8 Int8;
|
||||
typedef __int8 Byte;
|
||||
#elif __linux__
|
||||
typedef uint64_t UInt64;
|
||||
typedef uint32_t UInt32;
|
||||
typedef uint16_t UInt16;
|
||||
typedef uint8_t UInt8;
|
||||
typedef uint8_t UByte;
|
||||
|
||||
typedef int64_t Int64;
|
||||
typedef int32_t Int32;
|
||||
typedef int16_t Int16;
|
||||
typedef int8_t Int8;
|
||||
typedef char Byte;
|
||||
#endif
|
||||
|
||||
typedef ::size_t size_t;
|
||||
typedef ::off_t offset_t;
|
||||
|
||||
extern const vfs::size_t npos;
|
||||
}
|
||||
|
||||
namespace vfs
|
||||
@@ -26,7 +45,7 @@ namespace vfs
|
||||
namespace Const
|
||||
{
|
||||
inline const utf8string::str_t EMPTY() { return L""; };
|
||||
inline const utf8string::char_t EMPTY_CHAR() { return L''; };
|
||||
//inline const utf8string::char_t EMPTY_CHAR() { return L''; };
|
||||
|
||||
inline const utf8string::str_t DOT() { return L"."; };
|
||||
inline const utf8string::char_t DOT_CHAR() { return L'.'; };
|
||||
@@ -42,7 +61,7 @@ namespace vfs
|
||||
inline const utf8string::char_t SEPARATOR_CHAR() { return L'\\'; };
|
||||
#else
|
||||
inline const utf8string::str_t SEPARATOR() { return L"/"; };
|
||||
inline const utf8string::char_type SEPARATOR_CHAR() { return L'/'; };
|
||||
inline const utf8string::char_t SEPARATOR_CHAR() { return L'/'; };
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -53,77 +72,43 @@ namespace vfs
|
||||
{
|
||||
// remove leading and trailing white characters;
|
||||
template<typename StringType>
|
||||
StringType TrimString(StringType const& sStr, Int32 iMinPos, Int32 iMaxPos);
|
||||
StringType trimString(StringType const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
|
||||
template<>
|
||||
std::string TrimString<std::string>(std::string const& sStr, Int32 iMinPos, Int32 iMaxPos);
|
||||
std::string trimString<std::string>(std::string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
|
||||
template<>
|
||||
std::wstring TrimString<std::wstring>(std::wstring const& sStr, Int32 iMinPos, Int32 iMaxPos);
|
||||
std::wstring trimString<std::wstring>(std::wstring const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
|
||||
template<>
|
||||
utf8string TrimString<utf8string>(utf8string const& sStr, Int32 iMinPos, Int32 iMaxPos);
|
||||
utf8string trimString<utf8string>(utf8string const& sStr, vfs::size_t iMinPos, vfs::size_t iMaxPos);
|
||||
}
|
||||
|
||||
class PathAccess;
|
||||
namespace vfs
|
||||
class VFS_API BuildString
|
||||
{
|
||||
class Path
|
||||
public:
|
||||
template<typename T>
|
||||
BuildString& add(T const& value)
|
||||
{
|
||||
friend class PathAccess;
|
||||
public:
|
||||
class Less{
|
||||
public:
|
||||
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
|
||||
};
|
||||
class Equal{
|
||||
public:
|
||||
bool operator()(vfs::Path const& s1, vfs::Path const& s2) const;
|
||||
};
|
||||
public:
|
||||
Path() : _first(-1), _last(-1) {};
|
||||
Path(const char* sPath);
|
||||
Path(const wchar_t* sPath);
|
||||
Path(utf8string const& sPath);
|
||||
_strstr << value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const utf8string& operator()() const;
|
||||
Path& operator+=(Path const& p);
|
||||
utf8string::str_t get()
|
||||
{
|
||||
return _strstr.str();
|
||||
}
|
||||
private:
|
||||
std::basic_stringstream<utf8string::char_t> _strstr;
|
||||
};
|
||||
|
||||
bool empty() const;
|
||||
|
||||
utf8string::size_t length() const;
|
||||
|
||||
void DoCheck();
|
||||
|
||||
bool SplitLast(utf8string& rsHead, utf8string& rsLast) const;
|
||||
bool SplitLast(Path &rsHead, Path &rsLast) const;
|
||||
|
||||
bool SplitFirst(utf8string& rsFirst, utf8string& rsTail) const;
|
||||
bool SplitFirst(Path &rsFirst, Path &rsTail) const;
|
||||
|
||||
bool Extension(utf8string &sExt) const;
|
||||
|
||||
bool operator==(vfs::Path const& p2);
|
||||
private:
|
||||
utf8string _path;
|
||||
vfs::Int32 _first,_last;
|
||||
};
|
||||
}
|
||||
|
||||
// add only valid Path objects
|
||||
vfs::Path operator+(vfs::Path const& p1, vfs::Path const& p2);
|
||||
|
||||
// compare path to string (that can be an invalid path)
|
||||
bool operator==(vfs::Path const& p1, vfs::Path const& p2);
|
||||
// use with care as these string can be different from the internal representation although they seem to be equal
|
||||
bool operator==(vfs::Path const& p1, utf8string const& p2);
|
||||
bool operator==(vfs::Path const& p1, utf8string::str_t const& p2);
|
||||
bool operator==(vfs::Path const& p1, const utf8string::char_t* p2);
|
||||
template<>
|
||||
BuildString& BuildString::add<utf8string>(utf8string const& value);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
bool MatchPattern(utf8string const& sPattern, utf8string const& sStr);
|
||||
bool MatchPattern(utf8string const& sPattern, utf8string::str_t const& sStr);
|
||||
bool matchPattern(utf8string const& sPattern, utf8string const& sStr);
|
||||
bool matchPattern(utf8string const& sPattern, utf8string::str_t const& sStr);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
@@ -169,6 +154,8 @@ public:
|
||||
}
|
||||
}
|
||||
private:
|
||||
void operator=(ObjBlockAllocator<T> const& t);
|
||||
|
||||
typedef std::vector<T> tBlock;
|
||||
std::vector<tBlock*> _ObjPool;
|
||||
unsigned int _ObjNew;
|
||||
|
||||
+26
-27
@@ -5,14 +5,14 @@
|
||||
// static member
|
||||
ObjBlockAllocator<vfs::CVirtualFile>* vfs::CVirtualFile::_vfile_pool = NULL;
|
||||
|
||||
vfs::CVirtualFile* vfs::CVirtualFile::Create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack)
|
||||
vfs::CVirtualFile* vfs::CVirtualFile::create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack)
|
||||
{
|
||||
unsigned int ID=0;
|
||||
#ifdef VFILE_BLOCK_CREATE
|
||||
if(!_vfile_pool)
|
||||
{
|
||||
_vfile_pool = new ObjBlockAllocator<vfs::CVirtualFile>();
|
||||
CFileAllocator::RegisterAllocator(_vfile_pool);
|
||||
CFileAllocator::registerAllocator(_vfile_pool);
|
||||
}
|
||||
CVirtualFile* file = _vfile_pool->New(&ID);
|
||||
#else
|
||||
@@ -24,7 +24,7 @@ vfs::CVirtualFile* vfs::CVirtualFile::Create(vfs::Path const& sFilePath, vfs::CP
|
||||
return file;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFile::Destroy()
|
||||
void vfs::CVirtualFile::destroy()
|
||||
{
|
||||
#ifndef VFILE_BLOCK_CREATE
|
||||
delete this;
|
||||
@@ -33,8 +33,7 @@ void vfs::CVirtualFile::Destroy()
|
||||
|
||||
|
||||
vfs::CVirtualFile::CVirtualFile()
|
||||
: _path(""), _top_pname("_INVALID_"), _top_file(NULL), _pstack(NULL)
|
||||
, _myID(-1)
|
||||
: _path(L""), _top_pname(L"_INVALID_"), _top_file(NULL), _pstack(NULL), _myID(vfs::UInt32(-1))
|
||||
{
|
||||
};
|
||||
|
||||
@@ -42,12 +41,12 @@ vfs::CVirtualFile::~CVirtualFile()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::Path const& vfs::CVirtualFile::Path()
|
||||
vfs::Path const& vfs::CVirtualFile::path()
|
||||
{
|
||||
return _path;
|
||||
}
|
||||
|
||||
void vfs::CVirtualFile::Add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace)
|
||||
void vfs::CVirtualFile::add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace)
|
||||
{
|
||||
if(pFile)
|
||||
{
|
||||
@@ -65,18 +64,18 @@ void vfs::CVirtualFile::Add(vfs::IBaseFile *pFile, utf8string sProfileName, bool
|
||||
THROWIFFALSE( StrCmp::Equal(sProfileName,_top_pname), L"same file, different profile name");
|
||||
}
|
||||
// OK, not the same file, but these two different files are supposed to have the asme filename
|
||||
THROWIFFALSE( _top_file->GetFileName() == pFile->GetFileName(), L"different filenames");
|
||||
THROWIFFALSE( _top_file->getName() == pFile->getName(), L"different filenames");
|
||||
// set new file only when its profile is on top of the current file's profile
|
||||
bool bFoundOld = false, bFoundNew = false;
|
||||
vfs::CProfileStack::Iterator it = _pstack->begin();
|
||||
for(; !it.end(); it.next())
|
||||
{
|
||||
if(_top_pname == it.value()->Name)
|
||||
if(_top_pname == it.value()->cName)
|
||||
{
|
||||
bFoundOld = true;
|
||||
break;
|
||||
}
|
||||
else if(sProfileName == it.value()->Name)
|
||||
else if(sProfileName == it.value()->cName)
|
||||
{
|
||||
bFoundNew = true;
|
||||
break;
|
||||
@@ -94,11 +93,11 @@ void vfs::CVirtualFile::Add(vfs::IBaseFile *pFile, utf8string sProfileName, bool
|
||||
* @returns : returns true if pFile is not top file or top file could be replaced with another file
|
||||
* returns false if there is no more files with given name. in this case object should be destroyed
|
||||
*/
|
||||
bool vfs::CVirtualFile::Remove(vfs::IBaseFile *pFile)
|
||||
bool vfs::CVirtualFile::remove(vfs::IBaseFile *pFile)
|
||||
{
|
||||
if(_top_file == pFile)
|
||||
{
|
||||
if(_path == pFile->GetFullPath())
|
||||
if(_path == pFile->getPath())
|
||||
{
|
||||
// need to replace '_top_file'
|
||||
vfs::CProfileStack::Iterator prof_it = _pstack->begin();
|
||||
@@ -107,11 +106,11 @@ bool vfs::CVirtualFile::Remove(vfs::IBaseFile *pFile)
|
||||
CVirtualProfile *pProf = prof_it.value();
|
||||
if(pProf)
|
||||
{
|
||||
vfs::IBaseFile *file = pProf->GetFile(_path);
|
||||
vfs::IBaseFile *file = pProf->getFile(_path);
|
||||
if(file && (file != pFile))
|
||||
{
|
||||
_top_file = file;
|
||||
_top_pname = pProf->Name;
|
||||
_top_pname = pProf->cName;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -129,21 +128,21 @@ bool vfs::CVirtualFile::Remove(vfs::IBaseFile *pFile)
|
||||
return true;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFile::File(ESearchFile eSearch)
|
||||
vfs::IBaseFile* vfs::CVirtualFile::file(ESearchFile eSearch)
|
||||
{
|
||||
if(eSearch == SF_TOP)
|
||||
{
|
||||
return _top_file;
|
||||
}
|
||||
else if(eSearch == SF_FIRST_WRITEABLE)
|
||||
else if(eSearch == SF_FIRST_WRITABLE)
|
||||
{
|
||||
CVirtualProfile *pVProf = _pstack->GetWriteProfile();
|
||||
CVirtualProfile *pVProf = _pstack->getWriteProfile();
|
||||
if(pVProf)
|
||||
{
|
||||
return pVProf->GetFile(_path);
|
||||
return pVProf->getFile(_path);
|
||||
}
|
||||
}
|
||||
else if(eSearch == SF_STOP_ON_WRITEABLE_PROFILE)
|
||||
else if(eSearch == SF_STOP_ON_WRITABLE_PROFILE)
|
||||
{
|
||||
vfs::CProfileStack::Iterator prof_it = _pstack->begin();
|
||||
for(; !prof_it.end(); prof_it.next())
|
||||
@@ -151,13 +150,13 @@ vfs::IBaseFile* vfs::CVirtualFile::File(ESearchFile eSearch)
|
||||
CVirtualProfile *pProf = prof_it.value();
|
||||
if(pProf)
|
||||
{
|
||||
if(pProf->Writeable)
|
||||
if(pProf->cWritable)
|
||||
{
|
||||
return pProf->GetFile(_path);
|
||||
return pProf->getFile(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
vfs::IBaseFile *pFile = pProf->GetFile(_path);
|
||||
vfs::IBaseFile *pFile = pProf->getFile(_path);
|
||||
if(pFile)
|
||||
{
|
||||
return pFile;
|
||||
@@ -169,25 +168,25 @@ vfs::IBaseFile* vfs::CVirtualFile::File(ESearchFile eSearch)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualFile::File(utf8string const& sProfileName)
|
||||
vfs::IBaseFile* vfs::CVirtualFile::file(utf8string const& sProfileName)
|
||||
{
|
||||
if(sProfileName == _top_pname)
|
||||
{
|
||||
return vfs::tReadableFile::Cast(_top_file);
|
||||
return vfs::tReadableFile::cast(_top_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
CVirtualProfile* pProf = _pstack->GetProfile(sProfileName);
|
||||
CVirtualProfile* pProf = _pstack->getProfile(sProfileName);
|
||||
if(pProf)
|
||||
{
|
||||
CVirtualProfile::Iterator loc_it = pProf->begin();
|
||||
for(; !loc_it.end(); loc_it.next())
|
||||
{
|
||||
if(loc_it.value() && loc_it.value()->FileExists(_path))
|
||||
if(loc_it.value() && loc_it.value()->fileExists(_path))
|
||||
{
|
||||
if(loc_it.value())
|
||||
{
|
||||
return loc_it.value()->GetFile(_path);
|
||||
return loc_it.value()->getFile(_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-17
@@ -14,33 +14,31 @@ namespace vfs
|
||||
enum ESearchFile
|
||||
{
|
||||
SF_TOP,
|
||||
SF_FIRST_WRITEABLE,
|
||||
SF_STOP_ON_WRITEABLE_PROFILE,
|
||||
SF_FIRST_WRITABLE,
|
||||
SF_STOP_ON_WRITABLE_PROFILE,
|
||||
};
|
||||
public:
|
||||
~CVirtualFile();
|
||||
void Destroy();
|
||||
static CVirtualFile* Create(vfs::Path const& sFilePath, CProfileStack& rPStack);
|
||||
|
||||
vfs::Path const& Path();
|
||||
void Add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace = false);
|
||||
bool Remove(vfs::IBaseFile *pFile);
|
||||
//////////////////////////////////////////////////
|
||||
vfs::IBaseFile* File(ESearchFile eSearch);
|
||||
vfs::IBaseFile* File(utf8string const& sProfileName);
|
||||
//////////////////////////////////////////////////
|
||||
private:
|
||||
friend class std::vector<vfs::CVirtualFile>;
|
||||
CVirtualFile();
|
||||
~CVirtualFile();
|
||||
void destroy();
|
||||
static CVirtualFile* create(vfs::Path const& sFilePath, vfs::CProfileStack& rPStack);
|
||||
|
||||
vfs::Path const& path();
|
||||
void add(vfs::IBaseFile *pFile, utf8string sProfileName, bool bReplace = false);
|
||||
bool remove(vfs::IBaseFile *pFile);
|
||||
//////////////////////////////////////////////////
|
||||
vfs::IBaseFile* file(ESearchFile eSearch);
|
||||
vfs::IBaseFile* file(utf8string const& sProfileName);
|
||||
//////////////////////////////////////////////////
|
||||
private:
|
||||
vfs::Path _path;
|
||||
utf8string _top_pname;
|
||||
vfs::IBaseFile* _top_file;
|
||||
CProfileStack* _pstack;
|
||||
private:
|
||||
unsigned int _myID;
|
||||
vfs::UInt32 _myID;
|
||||
#ifdef VFILE_BLOCK_CREATE
|
||||
static ObjBlockAllocator<CVirtualFile>* _vfile_pool;
|
||||
static ObjBlockAllocator<vfs::CVirtualFile>* _vfile_pool;
|
||||
#endif
|
||||
};
|
||||
} // end namspace
|
||||
|
||||
+72
-71
@@ -5,134 +5,135 @@
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
vfs::CVirtualLocation::Iterator::Iterator(CVirtualLocation* pLoc)
|
||||
: m_pLoc(pLoc)
|
||||
class vfs::CVirtualLocation::VFileIterator : public vfs::CVirtualLocation::Iterator::IImplementation
|
||||
{
|
||||
_vfile_iter = m_pLoc->m_mapVFiles.begin();
|
||||
}
|
||||
friend class vfs::CVirtualLocation;
|
||||
typedef vfs::CVirtualLocation::Iterator::IImplementation tBaseClass;
|
||||
|
||||
vfs::CVirtualLocation::Iterator::Iterator()
|
||||
: m_pLoc(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CVirtualLocation::Iterator::~Iterator()
|
||||
{
|
||||
}
|
||||
|
||||
vfs::CVirtualFile* vfs::CVirtualLocation::Iterator::value()
|
||||
{
|
||||
if(m_pLoc && _vfile_iter != m_pLoc->m_mapVFiles.end())
|
||||
VFileIterator(vfs::CVirtualLocation* pLoc): tBaseClass(), m_pLoc(pLoc)
|
||||
{
|
||||
return _vfile_iter->second;
|
||||
THROWIFFALSE(pLoc, L"");
|
||||
_vfile_iter = m_pLoc->m_VFiles.begin();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vfs::CVirtualLocation::Iterator::next()
|
||||
{
|
||||
if(m_pLoc && _vfile_iter != m_pLoc->m_mapVFiles.end())
|
||||
public:
|
||||
VFileIterator() : tBaseClass(), m_pLoc(NULL)
|
||||
{};
|
||||
virtual ~VFileIterator()
|
||||
{};
|
||||
virtual vfs::CVirtualFile* value()
|
||||
{
|
||||
_vfile_iter++;
|
||||
if(m_pLoc && _vfile_iter != m_pLoc->m_VFiles.end())
|
||||
{
|
||||
return _vfile_iter->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool vfs::CVirtualLocation::Iterator::end()
|
||||
{
|
||||
if(m_pLoc)
|
||||
virtual void next()
|
||||
{
|
||||
return _vfile_iter == m_pLoc->m_mapVFiles.end();
|
||||
if(m_pLoc && _vfile_iter != m_pLoc->m_VFiles.end())
|
||||
{
|
||||
_vfile_iter++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected:
|
||||
virtual tBaseClass* clone()
|
||||
{
|
||||
VFileIterator* iter = new VFileIterator(m_pLoc);
|
||||
iter->_vfile_iter = _vfile_iter;
|
||||
return iter;
|
||||
}
|
||||
private:
|
||||
vfs::CVirtualLocation* m_pLoc;
|
||||
vfs::CVirtualLocation::tVFiles::iterator _vfile_iter;
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
vfs::CVirtualLocation::CVirtualLocation(vfs::Path const& sPath)
|
||||
: Path(sPath), m_bExclusive(false)
|
||||
vfs::CVirtualLocation::CVirtualLocation(vfs::Path const& path)
|
||||
: cPath(path), m_exclusive(false)
|
||||
{};
|
||||
|
||||
vfs::CVirtualLocation::~CVirtualLocation()
|
||||
{
|
||||
tVFiles::iterator it = m_mapVFiles.begin();
|
||||
for(; it != m_mapVFiles.end(); ++it)
|
||||
tVFiles::iterator it = m_VFiles.begin();
|
||||
for(; it != m_VFiles.end(); ++it)
|
||||
{
|
||||
it->second->Destroy();
|
||||
it->second->destroy();
|
||||
}
|
||||
m_mapVFiles.clear();
|
||||
m_VFiles.clear();
|
||||
}
|
||||
|
||||
void vfs::CVirtualLocation::SetIsExclusive(bool bExclusive)
|
||||
void vfs::CVirtualLocation::setIsExclusive(bool exclusive)
|
||||
{
|
||||
m_bExclusive = bExclusive;
|
||||
m_exclusive = exclusive;
|
||||
}
|
||||
bool vfs::CVirtualLocation::GetIsExclusive()
|
||||
bool vfs::CVirtualLocation::getIsExclusive()
|
||||
{
|
||||
return m_bExclusive;
|
||||
return m_exclusive;
|
||||
}
|
||||
|
||||
void vfs::CVirtualLocation::AddFile(vfs::IBaseFile* pFile, utf8string const& sProfileName)
|
||||
void vfs::CVirtualLocation::addFile(vfs::IBaseFile* file, utf8string const& profileName)
|
||||
{
|
||||
tVFiles::iterator it = m_mapVFiles.find(pFile->GetFileName());
|
||||
CVirtualFile *pVFile = NULL;
|
||||
if(it == m_mapVFiles.end())
|
||||
tVFiles::iterator it = m_VFiles.find(file->getName());
|
||||
vfs::CVirtualFile *pVFile = NULL;
|
||||
if(it == m_VFiles.end())
|
||||
{
|
||||
vfs::Path& fp = pFile->GetFullPath();
|
||||
vfs::CProfileStack& stack = *(GetVFS()->GetProfileStack());
|
||||
pVFile = vfs::CVirtualFile::Create(fp,stack);
|
||||
it = m_mapVFiles.insert(m_mapVFiles.end(), std::pair<vfs::Path,vfs::CVirtualFile*>(pFile->GetFileName(),pVFile));
|
||||
vfs::Path fp = file->getPath();
|
||||
vfs::CProfileStack& stack = *(getVFS()->getProfileStack());
|
||||
pVFile = vfs::CVirtualFile::create(fp,stack);
|
||||
it = m_VFiles.insert(m_VFiles.end(), std::pair<vfs::Path,vfs::CVirtualFile*>(file->getName(),pVFile));
|
||||
}
|
||||
it->second->Add(pFile,sProfileName,true);
|
||||
it->second->add(file,profileName,true);
|
||||
}
|
||||
|
||||
vfs::IBaseFile* vfs::CVirtualLocation::GetFile(vfs::Path const& sFilename, utf8string const& sProfileName) const
|
||||
vfs::IBaseFile* vfs::CVirtualLocation::getFile(vfs::Path const& filename, utf8string const& profileName) const
|
||||
{
|
||||
tVFiles::const_iterator cit = m_mapVFiles.find(sFilename);
|
||||
if(cit != m_mapVFiles.end() && cit->second)
|
||||
tVFiles::const_iterator cit = m_VFiles.find(filename);
|
||||
if(cit != m_VFiles.end() && cit->second)
|
||||
{
|
||||
if(sProfileName.empty())
|
||||
if(profileName.empty())
|
||||
{
|
||||
if(m_bExclusive)
|
||||
if(m_exclusive)
|
||||
{
|
||||
return cit->second->File(vfs::CVirtualFile::SF_STOP_ON_WRITEABLE_PROFILE);
|
||||
return cit->second->file(vfs::CVirtualFile::SF_STOP_ON_WRITABLE_PROFILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cit->second->File(vfs::CVirtualFile::SF_TOP);
|
||||
return cit->second->file(vfs::CVirtualFile::SF_TOP);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// you know what you are doing
|
||||
return cit->second->File(sProfileName);
|
||||
return cit->second->file(profileName);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
vfs::CVirtualFile* vfs::CVirtualLocation::GetVFile(vfs::Path const& sFilename)
|
||||
vfs::CVirtualFile* vfs::CVirtualLocation::getVirtualFile(vfs::Path const& filename)
|
||||
{
|
||||
tVFiles::const_iterator cit = m_mapVFiles.find(sFilename);
|
||||
if(cit != m_mapVFiles.end())
|
||||
tVFiles::const_iterator cit = m_VFiles.find(filename);
|
||||
if(cit != m_VFiles.end())
|
||||
{
|
||||
return cit->second;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool vfs::CVirtualLocation::RemoveFile(vfs::IBaseFile* pFile)
|
||||
bool vfs::CVirtualLocation::removeFile(vfs::IBaseFile* file)
|
||||
{
|
||||
if(pFile)
|
||||
if(file)
|
||||
{
|
||||
vfs::Path sDir,sFile;
|
||||
pFile->GetFullPath().SplitLast(sDir,sFile);
|
||||
tVFiles::iterator it = m_mapVFiles.find(sFile);
|
||||
if(it != m_mapVFiles.end())
|
||||
file->getPath().splitLast(sDir,sFile);
|
||||
tVFiles::iterator it = m_VFiles.find(sFile);
|
||||
if(it != m_VFiles.end())
|
||||
{
|
||||
if(!it->second->Remove(pFile))
|
||||
if(!it->second->remove(file))
|
||||
{
|
||||
CVirtualFile* vfile = it->second;
|
||||
//CVirtualFile* vfile = it->second;
|
||||
//delete vfile;
|
||||
m_mapVFiles.erase(it);
|
||||
m_VFiles.erase(it);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -143,6 +144,6 @@ bool vfs::CVirtualLocation::RemoveFile(vfs::IBaseFile* pFile)
|
||||
|
||||
vfs::CVirtualLocation::Iterator vfs::CVirtualLocation::iterate()
|
||||
{
|
||||
return Iterator(this);
|
||||
return Iterator(new VFileIterator(this));
|
||||
}
|
||||
|
||||
|
||||
+14
-24
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "vfs_types.h"
|
||||
#include "Interface/vfs_file_interface.h"
|
||||
#include "Interface/vfs_iterator_interface.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -12,42 +13,31 @@ namespace vfs
|
||||
|
||||
class CVirtualLocation
|
||||
{
|
||||
class VFileIterator;
|
||||
typedef std::map<vfs::Path, CVirtualFile*, vfs::Path::Less> tVFiles;
|
||||
public:
|
||||
class Iterator
|
||||
{
|
||||
friend class CVirtualLocation;
|
||||
Iterator(CVirtualLocation* pLoc);
|
||||
public:
|
||||
Iterator();
|
||||
~Iterator();
|
||||
typedef vfs::TIterator<CVirtualFile> Iterator;
|
||||
|
||||
CVirtualFile* value();
|
||||
void next();
|
||||
bool end();
|
||||
private:
|
||||
CVirtualLocation* m_pLoc;
|
||||
tVFiles::iterator _vfile_iter;
|
||||
};
|
||||
public:
|
||||
CVirtualLocation(vfs::Path const& sPath);
|
||||
~CVirtualLocation();
|
||||
|
||||
const vfs::Path Path;
|
||||
const vfs::Path cPath;
|
||||
|
||||
void SetIsExclusive(bool bExclusive);
|
||||
bool GetIsExclusive();
|
||||
void setIsExclusive(bool exclusive);
|
||||
bool getIsExclusive();
|
||||
|
||||
void AddFile(vfs::IBaseFile* pFile, utf8string const& sProfileName);
|
||||
vfs::IBaseFile* GetFile(vfs::Path const& sFilename, utf8string const& sProfileName = "") const;
|
||||
vfs::CVirtualFile* GetVFile(vfs::Path const& sFilename);
|
||||
void addFile(vfs::IBaseFile* pile, utf8string const& profileName);
|
||||
vfs::IBaseFile* getFile(vfs::Path const& filename, utf8string const& profileName = "") const;
|
||||
vfs::CVirtualFile* getVirtualFile(vfs::Path const& filename);
|
||||
|
||||
bool RemoveFile(vfs::IBaseFile* pFile);
|
||||
bool removeFile(vfs::IBaseFile* file);
|
||||
|
||||
Iterator iterate();
|
||||
private:
|
||||
bool m_bExclusive;
|
||||
tVFiles m_mapVFiles;
|
||||
void operator=(vfs::CVirtualLocation const& vloc);
|
||||
|
||||
bool m_exclusive;
|
||||
tVFiles m_VFiles;
|
||||
};
|
||||
} // end namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user