mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-04 06:40:03 +00:00
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:
parent
6eb19ec78c
commit
4fef62aa3b
@ -131,7 +131,7 @@ IBlobReader* CreateBlobReader(const char* filename)
|
|||||||
if (IsCompressedBlob(filename))
|
if (IsCompressedBlob(filename))
|
||||||
return CompressedBlobReader::Create(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);
|
return PlainFileReader::Create(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,23 +21,34 @@
|
|||||||
namespace DiscIO
|
namespace DiscIO
|
||||||
{
|
{
|
||||||
DriveReader::DriveReader(const char *drive)
|
DriveReader::DriveReader(const char *drive)
|
||||||
|
: hDisc(INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
strncpy(path, drive, 3);
|
strncpy(path, drive, 3);
|
||||||
path[2] = 0;
|
path[2] = 0;
|
||||||
sprintf(path, "\\\\.\\%s", drive);
|
sprintf(path, "\\\\.\\%s", drive);
|
||||||
|
SectorReader::SetSectorSize(2048);
|
||||||
hDisc = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
hDisc = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
|
NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||||
if (hDisc != INVALID_HANDLE_VALUE)
|
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)¬_used, NULL))
|
||||||
|
{
|
||||||
|
// OK, something is wrong.
|
||||||
|
CloseHandle(hDisc);
|
||||||
|
hDisc = INVALID_HANDLE_VALUE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _LOCKDRIVE // Do we want to lock the drive?
|
#ifdef _LOCKDRIVE // Do we want to lock the drive?
|
||||||
// Lock the compact disc in the CD-ROM drive to prevent accidental
|
// Lock the compact disc in the CD-ROM drive to prevent accidental
|
||||||
// removal while reading from it.
|
// removal while reading from it.
|
||||||
pmrLockCDROM.PreventMediaRemoval = TRUE;
|
pmrLockCDROM.PreventMediaRemoval = TRUE;
|
||||||
DeviceIoControl (hDisc, IOCTL_CDROM_MEDIA_REMOVAL,
|
DeviceIoControl(hDisc, IOCTL_CDROM_MEDIA_REMOVAL,
|
||||||
&pmrLockCDROM, sizeof(pmrLockCDROM), NULL,
|
&pmrLockCDROM, sizeof(pmrLockCDROM), NULL,
|
||||||
0, &dwNotUsed, NULL);
|
0, &dwNotUsed, NULL);
|
||||||
#endif
|
#endif
|
||||||
@ -46,11 +57,10 @@ namespace DiscIO
|
|||||||
if (file_)
|
if (file_)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
SectorReader::SetSectorSize(2048);
|
|
||||||
}
|
}
|
||||||
else
|
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
|
} // DriveReader::DriveReader
|
||||||
|
|
||||||
@ -67,15 +77,23 @@ namespace DiscIO
|
|||||||
if (hDisc != INVALID_HANDLE_VALUE)
|
if (hDisc != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
CloseHandle(hDisc);
|
CloseHandle(hDisc);
|
||||||
|
hDisc = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
fclose(file_);
|
fclose(file_);
|
||||||
|
file_ = 0;
|
||||||
#endif
|
#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)
|
void DriveReader::GetBlock(u64 block_num, u8 *out_ptr)
|
||||||
@ -88,7 +106,7 @@ namespace DiscIO
|
|||||||
LONG off_high = (LONG)(offset >> 32);
|
LONG off_high = (LONG)(offset >> 32);
|
||||||
SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
|
SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
|
||||||
if (!ReadFile(hDisc, lpSector, m_blocksize, (LPDWORD)&NotUsed, NULL))
|
if (!ReadFile(hDisc, lpSector, m_blocksize, (LPDWORD)&NotUsed, NULL))
|
||||||
PanicAlert("DRE");
|
PanicAlert("Disc Read Error");
|
||||||
#else
|
#else
|
||||||
fseek(file_, m_blocksize*block_num, SEEK_SET);
|
fseek(file_, m_blocksize*block_num, SEEK_SET);
|
||||||
fread(lpSector, 1, m_blocksize, file_);
|
fread(lpSector, 1, m_blocksize, file_);
|
||||||
@ -107,7 +125,7 @@ namespace DiscIO
|
|||||||
SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
|
SetFilePointer(hDisc, off_low, &off_high, FILE_BEGIN);
|
||||||
if (!ReadFile(hDisc, out_ptr, (DWORD)(m_blocksize * num_blocks), (LPDWORD)&NotUsed, NULL))
|
if (!ReadFile(hDisc, out_ptr, (DWORD)(m_blocksize * num_blocks), (LPDWORD)&NotUsed, NULL))
|
||||||
{
|
{
|
||||||
PanicAlert("DRE");
|
PanicAlert("Disc Read Error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -37,8 +37,10 @@ private:
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HANDLE hDisc;
|
HANDLE hDisc;
|
||||||
PREVENT_MEDIA_REMOVAL pmrLockCDROM;
|
PREVENT_MEDIA_REMOVAL pmrLockCDROM;
|
||||||
|
bool IsOK() {return hDisc != INVALID_HANDLE_VALUE;}
|
||||||
#else
|
#else
|
||||||
FILE* file_;
|
FILE* file_;
|
||||||
|
bool IsOK() {return file_ != 0;}
|
||||||
#endif
|
#endif
|
||||||
s64 size;
|
s64 size;
|
||||||
u64 *block_pointers;
|
u64 *block_pointers;
|
||||||
|
@ -93,7 +93,7 @@ IVolume* CreateVolumeFromFilename(const std::string& _rFilename)
|
|||||||
delete pReader;
|
delete pReader;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(pVolume);
|
return pVolume;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -133,17 +133,17 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
|
|||||||
FILE* pT = fopen(MasterKeyFile, "rb");
|
FILE* pT = fopen(MasterKeyFile, "rb");
|
||||||
if (pT == NULL)
|
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))
|
"'%s' before pressing [YES].", MasterKeyFile, MasterKeyFileHex))
|
||||||
{
|
{
|
||||||
pT = fopen(MasterKeyFileHex, "r");
|
pT = fopen(MasterKeyFileHex, "r");
|
||||||
if(pT==NULL){
|
if (!pT) {
|
||||||
PanicAlert("could not open %s", MasterKeyFileHex);
|
PanicAlert("could not open %s", MasterKeyFileHex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char hexkey[32];
|
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);
|
PanicAlert("%s is not the right size", MasterKeyFileHex);
|
||||||
fclose(pT);
|
fclose(pT);
|
||||||
@ -152,24 +152,24 @@ IVolume* CreateVolumeFromCryptedWiiImage(IBlobReader& _rReader, u32 _VolumeType,
|
|||||||
fclose(pT);
|
fclose(pT);
|
||||||
|
|
||||||
static char binkey[16];
|
static char binkey[16];
|
||||||
char *t=hexkey;
|
char *t = hexkey;
|
||||||
for(int i=0;i<16;i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
char h[3]={*(t++),*(t++),0};
|
char h[3] = {*(t++), *(t++), 0};
|
||||||
binkey[i] = (char) strtol(h,NULL,16);
|
binkey[i] = (char)strtol(h, NULL, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
pT = fopen(MasterKeyFile, "wb");
|
pT = fopen(MasterKeyFile, "wb");
|
||||||
if(pT==NULL){
|
if (!pT) {
|
||||||
PanicAlert("could not open/make '%s' for writing!", MasterKeyFile);
|
PanicAlert("could not open/make '%s' for writing!", MasterKeyFile);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(binkey,16,1,pT);
|
fwrite(binkey, 16, 1, pT);
|
||||||
fclose(pT);
|
fclose(pT);
|
||||||
|
|
||||||
pT = fopen(MasterKeyFileHex, "rb");
|
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);
|
PanicAlert("could not open '%s' for reading!\n did the file get deleted or locked after converting?", MasterKeyFileHex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user