Core/OpenMode: Rename ReadOnly/WriteOnly to Read/Write
This commit is contained in:
parent
754a3d3614
commit
4065fbfb1a
|
|
@ -98,13 +98,13 @@ namespace Nz
|
|||
Defer, //< Defers file opening until a read/write operation is performed on it
|
||||
Lock, //< Prevents file modification by other handles while it's open
|
||||
MustExist, //< Fails if the file doesn't exists, even if opened in write mode
|
||||
ReadOnly, //< Allows read operations
|
||||
Read, //< Allows read operations
|
||||
Text, //< Opens in text mode (converts system line endings from/to \n)
|
||||
Truncate, //< Creates the file if it doesn't exist and empties it otherwise
|
||||
Unbuffered, //< Each read/write operations are performed directly using system calls (very slow)
|
||||
WriteOnly, //< Allows write operations, creates the file if it doesn't exist
|
||||
Write, //< Allows write operations, creates the file if it doesn't exist
|
||||
|
||||
Max = WriteOnly
|
||||
Max = Write
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
@ -115,7 +115,7 @@ namespace Nz
|
|||
|
||||
using OpenModeFlags = Flags<OpenMode>;
|
||||
|
||||
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode::ReadOnly | OpenMode::WriteOnly;
|
||||
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode::Read | OpenMode::Write;
|
||||
|
||||
enum class ParameterType
|
||||
{
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace Nz
|
|||
{
|
||||
if (!file.IsOpen())
|
||||
{
|
||||
if (!file.Open(OpenMode::ReadOnly))
|
||||
if (!file.Open(OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to load resource: unable to open \"{0}\"", filePath);
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace Nz
|
|||
{
|
||||
File file(filePath);
|
||||
|
||||
if (!file.Open(OpenMode::WriteOnly | OpenMode::Truncate))
|
||||
if (!file.Open(OpenMode::Write | OpenMode::Truncate))
|
||||
{
|
||||
NazaraErrorFmt("failed to save to file: unable to open \"{0}\" in write mode", filePath);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ namespace Nz
|
|||
|
||||
inline bool Stream::IsReadable() const
|
||||
{
|
||||
return m_openMode.Test(OpenMode::ReadOnly);
|
||||
return m_openMode.Test(OpenMode::Read);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -169,7 +169,7 @@ namespace Nz
|
|||
*/
|
||||
inline bool Stream::IsWritable() const
|
||||
{
|
||||
return m_openMode.Test(OpenMode::WriteOnly);
|
||||
return m_openMode.Test(OpenMode::Write);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Nz
|
|||
class NAZARA_CORE_API VirtualDirectoryFilesystemResolver : public VirtualDirectoryResolver
|
||||
{
|
||||
public:
|
||||
inline VirtualDirectoryFilesystemResolver(std::filesystem::path physicalPath, OpenModeFlags fileOpenMode = OpenMode::ReadOnly | OpenMode::Defer);
|
||||
inline VirtualDirectoryFilesystemResolver(std::filesystem::path physicalPath, OpenModeFlags fileOpenMode = OpenMode::Read | OpenMode::Defer);
|
||||
VirtualDirectoryFilesystemResolver(const VirtualDirectoryFilesystemResolver&) = delete;
|
||||
VirtualDirectoryFilesystemResolver(VirtualDirectoryFilesystemResolver&&) = delete;
|
||||
~VirtualDirectoryFilesystemResolver() = default;
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ namespace Nz
|
|||
|
||||
inline void NetPacket::Reset(UInt16 netCode, const void* ptr, std::size_t size)
|
||||
{
|
||||
InitStream(HeaderSize + size, HeaderSize, OpenMode::ReadOnly);
|
||||
InitStream(HeaderSize + size, HeaderSize, OpenMode::Read);
|
||||
m_buffer->Resize(HeaderSize + size);
|
||||
|
||||
if (ptr)
|
||||
|
|
|
|||
|
|
@ -89,21 +89,21 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod
|
|||
|
||||
if (std::strchr(openMode, 'r'))
|
||||
{
|
||||
openModeEnum |= OpenMode::ReadOnly;
|
||||
openModeEnum |= OpenMode::Read;
|
||||
if (std::strchr(openMode, '+'))
|
||||
openModeEnum |= OpenMode_ReadWrite | OpenMode::MustExist;
|
||||
}
|
||||
else if (std::strchr(openMode, 'w'))
|
||||
{
|
||||
openModeEnum |= OpenMode::WriteOnly | OpenMode::Truncate;
|
||||
openModeEnum |= OpenMode::Write | OpenMode::Truncate;
|
||||
if (std::strchr(openMode, '+'))
|
||||
openModeEnum |= OpenMode::ReadOnly;
|
||||
openModeEnum |= OpenMode::Read;
|
||||
}
|
||||
else if (std::strchr(openMode, 'a'))
|
||||
{
|
||||
openModeEnum |= OpenMode::WriteOnly | OpenMode::Append;
|
||||
openModeEnum |= OpenMode::Write | OpenMode::Append;
|
||||
if (std::strchr(openMode, '+'))
|
||||
openModeEnum |= OpenMode::ReadOnly;
|
||||
openModeEnum |= OpenMode::Read;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ namespace
|
|||
bool SetFile(const std::filesystem::path& filePath)
|
||||
{
|
||||
std::unique_ptr<Nz::File> file = std::make_unique<Nz::File>();
|
||||
if (!file->Open(filePath, Nz::OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, Nz::OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Nz::Error::GetLastError());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ namespace Nz
|
|||
Result<void, ResourceLoadingError> Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
|
||||
{
|
||||
std::unique_ptr<File> file = std::make_unique<File>();
|
||||
if (!file->Open(filePath, OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return Err(ResourceLoadingError::FailedToOpenFile);
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ namespace Nz
|
|||
Result<void, ResourceLoadingError> Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
|
||||
{
|
||||
std::unique_ptr<File> file = std::make_unique<File>();
|
||||
if (!file->Open(filePath, OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return Err(ResourceLoadingError::FailedToOpenFile);
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ namespace Nz
|
|||
Result<void, ResourceLoadingError> Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
|
||||
{
|
||||
std::unique_ptr<File> file = std::make_unique<File>();
|
||||
if (!file->Open(filePath, OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return Err(ResourceLoadingError::FailedToOpenFile);
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ namespace Nz
|
|||
Result<void, ResourceLoadingError> Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
|
||||
{
|
||||
std::unique_ptr<File> file = std::make_unique<File>();
|
||||
if (!file->Open(filePath, OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return Err(ResourceLoadingError::FailedToOpenFile);
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ namespace Nz
|
|||
std::optional<std::vector<UInt8>> File::ReadWhole(const std::filesystem::path& path)
|
||||
{
|
||||
File file(path);
|
||||
if (!file.Open(OpenMode::ReadOnly | OpenMode::Unbuffered)) //< unbuffered since we will read all the file at once
|
||||
if (!file.Open(OpenMode::Read | OpenMode::Unbuffered)) //< unbuffered since we will read all the file at once
|
||||
{
|
||||
NazaraErrorFmt("failed to open \"{0}\"", path);
|
||||
return std::nullopt;
|
||||
|
|
@ -299,7 +299,7 @@ namespace Nz
|
|||
bool File::WriteWhole(const std::filesystem::path& path, const void* data, std::size_t size)
|
||||
{
|
||||
File file(path);
|
||||
if (!file.Open(OpenMode::WriteOnly | OpenMode::Unbuffered)) //< unbuffered since we will write all the file at once
|
||||
if (!file.Open(OpenMode::Write | OpenMode::Unbuffered)) //< unbuffered since we will write all the file at once
|
||||
{
|
||||
NazaraErrorFmt("failed to open \"{0}\"", path);
|
||||
return false;
|
||||
|
|
@ -453,7 +453,7 @@ namespace Nz
|
|||
NAZARA_CORE_API bool HashAppend(AbstractHash& hash, const File& originalFile)
|
||||
{
|
||||
File file(originalFile.GetPath());
|
||||
if (!file.Open(OpenMode::ReadOnly))
|
||||
if (!file.Open(OpenMode::Read))
|
||||
{
|
||||
NazaraError("unable to open file");
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
|||
*/
|
||||
|
||||
MemoryView::MemoryView(const void* ptr, UInt64 size) :
|
||||
Stream(StreamOption::MemoryMapped, OpenMode::ReadOnly),
|
||||
Stream(StreamOption::MemoryMapped, OpenMode::Read),
|
||||
m_ptr(static_cast<UInt8*>(const_cast<void*>(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only
|
||||
m_pos(0),
|
||||
m_size(size)
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ namespace Nz
|
|||
int flags;
|
||||
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
|
||||
if ((mode & OpenMode_ReadWrite) == OpenMode_ReadWrite)
|
||||
if (mode.Test(OpenMode_ReadWrite))
|
||||
flags = O_CREAT | O_RDWR;
|
||||
else if ((mode & OpenMode::ReadOnly) == OpenMode::ReadOnly)
|
||||
else if (mode.Test(OpenMode::Read))
|
||||
flags = O_RDONLY;
|
||||
else if ((mode & OpenMode::WriteOnly) == OpenMode::WriteOnly)
|
||||
else if (mode.Test(OpenMode::Write))
|
||||
flags = O_CREAT | O_WRONLY;
|
||||
else
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -63,30 +63,30 @@ namespace Nz
|
|||
DWORD shareMode = FILE_SHARE_READ;
|
||||
DWORD openMode = 0;
|
||||
|
||||
if (mode & OpenMode::ReadOnly)
|
||||
if (mode.Test(OpenMode::Read))
|
||||
{
|
||||
access |= GENERIC_READ;
|
||||
|
||||
if (mode & OpenMode::MustExist || (mode & OpenMode::WriteOnly) == 0)
|
||||
if (mode.Test(OpenMode::MustExist) || !mode.Test(OpenMode::Write))
|
||||
openMode |= OPEN_EXISTING;
|
||||
}
|
||||
|
||||
if (mode & OpenMode::WriteOnly)
|
||||
if (mode.Test(OpenMode::Write))
|
||||
{
|
||||
if (mode & OpenMode::Append)
|
||||
if (mode.Test(OpenMode::Append))
|
||||
access |= FILE_APPEND_DATA;
|
||||
else
|
||||
access |= GENERIC_WRITE;
|
||||
|
||||
if (mode & OpenMode::Truncate)
|
||||
if (mode.Test(OpenMode::Truncate))
|
||||
openMode |= CREATE_ALWAYS;
|
||||
else if (mode & OpenMode::MustExist)
|
||||
else if (mode.Test(OpenMode::MustExist))
|
||||
openMode |= OPEN_EXISTING;
|
||||
else
|
||||
openMode |= OPEN_ALWAYS;
|
||||
}
|
||||
|
||||
if ((mode & OpenMode::Lock) == 0)
|
||||
if (!mode.Test(OpenMode::Lock))
|
||||
shareMode |= FILE_SHARE_WRITE;
|
||||
|
||||
if constexpr (std::is_same_v<std::filesystem::path::value_type, wchar_t>)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Nz
|
|||
std::shared_ptr<ShaderModule> RenderDevice::InstantiateShaderModule(nzsl::ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const std::filesystem::path& sourcePath, const nzsl::ShaderWriter::States& states)
|
||||
{
|
||||
File file(sourcePath);
|
||||
if (!file.Open(OpenMode::ReadOnly | OpenMode::Text))
|
||||
if (!file.Open(OpenMode::Read | OpenMode::Text))
|
||||
{
|
||||
NazaraErrorFmt("failed to open \"{0}\"", sourcePath);
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ namespace Nz
|
|||
bool SetFile(const std::filesystem::path& filePath)
|
||||
{
|
||||
std::unique_ptr<File> file = std::make_unique<File>();
|
||||
if (!file->Open(filePath, OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -448,7 +448,7 @@ namespace Nz
|
|||
bool SetFile(const std::filesystem::path& filePath)
|
||||
{
|
||||
std::unique_ptr<File> file = std::make_unique<File>();
|
||||
if (!file->Open(filePath, OpenMode::ReadOnly))
|
||||
if (!file->Open(filePath, OpenMode::Read))
|
||||
{
|
||||
NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Nz
|
|||
bool ParseMTL(Mesh& mesh, const std::filesystem::path& filePath, const std::string* materials, const OBJParser::Mesh* meshes, std::size_t meshCount)
|
||||
{
|
||||
File file(filePath);
|
||||
if (!file.Open(OpenMode::ReadOnly | OpenMode::Text))
|
||||
if (!file.Open(OpenMode::Read | OpenMode::Text))
|
||||
{
|
||||
NazaraErrorFmt("failed to open MTL file ({0})", file.GetPath());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ namespace Nz
|
|||
|
||||
if (!mtlPath.empty())
|
||||
{
|
||||
File mtlFile(mtlPath, OpenMode::WriteOnly | OpenMode::Truncate);
|
||||
File mtlFile(mtlPath, OpenMode::Write | OpenMode::Truncate);
|
||||
if (mtlFile.IsOpen())
|
||||
mtlFormat.Save(mtlFile);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ void MainWindow::OnCompile()
|
|||
if (!fileName.endsWith("nzslb", Qt::CaseInsensitive))
|
||||
fileName += ".nzslb";
|
||||
|
||||
Nz::File file(fileName.toStdString(), Nz::OpenMode::WriteOnly);
|
||||
Nz::File file(fileName.toStdString(), Nz::OpenMode::Write);
|
||||
nzsl::Serializer serializer;
|
||||
nzsl::Ast::SerializeShader(serializer, *shaderModule);
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ SCENARIO("File", "[CORE][FILE]")
|
|||
{
|
||||
REQUIRE(std::filesystem::exists(GetAssetDir() / "Core/FileTest.txt"));
|
||||
|
||||
Nz::File fileTest(GetAssetDir() / "Core/FileTest.txt", Nz::OpenMode::ReadOnly | Nz::OpenMode::Text);
|
||||
Nz::File fileTest(GetAssetDir() / "Core/FileTest.txt", Nz::OpenMode::Read | Nz::OpenMode::Text);
|
||||
|
||||
WHEN("We read the first line of the file")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ TEST_CASE("VirtualDirectory", "[Core][VirtualDirectory]")
|
|||
}
|
||||
AND_THEN("Overriding the physical file with another one")
|
||||
{
|
||||
resourceDir->StoreFile("Logo.png", std::make_shared<Nz::File>(GetAssetDir() / "Audio/ambience.ogg", Nz::OpenMode::ReadOnly));
|
||||
resourceDir->StoreFile("Logo.png", std::make_shared<Nz::File>(GetAssetDir() / "Audio/ambience.ogg", Nz::OpenMode::Read));
|
||||
|
||||
CHECK(CheckFileHash(resourceDir, "Audio/ambience.ogg", "49C486F44E43F023D54C9F375D902C21375DDB2748D3FA1863C9581D30E17F94"));
|
||||
CHECK(CheckFileHash(resourceDir, "Logo.png", "49C486F44E43F023D54C9F375D902C21375DDB2748D3FA1863C9581D30E17F94"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue