mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-21 07:43:59 -07:00
- properly differentiate between buffer/offset alignment and length alignment (relevant since block size has been increased to 256k) - use VfsPath for most game paths instead of CStr - clean up timer interface and implementation - self-tests no longer crash - file_cache.cpp: fix for the case where allocation fails (prevent deleter from seeing a null pointer) - allocators: move all shared_ptr-related stuff to its own component; add DummySharedPtr - codec: disable checksums (important for performance at work) - File: made into an interface class to avoid export problems. not entirely sure about this.. - vfs_path.h, path.h, os_path.h: proper fix for using fs::change_extension and similar utility functions with derivatives of basic_path - lib_api: automatically link against import lib if building lib/ as a DLL - path_util: remove unused functions (this component is deprecated) - compiler.h: add INLINE - Xeromyces.cpp: pass PIVFS so that GetXMBPath works in self-test (should do this mostly everywhere rather than have one singleton g_VFS) This was SVN commit r5537.
67 lines
1.7 KiB
C++
67 lines
1.7 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
|
|
{
|
|
PIFile file = CreateFile_Posix();
|
|
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);
|
|
|
|
{
|
|
PIFile file = CreateFile_Posix();
|
|
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()));
|
|
}
|