[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / MediaSource.cpp
blob6782ca3f1c0827894e319d2cd9f679fc8c6c378f
1 /*
2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "MediaSource.h"
11 #include "URL.h"
12 #include "Util.h"
13 #include "filesystem/MultiPathDirectory.h"
14 #include "media/MediaLockState.h"
15 #include "utils/StringUtils.h"
16 #include "utils/URIUtils.h"
18 using namespace XFILE;
20 bool CMediaSource::IsWritable() const
22 return CUtil::SupportsWriteFileOperations(strPath);
25 void CMediaSource::FromNameAndPaths(const std::string &category, const std::string &name, const std::vector<std::string> &paths)
27 vecPaths = paths;
28 if (paths.empty())
29 { // no paths - return
30 strPath.clear();
32 else if (paths.size() == 1)
33 { // only one valid path? make it the strPath
34 strPath = paths[0];
36 else
37 { // multiple valid paths?
38 strPath = CMultiPathDirectory::ConstructMultiPath(vecPaths);
41 strName = name;
42 m_iLockMode = LOCK_MODE_EVERYONE;
43 m_strLockCode = "0";
44 m_iBadPwdCount = 0;
45 m_iHasLock = LOCK_STATE_NO_LOCK;
46 m_allowSharing = true;
48 if (URIUtils::IsMultiPath(strPath))
49 m_iDriveType = SOURCE_TYPE_VPATH;
50 else if (StringUtils::StartsWithNoCase(strPath, "udf:"))
52 m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
53 strPath = "D:\\";
55 else if (URIUtils::IsISO9660(strPath))
56 m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
57 else if (URIUtils::IsDVD(strPath))
58 m_iDriveType = SOURCE_TYPE_DVD;
59 else if (URIUtils::IsRemote(strPath))
60 m_iDriveType = SOURCE_TYPE_REMOTE;
61 else if (URIUtils::IsHD(strPath))
62 m_iDriveType = SOURCE_TYPE_LOCAL;
63 else
64 m_iDriveType = SOURCE_TYPE_UNKNOWN;
65 // check - convert to url and back again to make sure strPath is accurate
66 // in terms of what we expect
67 strPath = CURL(strPath).Get();
70 bool CMediaSource::operator==(const CMediaSource &share) const
72 // NOTE: we may wish to filter this through CURL to enable better "fuzzy" matching
73 if (strPath != share.strPath)
74 return false;
75 if (strName != share.strName)
76 return false;
77 return true;
80 void AddOrReplace(VECSOURCES& sources, const VECSOURCES& extras)
82 unsigned int i;
83 for( i=0;i<extras.size();++i )
85 unsigned int j;
86 for ( j=0;j<sources.size();++j)
88 if (StringUtils::EqualsNoCase(sources[j].strPath, extras[i].strPath))
90 sources[j] = extras[i];
91 break;
94 if (j == sources.size())
95 sources.push_back(extras[i]);
99 void AddOrReplace(VECSOURCES& sources, const CMediaSource& source)
101 unsigned int i;
102 for( i=0;i<sources.size();++i )
104 if (StringUtils::EqualsNoCase(sources[i].strPath, source.strPath))
106 sources[i] = source;
107 break;
110 if (i == sources.size())
111 sources.push_back(source);