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 "MultiPathFile.h"
22 #include "MultiPathDirectory.h"
23 #include "utils/URIUtils.h"
26 using namespace XFILE;
28 using namespace XFILE;
30 CMultiPathFile::CMultiPathFile(void)
34 CMultiPathFile::~CMultiPathFile(void)
39 bool CMultiPathFile::Open(const CURL& url)
41 // grab the filename off the url
42 CStdString path, fileName;
43 URIUtils::Split(url.Get(), path, fileName);
44 vector<CStdString> vecPaths;
45 if (!CMultiPathDirectory::GetPaths(path, vecPaths))
48 for (unsigned int i = 0; i < vecPaths.size(); i++)
50 CStdString filePath = vecPaths[i];
51 filePath = URIUtils::AddFileToFolder(filePath, fileName);
52 if (m_file.Open(filePath))
58 bool CMultiPathFile::Exists(const CURL& url)
60 // grab the filename off the url
61 CStdString path, fileName;
62 URIUtils::Split(url.Get(), path, fileName);
63 vector<CStdString> vecPaths;
64 if (!CMultiPathDirectory::GetPaths(path, vecPaths))
67 for (unsigned int i = 0; i < vecPaths.size(); i++)
69 CStdString filePath = vecPaths[i];
70 filePath = URIUtils::AddFileToFolder(filePath, fileName);
71 if (CFile::Exists(filePath))
77 int CMultiPathFile::Stat(const CURL& url, struct __stat64* buffer)
79 // grab the filename off the url
80 CStdString path, fileName;
81 URIUtils::Split(url.Get(), path, fileName);
82 vector<CStdString> vecPaths;
83 if (!CMultiPathDirectory::GetPaths(path, vecPaths))
86 for (unsigned int i = 0; i < vecPaths.size(); i++)
88 CStdString filePath = vecPaths[i];
89 filePath = URIUtils::AddFileToFolder(filePath, fileName);
90 int ret = CFile::Stat(filePath, buffer);
97 unsigned int CMultiPathFile::Read(void* lpBuf, int64_t uiBufSize)
99 return m_file.Read(lpBuf, uiBufSize);
102 int64_t CMultiPathFile::Seek(int64_t iFilePosition, int iWhence /*=SEEK_SET*/)
104 return m_file.Seek(iFilePosition, iWhence);
107 void CMultiPathFile::Close()
112 int64_t CMultiPathFile::GetPosition()
114 return m_file.GetPosition();
117 int64_t CMultiPathFile::GetLength()
119 return m_file.GetLength();