00001
00006 #undef UNICODE
00007 #define _WIN32_WINNT 0x0500
00008 #include "compat.h"
00009
00010 #include "mediamonitor-windows.h"
00011 #include "mythcontext.h"
00012 #include "mythcdrom.h"
00013 #include "mythhdd.h"
00014
00015
00022 MediaMonitorWindows::MediaMonitorWindows(QObject* par,
00023 unsigned long interval,
00024 bool allowEject)
00025 : MediaMonitor(par, interval, allowEject)
00026 {
00027 char strDrives[128];
00028 if (!::GetLogicalDriveStrings(sizeof(strDrives), strDrives))
00029 return;
00030
00031 for (char *driveName = strDrives; *driveName;
00032 driveName += strlen(driveName) + 1)
00033 {
00034 uint type = ::GetDriveType(driveName);
00035 if (type != DRIVE_REMOVABLE && type != DRIVE_CDROM)
00036 continue;
00037
00038 MythMediaDevice *media = NULL;
00039
00040 if (type == DRIVE_CDROM)
00041 media = MythCDROM::get(this, driveName, false, allowEject);
00042 else
00043 media = MythHDD::Get(this, driveName, false, allowEject);
00044
00045 if (!media)
00046 {
00047 VERBOSE(VB_IMPORTANT,
00048 "Error. Couldn't create MythMediaDevice.");
00049 return;
00050 }
00051
00052
00053
00054 char volumeName[256];
00055 if (GetVolumeNameForVolumeMountPoint(
00056 driveName, volumeName, sizeof(volumeName)))
00057 {
00058 media->setVolumeID(volumeName);
00059 }
00060 else
00061 {
00062 media->setVolumeID(driveName);
00063 }
00064
00065 AddDevice(media);
00066 }
00067
00068 VERBOSE(VB_MEDIA, "Initial device list: " + listDevices());
00069 }
00070
00071 bool MediaMonitorWindows::AddDevice(MythMediaDevice *pDevice)
00072 {
00073 if (!pDevice)
00074 {
00075 VERBOSE(VB_IMPORTANT, "Error - MediaMonitorWindows::AddDevice(null)");
00076 return false;
00077 }
00078
00079
00080
00081
00082 QValueList<MythMediaDevice*>::const_iterator itr = m_Devices.begin();
00083 for (; itr != m_Devices.end(); ++itr)
00084 {
00085 if ((*itr)->getDevicePath() == pDevice->getDevicePath())
00086 {
00087 VERBOSE(VB_MEDIA, "MediamonitorWindows::AddDevice() -- " +
00088 QString("Not adding '%1', it appears to be a duplicate.")
00089 .arg(pDevice->getDevicePath()));
00090
00091 return false;
00092 }
00093 }
00094
00095 pDevice->setDeviceModel(pDevice->getDevicePath());
00096
00097 QMutexLocker locker(&m_DevicesLock);
00098 connect(pDevice, SIGNAL(statusChanged( MediaStatus, MythMediaDevice*)),
00099 this, SLOT(mediaStatusChanged(MediaStatus, MythMediaDevice*)));
00100 m_Devices.push_back(pDevice);
00101 m_UseCount[pDevice] = 0;
00102
00103 return true;
00104 }
00105
00106 QStringList MediaMonitorWindows::GetCDROMBlockDevices()
00107 {
00108 QStringList list;
00109
00110 char strDrives[128];
00111 if (::GetLogicalDriveStrings(sizeof(strDrives), strDrives))
00112 {
00113 for (char* driveName = strDrives; *driveName;
00114 driveName += strlen(driveName) + 1)
00115 {
00116 if (::GetDriveType(driveName) == DRIVE_CDROM)
00117 list.append(driveName);
00118 }
00119 }
00120
00121 return list;
00122 }