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 "RarDirectory.h"
22 #include "RarManager.h"
23 #include "utils/log.h"
24 #include "utils/URIUtils.h"
27 #include "utils/StringUtils.h"
31 CRarDirectory::CRarDirectory()
35 CRarDirectory::~CRarDirectory()
39 bool CRarDirectory::GetDirectory(const CStdString& strPathOrig, CFileItemList& items)
43 /* if this isn't a proper archive path, assume it's the path to a archive file */
44 if( !StringUtils::StartsWithNoCase(strPathOrig, "rar://") )
45 URIUtils::CreateArchivePath(strPath, "rar", strPathOrig, "");
47 strPath = strPathOrig;
50 CStdString strArchive = url.GetHostName();
51 CStdString strOptions = url.GetOptions();
52 CStdString strPathInArchive = url.GetFileName();
55 CStdString strSlashPath = url.Get();
57 // the RAR code depends on things having a "\" at the end of the path
58 URIUtils::AddSlashAtEnd(strSlashPath);
60 if (g_RarManager.GetFilesInRar(items,strArchive,true,strPathInArchive))
63 for( int iEntry=0;iEntry<items.Size();++iEntry)
65 if (items[iEntry]->IsParentFolder())
67 items[iEntry]->SetPath(URIUtils::AddFileToFolder(strSlashPath,items[iEntry]->GetPath()+strOptions));
68 items[iEntry]->m_iDriveType = 0;
69 //CLog::Log(LOGDEBUG, "RarXFILE::GetDirectory() retrieved file: %s", items[iEntry]->m_strPath.c_str());
75 CLog::Log(LOGWARNING,"%s: rar lib returned no files in archive %s, likely corrupt",__FUNCTION__,strArchive.c_str());
80 bool CRarDirectory::Exists(const char* strPath)
83 if (GetDirectory(strPath,items))
89 bool CRarDirectory::ContainsFiles(const CStdString& strPath)
92 if (g_RarManager.GetFilesInRar(items,strPath))