Core/OpenMode: Rename ReadOnly/WriteOnly to Read/Write
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user