diff options
| author | donkopunchstania <donkopunchstania@gmail.com> | 2010-05-30 17:57:56 +0000 |
|---|---|---|
| committer | donkopunchstania <donkopunchstania@gmail.com> | 2010-05-30 17:57:56 +0000 |
| commit | 33566b5c07aa0104b5e3ea3ea232d19adeeb9285 (patch) | |
| tree | 82534692db60163baa8ac3e312d240af6878ef3e /Source/Core/DiscIO | |
| parent | c2daee96cc27154c4d09b2e0dc8efea7081a5daf (diff) | |
Limit buffer size required to extract files. This helps avoid out of memory errors.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5553 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/DiscIO')
| -rw-r--r-- | Source/Core/DiscIO/Src/FileSystemGCWii.cpp | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp index 9d8ace70da..eeaae84099 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp @@ -92,31 +92,46 @@ u64 CFileSystemGCWii::ReadFile(const char* _rFullPath, u8* _pBuffer, size_t _Max bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFilename) const { - size_t filesize = (size_t) GetFileSize(_rFullPath); + const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); - if (filesize == 0) + if (!pFileInfo || pFileInfo->m_FileSize == 0) return false; - u8* buffer = new u8[filesize]; + u64 remainingSize = pFileInfo->m_FileSize; + u64 fileOffset = pFileInfo->m_Offset; - if (!ReadFile(_rFullPath, buffer, filesize)) - { - delete[] buffer; + FILE* f = fopen(_rExportFilename, "wb"); + if (!f) return false; - } - FILE* f = fopen(_rExportFilename, "wb"); + bool result = true; - if (f) + while (remainingSize) { - fwrite(buffer, filesize, 1, f); - fclose(f); + // Limit read size to 128 MB + size_t readSize = (size_t)min(remainingSize, (u64)0x08000000); + + u8* buffer = new u8[readSize]; + + result = m_rVolume->Read(fileOffset, readSize, buffer); + + if (!result) + { + delete[] buffer; + break; + } + + fwrite(buffer, readSize, 1, f); + + remainingSize -= readSize; + fileOffset += readSize; + delete[] buffer; - return true; } - delete[] buffer; - return false; + fclose(f); + + return result; } bool CFileSystemGCWii::ExportApploader(const char* _rExportFolder) const |
