Core/File: Add OpenMode::Defer

This commit is contained in:
SirLynix
2023-03-03 13:14:28 +01:00
parent 36d7e98299
commit 6bf4304817
4 changed files with 45 additions and 3 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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>