changed: Add logic to properly handle subtitles for stacked files
[vuplus_xbmc] / xbmc / filesystem / UDFFile.cpp
1 /*
2  *      Copyright (C) 2010 Team Boxee
3  *      http://www.boxee.tv
4  *
5  *      Copyright (C) 2010-2013 Team XBMC
6  *      http://xbmc.org
7  *
8  *  This Program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  This Program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with XBMC; see the file COPYING.  If not, see
20  *  <http://www.gnu.org/licenses/>.
21  *
22  */
23 #include "UDFFile.h"
24 #include "URL.h"
25 #include "Util.h"
26
27 #include <sys/stat.h>
28 #include <errno.h>
29
30 using namespace std;
31 using namespace XFILE;
32
33 //////////////////////////////////////////////////////////////////////
34 // Construction/Destruction
35 //////////////////////////////////////////////////////////////////////
36 //*********************************************************************************************
37 CUDFFile::CUDFFile()
38 {
39   m_bOpened = false;
40 }
41
42 //*********************************************************************************************
43 CUDFFile::~CUDFFile()
44 {
45   if (m_bOpened)
46   {
47     Close();
48   }
49 }
50 //*********************************************************************************************
51 bool CUDFFile::Open(const CURL& url)
52 {
53   if(!m_udfIsoReaderLocal.Open(url.GetHostName()))
54      return false;
55
56   m_hFile = m_udfIsoReaderLocal.OpenFile(url.GetFileName());
57   if (m_hFile == INVALID_HANDLE_VALUE)
58   {
59     m_bOpened = false;
60     return false;
61   }
62
63   m_bOpened = true;
64   return true;
65 }
66
67 //*********************************************************************************************
68 unsigned int CUDFFile::Read(void *lpBuf, int64_t uiBufSize)
69 {
70   if (!m_bOpened) return 0;
71   char *pData = (char *)lpBuf;
72
73   int iResult = m_udfIsoReaderLocal.ReadFile( m_hFile, (unsigned char*)pData, (long)uiBufSize);
74   if (iResult == -1)
75     return 0;
76   return iResult;
77 }
78
79 //*********************************************************************************************
80 void CUDFFile::Close()
81 {
82   if (!m_bOpened) return ;
83   m_udfIsoReaderLocal.CloseFile( m_hFile);
84   m_bOpened = false;
85 }
86
87 //*********************************************************************************************
88 int64_t CUDFFile::Seek(int64_t iFilePosition, int iWhence)
89 {
90   if (!m_bOpened) return -1;
91   int64_t lNewPos = m_udfIsoReaderLocal.Seek(m_hFile, iFilePosition, iWhence);
92   return lNewPos;
93 }
94
95 //*********************************************************************************************
96 int64_t CUDFFile::GetLength()
97 {
98   if (!m_bOpened) return -1;
99   return m_udfIsoReaderLocal.GetFileSize(m_hFile);
100 }
101
102 //*********************************************************************************************
103 int64_t CUDFFile::GetPosition()
104 {
105   if (!m_bOpened) return -1;
106   return m_udfIsoReaderLocal.GetFilePosition(m_hFile);
107 }
108
109 bool CUDFFile::Exists(const CURL& url)
110 {
111   if(!m_udfIsoReaderLocal.Open(url.GetHostName()))
112      return false;
113
114   m_hFile = m_udfIsoReaderLocal.OpenFile(url.GetFileName());
115   if (m_hFile == INVALID_HANDLE_VALUE)
116     return false;
117
118   m_udfIsoReaderLocal.CloseFile(m_hFile);
119   m_hFile = INVALID_HANDLE_VALUE;
120   return true;
121 }
122
123 int CUDFFile::Stat(const CURL& url, struct __stat64* buffer)
124 {
125   if(!m_udfIsoReaderLocal.Open(url.GetHostName()))
126      return -1;
127
128   m_hFile = m_udfIsoReaderLocal.OpenFile(url.GetFileName());
129   if (m_hFile != INVALID_HANDLE_VALUE)
130   {
131     buffer->st_size = m_udfIsoReaderLocal.GetFileSize(m_hFile);
132     buffer->st_mode = _S_IFREG;
133     m_udfIsoReaderLocal.CloseFile(m_hFile);
134     return 0;
135   }
136   errno = ENOENT;
137   return -1;
138 }