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"
27 #include "utils/StringUtils.h"
30 using namespace XFILE;
32 bool CMediaSource::IsWritable() const
34 return CUtil::SupportsWriteFileOperations(strPath);
37 void CMediaSource::FromNameAndPaths(const CStdString &category, const CStdString &name, const vector<CStdString> &paths)
40 if (paths.size() == 0)
41 { // no paths - return
44 else if (paths.size() == 1)
45 { // only one valid path? make it the strPath
49 { // multiple valid paths?
50 strPath = CMultiPathDirectory::ConstructMultiPath(vecPaths);
54 m_iLockMode = LOCK_MODE_EVERYONE;
58 m_allowSharing = true;
60 if (URIUtils::IsMultiPath(strPath))
61 m_iDriveType = SOURCE_TYPE_VPATH;
62 else if (StringUtils::StartsWithNoCase(strPath, "udf:"))
64 m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
67 else if (URIUtils::IsISO9660(strPath))
68 m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
69 else if (URIUtils::IsDVD(strPath))
70 m_iDriveType = SOURCE_TYPE_DVD;
71 else if (URIUtils::IsRemote(strPath))
72 m_iDriveType = SOURCE_TYPE_REMOTE;
73 else if (URIUtils::IsHD(strPath))
74 m_iDriveType = SOURCE_TYPE_LOCAL;
76 m_iDriveType = SOURCE_TYPE_UNKNOWN;
77 // check - convert to url and back again to make sure strPath is accurate
78 // in terms of what we expect
79 strPath = CURL(strPath).Get();
82 bool CMediaSource::operator==(const CMediaSource &share) const
84 // NOTE: we may wish to filter this through CURL to enable better "fuzzy" matching
85 if (strPath != share.strPath)
87 if (strName != share.strName)
92 void AddOrReplace(VECSOURCES& sources, const VECSOURCES& extras)
95 for( i=0;i<extras.size();++i )
98 for ( j=0;j<sources.size();++j)
100 if (sources[j].strPath.Equals(extras[i].strPath))
102 sources[j] = extras[i];
106 if (j == sources.size())
107 sources.push_back(extras[i]);
111 void AddOrReplace(VECSOURCES& sources, const CMediaSource& source)
114 for( i=0;i<sources.size();++i )
116 if (sources[i].strPath.Equals(source.strPath))
122 if (i == sources.size())
123 sources.push_back(source);