The data from strdup must be deallocated with free, not delete. I got rid of that ugly strdup and replaced the A though Z cdrom drive letter searching with Windows API stuffs.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7335 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
0cc8eda124
commit
26b6a9af61
|
@ -23,47 +23,33 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// Returns a string that can be used in a CreateFile call if
|
// takes a root drive path, returns true if it is a cdrom drive
|
||||||
// c_drive letter is a character. If not NULL is returned.
|
bool is_cdrom(const char drive[])
|
||||||
const char *is_cdrom(const char c_drive_letter)
|
|
||||||
{
|
{
|
||||||
UINT uDriveType;
|
return (DRIVE_CDROM == GetDriveType(drive));
|
||||||
char sz_win32_drive[4];
|
|
||||||
|
|
||||||
sz_win32_drive[0]= c_drive_letter;
|
|
||||||
sz_win32_drive[1]=':';
|
|
||||||
sz_win32_drive[2]='\\';
|
|
||||||
sz_win32_drive[3]='\0';
|
|
||||||
|
|
||||||
uDriveType = GetDriveType(sz_win32_drive);
|
|
||||||
|
|
||||||
switch(uDriveType)
|
|
||||||
{
|
|
||||||
case DRIVE_CDROM:
|
|
||||||
{
|
|
||||||
char sz_win32_drive_full[] = "\\\\.\\X:";
|
|
||||||
sz_win32_drive_full[4] = c_drive_letter;
|
|
||||||
return __strdup(&sz_win32_drive_full[4]);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
//cdio_debug("Drive %c is not a CD-ROM", c_drive_letter);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a pointer to an array of strings with the device names
|
// Returns a vector with the device names
|
||||||
std::vector<std::string> cdio_get_devices() {
|
std::vector<std::string> cdio_get_devices()
|
||||||
|
{
|
||||||
std::vector<std::string> drives;
|
std::vector<std::string> drives;
|
||||||
char drive_letter;
|
|
||||||
|
|
||||||
// Scan the system for CD-ROM drives.
|
const DWORD buffsize = GetLogicalDriveStrings(0, NULL);
|
||||||
for (drive_letter='A'; drive_letter <= 'Z'; drive_letter++) {
|
std::unique_ptr<char[]> buff(new char[buffsize]);
|
||||||
const char *drive_str=is_cdrom(drive_letter);
|
if (GetLogicalDriveStrings(buffsize, buff.get()) == buffsize - 1)
|
||||||
if (drive_str != NULL) {
|
{
|
||||||
drives.push_back(drive_str);
|
const char* drive = buff.get();
|
||||||
delete drive_str;
|
while (*drive)
|
||||||
|
{
|
||||||
|
if (is_cdrom(drive))
|
||||||
|
{
|
||||||
|
std::string str(drive);
|
||||||
|
str.pop_back(); // we don't want the final backslash
|
||||||
|
drives.push_back(std::move(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
// advance to next drive
|
||||||
|
while (*drive++) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return drives;
|
return drives;
|
||||||
|
|
Loading…
Reference in New Issue