aboutsummaryrefslogtreecommitdiff
path: root/xbmc/filesystem/ISO9660Directory.cpp
blob: 542f12c5778ced5a6ea015330a6c4ae9186b2158 (plain)
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
/*
 *  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 "utils/URIUtils.h"

#include <cdio++/iso9660.hpp>

using namespace XFILE;

bool CISO9660Directory::GetDirectory(const CURL& url, CFileItemList& items)
{
  CURL url2(url);
  if (!url2.IsProtocol("iso9660"))
  {
    url2.Reset();
    url2.SetProtocol("iso9660");
    url2.SetHostName(url.Get());
  }

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

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

  std::unique_ptr<ISO9660::IFS> iso(new ISO9660::IFS);

  if (!iso->open(url2.GetHostName().c_str()))
    return false;

  std::vector<ISO9660::Stat*> isoFiles;

  if (iso->readdir(strSub.c_str(), isoFiles))
  {
    for (const auto file : isoFiles)
    {
      std::string filename(file->p_stat->filename);

      if (file->p_stat->type == 2)
      {
        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
      {
        CFileItemPtr pItem(new CFileItem(filename));
        pItem->SetPath(strRoot + filename);
        pItem->m_bIsFolder = false;
        pItem->m_dwSize = file->p_stat->size;
        items.Add(pItem);
      }
    }

    isoFiles.clear();
    return true;
  }

  return false;
}

bool CISO9660Directory::Exists(const CURL& url)
{
  CFileItemList items;
  return GetDirectory(url, items);
}

bool CISO9660Directory::Resolve(CFileItem& item) const
{
  const CURL url{item.GetDynPath()};
  if (url.GetProtocol() != "iso9660" && url.GetFileType() != "iso")
  {
    return false;
  }

  // translate a generic iso9660:// url to the actual disc drive for playback
  if (!url.GetHostName().empty() && url.GetFileName() == "VIDEO_TS/video_ts.ifo")
  {
    item.SetDynPath(url.GetHostName());
  }
  return true;
}