Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Actually export 0-sized files.
Fixes issue 5177.
  • Loading branch information
jordan-woyak committed Jan 9, 2013
1 parent d9ea718 commit 32855a2
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions Source/Core/DiscIO/Src/FileSystemGCWii.cpp
Expand Up @@ -19,6 +19,7 @@
#include "FileUtil.h"

#include <string>
#include <vector>

#include "FileSystemGCWii.h"
#include "StringUtil.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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<u8> 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;
Expand All @@ -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<u8> 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;
}

Expand All @@ -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<u8> 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;
}

Expand Down

0 comments on commit 32855a2

Please sign in to comment.