Skip to content

Commit

Permalink
FileWrapper: added WriteFile static method
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 4, 2024
1 parent fee8fb5 commit 53ad6f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions Common/interface/FileWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class FileWrapper

static bool ReadWholeFile(const char* FilePath, std::vector<Uint8>& Data, bool Silent = false);
static bool ReadWholeFile(const char* FilePath, IDataBlob** ppData, bool Silent = false);
static bool WriteFile(const char* FilePath, const void* Data, size_t Size, bool Silent = false);

private:
FileWrapper(const FileWrapper&);
Expand Down
36 changes: 36 additions & 0 deletions Common/src/FileWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,40 @@ bool FileWrapper::ReadWholeFile(const char* FilePath, IDataBlob** ppData, bool S
return true;
}

bool FileWrapper::WriteFile(const char* FilePath, const void* Data, size_t Size, bool Silent)
{
if (FilePath == nullptr || FilePath[0] == '\0')
{
DEV_ERROR("File path must not be null or empty");
return false;
}

if (Data == nullptr)
{
DEV_ERROR("Data pointer must not be null");
return false;
}

FileWrapper File{FilePath, EFileAccessMode::Overwrite};
if (!File)
{
if (!Silent)
{
LOG_ERROR_MESSAGE("Failed to open file '", FilePath, "'.");
}
return false;
}

if (!File->Write(Data, Size))
{
if (!Silent)
{
LOG_ERROR_MESSAGE("Failed to write to file '", FilePath, "'.");
}
return false;
}

return true;
}

} // namespace Diligent

0 comments on commit 53ad6f3

Please sign in to comment.