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/>.
21 #include "MediaSource.h"
22 #include "settings/AdvancedSettings.h"
25 #include "filesystem/MultiPathDirectory.h"
26 #include "utils/URIUtils.h"
29 using namespace XFILE;
31 bool CMediaSource::IsWritable() const
33 return CUtil::SupportsWriteFileOperations(strPath);
36 void CMediaSource::FromNameAndPaths(const CStdString &category, const CStdString &name, const vector<CStdString> &paths)
39 if (paths.size() == 0)
40 { // no paths - return
43 else if (paths.size() == 1)
44 { // only one valid path? make it the strPath
48 { // multiple valid paths?
49 strPath = CMultiPathDirectory::ConstructMultiPath(vecPaths);
53 m_iLockMode = LOCK_MODE_EVERYONE;
57 m_allowSharing = true;
59 if (URIUtils::IsMultiPath(strPath))
60 m_iDriveType = SOURCE_TYPE_VPATH;
61 else if (strPath.Left(4).Equals("udf:"))
63 m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
66 else if (URIUtils::IsISO9660(strPath))
67 m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
68 else if (URIUtils::IsDVD(strPath))
69 m_iDriveType = SOURCE_TYPE_DVD;
70 else if (URIUtils::IsRemote(strPath))
71 m_iDriveType = SOURCE_TYPE_REMOTE;
72 else if (URIUtils::IsHD(strPath))
73 m_iDriveType = SOURCE_TYPE_LOCAL;
75 m_iDriveType = SOURCE_TYPE_UNKNOWN;
76 // check - convert to url and back again to make sure strPath is accurate
77 // in terms of what we expect
78 strPath = CURL(strPath).Get();
81 bool CMediaSource::operator==(const CMediaSource &share) const
83 // NOTE: we may wish to filter this through CURL to enable better "fuzzy" matching
84 if (strPath != share.strPath)
86 if (strName != share.strName)
91 void AddOrReplace(VECSOURCES& sources, const VECSOURCES& extras)
94 for( i=0;i<extras.size();++i )
97 for ( j=0;j<sources.size();++j)
99 if (sources[j].strPath.Equals(extras[i].strPath))
101 sources[j] = extras[i];
105 if (j == sources.size())
106 sources.push_back(extras[i]);
110 void AddOrReplace(VECSOURCES& sources, const CMediaSource& source)
113 for( i=0;i<sources.size();++i )
115 if (sources[i].strPath.Equals(source.strPath))
121 if (i == sources.size())
122 sources.push_back(source);