mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-19 23:03:56 -07:00
- directoryPosix: replace most methods with boost filesystem (but not all: the latter cannot efficiently enumerate files AND query their size/mtime) - AllocatorChecker: better name for member functions - file: move the File class here - trace: bugfix - io: move UnalignedWriter to write_buffer.cpp (basically the same thing) - vfs: remove unnecessary "vfs" warts from variable names - vfs_tree: VfsFile now stores single Name/Size/MTime fields instead of the FileInfo record (less clunky) - vfs_path: use boost filesystem's version of the basename/extension functions - lf_alloc: remove (no longer necessary, won't be finished - not worth the trouble) - path_util: remove path_foreach_component (replaced by better path traversal logic) and PathPackage (obsoleted by fs::path) ! resource loading code now receives VfsPath as its filename. there is also OsPath (native absolute path) and Path (relative to binaries/data) - tex is now independent of file loading code; it just en/decodes in-memory buffers - wdll_ver: clean up, use smart pointer to simplify bailout code - wsdl: remove nonexistent failure path from calc_gamma (cruised by here because SDL_SetGamme is failing once after a cold boot at work) - wsnd: simplify OpenAL DLL search, use boost::filesystem - wutil: Wow64 redirection is now packaged in a (RAII) class This was SVN commit r5525.
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include "precompiled.h"
|
|
#include "real_directory.h"
|
|
|
|
#include "lib/path_util.h"
|
|
#include "lib/file/file.h"
|
|
#include "lib/file/io/io.h"
|
|
|
|
|
|
RealDirectory::RealDirectory(const Path& path, unsigned priority, unsigned flags)
|
|
: m_path(path), m_priority(priority), m_flags(flags)
|
|
{
|
|
}
|
|
|
|
|
|
/*virtual*/ unsigned RealDirectory::Precedence() const
|
|
{
|
|
return 1u;
|
|
}
|
|
|
|
|
|
/*virtual*/ char RealDirectory::LocationCode() const
|
|
{
|
|
return 'F';
|
|
}
|
|
|
|
|
|
/*virtual*/ LibError RealDirectory::Load(const std::string& name, shared_ptr<u8> buf, size_t size) const
|
|
{
|
|
File file;
|
|
RETURN_ERR(file.Open(m_path/name, 'r'));
|
|
|
|
RETURN_ERR(io_ReadAligned(file, 0, buf.get(), size));
|
|
return INFO::OK;
|
|
}
|
|
|
|
|
|
LibError RealDirectory::Store(const std::string& name, shared_ptr<u8> fileContents, size_t size)
|
|
{
|
|
const Path pathname(m_path/name);
|
|
|
|
{
|
|
File file;
|
|
RETURN_ERR(file.Open(pathname, 'w'));
|
|
RETURN_ERR(io_WriteAligned(file, 0, fileContents.get(), size));
|
|
}
|
|
|
|
// io_WriteAligned pads the file; we need to truncate it to the actual
|
|
// length. ftruncate can't be used because Windows' FILE_FLAG_NO_BUFFERING
|
|
// only allows resizing to sector boundaries, so the file must first
|
|
// be closed.
|
|
truncate(pathname.external_file_string().c_str(), (off_t)size);
|
|
|
|
return INFO::OK;
|
|
}
|
|
|
|
|
|
void RealDirectory::Watch()
|
|
{
|
|
//m_watch = CreateWatch(Path().external_file_string().c_str());
|
|
}
|
|
|
|
|
|
PRealDirectory CreateRealSubdirectory(PRealDirectory realDirectory, const std::string& subdirectoryName)
|
|
{
|
|
const Path path(realDirectory->GetPath()/subdirectoryName);
|
|
return PRealDirectory(new RealDirectory(path, realDirectory->Priority(), realDirectory->Flags()));
|
|
}
|