#include "OpticalDrive.hpp" #include "IoCtl.hpp" #ifdef _WIN32 #include #endif #define BUFFER_SIZE (0x1000) #define NODISC ("NO DISC") namespace Li::Scsi { void OpticalDrive::getDriveInformation(std::string drv) { #ifdef _WIN32 this->drivePath = drv.substr(0, drv.size() - 1); std::wstring wdrive = std::wstring(this->drivePath.begin(), this->drivePath.end()); WCHAR* wChrVolumeName = new WCHAR[BUFFER_SIZE]; if (!GetVolumeInformation(wdrive.c_str(), wChrVolumeName, BUFFER_SIZE, NULL, NULL, NULL, NULL, NULL)) { this->volumeName = NODISC; this->discInDrive = false; } else { std::wstring wVolumeName = std::wstring(wChrVolumeName); this->volumeName = std::string(wVolumeName.begin(), wVolumeName.end()); this->discInDrive = true; } delete wChrVolumeName; #endif } OpticalDrive::OpticalDrive(std::string drv) { this->getDriveInformation(drv); if (this->discInDrive) { IoCtl* ctl = new IoCtl(this->drivePath); this->supportedSpeeds = ctl->GetSupportedReadSpeeds(); this->sectors = ctl->GetTotalSectors(); delete ctl; } } OpticalDrive::~OpticalDrive() { if(this->discInDrive) delete this->supportedSpeeds; } std::vector* OpticalDrive::SupportedSpeeds() { return this->supportedSpeeds; } std::string OpticalDrive::VolumeName() { return this->volumeName; } std::string OpticalDrive::DrivePath() { return this->drivePath; } uint64_t OpticalDrive::Sectors() { return this->sectors; } bool OpticalDrive::DiscInDrive() { return this->discInDrive; } std::vector* OpticalDrive::ListOpticalDrives() { std::vector* drives = new std::vector(); #ifdef _WIN32 WCHAR* drivesList = new WCHAR[BUFFER_SIZE]; GetLogicalDriveStrings(BUFFER_SIZE, drivesList); WCHAR* curDrive = drivesList; while (*curDrive != '\0') { UINT driveType = GetDriveType(curDrive); if (driveType == DRIVE_CDROM) { std::wstring wDrive = std::wstring(curDrive); std::string drive = std::string(wDrive.begin(), wDrive.end()); OpticalDrive* opticalDrive = new OpticalDrive(drive); drives->push_back(opticalDrive); } curDrive += lstrlen(curDrive) + 1; } delete drivesList; #endif return drives; } }