From 32855a289c2be54da72e846f3b3670d3275c822a Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 9 Jan 2013 01:16:23 -0600 Subject: [PATCH] Actually export 0-sized files. Fixes issue 5177. --- Source/Core/DiscIO/Src/FileSystemGCWii.cpp | 39 +++++++++------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp index 8f40ab2f18..6103f53e67 100644 --- a/Source/Core/DiscIO/Src/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/Src/FileSystemGCWii.cpp @@ -19,6 +19,7 @@ #include "FileUtil.h" #include +#include #include "FileSystemGCWii.h" #include "StringUtil.h" @@ -95,7 +96,7 @@ bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFi const SFileInfo* pFileInfo = FindFileInfo(_rFullPath); - if (!pFileInfo || pFileInfo->m_FileSize == 0) + if (!pFileInfo) return false; u64 remainingSize = pFileInfo->m_FileSize; @@ -112,22 +113,17 @@ bool CFileSystemGCWii::ExportFile(const char* _rFullPath, const char* _rExportFi // Limit read size to 128 MB size_t readSize = (size_t)min(remainingSize, (u64)0x08000000); - u8* buffer = new u8[readSize]; + std::vector buffer(readSize); - result = m_rVolume->Read(fileOffset, readSize, buffer); + result = m_rVolume->Read(fileOffset, readSize, &buffer[0]); if (!result) - { - delete[] buffer; break; - } - f.WriteBytes(buffer, readSize); + f.WriteBytes(&buffer[0], readSize); remainingSize -= readSize; fileOffset += readSize; - - delete[] buffer; } return result; @@ -140,22 +136,20 @@ bool CFileSystemGCWii::ExportApploader(const char* _rExportFolder) const AppSize += 0x20; // + header size DEBUG_LOG(DISCIO,"AppSize -> %x", AppSize); - u8* buffer = new u8[AppSize]; - if (m_rVolume->Read(0x2440, AppSize, buffer)) + std::vector buffer(AppSize); + if (m_rVolume->Read(0x2440, AppSize, &buffer[0])) { - char exportName[512]; - sprintf(exportName, "%s/apploader.img", _rExportFolder); + std::string exportName(_rExportFolder); + exportName += "/apploader.img"; File::IOFile AppFile(exportName, "wb"); if (AppFile) { - AppFile.WriteBytes(buffer, AppSize); - delete[] buffer; + AppFile.WriteBytes(&buffer[0], AppSize); return true; } } - delete[] buffer; return false; } @@ -182,21 +176,20 @@ bool CFileSystemGCWii::ExportDOL(const char* _rExportFolder) const DolSize = offset + size; } - u8* buffer = new u8[DolSize]; - if (m_rVolume->Read(DolOffset, DolSize, buffer)) + std::vector buffer(DolSize); + if (m_rVolume->Read(DolOffset, DolSize, &buffer[0])) { - char exportName[512]; - sprintf(exportName, "%s/boot.dol", _rExportFolder); + std::string exportName(_rExportFolder); + exportName += "/boot.dol"; + File::IOFile DolFile(exportName, "wb"); if (DolFile) { - DolFile.WriteBytes(buffer, DolSize); - delete[] buffer; + DolFile.WriteBytes(&buffer[0], DolSize); return true; } } - delete[] buffer; return false; }