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.
9 #include "MediaSource.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
)
29 { // no paths - return
32 else if (paths
.size() == 1)
33 { // only one valid path? make it the strPath
37 { // multiple valid paths?
38 strPath
= CMultiPathDirectory::ConstructMultiPath(vecPaths
);
42 m_iLockMode
= LOCK_MODE_EVERYONE
;
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
;
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
;
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
)
75 if (strName
!= share
.strName
)
80 void AddOrReplace(VECSOURCES
& sources
, const VECSOURCES
& extras
)
83 for( i
=0;i
<extras
.size();++i
)
86 for ( j
=0;j
<sources
.size();++j
)
88 if (StringUtils::EqualsNoCase(sources
[j
].strPath
, extras
[i
].strPath
))
90 sources
[j
] = extras
[i
];
94 if (j
== sources
.size())
95 sources
.push_back(extras
[i
]);
99 void AddOrReplace(VECSOURCES
& sources
, const CMediaSource
& source
)
102 for( i
=0;i
<sources
.size();++i
)
104 if (StringUtils::EqualsNoCase(sources
[i
].strPath
, source
.strPath
))
110 if (i
== sources
.size())
111 sources
.push_back(source
);