-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
/
ISO9660Directory.cpp
109 lines (93 loc) · 2.62 KB
/
ISO9660Directory.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
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "ISO9660Directory.h"
#include "FileItem.h"
#include "URL.h"
#include "Util.h"
#include "iso9660.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "utils/XTimeUtils.h"
#ifdef TARGET_WINDOWS
#include "platform/win32/CharsetConverter.h"
#endif
using namespace XFILE;
CISO9660Directory::CISO9660Directory(void) = default;
CISO9660Directory::~CISO9660Directory(void) = default;
bool CISO9660Directory::GetDirectory(const CURL& url, CFileItemList &items)
{
std::string strRoot = url.Get();
URIUtils::AddSlashAtEnd(strRoot);
// Scan active disc if not done before
if (!m_isoReader.IsScanned())
m_isoReader.Scan();
Win32FindData wfd;
HANDLE hFind;
memset(&wfd, 0, sizeof(wfd));
std::string strSearchMask;
std::string strDirectory = url.GetFileName();
if (strDirectory != "")
{
strSearchMask = StringUtils::Format("\\%s", strDirectory.c_str());
}
else
{
strSearchMask = "\\";
}
for (int i = 0; i < (int)strSearchMask.size(); ++i )
{
if (strSearchMask[i] == '/') strSearchMask[i] = '\\';
}
hFind = m_isoReader.FindFirstFile9660(strSearchMask.c_str(), &wfd);
if (hFind == NULL)
return false;
do
{
if (wfd.fileName[0] != 0)
{
if ((wfd.fileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
std::string strDir = wfd.fileName;
if (strDir != "." && strDir != "..")
{
CFileItemPtr pItem(new CFileItem(strDir));
std::string path = strRoot + strDir;
URIUtils::AddSlashAtEnd(path);
pItem->SetPath(path);
pItem->m_bIsFolder = true;
FILETIME localTime;
KODI::TIME::FileTimeToLocalFileTime(&wfd.lastWriteTime, &localTime);
pItem->m_dateTime=localTime;
items.Add(pItem);
}
}
else
{
std::string strDir = wfd.fileName;
CFileItemPtr pItem(new CFileItem(strDir));
pItem->SetPath(strRoot + strDir);
pItem->m_bIsFolder = false;
pItem->m_dwSize = CUtil::ToInt64(wfd.fileSizeHigh, wfd.fileSizeLow);
FILETIME localTime;
KODI::TIME::FileTimeToLocalFileTime(&wfd.lastWriteTime, &localTime);
pItem->m_dateTime=localTime;
items.Add(pItem);
}
}
}
while (m_isoReader.FindNextFile(hFind, &wfd));
m_isoReader.FindClose(hFind);
return true;
}
bool CISO9660Directory::Exists(const CURL& url)
{
CFileItemList items;
if (GetDirectory(url,items))
return true;
return false;
}