2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
20 #include "Win32StorageProvider.h"
21 #include "WIN32Util.h"
22 #include "guilib/LocalizeStrings.h"
23 #include "filesystem/SpecialProtocol.h"
24 #include "storage/MediaManager.h"
25 #include "utils/JobManager.h"
26 #include "utils/log.h"
28 bool CWin32StorageProvider::xbevent = false;
30 void CWin32StorageProvider::Initialize()
32 // check for a DVD drive
34 CWIN32Util::GetDrivesByType(vShare, DVD_DRIVES);
36 g_mediaManager.SetHasOpticalDrive(true);
38 CLog::Log(LOGDEBUG, "%s: No optical drive found.", __FUNCTION__);
40 // Can be removed once the StorageHandler supports optical media
41 VECSOURCES::const_iterator it;
42 for(it=vShare.begin();it!=vShare.end();++it)
43 if(g_mediaManager.GetDriveStatus(it->strPath) == DRIVE_CLOSED_MEDIA_PRESENT)
44 CJobManager::GetInstance().AddJob(new CDetectDisc(it->strPath, false), NULL);
48 void CWin32StorageProvider::GetLocalDrives(VECSOURCES &localDrives)
51 share.strPath = CSpecialProtocol::TranslatePath("special://home");
52 share.strName = g_localizeStrings.Get(21440);
53 share.m_ignore = true;
54 share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
55 localDrives.push_back(share);
57 CWIN32Util::GetDrivesByType(localDrives, LOCAL_DRIVES);
60 void CWin32StorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
62 CWIN32Util::GetDrivesByType(removableDrives, REMOVABLE_DRIVES, true);
65 std::string CWin32StorageProvider::GetFirstOpticalDeviceFileName()
67 return CWIN32Util::GetFirstOpticalDrive();
70 bool CWin32StorageProvider::Eject(CStdString mountpath)
72 if (!mountpath.IsEmpty())
74 return CWIN32Util::EjectDrive(mountpath[0]);
79 std::vector<CStdString> CWin32StorageProvider::GetDiskUsage()
81 return CWIN32Util::GetDiskUsage();
84 bool CWin32StorageProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
91 CDetectDisc::CDetectDisc(const CStdString &strPath, const bool bautorun)
92 : m_strPath(strPath), m_bautorun(bautorun)
96 bool CDetectDisc::DoWork()
98 CLog::Log(LOGDEBUG, "%s: Optical media found in drive %s", __FUNCTION__, m_strPath.c_str());
100 share.strPath = m_strPath;
101 share.strStatus = g_mediaManager.GetDiskLabel(share.strPath);
102 share.strDiskUniqueId = g_mediaManager.GetDiskUniqueId(share.strPath);
103 if(g_mediaManager.IsAudio(share.strPath))
104 share.strStatus = "Audio-CD";
105 else if(share.strStatus == "")
106 share.strStatus = g_localizeStrings.Get(446);
107 share.strName = share.strPath;
108 share.m_ignore = true;
109 share.m_iDriveType = CMediaSource::SOURCE_TYPE_DVD;
110 g_mediaManager.AddAutoSource(share, m_bautorun);