cdvdgigaherz:windows: Refactor to use early returns

This commit is contained in:
Jonathan Li 2018-01-30 01:39:26 +00:00
parent 5c158b4df9
commit 75c803df11
1 changed files with 31 additions and 32 deletions

View File

@ -206,9 +206,10 @@ bool IOCtlSrc::ReadDVDInfo()
std::array<u8, 22> buffer;
DVD_READ_STRUCTURE dvdrs{{0}, DvdPhysicalDescriptor, 0, 0};
BOOL ret = DeviceIoControl(m_device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs),
buffer.data(), buffer.size(), &unused, nullptr);
if (ret) {
if (!DeviceIoControl(m_device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs),
buffer.data(), buffer.size(), &unused, nullptr))
return false;
auto &layer = *reinterpret_cast<DVD_LAYER_DESCRIPTOR *>(
reinterpret_cast<DVD_DESCRIPTOR_HEADER *>(buffer.data())->Data);
@ -223,16 +224,15 @@ bool IOCtlSrc::ReadDVDInfo()
} else if (layer.TrackPath == 0) {
// Dual layer, Parallel Track Path
dvdrs.LayerNumber = 1;
ret = DeviceIoControl(m_device, IOCTL_DVD_READ_STRUCTURE, &dvdrs,
sizeof(dvdrs), buffer.data(), buffer.size(), &unused, nullptr);
if (ret) {
if (!DeviceIoControl(m_device, IOCTL_DVD_READ_STRUCTURE, &dvdrs, sizeof(dvdrs),
buffer.data(), buffer.size(), &unused, nullptr))
return false;
u32 layer1_start_sector = _byteswap_ulong(layer.StartingDataSector);
u32 layer1_end_sector = _byteswap_ulong(layer.EndDataSector);
m_media_type = 1;
m_layer_break = end_sector - start_sector;
m_sectors = end_sector - start_sector + 1 + layer1_end_sector - layer1_start_sector + 1;
}
} else {
// Dual layer, Opposite Track Path
u32 end_sector_layer0 = _byteswap_ulong(layer.EndLayerZeroSector);
@ -240,9 +240,8 @@ bool IOCtlSrc::ReadDVDInfo()
m_layer_break = end_sector_layer0 - start_sector;
m_sectors = end_sector_layer0 - start_sector + 1 + end_sector - (~end_sector_layer0 & 0xFFFFFFU) + 1;
}
}
return !!ret;
return true;
}
bool IOCtlSrc::ReadCDInfo()