2 * Copyright (c) 2002 Frodo
3 * Portions Copyright (c) by the authors of ffmpeg and xvid
4 * Copyright (C) 2002-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
30 using namespace XFILE
;
32 //////////////////////////////////////////////////////////////////////
33 // Construction/Destruction
34 //////////////////////////////////////////////////////////////////////
35 //*********************************************************************************************
41 //*********************************************************************************************
49 //*********************************************************************************************
50 bool CISOFile::Open(const CURL
& url
)
52 string strFName
= "\\";
53 strFName
+= url
.GetFileName();
54 for (int i
= 0; i
< (int)strFName
.size(); ++i
)
56 if (strFName
[i
] == '/') strFName
[i
] = '\\';
58 m_hFile
= m_isoReader
.OpenFile((char*)strFName
.c_str());
59 if (m_hFile
== INVALID_HANDLE_VALUE
)
69 //*********************************************************************************************
70 unsigned int CISOFile::Read(void *lpBuf
, int64_t uiBufSize
)
72 if (!m_bOpened
) return 0;
73 char *pData
= (char *)lpBuf
;
75 if (m_cache
.getSize() > 0)
77 long lTotalBytesRead
= 0;
80 if (m_cache
.getMaxReadSize() )
82 long lBytes2Read
= m_cache
.getMaxReadSize();
83 if (lBytes2Read
> uiBufSize
) lBytes2Read
= (long)uiBufSize
;
84 m_cache
.ReadData(pData
, lBytes2Read
);
85 uiBufSize
-= lBytes2Read
;
87 lTotalBytesRead
+= lBytes2Read
;
90 if (m_cache
.getMaxWriteSize() > 5000)
93 long lBytesRead
= m_isoReader
.ReadFile( m_hFile
, buffer
, sizeof(buffer
));
95 m_cache
.WriteData((char*)buffer
, lBytesRead
);
100 return lTotalBytesRead
;
102 int iResult
= m_isoReader
.ReadFile( m_hFile
, (uint8_t*)pData
, (long)uiBufSize
);
108 //*********************************************************************************************
109 void CISOFile::Close()
111 if (!m_bOpened
) return ;
112 m_isoReader
.CloseFile( m_hFile
);
115 //*********************************************************************************************
116 int64_t CISOFile::Seek(int64_t iFilePosition
, int iWhence
)
118 if (!m_bOpened
) return -1;
119 int64_t lNewPos
= m_isoReader
.Seek(m_hFile
, iFilePosition
, iWhence
);
125 //*********************************************************************************************
126 int64_t CISOFile::GetLength()
128 if (!m_bOpened
) return -1;
129 return m_isoReader
.GetFileSize(m_hFile
);
132 //*********************************************************************************************
133 int64_t CISOFile::GetPosition()
135 if (!m_bOpened
) return -1;
136 return m_isoReader
.GetFilePosition(m_hFile
);
139 bool CISOFile::Exists(const CURL
& url
)
141 string strFName
= "\\";
142 strFName
+= url
.GetFileName();
143 for (int i
= 0; i
< (int)strFName
.size(); ++i
)
145 if (strFName
[i
] == '/') strFName
[i
] = '\\';
147 m_hFile
= m_isoReader
.OpenFile((char*)strFName
.c_str());
148 if (m_hFile
== INVALID_HANDLE_VALUE
)
151 m_isoReader
.CloseFile(m_hFile
);
155 int CISOFile::Stat(const CURL
& url
, struct __stat64
* buffer
)
157 string strFName
= "\\";
158 strFName
+= url
.GetFileName();
159 for (int i
= 0; i
< (int)strFName
.size(); ++i
)
161 if (strFName
[i
] == '/') strFName
[i
] = '\\';
163 m_hFile
= m_isoReader
.OpenFile((char*)strFName
.c_str());
164 if (m_hFile
!= INVALID_HANDLE_VALUE
)
166 memset(buffer
, 0, sizeof(struct __stat64
));
167 buffer
->st_size
= m_isoReader
.GetFileSize(m_hFile
);
168 buffer
->st_mode
= _S_IFREG
;
169 m_isoReader
.CloseFile(m_hFile
);