514b385fab836c1a365d64e545f0020bb64e00d6
[vuplus_xbmc] / xbmc / filesystem / ISO9660Directory.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "ISO9660Directory.h"
22 #include "iso9660.h"
23 #include "Util.h"
24 #include "utils/URIUtils.h"
25 #include "URL.h"
26 #include "FileItem.h"
27
28 using namespace XFILE;
29
30 CISO9660Directory::CISO9660Directory(void)
31 {}
32
33 CISO9660Directory::~CISO9660Directory(void)
34 {}
35
36 bool CISO9660Directory::GetDirectory(const CStdString& strPath, CFileItemList &items)
37 {
38   CStdString strRoot = strPath;
39   URIUtils::AddSlashAtEnd(strRoot);
40
41   // Scan active disc if not done before
42   if (!m_isoReader.IsScanned())
43     m_isoReader.Scan();
44
45   CURL url(strPath);
46
47   WIN32_FIND_DATA wfd;
48   HANDLE hFind;
49
50   memset(&wfd, 0, sizeof(wfd));
51
52   CStdString strSearchMask;
53   CStdString strDirectory = url.GetFileName();
54   if (strDirectory != "")
55   {
56     strSearchMask.Format("\\%s", strDirectory.c_str());
57   }
58   else
59   {
60     strSearchMask = "\\";
61   }
62   for (int i = 0; i < (int)strSearchMask.size(); ++i )
63   {
64     if (strSearchMask[i] == '/') strSearchMask[i] = '\\';
65   }
66
67   hFind = m_isoReader.FindFirstFile((char*)strSearchMask.c_str(), &wfd);
68   if (hFind == NULL)
69     return false;
70
71   do
72   {
73     if (wfd.cFileName[0] != 0)
74     {
75       if ( (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
76       {
77         CStdString strDir = wfd.cFileName;
78         if (strDir != "." && strDir != "..")
79         {
80           CFileItemPtr pItem(new CFileItem(wfd.cFileName));
81           CStdString path = strRoot + wfd.cFileName;
82           URIUtils::AddSlashAtEnd(path);
83           pItem->SetPath(path);
84           pItem->m_bIsFolder = true;
85           FILETIME localTime;
86           FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
87           pItem->m_dateTime=localTime;
88           items.Add(pItem);
89         }
90       }
91       else
92       {
93         CFileItemPtr pItem(new CFileItem(wfd.cFileName));
94         pItem->SetPath(strRoot + wfd.cFileName);
95         pItem->m_bIsFolder = false;
96         pItem->m_dwSize = CUtil::ToInt64(wfd.nFileSizeHigh, wfd.nFileSizeLow);
97         FILETIME localTime;
98         FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localTime);
99         pItem->m_dateTime=localTime;
100         items.Add(pItem);
101       }
102     }
103   }
104   while (m_isoReader.FindNextFile(hFind, &wfd));
105   m_isoReader.FindClose(hFind);
106
107   return true;
108 }
109
110 bool CISO9660Directory::Exists(const char* strPath)
111 {
112   CFileItemList items;
113   if (GetDirectory(strPath,items))
114     return true;
115
116   return false;
117 }