From 98ddeadbbf31247d0d88439f42df975da3f57c58 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Mon, 8 Feb 2010 22:22:20 +0000 Subject: [PATCH] Use standard C file i/o in PlainFileReader instead of Windows' functions. Fix a memleak in CompressedBlob and VolumeDirectory. Thanks to baby.lueshi for finding the File i/o issue :) git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5031 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DiscIO/Src/CompressedBlob.cpp | 4 ++ Source/Core/DiscIO/Src/FileBlob.cpp | 54 +--------------------- Source/Core/DiscIO/Src/FileBlob.h | 9 ---- Source/Core/DiscIO/Src/VolumeDirectory.cpp | 4 +- 4 files changed, 9 insertions(+), 62 deletions(-) diff --git a/Source/Core/DiscIO/Src/CompressedBlob.cpp b/Source/Core/DiscIO/Src/CompressedBlob.cpp index dcaa9da2b6..283633ae85 100644 --- a/Source/Core/DiscIO/Src/CompressedBlob.cpp +++ b/Source/Core/DiscIO/Src/CompressedBlob.cpp @@ -179,7 +179,10 @@ bool CompressFileToBlob(const char* infile, const char* outfile, u32 sub_type, FILE* f = fopen(outfile, "wb"); if (!f) + { + fclose(inf); return false; + } callback("Files opened, ready to compress.", 0, arg); @@ -209,6 +212,7 @@ bool CompressFileToBlob(const char* infile, const char* outfile, u32 sub_type, u64 position = 0; int num_compressed = 0; int num_stored = 0; + for (u32 i = 0; i < header.num_blocks; i++) { if (i % (header.num_blocks / 1000) == 0) diff --git a/Source/Core/DiscIO/Src/FileBlob.cpp b/Source/Core/DiscIO/Src/FileBlob.cpp index ae828325a0..faee3e5c6c 100644 --- a/Source/Core/DiscIO/Src/FileBlob.cpp +++ b/Source/Core/DiscIO/Src/FileBlob.cpp @@ -20,61 +20,13 @@ #include "Blob.h" #include "FileBlob.h" -#ifdef _WIN32 - #include -#endif - namespace DiscIO { -#ifdef _WIN32 - -PlainFileReader::PlainFileReader(HANDLE hFile_) -{ - hFile = hFile_; - GetFileSizeEx(hFile, (PLARGE_INTEGER)&size); -} - -PlainFileReader* PlainFileReader::Create(const char* filename) -{ - HANDLE hFile = CreateFile( - filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); - if (hFile != INVALID_HANDLE_VALUE) - return new PlainFileReader(hFile); - else - return 0; -} - -PlainFileReader::~PlainFileReader() -{ - CloseHandle(hFile); -} - -bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) -{ - if (!SetFilePointerEx(hFile, *(LARGE_INTEGER*)&offset, NULL, FILE_BEGIN)) - return false; - - DWORD bytesRead = 0; - if (!ReadFile(hFile, out_ptr, (DWORD)nbytes, &bytesRead, NULL)) - return false; - if (bytesRead != nbytes) - return false; - - return true; -} - -#else // POSIX - PlainFileReader::PlainFileReader(FILE* file__) { file_ = file__; - #if 0 - fseek64(file_, 0, SEEK_END); - #else - fseek(file_, 0, SEEK_END); // I don't have fseek64 with gcc 4.3 - #endif + fseek(file_, 0, SEEK_END); size = ftell(file_); fseek(file_, 0, SEEK_SET); } @@ -85,7 +37,7 @@ PlainFileReader* PlainFileReader::Create(const char* filename) if (file_) return new PlainFileReader(file_); else - return 0; + return NULL; } PlainFileReader::~PlainFileReader() @@ -102,6 +54,4 @@ bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) return bytesRead == nbytes; } -#endif - } // namespace diff --git a/Source/Core/DiscIO/Src/FileBlob.h b/Source/Core/DiscIO/Src/FileBlob.h index d1199ad24b..b911516e79 100644 --- a/Source/Core/DiscIO/Src/FileBlob.h +++ b/Source/Core/DiscIO/Src/FileBlob.h @@ -20,24 +20,15 @@ #include "Blob.h" -#ifdef _WIN32 -#include -#else #include -#endif namespace DiscIO { class PlainFileReader : public IBlobReader { -#ifdef _WIN32 - HANDLE hFile; - PlainFileReader(HANDLE hFile_); -#else FILE* file_; PlainFileReader(FILE* file__); -#endif s64 size; public: diff --git a/Source/Core/DiscIO/Src/VolumeDirectory.cpp b/Source/Core/DiscIO/Src/VolumeDirectory.cpp index ec26a6a549..f13b3dc11c 100644 --- a/Source/Core/DiscIO/Src/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/Src/VolumeDirectory.cpp @@ -49,7 +49,7 @@ CVolumeDirectory::CVolumeDirectory(const std::string& _rDirectory, bool _bIsWii, // create the default disk header m_diskHeader = new u8[DISKHEADERINFO_ADDRESS]; memset(m_diskHeader, 0, (size_t)DISKHEADERINFO_ADDRESS); - SetUniqueID("RZDE01"); + SetUniqueID("AGBJ01"); SetName("Default name"); if(_bIsWii) @@ -170,6 +170,8 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const _dbg_assert_(DVDINTERFACE, fileIter->first >= _Offset); PadToAddress(fileIter->first, _Offset, _Length, _pBuffer); } + + delete reader; } return true;