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,23 +21,34 @@
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
// removal while reading from it.
pmrLockCDROM.PreventMediaRemoval = TRUE;
DeviceIoControl (hDisc, IOCTL_CDROM_MEDIA_REMOVAL,
DeviceIoControl(hDisc, IOCTL_CDROM_MEDIA_REMOVAL,
&pmrLockCDROM, sizeof(pmrLockCDROM), NULL,
0, &dwNotUsed, NULL);
#endif
@ -46,11 +57,10 @@ namespace DiscIO
if (file_)
{
#endif
SectorReader::SetSectorSize(2048);
}
else
{
PanicAlert("Load from DVD backup failed or no disc in drive %s",drive);
{
PanicAlert("Load from DVD backup failed or no disc in drive %s", drive);
}
} // DriveReader::DriveReader
@ -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)
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

@ -36,9 +36,11 @@ private:
#ifdef _WIN32
HANDLE hDisc;
PREVENT_MEDIA_REMOVAL pmrLockCDROM;
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;
@ -133,17 +133,17 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
FILE* pT = fopen(MasterKeyFile, "rb");
if (pT == NULL)
{
if(PanicYesNo("Can't open '%s'.\n If you know the key, now it's the time to paste it into "
if (PanicYesNo("Can't open '%s'.\n If you know the key, now it's the time to paste it into "
"'%s' before pressing [YES].", MasterKeyFile, MasterKeyFileHex))
{
pT = fopen(MasterKeyFileHex, "r");
if(pT==NULL){
if (!pT) {
PanicAlert("could not open %s", MasterKeyFileHex);
return NULL;
}
static char hexkey[32];
if(fread(hexkey,1,32,pT)<32)
if (fread(hexkey, 1, 32, pT)<32)
{
PanicAlert("%s is not the right size", MasterKeyFileHex);
fclose(pT);
@ -152,24 +152,24 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
fclose(pT);
static char binkey[16];
char *t=hexkey;
for(int i=0;i<16;i++)
char *t = hexkey;
for (int i = 0; i < 16; i++)
{
char h[3]={*(t++),*(t++),0};
binkey[i] = (char) strtol(h,NULL,16);
char h[3] = {*(t++), *(t++), 0};
binkey[i] = (char)strtol(h, NULL, 16);
}
pT = fopen(MasterKeyFile, "wb");
if(pT==NULL){
if (!pT) {
PanicAlert("could not open/make '%s' for writing!", MasterKeyFile);
return NULL;
}
fwrite(binkey,16,1,pT);
fwrite(binkey, 16, 1, pT);
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;
}