[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / storage / windows / Win32StorageProvider.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
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"
27
28 bool CWin32StorageProvider::xbevent = false;
29
30 void CWin32StorageProvider::Initialize()
31 {
32   // check for a DVD drive
33   VECSOURCES vShare;
34   CWIN32Util::GetDrivesByType(vShare, DVD_DRIVES);
35   if(!vShare.empty())
36     g_mediaManager.SetHasOpticalDrive(true);
37   else
38     CLog::Log(LOGDEBUG, "%s: No optical drive found.", __FUNCTION__);
39
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);
45   // remove end
46 }
47
48 void CWin32StorageProvider::GetLocalDrives(VECSOURCES &localDrives)
49 {
50   CMediaSource share;
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);
56
57   CWIN32Util::GetDrivesByType(localDrives, LOCAL_DRIVES);
58 }
59
60 void CWin32StorageProvider::GetRemovableDrives(VECSOURCES &removableDrives)
61 {
62   CWIN32Util::GetDrivesByType(removableDrives, REMOVABLE_DRIVES, true);
63 }
64
65 std::string CWin32StorageProvider::GetFirstOpticalDeviceFileName()
66 {
67   return CWIN32Util::GetFirstOpticalDrive();
68 }
69
70 bool CWin32StorageProvider::Eject(CStdString mountpath)
71 {
72   if (!mountpath.IsEmpty())
73   {
74     return CWIN32Util::EjectDrive(mountpath[0]);
75   }
76   return false;
77 }
78
79 std::vector<CStdString> CWin32StorageProvider::GetDiskUsage()
80 {
81   return CWIN32Util::GetDiskUsage();
82 }
83
84 bool CWin32StorageProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
85 {
86   bool b = xbevent;
87   xbevent = false;
88   return b;
89 }
90
91 CDetectDisc::CDetectDisc(const CStdString &strPath, const bool bautorun)
92   : m_strPath(strPath), m_bautorun(bautorun)
93 {
94 }
95
96 bool CDetectDisc::DoWork()
97 {
98   CLog::Log(LOGDEBUG, "%s: Optical media found in drive %s", __FUNCTION__, m_strPath.c_str());
99   CMediaSource share;
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);
111   return true;
112 }