summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2011-03-11 10:21:46 +0000
committerJordan Woyak <jordan.woyak@gmail.com>2011-03-11 10:21:46 +0000
commit59fd1008ca9cf4e9f75fdd6ee8ec53a2c7d7a13b (patch)
tree1de127fb452967ccc052324d9aff0775ea1b76cf /Source/Core/VideoCommon
parent4f69672b2b31581746aae907e7757981fc48db77 (diff)
Wrapped fopen/close/read/write functions inside a simple "IOFile" class. Reading, writing, and error checking became simpler in most cases. It should be near impossible to forget to close a file now that the destructor takes care of it. (I hope this fixes Issue 3635) I have tested the functionality of most things, but it is possible I broke something. :p
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7328 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/Src/ImageWrite.cpp44
-rw-r--r--Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp26
2 files changed, 32 insertions, 38 deletions
diff --git a/Source/Core/VideoCommon/Src/ImageWrite.cpp b/Source/Core/VideoCommon/Src/ImageWrite.cpp
index 404932e054..23b0e73427 100644
--- a/Source/Core/VideoCommon/Src/ImageWrite.cpp
+++ b/Source/Core/VideoCommon/Src/ImageWrite.cpp
@@ -15,11 +15,11 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
-#include <stdio.h>
#include <list>
#include <vector>
#include "ImageWrite.h"
+#include "FileUtil.h"
#pragma pack(push, 1)
@@ -47,32 +47,30 @@ struct TGA_HEADER
bool SaveTGA(const char* filename, int width, int height, void* pdata)
{
- TGA_HEADER hdr;
- FILE* f = fopen(filename, "wb");
- if (f == NULL)
- return false;
+ TGA_HEADER hdr;
+ File::IOFile f(filename, "wb");
+ if (!f)
+ return false;
- _assert_(sizeof(TGA_HEADER) == 18 && sizeof(hdr) == 18);
+ _assert_(sizeof(TGA_HEADER) == 18 && sizeof(hdr) == 18);
- memset(&hdr, 0, sizeof(hdr));
- hdr.imagetype = 2;
- hdr.bits = 32;
- hdr.width = width;
- hdr.height = height;
- hdr.descriptor |= 8|(1<<5); // 8bit alpha, flip vertical
-
- fwrite(&hdr, sizeof(hdr), 1, f);
- fwrite(pdata, width * height * 4, 1, f);
- fclose(f);
- return true;
+ memset(&hdr, 0, sizeof(hdr));
+ hdr.imagetype = 2;
+ hdr.bits = 32;
+ hdr.width = width;
+ hdr.height = height;
+ hdr.descriptor |= 8|(1<<5); // 8bit alpha, flip vertical
+
+ f.WriteArray(&hdr, 1);
+ f.WriteBytes(pdata, width * height * 4);
+
+ return true;
}
bool SaveData(const char* filename, const char* data)
{
- FILE *f = fopen(filename, "wb");
- if (!f)
- return false;
- fwrite(data, strlen(data), 1, f);
- fclose(f);
- return true;
+ std::ofstream f(filename, std::ios::binary);
+ f << data;
+
+ return true;
}
diff --git a/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp b/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp
index be98e939ab..72643c617f 100644
--- a/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp
+++ b/Source/Core/VideoCommon/Src/OpenCL/OCLTextureDecoder.cpp
@@ -105,22 +105,20 @@ void TexDecoder_OpenCL_Initialize()
filename = File::GetUserPath(D_OPENCL_IDX) + "kernel.bin";
snprintf(dolphin_rev, HEADER_SIZE, "%-31s", svn_rev_str);
- FILE *input = NULL;
-
- input = fopen(filename.c_str(), "rb");
- if (input == NULL)
+ {
+ File::IOFile input(filename, "rb");
+ if (!input)
{
binary_size = 0;
}
else
{
- binary_size = File::GetSize(input);
+ binary_size = input.GetSize();
header = new char[HEADER_SIZE];
binary = new char[binary_size];
- fread(header, sizeof(char), HEADER_SIZE, input);
- binary_size = fread(binary, sizeof(char),
- binary_size - HEADER_SIZE, input);
- fclose(input);
+ input.ReadBytes(header, HEADER_SIZE);
+ input.ReadBytes(binary, binary_size);
+ }
}
if (binary_size > 0)
@@ -202,19 +200,17 @@ void TexDecoder_OpenCL_Initialize()
if (!err)
{
filename = File::GetUserPath(D_OPENCL_IDX) + "kernel.bin";
- FILE *output = NULL;
- output = fopen(filename.c_str(), "wb");
- if (output == NULL)
+ File::IOFile output(filename, "wb");
+ if (!output)
{
binary_size = 0;
}
else
{
// Supporting one OpenCL device for now
- fwrite(dolphin_rev, sizeof(char), HEADER_SIZE, output);
- fwrite(binaries[0], sizeof(char), binary_sizes[0], output);
- fclose(output);
+ output.WriteBytes(dolphin_rev, HEADER_SIZE);
+ output.WriteBytes(binaries[0], binary_sizes[0]);
}
}
}