mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
Fix since mth's version killed everything, even the baby sea lions
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@572 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
67aa39c89e
commit
1a7f5bb564
@ -22,13 +22,10 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
PlainFileReader::PlainFileReader(HANDLE hFile_)
|
PlainFileReader::PlainFileReader(HANDLE hFile_)
|
||||||
{
|
{
|
||||||
hFile = hFile_;
|
hFile = hFile_;
|
||||||
@ -53,58 +50,62 @@ PlainFileReader::~PlainFileReader()
|
|||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
bool PlainFileReader::Read(u64 offset, u64 size, u8* out_ptr)
|
||||||
{
|
{
|
||||||
LONG offset_high = (LONG)(offset >> 32);
|
LONG offset_high = (LONG)(offset >> 32);
|
||||||
SetFilePointer(hFile, (DWORD)(offset & 0xFFFFFFFF), &offset_high, FILE_BEGIN);
|
SetFilePointer(hFile, (DWORD)(offset & 0xFFFFFFFF), &offset_high, FILE_BEGIN);
|
||||||
|
|
||||||
if (nbytes >= 0x100000000ULL)
|
if (size >= 0x100000000ULL)
|
||||||
return false; // WTF, does windows really have this limitation?
|
return false; // WTF, does windows really have this limitation?
|
||||||
|
|
||||||
DWORD unused;
|
DWORD unused;
|
||||||
if (!ReadFile(hFile, out_ptr, DWORD(nbytes & 0xFFFFFFFF), &unused, NULL))
|
if (!ReadFile(hFile, out_ptr, DWORD(size & 0xFFFFFFFF), &unused, NULL))
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // POSIX
|
} // namespace
|
||||||
|
|
||||||
PlainFileReader::PlainFileReader(FILE* file__)
|
#else // linux, 64-bit. We do not yet care about linux32
|
||||||
{
|
|
||||||
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
|
|
||||||
size = ftell(file_);
|
|
||||||
fseek(file_, 0, SEEK_SET);
|
|
||||||
}
|
|
||||||
|
|
||||||
PlainFileReader* PlainFileReader::Create(const char* filename)
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
FILE* file_ = fopen(filename, "rb");
|
|
||||||
if (file_)
|
PlainFileReader::PlainFileReader(FILE* file__)
|
||||||
return new PlainFileReader(file_);
|
{
|
||||||
else
|
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
|
||||||
|
size = ftell(file_);
|
||||||
|
fseek(file_, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlainFileReader* PlainFileReader::Create(const char* filename)
|
||||||
|
{
|
||||||
|
FILE* file_ = fopen(filename, "rb");
|
||||||
|
if (file_)
|
||||||
|
{
|
||||||
|
return new PlainFileReader(file_);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlainFileReader::~PlainFileReader()
|
PlainFileReader::~PlainFileReader()
|
||||||
{
|
{
|
||||||
fclose(file_);
|
fclose(file_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||||
{
|
{
|
||||||
int seekStatus = fseek(file_, offset, SEEK_SET);
|
fseek(file_, offset, SEEK_SET);
|
||||||
if (seekStatus != 0)
|
fread(out_ptr, nbytes, 1, file_);
|
||||||
return false;
|
return true;
|
||||||
size_t bytesRead = fread(out_ptr, nbytes, 1, file_);
|
}
|
||||||
return bytesRead == nbytes;
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
|
||||||
#include <cstdio>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
@ -35,8 +33,8 @@ class PlainFileReader : public IBlobReader
|
|||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
PlainFileReader(HANDLE hFile_);
|
PlainFileReader(HANDLE hFile_);
|
||||||
#else
|
#else
|
||||||
FILE* file_;
|
FILE *file_;
|
||||||
PlainFileReader(FILE* file__);
|
PlainFileReader(FILE *file__);
|
||||||
#endif
|
#endif
|
||||||
s64 size;
|
s64 size;
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ public:
|
|||||||
~PlainFileReader();
|
~PlainFileReader();
|
||||||
u64 GetDataSize() const { return size; }
|
u64 GetDataSize() const { return size; }
|
||||||
u64 GetRawSize() const { return size; }
|
u64 GetRawSize() const { return size; }
|
||||||
bool Read(u64 offset, u64 nbytes, u8* out_ptr);
|
bool Read(u64 offset, u64 size, u8* out_ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user