Skip to content

Commit

Permalink
udf: rework IFile and IFileDirectory implementation
Browse files Browse the repository at this point in the history
This change allows using libcdio's libudf
  • Loading branch information
lrusak committed Mar 5, 2020
1 parent 4181e25 commit 558b54a
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 1,608 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -154,6 +154,7 @@ set(optional_deps Alsa
SmbClient
Sndio
UDEV
Udf
XSLT
${PLATFORM_OPTIONAL_DEPS})

Expand Down
36 changes: 36 additions & 0 deletions cmake/modules/FindUdf.cmake
@@ -0,0 +1,36 @@
#.rst:
# FindUdf
# --------
# Finds the udf library
#
# This will define the following variables::
#
# UDF_FOUND - system has udf
# UDF_INCLUDE_DIRS - the udf include directory
# UDF_LIBRARIES - the udf libraries
# UDF_DEFINITIONS - the udf definitions

if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_UDF libudf>=0.94 QUIET)
endif()

find_path(UDF_INCLUDE_DIR NAMES cdio/udf.h
PATHS ${PC_UDF_INCLUDEDIR})

find_library(UDF_LIBRARY NAMES udf libudf
PATHS ${PC_UDF_LIBDIR})

set(UDF_VERSION ${PC_UDF_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Udf
REQUIRED_VARS UDF_LIBRARY UDF_INCLUDE_DIR
VERSION_VAR UDF_VERSION)

if(UDF_FOUND)
set(UDF_LIBRARIES ${UDF_LIBRARY})
set(UDF_INCLUDE_DIRS ${UDF_INCLUDE_DIR})
set(UDF_DEFINITIONS -DHAS_UDF=1)
endif()

mark_as_advanced(UDF_INCLUDE_DIR UDF_LIBRARY)
13 changes: 7 additions & 6 deletions xbmc/filesystem/CMakeLists.txt
Expand Up @@ -49,9 +49,6 @@ set(SOURCES AddonsDirectory.cpp
SpecialProtocolDirectory.cpp
SpecialProtocolFile.cpp
StackDirectory.cpp
udf25.cpp
UDFDirectory.cpp
UDFFile.cpp
VideoDatabaseDirectory.cpp
VideoDatabaseFile.cpp
VirtualDirectory.cpp
Expand Down Expand Up @@ -116,9 +113,6 @@ set(HEADERS AddonsDirectory.h
SpecialProtocolDirectory.h
SpecialProtocolFile.h
StackDirectory.h
udf25.h
UDFDirectory.h
UDFFile.h
VideoDatabaseDirectory.h
VirtualDirectory.h
XbtDirectory.h
Expand All @@ -136,6 +130,13 @@ if(ISO9660PP_FOUND)
ISO9660File.h)
endif()

if(UDF_FOUND)
list(APPEND SOURCES UDFDirectory.cpp
UDFFile.cpp)
list(APPEND HEADERS UDFDirectory.h
UDFFile.h)
endif()

if(BLURAY_FOUND)
list(APPEND SOURCES BlurayCallback.cpp
BlurayDirectory.cpp
Expand Down
4 changes: 4 additions & 0 deletions xbmc/filesystem/DirectoryFactory.cpp
Expand Up @@ -25,7 +25,9 @@
#include "FTPDirectory.h"
#include "HTTPDirectory.h"
#include "DAVDirectory.h"
#if defined(HAS_UDF)
#include "UDFDirectory.h"
#endif
#include "utils/log.h"
#include "network/WakeOnAccess.h"

Expand Down Expand Up @@ -133,7 +135,9 @@ IDirectory* CDirectoryFactory::Create(const CURL& url)
#if defined(HAS_ISO9660PP)
if (url.IsProtocol("iso9660")) return new CISO9660Directory();
#endif
#if defined(HAS_UDF)
if (url.IsProtocol("udf")) return new CUDFDirectory();
#endif
if (url.IsProtocol("plugin")) return new CPluginDirectory();
#if defined(TARGET_ANDROID)
if (url.IsProtocol("apk")) return new CAPKDirectory();
Expand Down
8 changes: 8 additions & 0 deletions xbmc/filesystem/FileDirectoryFactory.cpp
Expand Up @@ -11,6 +11,9 @@
#if defined(HAS_ISO9660PP)
#include "ISO9660Directory.h"
#endif
#if defined(HAS_UDF)
#include "UDFDirectory.h"
#endif
#include "RSSDirectory.h"
#include "UDFDirectory.h"
#include "utils/URIUtils.h"
Expand Down Expand Up @@ -116,6 +119,7 @@ IFileDirectory* CFileDirectoryFactory::Create(const CURL& url, CFileItem* pItem,
if (pItem->IsRSS())
return new CRSSDirectory();


if (pItem->IsDiscImage())
{
#if defined(HAS_ISO9660PP)
Expand All @@ -126,7 +130,11 @@ IFileDirectory* CFileDirectoryFactory::Create(const CURL& url, CFileItem* pItem,
delete iso;
#endif

#if defined(HAS_UDF)
return new CUDFDirectory();
#endif

return nullptr;
}

#if defined(TARGET_ANDROID)
Expand Down
7 changes: 6 additions & 1 deletion xbmc/filesystem/FileFactory.cpp
Expand Up @@ -56,7 +56,9 @@
#include "PluginFile.h"
#include "SpecialProtocolFile.h"
#include "MultiPathFile.h"
#if defined(HAS_UDF)
#include "UDFFile.h"
#endif
#include "ImageFile.h"
#include "ResourceFile.h"
#include "URL.h"
Expand Down Expand Up @@ -134,7 +136,10 @@ IFile* CFileFactory::CreateLoader(const CURL& url)
else if (url.IsProtocol("iso9660"))
return new CISO9660File();
#endif
else if(url.IsProtocol("udf")) return new CUDFFile();
#if defined(HAS_UDF)
else if(url.IsProtocol("udf"))
return new CUDFFile();
#endif
#if defined(TARGET_ANDROID)
else if (url.IsProtocol("androidapp")) return new CFileAndroidApp();
#endif
Expand Down
73 changes: 42 additions & 31 deletions xbmc/filesystem/UDFDirectory.cpp
Expand Up @@ -8,56 +8,68 @@
* 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 "udf25.h"
#include "utils/URIUtils.h"

using namespace XFILE;

CUDFDirectory::CUDFDirectory(void) = default;
#include <cdio/udf.h>

CUDFDirectory::~CUDFDirectory(void) = default;
using namespace XFILE;

bool CUDFDirectory::GetDirectory(const CURL& url,
CFileItemList &items)
bool CUDFDirectory::GetDirectory(const CURL& url, CFileItemList& items)
{
std::string strRoot, strSub;
CURL url2(url);
if (!url2.IsProtocol("udf"))
{ // path to an image
{
url2.Reset();
url2.SetProtocol("udf");
url2.SetHostName(url.Get());
}
strRoot = url2.Get();
strSub = url2.GetFileName();

std::string strRoot(url2.Get());
std::string strSub(url2.GetFileName());

URIUtils::AddSlashAtEnd(strRoot);
URIUtils::AddSlashAtEnd(strSub);

udf25 udfIsoReader;
if(!udfIsoReader.Open(url2.GetHostName().c_str()))
return false;
udf_t* udf = udf_open(url2.GetHostName().c_str());

if (!udf)
return false;

udf_dir_t *dirp = udfIsoReader.OpenDir(strSub.c_str());
udf_dirent_t* root = udf_get_root(udf, true, 0);

if (dirp == NULL)
if (!root)
{
udf_close(udf);
return false;
}

udf_dirent_t* path = udf_fopen(root, strSub.c_str());

if (!path)
{
udf_dirent_free(root);
udf_close(udf);
return false;
}

udf_dirent_t *dp = NULL;
while ((dp = udfIsoReader.ReadDir(dirp)) != NULL)
while (udf_readdir(path))
{
if (dp->d_type == DVD_DT_DIR)
if (path->b_parent)
continue;

if (udf_is_dir(path))
{
std::string strDir = (char*)dp->d_name;
if (strDir != "." && strDir != "..")
std::string filename = udf_get_filename(path);
if (filename != "." && filename != "..")
{
CFileItemPtr pItem(new CFileItem((char*)dp->d_name));
strDir = strRoot + (char*)dp->d_name;
CFileItemPtr pItem(new CFileItem(filename));
std::string strDir(strRoot + filename);
URIUtils::AddSlashAtEnd(strDir);
pItem->SetPath(strDir);
pItem->m_bIsFolder = true;
Expand All @@ -67,25 +79,24 @@ bool CUDFDirectory::GetDirectory(const CURL& url,
}
else
{
CFileItemPtr pItem(new CFileItem((char*)dp->d_name));
pItem->SetPath(strRoot + (char*)dp->d_name);
std::string filename = udf_get_filename(path);
CFileItemPtr pItem(new CFileItem(filename));
pItem->SetPath(strRoot + filename);
pItem->m_bIsFolder = false;
pItem->m_dwSize = dp->d_filesize;
pItem->m_dwSize = udf_get_file_length(path);

items.Add(pItem);
}
}

udfIsoReader.CloseDir(dirp);
udf_dirent_free(root);
udf_close(udf);

return true;
}

bool CUDFDirectory::Exists(const CURL& url)
{
CFileItemList items;
if (GetDirectory(url, items))
return true;

return false;
return GetDirectory(url, items);
}
10 changes: 5 additions & 5 deletions xbmc/filesystem/UDFDirectory.h
Expand Up @@ -15,13 +15,13 @@

namespace XFILE
{
class CUDFDirectory :
public IFileDirectory

class CUDFDirectory : public IFileDirectory
{
public:
CUDFDirectory(void);
~CUDFDirectory(void) override;
bool GetDirectory(const CURL& url, CFileItemList &items) override;
CUDFDirectory() = default;
~CUDFDirectory() = default;
bool GetDirectory(const CURL& url, CFileItemList& items) override;
bool Exists(const CURL& url) override;
bool ContainsFiles(const CURL& url) override { return true; }
};
Expand Down

0 comments on commit 558b54a

Please sign in to comment.