diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index 7529a818f..bd3493d7e 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -57,6 +57,7 @@ namespace Nz static inline ByteArray ComputeHash(HashType hash, const std::filesystem::path& filePath); static inline ByteArray ComputeHash(AbstractHash& hash, const std::filesystem::path& filePath); static std::optional> ReadWhole(const std::filesystem::path& path); + static bool WriteWhole(const std::filesystem::path& path, const void* data, std::size_t size); private: void FlushStream() override; diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index d8196887a..196c6ec4b 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -272,7 +272,7 @@ namespace Nz File file(path); if (!file.Open(OpenMode::ReadOnly | OpenMode::Unbuffered)) //< unbuffered since we will read all the file at once { - NazaraError("Failed to open \"" + path.generic_u8string() + '"'); + NazaraError("failed to open \"" + path.generic_u8string() + '"'); return std::nullopt; } @@ -280,13 +280,31 @@ namespace Nz std::vector content(size); if (size > 0 && file.Read(&content[0], size) != size) { - NazaraError("Failed to read file"); + NazaraError("failed to read file"); return std::nullopt; } return content; } + 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 + { + NazaraError("failed to open \"" + path.generic_u8string() + '"'); + return false; + } + + if (file.Write(data, size) != size) + { + NazaraError("failed to write file"); + return false; + } + + return true; + } + /*! * \brief Flushes the stream *