Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / filesystem / UDFDirectory.cpp
blob155da29af42934bcb35b6e7f011418044b7ed5b1
1 /*
2 * Copyright (C) 2010 Team Boxee
3 * http://www.boxee.tv
5 * Copyright (C) 2010-2013 Team XBMC
6 * http://xbmc.org
8 * This Program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
13 * This Program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with XBMC; see the file COPYING. If not, see
20 * <http://www.gnu.org/licenses/>.
23 #include "UDFDirectory.h"
24 #include "udf25.h"
25 #include "Util.h"
26 #include "URL.h"
27 #include "FileItem.h"
28 #include "utils/URIUtils.h"
30 using namespace XFILE;
32 CUDFDirectory::CUDFDirectory(void)
36 CUDFDirectory::~CUDFDirectory(void)
40 bool CUDFDirectory::GetDirectory(const CStdString& strPath,
41 CFileItemList &items)
43 CStdString strRoot, strSub;
44 CURL url;
45 if(StringUtils::StartsWith(strPath, "udf://"))
47 url.Parse(strPath);
48 CURL url(strPath);
50 else
52 url.SetProtocol("udf");
53 url.SetHostName(strPath);
55 strRoot = url.Get();
56 strSub = url.GetFileName();
58 URIUtils::AddSlashAtEnd(strRoot);
59 URIUtils::AddSlashAtEnd(strSub);
61 udf25 udfIsoReader;
62 if(!udfIsoReader.Open(url.GetHostName()))
63 return false;
65 udf_dir_t *dirp = udfIsoReader.OpenDir(strSub);
67 if (dirp == NULL)
68 return false;
70 udf_dirent_t *dp = NULL;
71 while ((dp = udfIsoReader.ReadDir(dirp)) != NULL)
73 if (dp->d_type == DVD_DT_DIR)
75 CStdString strDir = (char*)dp->d_name;
76 if (strDir != "." && strDir != "..")
78 CFileItemPtr pItem(new CFileItem((char*)dp->d_name));
79 strDir = strRoot + (char*)dp->d_name;
80 URIUtils::AddSlashAtEnd(strDir);
81 pItem->SetPath(strDir);
82 pItem->m_bIsFolder = true;
84 items.Add(pItem);
87 else
89 CFileItemPtr pItem(new CFileItem((char*)dp->d_name));
90 pItem->SetPath(strRoot + (char*)dp->d_name);
91 pItem->m_bIsFolder = false;
92 pItem->m_dwSize = dp->d_filesize;
94 items.Add(pItem);
98 udfIsoReader.CloseDir(dirp);
100 return true;
103 bool CUDFDirectory::Exists(const char* strPath)
105 CFileItemList items;
106 if (GetDirectory(strPath,items))
107 return true;
109 return false;