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
This commit is contained in:
parent
3f90bb215c
commit
98ddeadbbf
|
@ -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)
|
||||
|
|
|
@ -20,61 +20,13 @@
|
|||
#include "Blob.h"
|
||||
#include "FileBlob.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#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
|
||||
|
|
|
@ -20,24 +20,15 @@
|
|||
|
||||
#include "Blob.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
namespace DiscIO
|
||||
{
|
||||
|
||||
class PlainFileReader : public IBlobReader
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE hFile;
|
||||
PlainFileReader(HANDLE hFile_);
|
||||
#else
|
||||
FILE* file_;
|
||||
PlainFileReader(FILE* file__);
|
||||
#endif
|
||||
s64 size;
|
||||
|
||||
public:
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue