[fnd] Implemented fnd::WriteFile()

This commit is contained in:
jakcron 2017-07-05 19:17:04 +10:00
parent 18b5826bfb
commit 79e2ef5fd2
3 changed files with 29 additions and 3 deletions

View file

@ -40,5 +40,31 @@ void FileIO::ReadFile(const std::string& path, MemoryBlob & blob)
void FileIO::WriteFile(const std::string& path, const MemoryBlob & blob) void FileIO::WriteFile(const std::string& path, const MemoryBlob & blob)
{ {
WriteFile(blob.data(), blob.size());
}
void fnd::FileIO::WriteFile(const std::string & path, const u8 * data, size_t len)
{
FILE* fp;
size_t filesz, filepos;
if ((fp = fopen(path.c_str(), "wb")) == NULL)
{
throw Exception(kModuleName, "Failed to open \"" + path + "\"");
}
filesz = len;
for (filepos = 0; filesz > kBlockSize; filesz -= kBlockSize, filepos += kBlockSize)
{
fwrite(data + filepos, 1, kBlockSize, fp);
}
if (filesz)
{
fwrite(blob.data() + filepos, 1, filesz, fp);
}
fclose(fp);
} }

View file

@ -10,6 +10,7 @@ namespace fnd
static void ReadFile(const std::string& path, MemoryBlob& blob); static void ReadFile(const std::string& path, MemoryBlob& blob);
//static void ReadFile(const char* path, MemoryBlob& blob, size_t offset, size_t size); //static void ReadFile(const char* path, MemoryBlob& blob, size_t offset, size_t size);
static void WriteFile(const std::string& path, const MemoryBlob& blob); static void WriteFile(const std::string& path, const MemoryBlob& blob);
static void WriteFile(const std::string& path, const u8* data, size_t len);
//static void WriteFile(const char* path, const MemoryBlob& blob, size_t offset, size_t size); //static void WriteFile(const char* path, const MemoryBlob& blob, size_t offset, size_t size);
private: private:

View file

@ -92,8 +92,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories> <AdditionalIncludeDirectories>C:\Users\jkrca\Source\Repos\NXTools\lib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>