This commit is contained in:
Li 2023-03-16 21:35:31 +13:00
parent 079cb1129e
commit 7eeee60df5
4 changed files with 96 additions and 11 deletions

View File

@ -25,6 +25,7 @@
namespace Li::Gui { namespace Li::Gui {
DumpDVD::DumpDVD() { DumpDVD::DumpDVD() {
this->discInserted = false;
this->keepPolling = true; this->keepPolling = true;
this->showDemoWindow = true; this->showDemoWindow = true;
this->imRippinIt = false; this->imRippinIt = false;
@ -69,6 +70,7 @@ namespace Li::Gui {
drive->AllowReadingPastDisc(); drive->AllowReadingPastDisc();
drive->SetDriveSpeed(speed, speed); drive->SetDriveSpeed(speed, speed);
drive->ExclusiveLockDrive();
this->sectorsReadSoFar = 0; this->sectorsReadSoFar = 0;
dvdcss_seek(drive->GetDvdCssHandle(), 0, DVDCSS_SEEK_KEY); dvdcss_seek(drive->GetDvdCssHandle(), 0, DVDCSS_SEEK_KEY);
@ -81,21 +83,24 @@ namespace Li::Gui {
} }
int numRead = dvdcss_read(drive->GetDvdCssHandle(), buffer, sectorsToRead, DVDCSS_READ_DECRYPT); int numRead = dvdcss_read(drive->GetDvdCssHandle(), buffer, sectorsToRead, DVDCSS_READ_DECRYPT);
if (numRead <= 0) { if (numRead <= 0) {
this->error = true; this->error = true;
this->errorMsg = std::string(dvdcss_error(drive->GetDvdCssHandle()));
break; break;
} }
iso->write((const char*)buffer, DVDCSS_BLOCK_SIZE * numRead); iso->write((const char*)buffer, DVDCSS_BLOCK_SIZE * numRead);
this->sectorsReadSoFar += numRead; this->sectorsReadSoFar += numRead;
} while (this->sectorsReadSoFar < totalSectors); } while (this->sectorsReadSoFar < totalSectors && this->imRippinIt);
this->done = true;
drive->ExclusiveUnlockDrive();
iso->close();
this->done = true;
delete buffer; delete buffer;
delete drive; delete drive;
iso->close();
delete iso; delete iso;
} }
@ -109,12 +114,10 @@ namespace Li::Gui {
void DumpDVD::refreshDriveList() { void DumpDVD::refreshDriveList() {
std::vector<Li::Scsi::OpticalDrive*>* pollDrives = Li::Scsi::OpticalDrive::ListOpticalDrives(); std::vector<Li::Scsi::OpticalDrive*>* pollDrives = Li::Scsi::OpticalDrive::ListOpticalDrives();
if(this->lock != nullptr) this->lock->lock();
this->lock->lock();
this->freeOldDriveList(); this->freeOldDriveList();
this->drivesList = pollDrives; this->drivesList = pollDrives;
if (this->lock != nullptr) this->lock->unlock();
this->lock->unlock();
} }
void DumpDVD::freeOldDriveList() { void DumpDVD::freeOldDriveList() {
@ -165,7 +168,6 @@ namespace Li::Gui {
delete this->pollDrives; delete this->pollDrives;
this->pollDrives = new std::thread(&DumpDVD::ripDiscThread, this); this->pollDrives = new std::thread(&DumpDVD::ripDiscThread, this);
this->imRippinIt = true; this->imRippinIt = true;
} }
} }
@ -175,9 +177,10 @@ namespace Li::Gui {
this->imRippinIt = false; this->imRippinIt = false;
this->reset(); this->reset();
this->sectorsReadSoFar = 0; this->sectorsReadSoFar = 0;
this->counter = 0;
this->pollDrives->join(); this->pollDrives->join();
delete this->pollDrives;
this->keepPolling = true;
this->drivesList = Li::Scsi::OpticalDrive::ListOpticalDrives(); this->drivesList = Li::Scsi::OpticalDrive::ListOpticalDrives();
this->pollDrives = new std::thread(&DumpDVD::pollDrivesThread, this); this->pollDrives = new std::thread(&DumpDVD::pollDrivesThread, this);
} }
@ -198,6 +201,12 @@ namespace Li::Gui {
ImGui::Text("Total %s / %s", Utils::HumanReadableByteStr(szSoFar).c_str(), Utils::HumanReadableByteStr(szTotal).c_str()); ImGui::Text("Total %s / %s", Utils::HumanReadableByteStr(szSoFar).c_str(), Utils::HumanReadableByteStr(szTotal).c_str());
ImGui::Text("Output file: \"%s\"", this->outputFile);
if (ImGui::Button("Cancel")) {
this->endRipAndGoBackToMenu();
std::filesystem::remove(std::string(this->outputFile));
}
if (this->done) { if (this->done) {
if (!this->error) { if (!this->error) {
@ -210,13 +219,16 @@ namespace Li::Gui {
} }
else { else {
ImGui::Begin("Error", &done, this->windowFlags); ImGui::Begin("Error", &done, this->windowFlags);
ImGui::Text("Error occured when creating an ISO"); ImGui::Text("Error occured when creating an ISO\n\"%s\"", this->errorMsg.c_str());
if (ImGui::Button("OK")) { if (ImGui::Button("OK")) {
this->endRipAndGoBackToMenu(); this->endRipAndGoBackToMenu();
std::filesystem::remove(std::string(this->outputFile));
} }
ImGui::End(); ImGui::End();
} }
} }
} }
void DumpDVD::showRipMenu() { void DumpDVD::showRipMenu() {
@ -234,8 +246,13 @@ namespace Li::Gui {
if (!GetCurrentSelectedDrive()->DiscInDrive()) { if (!GetCurrentSelectedDrive()->DiscInDrive()) {
ImGui::Text("Put a disc in the drive to continue ..."); ImGui::Text("Put a disc in the drive to continue ...");
this->discInserted = false;
} }
else { else {
if (!this->discInserted) {
this->discInserted = true;
this->reset();
}
int numDrvSpeeds = GetCurrentSelectedDrive()->SupportedSpeeds()->size() + 1; int numDrvSpeeds = GetCurrentSelectedDrive()->SupportedSpeeds()->size() + 1;
std::string driveSpeedName = "Unknown"; std::string driveSpeedName = "Unknown";

View File

@ -20,9 +20,11 @@ namespace Li::Gui {
bool error; bool error;
bool done; bool done;
std::string errorMsg;
uint64_t sectorsReadSoFar; uint64_t sectorsReadSoFar;
int sectorsAtOnce; int sectorsAtOnce;
bool discInserted;
int selectedDrive; int selectedDrive;
ImGuiWindowFlags windowFlags; ImGuiWindowFlags windowFlags;
int selectedDriveSpeed; int selectedDriveSpeed;

View File

@ -112,6 +112,68 @@ namespace Li::Scsi {
return success; return success;
#endif #endif
} }
bool IoCtl::UnmountVolume() {
#ifdef _WIN32
DWORD unused;
BOOL success = DeviceIoControl((HANDLE)this->osFileHandle, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0, &unused, nullptr);
if (!success) {
std::cerr << "Error unmounting drive: " << std::to_string(GetLastError()) << std::endl;
}
return success;
#endif
}
bool IoCtl::MountVolume() {
#ifdef _WIN32
DWORD unused;
BOOL success = DeviceIoControl((HANDLE)this->osFileHandle, FSCTL_UNLOCK_VOLUME, nullptr, 0, nullptr, 0, &unused, nullptr);
if (!success) {
std::cerr << "Error mounting drive: " << std::to_string(GetLastError()) << std::endl;
}
return success;
#endif
}
bool IoCtl::ExclusiveLockDrive() {
#ifdef _WIN32
this->UnmountVolume();
DWORD unused;
CDROM_EXCLUSIVE_LOCK exclusiveLockRequest;
memset(&exclusiveLockRequest, 0x00, sizeof(CDROM_EXCLUSIVE_LOCK));
exclusiveLockRequest.Access.RequestType = ExclusiveAccessLockDevice;
exclusiveLockRequest.Access.Flags = CDROM_LOCK_IGNORE_VOLUME;
strncpy((char*)(exclusiveLockRequest.CallerName), "LiDeeVeeDeeDumperProgramThing", CDROM_EXCLUSIVE_CALLER_LENGTH - 1);
BOOL success = DeviceIoControl((HANDLE)this->osFileHandle, IOCTL_CDROM_EXCLUSIVE_ACCESS, &exclusiveLockRequest, sizeof(CDROM_EXCLUSIVE_LOCK), nullptr, 0, &unused, nullptr);
if (!success) {
std::cerr << "Error Locking the drive: " << std::to_string(GetLastError()) << std::endl;
}
return success;
#endif
}
bool IoCtl::ExclusiveUnlockDrive() {
#ifdef _WIN32
DWORD unused;
CDROM_EXCLUSIVE_ACCESS exclusiveUnlockRequest;
memset(&exclusiveUnlockRequest, 0x00, sizeof(CDROM_EXCLUSIVE_ACCESS));
exclusiveUnlockRequest.RequestType = ExclusiveAccessUnlockDevice;
BOOL success = DeviceIoControl((HANDLE)this->osFileHandle, IOCTL_CDROM_EXCLUSIVE_ACCESS, &exclusiveUnlockRequest, sizeof(CDROM_EXCLUSIVE_LOCK), nullptr, 0, &unused, nullptr);
if (!success) {
std::cerr << "Error unlocking the drive: " << std::to_string(GetLastError()) << std::endl;
}
this->MountVolume();
return success;
#endif
}
bool IoCtl::SetDriveSpeed(int readSpeed, int writeSpeed) bool IoCtl::SetDriveSpeed(int readSpeed, int writeSpeed)
{ {
#ifdef _WIN32 #ifdef _WIN32

View File

@ -18,6 +18,10 @@ namespace Li::Scsi {
uint64_t GetTotalSectors(); uint64_t GetTotalSectors();
bool SetDriveSpeed(int readSpeed, int writeSpeed); bool SetDriveSpeed(int readSpeed, int writeSpeed);
bool AllowReadingPastDisc(); bool AllowReadingPastDisc();
bool ExclusiveLockDrive();
bool ExclusiveUnlockDrive();
bool UnmountVolume();
bool MountVolume();
std::vector<uint32_t>* GetSupportedReadSpeeds(); std::vector<uint32_t>* GetSupportedReadSpeeds();
}; };