From 5a5f25a950e8f6349d3f48a4f3526d4c93cd7194 Mon Sep 17 00:00:00 2001 From: Gawaboumga Date: Sun, 21 Feb 2016 14:37:37 +0100 Subject: [PATCH] Documentation for Documentation & File Former-commit-id: 8a69e6dca76fba4a23b36c563b52c4ccbbec7309 --- include/Nazara/Core/File.inl | 16 ++ src/Nazara/Core/Directory.cpp | 173 +++++++++++++++- src/Nazara/Core/File.cpp | 374 +++++++++++++++++++++++++++++++--- 3 files changed, 523 insertions(+), 40 deletions(-) diff --git a/include/Nazara/Core/File.inl b/include/Nazara/Core/File.inl index 818d0098f..ff0d148fd 100644 --- a/include/Nazara/Core/File.inl +++ b/include/Nazara/Core/File.inl @@ -8,11 +8,27 @@ namespace Nz { + /*! + * \brief Computes the hash for the file + * \return ByteArray represing the result of the hash of the file + * + * \param hash Hash to execute + * \param filePath Path for the file + */ + inline ByteArray File::ComputeHash(HashType hash, const String& filePath) { return ComputeHash(AbstractHash::Get(hash).get(), filePath); } + /*! + * \brief Computes the hash for the file + * \return ByteArray represing the result of the hash of the file + * + * \param hash Hash to execute + * \param filePath Path for the file + */ + inline ByteArray File::ComputeHash(AbstractHash* hash, const String& filePath) { return Nz::ComputeHash(hash, File(filePath)); diff --git a/src/Nazara/Core/Directory.cpp b/src/Nazara/Core/Directory.cpp index ed8ed6bd0..b076b38d7 100644 --- a/src/Nazara/Core/Directory.cpp +++ b/src/Nazara/Core/Directory.cpp @@ -30,16 +30,31 @@ namespace Nz { namespace { - //FIXME: MinGW seems to dislike thread_local shared_ptr.. (using a std::string is a working hackfix) + //FIXME: MinGW seems to dislike thread_local shared_ptr.. (using a std::string is a working hackfix) thread_local std::string currentPath(DirectoryImpl::GetCurrent()); } + /*! + * \class Nz::Directory + * \brief Core class that represents a directory + */ + + /*! + * \brief Constructs a Directory object by default + */ + Directory::Directory() : m_pattern('*'), m_impl(nullptr) { } + /*! + * \brief Constructs a Directory object with a path + * + * \param dirPath Path to the directory + */ + Directory::Directory(const String& dirPath) : m_dirPath(dirPath), m_pattern('*'), @@ -47,11 +62,21 @@ namespace Nz { } + /*! + * \brief Destructs the object and calls Close + * + * \see Close + */ + Directory::~Directory() { Close(); } + /*! + * \brief Closes the directory + */ + void Directory::Close() { NazaraLock(m_mutex); @@ -64,16 +89,26 @@ namespace Nz } } + /*! + * \brief Checks whether the directory exists + * \return true if directory exists + */ + bool Directory::Exists() const { NazaraLock(m_mutex); if (IsOpen()) - return true; // Le fichier est ouvert, donc il existe + return true; // If directory is open, then it exists else return Exists(m_dirPath); } + /*! + * \brief Gets the path of the directory + * \return Path of the directory + */ + String Directory::GetPath() const { NazaraLock(m_mutex); @@ -81,6 +116,11 @@ namespace Nz return m_dirPath; } + /*! + * \brief Gets the pattern for the path of the directory + * \return Pattern for the path of the directory + */ + String Directory::GetPattern() const { NazaraLock(m_mutex); @@ -88,12 +128,19 @@ namespace Nz return m_pattern; } + /*! + * \brief Gets the result name of the directory + * \return Resulting name + * + * \remark Produces a NazaraError if directory is not open with NAZARA_CORE_SAFE defined + */ + String Directory::GetResultName() const { NazaraLock(m_mutex); #if NAZARA_CORE_SAFE - if (!m_impl) + if (!IsOpen()) { NazaraError("Directory not opened"); return String(); @@ -103,12 +150,19 @@ namespace Nz return m_impl->GetResultName(); } + /*! + * \brief Gets the result path of the directory + * \return Resulting path + * + * \remark Produces a NazaraError if directory is not open with NAZARA_CORE_SAFE defined + */ + String Directory::GetResultPath() const { NazaraLock(m_mutex); #if NAZARA_CORE_SAFE - if (!m_impl) + if (!IsOpen()) { NazaraError("Directory not opened"); return String(); @@ -118,12 +172,19 @@ namespace Nz return m_dirPath + NAZARA_DIRECTORY_SEPARATOR + m_impl->GetResultName(); } + /*! + * \brief Gets the resulting size of the directory + * \return Size of the directory + * + * \remark Produces a NazaraError if directory is not open with NAZARA_CORE_SAFE defined + */ + UInt64 Directory::GetResultSize() const { NazaraLock(m_mutex); #if NAZARA_CORE_SAFE - if (!m_impl) + if (!IsOpen()) { NazaraError("Directory not opened"); return 0; @@ -133,6 +194,11 @@ namespace Nz return m_impl->GetResultSize(); } + /*! + * \brief Checks whether the directory is open + * \return true if open + */ + bool Directory::IsOpen() const { NazaraLock(m_mutex); @@ -140,12 +206,19 @@ namespace Nz return m_impl != nullptr; } + /*! + * \brief Checks whether the directory is result + * \return true if result + * + * \remark Produces a NazaraError if directory is not open with NAZARA_CORE_SAFE defined + */ + bool Directory::IsResultDirectory() const { NazaraLock(m_mutex); #if NAZARA_CORE_SAFE - if (!m_impl) + if (!IsOpen()) { NazaraError("Directory not opened"); return false; @@ -155,12 +228,21 @@ namespace Nz return m_impl->IsResultDirectory(); } + /*! + * \brief Sets the next result in the directory + * \return true if directory has a next result + * + * \param skipDots Skips the dots in the path + * + * \remark Produces a NazaraError if directory is not open with NAZARA_CORE_SAFE defined + */ + bool Directory::NextResult(bool skipDots) { NazaraLock(m_mutex); #if NAZARA_CORE_SAFE - if (!m_impl) + if (!IsOpen()) { NazaraError("Directory not opened"); return false; @@ -185,6 +267,11 @@ namespace Nz return true; } + /*! + * \brief Opens the directory + * \return true if opening is successful + */ + bool Directory::Open() { NazaraLock(m_mutex); @@ -206,6 +293,12 @@ namespace Nz return true; } + /*! + * \brief Sets the path of the directory + * + * \param dirPath Path of the directory + */ + void Directory::SetPath(const String& dirPath) { NazaraLock(m_mutex); @@ -215,6 +308,12 @@ namespace Nz m_dirPath = File::AbsolutePath(dirPath); } + /*! + * \brief Sets the pattern of the directory + * + * \param dirPath Pattern of the directory + */ + void Directory::SetPattern(const String& pattern) { NazaraLock(m_mutex); @@ -222,6 +321,18 @@ namespace Nz m_pattern = pattern; } + /*! + * \brief Copies the first directory to a new directory path + * \return true if copy is successful + * + * \param sourcePath Path of the original directory + * \param targetPath Path of the copied directory + * + * \remark Produces a NazaraError if could not create destination directory + * \remark Produces a NazaraError if could not open origin directory + * \remark Produces a NazaraError if could not copy a file + */ + bool Directory::Copy(const String& sourcePath, const String& destPath) { if (sourcePath.IsEmpty() || destPath.IsEmpty()) @@ -262,6 +373,14 @@ namespace Nz return true; } + /*! + * \brief Creates a directory from a path + * \return true if creation is successful + * + * \param dirPath Path of the directory + * \param recursive Creates subdirectories + */ + bool Directory::Create(const String& dirPath, bool recursive) { if (dirPath.IsEmpty()) @@ -275,7 +394,7 @@ namespace Nz return false; #ifdef NAZARA_PLATFORM_WINDOWS - // Contrairement au disque (Ex: "C:"), le chemin réseau n'est pas considéré comme un dossier (Ex: "\\Laptop") + // Unlike to disk (Ex: "C:"), the netwrok path is not considered as a directory (Ex: "\\Laptop") if (path.Match("\\\\*")) { foundPos = path.Find('\\', 2); @@ -309,6 +428,13 @@ namespace Nz return DirectoryImpl::Create(File::NormalizePath(dirPath)); } + /*! + * \brief Checks whether the directory exists + * \return true if directory exists + * + * \param dirPath Path of the directory + */ + bool Directory::Exists(const String& dirPath) { if (dirPath.IsEmpty()) @@ -317,14 +443,24 @@ namespace Nz return DirectoryImpl::Exists(File::NormalizePath(dirPath)); } + /*! + * \brief Gets the current path of this directory + * \return Current path + */ + String Directory::GetCurrent() { return currentPath; } + /*! + * \brief Gets this current file relative to the engine + * \return Path to this file + */ + const char* Directory::GetCurrentFileRelativeToEngine(const char* currentFile) { - ///FIXME: Est-ce que cette méthode est au bon endroit ? + ///FIXME: Is this method in the right place ? const char* ptr = std::strstr(currentFile, "NazaraEngine/"); if (!ptr) ptr = std::strstr(currentFile, "NazaraEngine\\"); @@ -335,6 +471,14 @@ namespace Nz return ptr; } + /*! + * \brief Removes the directory + * \return true if remove is successful + * + * \param dirPath Path of the directory + * \param emptyDirectory Remove recursively + */ + bool Directory::Remove(const String& dirPath, bool emptyDirectory) { if (dirPath.IsEmpty()) @@ -344,7 +488,7 @@ namespace Nz { Directory dir(dirPath); if (!dir.Open()) - return DirectoryImpl::Remove(dirPath); // Si on n'arrive pas à ouvrir le dossier, on tente de le supprimer + return DirectoryImpl::Remove(dirPath); // If we can't open the directory, we try to delete it while (dir.NextResult(true)) { @@ -366,6 +510,13 @@ namespace Nz return DirectoryImpl::Remove(File::NormalizePath(dirPath)); } + /*! + * \brief Sets the current directory + * \return true if directory path exists + * + * \param dirPath Path of the directory + */ + bool Directory::SetCurrent(const String& dirPath) { String path = File::AbsolutePath(dirPath); @@ -376,5 +527,5 @@ namespace Nz } else return false; - } + } } diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index db71f2d95..55587c9e0 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -30,23 +30,51 @@ namespace Nz { + /*! + * \class Nz::File + * \brief Core class that represents a file + */ + + /*! + * \brief Constructs a File object by default + */ + File::File() : m_impl(nullptr) { } + /*! + * \brief Constructs a File object with a file path + * + * \param filePath Path to the file + */ + File::File(const String& filePath) : File() { SetFile(filePath); } + /*! + * \brief Constructs a File object with a file path and flags + * + * \param filePath Path to the file + * \param openMode Flag of the file + */ + File::File(const String& filePath, UInt32 openMode) : File() { Open(filePath, openMode); } + /*! + * \brief Constructs a File object by move semantic + * + * \param file File to move into this + */ + File::File(File&& file) noexcept : Stream(std::move(file)), m_filePath(std::move(file.m_filePath)), @@ -55,16 +83,33 @@ namespace Nz file.m_impl = nullptr; } + /*! + * \brief Destructs the object and calls Close + * + * \see Close + */ + File::~File() { Close(); } + /*! + * \brief Copies this file to a new file path + * \return true if copy is successful + * + * \param newFilePath Path of the new file + */ + bool File::Copy(const String& newFilePath) { return Copy(m_filePath, newFilePath); } + /*! + * \brief Closes the file + */ + void File::Close() { NazaraLock(m_mutex) @@ -79,6 +124,11 @@ namespace Nz } } + /*! + * \brief Deletes the file + * \return true if delete is successful + */ + bool File::Delete() { NazaraLock(m_mutex) @@ -88,6 +138,13 @@ namespace Nz return Delete(m_filePath); } + /*! + * \brief Checks whether the file has reached the end + * \return true if cursor is at the end of the file + * + * \remark Produces a NazaraError if file is not open with NAZARA_CORE_SAFE defined + */ + bool File::EndOfFile() const { NazaraLock(m_mutex) @@ -95,7 +152,7 @@ namespace Nz #if NAZARA_CORE_SAFE if (!IsOpen()) { - NazaraError("File not opened"); + NazaraError("File not open"); return false; } #endif @@ -103,11 +160,25 @@ namespace Nz return m_impl->EndOfFile(); } + /*! + * \brief Checks whether the file has reached the end of the stream + * \return true if cursor is at the end of the file + * + * \remark Produces a NazaraError if file is not open with NAZARA_CORE_SAFE defined + * + * \see EndOfFile + */ + bool File::EndOfStream() const { return EndOfFile(); } + /*! + * \brief Checks whether the file exists + * \return true if file exists + */ + bool File::Exists() const { NazaraLock(m_mutex) @@ -118,6 +189,11 @@ namespace Nz return Exists(m_filePath); } + /*! + * \brief Gets the creation time of the file + * \return Information about the creation time + */ + time_t File::GetCreationTime() const { NazaraLock(m_mutex) @@ -125,15 +201,27 @@ namespace Nz return GetCreationTime(m_filePath); } + /*! + * \brief Gets the position of the cursor in the file + * \return Position of the cursor + * + * \remark Produces a NazaraAssert if file is not open + */ + UInt64 File::GetCursorPos() const { NazaraLock(m_mutex) - NazaraAssert(IsOpen(), "File is not opened"); + NazaraAssert(IsOpen(), "File is not open"); return m_impl->GetCursorPos(); } + /*! + * \brief Gets the directory of the file + * \return Directory of the file + */ + String File::GetDirectory() const { NazaraLock(m_mutex) @@ -141,6 +229,11 @@ namespace Nz return m_filePath.SubStringTo(NAZARA_DIRECTORY_SEPARATOR, -1, true, true); } + /*! + * \brief Gets the name of the file + * \return Name of the file + */ + String File::GetFileName() const { NazaraLock(m_mutex) @@ -148,6 +241,11 @@ namespace Nz return m_filePath.SubStringFrom(NAZARA_DIRECTORY_SEPARATOR, -1, true); } + /*! + * \brief Gets the last time the file was accessed + * \return Information about the last access time + */ + time_t File::GetLastAccessTime() const { NazaraLock(m_mutex) @@ -155,6 +253,11 @@ namespace Nz return GetLastAccessTime(m_filePath); } + /*! + * \brief Gets the last time the file was written + * \return Information about the last writing time + */ + time_t File::GetLastWriteTime() const { NazaraLock(m_mutex) @@ -162,6 +265,11 @@ namespace Nz return GetLastWriteTime(m_filePath); } + /*! + * \brief Gets the path of the file + * \return Path of the file + */ + String File::GetPath() const { NazaraLock(m_mutex) @@ -169,6 +277,11 @@ namespace Nz return m_filePath; } + /*! + * \brief Gets the size of the file + * \return Size of the file + */ + UInt64 File::GetSize() const { NazaraLock(m_mutex) @@ -176,6 +289,11 @@ namespace Nz return GetSize(m_filePath); } + /*! + * \brief Checks whether the file is open + * \return true if open + */ + bool File::IsOpen() const { NazaraLock(m_mutex) @@ -183,22 +301,14 @@ namespace Nz return m_impl != nullptr; } - bool File::Rename(const String& newFilePath) - { - NazaraLock(m_mutex) - - bool opened = IsOpen(); - Close(); - - bool success = Rename(m_filePath, newFilePath); - if (success) - m_filePath = NormalizePath(newFilePath); - - if (opened) - Open(); - - return success; - } + /*! + * \brief Opens the file with flags + * \return true if opening is successful + * + * \param openMode Flag for file + * + * \remark Produces a NazaraError if OS error to open a file + */ bool File::Open(unsigned int openMode) { @@ -215,7 +325,7 @@ namespace Nz std::unique_ptr impl(new FileImpl(this)); if (!impl->Open(m_filePath, openMode)) { - ErrorFlags flags(ErrorFlag_Silent); // Silencieux par défaut + ErrorFlags flags(ErrorFlag_Silent); // Silent by default NazaraError("Failed to open \"" + m_filePath + "\": " + Error::GetLastSystemError()); return false; } @@ -231,6 +341,16 @@ namespace Nz return true; } + /*! + * \brief Opens the file with file path and flags + * \return true if opening is successful + * + * \param filePath Path to the file + * \param openMode Flag for file + * + * \remark Produces a NazaraError if OS error to open a file + */ + bool File::Open(const String& filePath, unsigned int openMode) { NazaraLock(m_mutex) @@ -241,24 +361,72 @@ namespace Nz return Open(openMode); } + /*! + * \brief Renames the file with a new name + * \return true if rename is successful + */ + + bool File::Rename(const String& newFilePath) + { + NazaraLock(m_mutex) + + bool open = IsOpen(); + Close(); + + bool success = Rename(m_filePath, newFilePath); + if (success) + m_filePath = NormalizePath(newFilePath); + + if (open) + Open(); + + return success; + } + + /*! + * \brief Sets the position of the cursor + * \return true if cursor is successfully positioned + * + * \param pos Position of the cursor + * \param offset Offset according to the cursor position + * + * \remark Produces a NazaraAssert if file is not open + */ + bool File::SetCursorPos(CursorPosition pos, Int64 offset) { NazaraLock(m_mutex) - NazaraAssert(IsOpen(), "File is not opened"); + NazaraAssert(IsOpen(), "File is not open"); return m_impl->SetCursorPos(pos, offset); } + /*! + * \brief Sets the position of the cursor + * \return true if cursor is successfully positioned + * + * \param offset Offset according to the cursor begin position + * + * \remark Produces a NazaraAssert if file is not open + */ + bool File::SetCursorPos(UInt64 offset) { NazaraLock(m_mutex) - NazaraAssert(IsOpen(), "File is not opened"); + NazaraAssert(IsOpen(), "File is not open"); return m_impl->SetCursorPos(CursorPosition_AtBegin, offset); } + /*! + * \brief Sets the file path + * \return true if file opening is successful + * + * \remark Produces a NazaraError if file path can not be open + */ + bool File::SetFile(const String& filePath) { NazaraLock(m_mutex) @@ -285,6 +453,13 @@ namespace Nz return true; } + /*! + * \brief Sets the file path + * \return A reference to this + * + * \remark Produces a NazaraError if file path can not be open + */ + File& File::operator=(const String& filePath) { SetFile(filePath); @@ -292,6 +467,13 @@ namespace Nz return *this; } + /*! + * \brief Moves the other file into this + * \return A reference to this + * + * \param file File to move in this + */ + File& File::operator=(File&& file) noexcept { NazaraLock(m_mutex) @@ -302,9 +484,18 @@ namespace Nz return *this; } + /*! + * \brief Gets the absolute path of the file + * \return Absolute path of the file + * + * \param filePath Path of the file + * + * \remark Produces a NazaraError if filePath is weird with NAZARA_PLATFORM_WINDOWS defined + */ + String File::AbsolutePath(const String& filePath) { - // Je n'utilise pas les fonctions de l'OS car elles ne fonctionnent que pour un chemin existant + // We don't use OS functions because they only work for existing path String path = NormalizePath(filePath); if (path.IsEmpty()) return String(); @@ -319,7 +510,7 @@ namespace Nz base = "\\\\"; start = 2; } - else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + else if (path.StartsWith('\\')) // Special : '\' refering to root { String drive = Directory::GetCurrent().SubStringTo('\\'); String end = path.SubString(1, -1); @@ -351,14 +542,14 @@ namespace Nz if (path.Split(sep, NAZARA_DIRECTORY_SEPARATOR) <= 1) return path; - // Nous avons un chemin absolu, mais il nous faut un peu le nettoyer + // We have the absolute path, but we need to clean it up for (unsigned int i = 0; i < sep.size(); ++i) { if (sep[i] == '.') sep.erase(sep.begin() + i--); else if (sep[i] == "..") { - if (i > start) // Si nous ne sommes pas dans la partie protégée + if (i > start) // If we are not in the protected area sep.erase(sep.begin() + i--); sep.erase(sep.begin() + i--); @@ -377,6 +568,14 @@ namespace Nz return stream; } + /*! + * \brief Copies the first file to a new file path + * \return true if copy is successful + * + * \param sourcePath Path of the original file + * \param targetPath Path of the copied file + */ + bool File::Copy(const String& sourcePath, const String& targetPath) { if (sourcePath.IsEmpty() || targetPath.IsEmpty()) @@ -385,6 +584,13 @@ namespace Nz return FileImpl::Copy(NormalizePath(sourcePath), NormalizePath(targetPath)); } + /*! + * \brief Deletes the file + * \return true if delete is successful + * + * \param filePath Path of the file + */ + bool File::Delete(const String& filePath) { if (filePath.IsEmpty()) @@ -393,6 +599,13 @@ namespace Nz return FileImpl::Delete(NormalizePath(filePath)); } + /*! + * \brief Checks whether the file exists + * \return true if file exists + * + * \param filePath Path of the file + */ + bool File::Exists(const String& filePath) { if (filePath.IsEmpty()) @@ -401,6 +614,13 @@ namespace Nz return FileImpl::Exists(NormalizePath(filePath)); } + /*! + * \brief Gets the creation time of the file + * \return Information about the creation time + * + * \param filePath Path of the file + */ + time_t File::GetCreationTime(const String& filePath) { if (filePath.IsEmpty()) @@ -409,10 +629,23 @@ namespace Nz return FileImpl::GetCreationTime(NormalizePath(filePath)); } + /*! + * \brief Gets the directory of the file + * \return Directory of the file + * + * \param filePath Path of the file + */ + String File::GetDirectory(const String& filePath) { return filePath.SubStringTo(NAZARA_DIRECTORY_SEPARATOR, -1, true, true); } + /*! + * \brief Gets the last time the file was accessed + * \return Information about the last access time + * + * \param filePath Path of the file + */ time_t File::GetLastAccessTime(const String& filePath) { @@ -422,6 +655,13 @@ namespace Nz return FileImpl::GetLastAccessTime(NormalizePath(filePath)); } + /*! + * \brief Gets the last time the file was written + * \return Information about the last writing time + * + * \param filePath Path of the file + */ + time_t File::GetLastWriteTime(const String& filePath) { if (filePath.IsEmpty()) @@ -430,6 +670,13 @@ namespace Nz return FileImpl::GetLastWriteTime(NormalizePath(filePath)); } + /*! + * \brief Gets the size of the file + * \return Size of the file + * + * \param filePath Path of the file + */ + UInt64 File::GetSize(const String& filePath) { if (filePath.IsEmpty()) @@ -438,6 +685,13 @@ namespace Nz return FileImpl::GetSize(NormalizePath(filePath)); } + /*! + * \brief Checks whether the file path is absolute + * \return true if path is absolute + * + * \param filePath Path to test + */ + bool File::IsAbsolute(const String& filePath) { String path(filePath.Trimmed()); @@ -451,7 +705,7 @@ namespace Nz return true; else if (path.Match("\\\\*")) // Ex: \\Laptop return true; - else if (path.StartsWith('\\')) // Spécial : '\' fait référence au disque racine + else if (path.StartsWith('\\')) // Special : '\' refering to the root return true; else return false; @@ -462,6 +716,13 @@ namespace Nz #endif } + /*! + * \brief Normalizes the file path + * \return Path normalized (replacing '/' with '\\' on Windows, ...) + * + * \param filePath Path to normalize + */ + String File::NormalizePath(const String& filePath) { String path = NormalizeSeparators(filePath.Trimmed()); @@ -475,6 +736,13 @@ namespace Nz return path; } + /*! + * \brief Normalizes the path separator + * \return Path normalized (replacing '/' with '\\' on Windows, ...) + * + * \param filePath Path to normalize + */ + String File::NormalizeSeparators(const String& filePath) { String path(filePath); @@ -490,6 +758,14 @@ namespace Nz return path; } + /*! + * \brief Renames the file with a new name + * \return true if rename is successful + * + * \param sourcePath Path of the original file + * \param targetPath Path of the renamed file + */ + bool File::Rename(const String& sourcePath, const String& targetPath) { if (sourcePath.IsEmpty() || targetPath.IsEmpty()) @@ -498,6 +774,12 @@ namespace Nz return FileImpl::Rename(NormalizePath(sourcePath), NormalizePath(targetPath)); } + /*! + * \brief Flushes the stream + * + * \remark Produces a NazaraAssert if file is not open + */ + void File::FlushStream() { NazaraLock(m_mutex) @@ -507,11 +789,21 @@ namespace Nz m_impl->Flush(); } + /*! + * \brief Reads blocks + * \return Number of blocks read + * + * \param buffer Preallocated buffer to contain information read + * \param size Size of the read and thus of the buffer + * + * \remark Produces a NazaraAssert if file is not open + */ + std::size_t File::ReadBlock(void* buffer, std::size_t size) { NazaraLock(m_mutex) - NazaraAssert(IsOpen(), "File is not opened"); + NazaraAssert(IsOpen(), "File is not open"); if (size == 0) return 0; @@ -520,7 +812,7 @@ namespace Nz return m_impl->Read(buffer, size); else { - // Si nous ne devons rien lire, nous avançons simplement + // If we don't have to read, we move forward UInt64 currentPos = m_impl->GetCursorPos(); m_impl->SetCursorPos(CursorPosition_AtCurrent, size); @@ -529,11 +821,22 @@ namespace Nz } } + /*! + * \brief Writes blocks + * \return Number of blocks written + * + * \param buffer Preallocated buffer containing information to write + * \param size Size of the writting and thus of the buffer + * + * \remark Produces a NazaraAssert if file is not open + * \remark Produces a NazaraAssert if buffer is nullptr + */ + std::size_t File::WriteBlock(const void* buffer, std::size_t size) { NazaraLock(m_mutex) - NazaraAssert(IsOpen(), "File is not opened"); + NazaraAssert(IsOpen(), "File is not open"); if (size == 0) return 0; @@ -543,9 +846,22 @@ namespace Nz return m_impl->Write(buffer, size); } + /*! + * \brief Appends the file to the hash + * \return true if hash is successful + * + * \param hash Hash to append data of the file + * \param originalFile Path of the file + * + * \remark Produces a NazaraAssert if hash is nullptr + * \remark Produces a NazaraError if file could not be open + * \remark Produces a NazaraError if file could not be read + */ NAZARA_CORE_API bool HashAppend(AbstractHash* hash, const File& originalFile) { + NazaraAssert(hash, "Invalid hash"); + File file(originalFile.GetPath()); if (!file.Open(OpenMode_ReadOnly)) {