Be friendlier when trying to but from empty DVD drives.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2422 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2009-02-24 19:57:29 +00:00
parent 6eb19ec78c
commit 4fef62aa3b
4 changed files with 42 additions and 22 deletions

View File

@ -131,7 +131,7 @@ IBlobReader* CreateBlobReader(const char* filename)
if (IsCompressedBlob(filename))
return CompressedBlobReader::Create(filename);
// Still here? Assume plain file.
// Still here? Assume plain file - since we know it exists due to the File::Exists check above.
return PlainFileReader::Create(filename);
}

View File

@ -21,17 +21,28 @@
namespace DiscIO
{
DriveReader::DriveReader(const char *drive)
: hDisc(INVALID_HANDLE_VALUE)
{
#ifdef _WIN32
char path[MAX_PATH];
strncpy(path, drive, 3);
path[2] = 0;
sprintf(path, "\\\\.\\%s", drive);
SectorReader::SetSectorSize(2048);
hDisc = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
if (hDisc != INVALID_HANDLE_VALUE)
{
// Do a test read to make sure everything is OK, since it seems you can get
// handles to empty drives.
DWORD not_used;
if (!ReadFile(hDisc, 0, m_blocksize, (LPDWORD)&not_used, NULL))
{
// OK, something is wrong.
CloseHandle(hDisc);
hDisc = INVALID_HANDLE_VALUE;
return;
}
#ifdef _LOCKDRIVE // Do we want to lock the drive?
// Lock the compact disc in the CD-ROM drive to prevent accidental
@ -46,7 +57,6 @@ namespace DiscIO
if (file_)
{
#endif
SectorReader::SetSectorSize(2048);
}
else
{
@ -67,15 +77,23 @@ namespace DiscIO
if (hDisc != INVALID_HANDLE_VALUE)
{
CloseHandle(hDisc);
hDisc = INVALID_HANDLE_VALUE;
}
#else
fclose(file_);
file_ = 0;
#endif
}
DriveReader *DriveReader::Create(const char *drive)
{
return new DriveReader(drive);
DriveReader *reader = new DriveReader(drive);
if (!reader->IsOK())
{
delete reader;
return 0;
}
return reader;
}
void DriveReader::GetBlock(u64 block_num, u8 *out_ptr)
@ -88,7 +106,7 @@ namespace DiscIO
LONG off_high = (LONG)(offset >> 32);
SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
if (!ReadFile(hDisc, lpSector, m_blocksize, (LPDWORD)&NotUsed, NULL))
PanicAlert("DRE");
PanicAlert("Disc Read Error");
#else
fseek(file_, m_blocksize*block_num, SEEK_SET);
fread(lpSector, 1, m_blocksize, file_);
@ -107,7 +125,7 @@ namespace DiscIO
SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
if (!ReadFile(hDisc, out_ptr, (DWORD)(m_blocksize * num_blocks), (LPDWORD)&NotUsed, NULL))
{
PanicAlert("DRE");
PanicAlert("Disc Read Error");
return false;
}
#else

View File

@ -37,8 +37,10 @@ private:
#ifdef _WIN32
HANDLE hDisc;
PREVENT_MEDIA_REMOVAL pmrLockCDROM;
bool IsOK() {return hDisc != INVALID_HANDLE_VALUE;}
#else
FILE* file_;
bool IsOK() {return file_ != 0;}
#endif
s64 size;
u64 *block_pointers;

View File

@ -93,7 +93,7 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename)
delete pReader;
}
return(pVolume);
return pVolume;
}
break;
@ -137,7 +137,7 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
"'%s' before pressing [YES].", MasterKeyFile, MasterKeyFileHex))
{
pT = fopen(MasterKeyFileHex, "r");
if(pT==NULL){
if (!pT) {
PanicAlert("could not open %s", MasterKeyFileHex);
return NULL;
}
@ -160,7 +160,7 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
}
pT = fopen(MasterKeyFile, "wb");
if(pT==NULL){
if (!pT) {
PanicAlert("could not open/make '%s' for writing!", MasterKeyFile);
return NULL;
}
@ -169,7 +169,7 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
fclose(pT);
pT = fopen(MasterKeyFileHex, "rb");
if(pT==NULL){
if (!pT) {
PanicAlert("could not open '%s' for reading!\n did the file get deleted or locked after converting?", MasterKeyFileHex);
return NULL;
}