Core/File: Add OpenMode::Defer
This commit is contained in:
@@ -97,6 +97,7 @@ namespace Nz
|
||||
NotOpen, // Use the current mod of opening
|
||||
|
||||
Append, // Disable writing on existing parts and put the cursor at the end
|
||||
Defer, // Defer file opening until a read/write operation is performed on it
|
||||
Lock, // Disable modifying the file before it is open
|
||||
MustExist, // Fail if the file doesn't exists, even if opened in write mode
|
||||
ReadOnly, // Open in read only
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace Nz
|
||||
static bool WriteWhole(const std::filesystem::path& path, const void* data, std::size_t size);
|
||||
|
||||
private:
|
||||
inline bool CheckFileOpening();
|
||||
void FlushStream() override;
|
||||
std::size_t ReadBlock(void* buffer, std::size_t size) override;
|
||||
bool SeekStreamCursor(UInt64 offset) override;
|
||||
|
||||
@@ -33,6 +33,20 @@ namespace Nz
|
||||
{
|
||||
return Nz::ComputeHash(hash, File(filePath));
|
||||
}
|
||||
|
||||
inline bool File::CheckFileOpening()
|
||||
{
|
||||
if (m_openMode.Test(OpenMode::Defer))
|
||||
{
|
||||
if (!Open(m_filePath, m_openMode & ~OpenMode::Defer))
|
||||
{
|
||||
NazaraError("failed to open file");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user