summaryrefslogtreecommitdiffstats
path: root/xbmc/filesystem/UDFDirectory.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/filesystem/UDFDirectory.cpp
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/filesystem/UDFDirectory.cpp')
-rw-r--r--xbmc/filesystem/UDFDirectory.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/xbmc/filesystem/UDFDirectory.cpp b/xbmc/filesystem/UDFDirectory.cpp
new file mode 100644
index 0000000..236b281
--- /dev/null
+++ b/xbmc/filesystem/UDFDirectory.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2010 Team Boxee
+ * http://www.boxee.tv
+ *
+ * Copyright (C) 2010-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 "UDFDirectory.h"
+
+#include "FileItem.h"
+#include "URL.h"
+#include "Util.h"
+#include "filesystem/UDFBlockInput.h"
+#include "utils/URIUtils.h"
+
+#include <udfread/udfread.h>
+
+using namespace XFILE;
+
+bool CUDFDirectory::GetDirectory(const CURL& url, CFileItemList& items)
+{
+ CURL url2(url);
+ if (!url2.IsProtocol("udf"))
+ {
+ url2.Reset();
+ url2.SetProtocol("udf");
+ url2.SetHostName(url.Get());
+ }
+
+ std::string strRoot(url2.Get());
+ std::string strSub(url2.GetFileName());
+
+ URIUtils::AddSlashAtEnd(strRoot);
+ URIUtils::AddSlashAtEnd(strSub);
+
+ auto udf = udfread_init();
+
+ if (!udf)
+ return false;
+
+ CUDFBlockInput udfbi;
+
+ auto bi = udfbi.GetBlockInput(url2.GetHostName());
+
+ if (udfread_open_input(udf, bi) < 0)
+ {
+ udfread_close(udf);
+ return false;
+ }
+
+ auto path = udfread_opendir(udf, strSub.c_str());
+ if (!path)
+ {
+ udfread_close(udf);
+ return false;
+ }
+
+ struct udfread_dirent dirent;
+
+ while (udfread_readdir(path, &dirent))
+ {
+ if (dirent.d_type == UDF_DT_DIR)
+ {
+ std::string filename = dirent.d_name;
+ if (filename != "." && filename != "..")
+ {
+ CFileItemPtr pItem(new CFileItem(filename));
+ std::string strDir(strRoot + filename);
+ URIUtils::AddSlashAtEnd(strDir);
+ pItem->SetPath(strDir);
+ pItem->m_bIsFolder = true;
+
+ items.Add(pItem);
+ }
+ }
+ else
+ {
+ std::string filename = dirent.d_name;
+ std::string filenameWithPath{strSub + filename};
+ auto file = udfread_file_open(udf, filenameWithPath.c_str());
+ if (!file)
+ continue;
+
+ CFileItemPtr pItem(new CFileItem(filename));
+ pItem->SetPath(strRoot + filename);
+ pItem->m_bIsFolder = false;
+ pItem->m_dwSize = udfread_file_size(file);
+ items.Add(pItem);
+
+ udfread_file_close(file);
+ }
+ }
+
+ udfread_closedir(path);
+ udfread_close(udf);
+
+ return true;
+}
+
+bool CUDFDirectory::Exists(const CURL& url)
+{
+ CFileItemList items;
+ return GetDirectory(url, items);
+}