This repository has been archived by the owner on Sep 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
MediaSource.cpp
124 lines (115 loc) · 3.28 KB
/
MediaSource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "MediaSource.h"
#include "settings/AdvancedSettings.h"
#include "Util.h"
#include "URL.h"
#include "filesystem/MultiPathDirectory.h"
#include "utils/URIUtils.h"
using namespace std;
using namespace XFILE;
bool CMediaSource::IsWritable() const
{
return CUtil::SupportsFileOperations(strPath);
}
void CMediaSource::FromNameAndPaths(const CStdString &category, const CStdString &name, const vector<CStdString> &paths)
{
vecPaths = paths;
if (paths.size() == 0)
{ // no paths - return
strPath.Empty();
}
else if (paths.size() == 1)
{ // only one valid path? make it the strPath
strPath = paths[0];
}
else
{ // multiple valid paths?
strPath = CMultiPathDirectory::ConstructMultiPath(vecPaths);
}
strName = name;
m_iLockMode = LOCK_MODE_EVERYONE;
m_strLockCode = "0";
m_iBadPwdCount = 0;
m_iHasLock = 0;
if (URIUtils::IsMultiPath(strPath))
m_iDriveType = SOURCE_TYPE_VPATH;
else if (strPath.Left(4).Equals("udf:"))
{
m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
strPath = "D:\\";
}
else if (URIUtils::IsISO9660(strPath))
m_iDriveType = SOURCE_TYPE_VIRTUAL_DVD;
else if (URIUtils::IsDVD(strPath))
m_iDriveType = SOURCE_TYPE_DVD;
else if (URIUtils::IsRemote(strPath))
m_iDriveType = SOURCE_TYPE_REMOTE;
else if (URIUtils::IsHD(strPath))
m_iDriveType = SOURCE_TYPE_LOCAL;
else
m_iDriveType = SOURCE_TYPE_UNKNOWN;
// check - convert to url and back again to make sure strPath is accurate
// in terms of what we expect
URIUtils::AddSlashAtEnd(strPath);
strPath = CURL(strPath).Get();
}
bool CMediaSource::operator==(const CMediaSource &share) const
{
// NOTE: we may wish to filter this through CURL to enable better "fuzzy" matching
if (strPath != share.strPath)
return false;
if (strName != share.strName)
return false;
return true;
}
void AddOrReplace(VECSOURCES& sources, const VECSOURCES& extras)
{
unsigned int i;
for( i=0;i<extras.size();++i )
{
unsigned int j;
for ( j=0;j<sources.size();++j)
{
if (sources[j].strPath.Equals(extras[i].strPath))
{
sources[j] = extras[i];
break;
}
}
if (j == sources.size())
sources.push_back(extras[i]);
}
}
void AddOrReplace(VECSOURCES& sources, const CMediaSource& source)
{
unsigned int i;
for( i=0;i<sources.size();++i )
{
if (sources[i].strPath.Equals(source.strPath))
{
sources[i] = source;
break;
}
}
if (i == sources.size())
sources.push_back(source);
}