diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index eb4204b3f..60ddcc31c 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -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; - constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode::ReadOnly | OpenMode::WriteOnly; + constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode::Read | OpenMode::Write; enum class ParameterType { diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl index 3c70fba2b..715e60d1c 100644 --- a/include/Nazara/Core/ResourceLoader.inl +++ b/include/Nazara/Core/ResourceLoader.inl @@ -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; diff --git a/include/Nazara/Core/ResourceSaver.inl b/include/Nazara/Core/ResourceSaver.inl index 7c73b2168..6938fbadf 100644 --- a/include/Nazara/Core/ResourceSaver.inl +++ b/include/Nazara/Core/ResourceSaver.inl @@ -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; diff --git a/include/Nazara/Core/Stream.inl b/include/Nazara/Core/Stream.inl index 27a923579..dc3395fe9 100644 --- a/include/Nazara/Core/Stream.inl +++ b/include/Nazara/Core/Stream.inl @@ -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); } /*! diff --git a/include/Nazara/Core/VirtualDirectoryFilesystemResolver.hpp b/include/Nazara/Core/VirtualDirectoryFilesystemResolver.hpp index 258f1227c..909d011eb 100644 --- a/include/Nazara/Core/VirtualDirectoryFilesystemResolver.hpp +++ b/include/Nazara/Core/VirtualDirectoryFilesystemResolver.hpp @@ -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; diff --git a/include/Nazara/Network/NetPacket.inl b/include/Nazara/Network/NetPacket.inl index 176cb7550..c327a2676 100644 --- a/include/Nazara/Network/NetPacket.inl +++ b/include/Nazara/Network/NetPacket.inl @@ -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) diff --git a/plugins/Assimp/CustomStream.cpp b/plugins/Assimp/CustomStream.cpp index 31577db17..8569176c0 100644 --- a/plugins/Assimp/CustomStream.cpp +++ b/plugins/Assimp/CustomStream.cpp @@ -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 { diff --git a/plugins/FFmpeg/Plugin.cpp b/plugins/FFmpeg/Plugin.cpp index 1969f3246..4db47ca21 100644 --- a/plugins/FFmpeg/Plugin.cpp +++ b/plugins/FFmpeg/Plugin.cpp @@ -284,7 +284,7 @@ namespace bool SetFile(const std::filesystem::path& filePath) { std::unique_ptr file = std::make_unique(); - 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; diff --git a/src/Nazara/Audio/Formats/drwavLoader.cpp b/src/Nazara/Audio/Formats/drwavLoader.cpp index 8daea23b4..f6ed06571 100644 --- a/src/Nazara/Audio/Formats/drwavLoader.cpp +++ b/src/Nazara/Audio/Formats/drwavLoader.cpp @@ -136,7 +136,7 @@ namespace Nz Result Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters) { std::unique_ptr file = std::make_unique(); - 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); diff --git a/src/Nazara/Audio/Formats/libflacLoader.cpp b/src/Nazara/Audio/Formats/libflacLoader.cpp index 487e63cde..fb0d0929e 100644 --- a/src/Nazara/Audio/Formats/libflacLoader.cpp +++ b/src/Nazara/Audio/Formats/libflacLoader.cpp @@ -296,7 +296,7 @@ namespace Nz Result Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters) { std::unique_ptr file = std::make_unique(); - 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); diff --git a/src/Nazara/Audio/Formats/libvorbisLoader.cpp b/src/Nazara/Audio/Formats/libvorbisLoader.cpp index 7ee97f2a8..b4e56d4d4 100644 --- a/src/Nazara/Audio/Formats/libvorbisLoader.cpp +++ b/src/Nazara/Audio/Formats/libvorbisLoader.cpp @@ -215,7 +215,7 @@ namespace Nz Result Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters) { std::unique_ptr file = std::make_unique(); - 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); diff --git a/src/Nazara/Audio/Formats/minimp3Loader.cpp b/src/Nazara/Audio/Formats/minimp3Loader.cpp index f5efa4796..ecd7e1bc5 100644 --- a/src/Nazara/Audio/Formats/minimp3Loader.cpp +++ b/src/Nazara/Audio/Formats/minimp3Loader.cpp @@ -161,7 +161,7 @@ namespace Nz Result Open(const std::filesystem::path& filePath, const SoundStreamParams& parameters) { std::unique_ptr file = std::make_unique(); - 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); diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 0f8c7696d..935701ef9 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -279,7 +279,7 @@ namespace Nz std::optional> 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; diff --git a/src/Nazara/Core/MemoryView.cpp b/src/Nazara/Core/MemoryView.cpp index 11453fc70..b6ac4ba25 100644 --- a/src/Nazara/Core/MemoryView.cpp +++ b/src/Nazara/Core/MemoryView.cpp @@ -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(const_cast(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only m_pos(0), m_size(size) diff --git a/src/Nazara/Core/Posix/FileImpl.cpp b/src/Nazara/Core/Posix/FileImpl.cpp index 5c012cb6d..a2f01247c 100644 --- a/src/Nazara/Core/Posix/FileImpl.cpp +++ b/src/Nazara/Core/Posix/FileImpl.cpp @@ -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; diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index 11e95d32d..1f22c5853 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -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) diff --git a/src/Nazara/Renderer/RenderDevice.cpp b/src/Nazara/Renderer/RenderDevice.cpp index adc354a52..e4e7713a1 100644 --- a/src/Nazara/Renderer/RenderDevice.cpp +++ b/src/Nazara/Renderer/RenderDevice.cpp @@ -14,7 +14,7 @@ namespace Nz std::shared_ptr 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 {}; diff --git a/src/Nazara/Utility/Formats/FreeTypeLoader.cpp b/src/Nazara/Utility/Formats/FreeTypeLoader.cpp index 6282985d7..ab5520252 100644 --- a/src/Nazara/Utility/Formats/FreeTypeLoader.cpp +++ b/src/Nazara/Utility/Formats/FreeTypeLoader.cpp @@ -318,7 +318,7 @@ namespace Nz bool SetFile(const std::filesystem::path& filePath) { std::unique_ptr file = std::make_unique(); - if (!file->Open(filePath, OpenMode::ReadOnly)) + if (!file->Open(filePath, OpenMode::Read)) { NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError()); return false; diff --git a/src/Nazara/Utility/Formats/GIFLoader.cpp b/src/Nazara/Utility/Formats/GIFLoader.cpp index 39b2cd337..c721eed91 100644 --- a/src/Nazara/Utility/Formats/GIFLoader.cpp +++ b/src/Nazara/Utility/Formats/GIFLoader.cpp @@ -448,7 +448,7 @@ namespace Nz bool SetFile(const std::filesystem::path& filePath) { std::unique_ptr file = std::make_unique(); - if (!file->Open(filePath, OpenMode::ReadOnly)) + if (!file->Open(filePath, OpenMode::Read)) { NazaraErrorFmt("failed to open stream from file: {0}", Error::GetLastError()); return false; diff --git a/src/Nazara/Utility/Formats/OBJLoader.cpp b/src/Nazara/Utility/Formats/OBJLoader.cpp index 5010f60b9..9ed01c666 100644 --- a/src/Nazara/Utility/Formats/OBJLoader.cpp +++ b/src/Nazara/Utility/Formats/OBJLoader.cpp @@ -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; diff --git a/src/Nazara/Utility/Formats/OBJSaver.cpp b/src/Nazara/Utility/Formats/OBJSaver.cpp index b487bd104..dfa553b1e 100644 --- a/src/Nazara/Utility/Formats/OBJSaver.cpp +++ b/src/Nazara/Utility/Formats/OBJSaver.cpp @@ -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); } diff --git a/src/ShaderNode/Widgets/MainWindow.cpp b/src/ShaderNode/Widgets/MainWindow.cpp index 22a4b4b47..e6b92b548 100644 --- a/src/ShaderNode/Widgets/MainWindow.cpp +++ b/src/ShaderNode/Widgets/MainWindow.cpp @@ -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); diff --git a/tests/UnitTests/Engine/Core/FileTest.cpp b/tests/UnitTests/Engine/Core/FileTest.cpp index 944658645..d0b5deace 100644 --- a/tests/UnitTests/Engine/Core/FileTest.cpp +++ b/tests/UnitTests/Engine/Core/FileTest.cpp @@ -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") { diff --git a/tests/UnitTests/Engine/Core/VirtualDirectoryTest.cpp b/tests/UnitTests/Engine/Core/VirtualDirectoryTest.cpp index 05c7ae038..a2f06ca86 100644 --- a/tests/UnitTests/Engine/Core/VirtualDirectoryTest.cpp +++ b/tests/UnitTests/Engine/Core/VirtualDirectoryTest.cpp @@ -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(GetAssetDir() / "Audio/ambience.ogg", Nz::OpenMode::ReadOnly)); + resourceDir->StoreFile("Logo.png", std::make_shared(GetAssetDir() / "Audio/ambience.ogg", Nz::OpenMode::Read)); CHECK(CheckFileHash(resourceDir, "Audio/ambience.ogg", "49C486F44E43F023D54C9F375D902C21375DDB2748D3FA1863C9581D30E17F94")); CHECK(CheckFileHash(resourceDir, "Logo.png", "49C486F44E43F023D54C9F375D902C21375DDB2748D3FA1863C9581D30E17F94"));