Skip to content

Commit 53ad6f3

Browse files
FileWrapper: added WriteFile static method
1 parent fee8fb5 commit 53ad6f3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Common/interface/FileWrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class FileWrapper
9292

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

9697
private:
9798
FileWrapper(const FileWrapper&);

Common/src/FileWrapper.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,40 @@ bool FileWrapper::ReadWholeFile(const char* FilePath, IDataBlob** ppData, bool S
9999
return true;
100100
}
101101

102+
bool FileWrapper::WriteFile(const char* FilePath, const void* Data, size_t Size, bool Silent)
103+
{
104+
if (FilePath == nullptr || FilePath[0] == '\0')
105+
{
106+
DEV_ERROR("File path must not be null or empty");
107+
return false;
108+
}
109+
110+
if (Data == nullptr)
111+
{
112+
DEV_ERROR("Data pointer must not be null");
113+
return false;
114+
}
115+
116+
FileWrapper File{FilePath, EFileAccessMode::Overwrite};
117+
if (!File)
118+
{
119+
if (!Silent)
120+
{
121+
LOG_ERROR_MESSAGE("Failed to open file '", FilePath, "'.");
122+
}
123+
return false;
124+
}
125+
126+
if (!File->Write(Data, Size))
127+
{
128+
if (!Silent)
129+
{
130+
LOG_ERROR_MESSAGE("Failed to write to file '", FilePath, "'.");
131+
}
132+
return false;
133+
}
134+
135+
return true;
136+
}
137+
102138
} // namespace Diligent

0 commit comments

Comments
 (0)