summaryrefslogtreecommitdiff
path: root/lib/cdreader.cpp
diff options
context:
space:
mode:
authorpixel <pixel>2003-12-11 16:53:42 +0000
committerpixel <pixel>2003-12-11 16:53:42 +0000
commitbacf50104daa09cd90f8dc36c06a6982d91000af (patch)
tree863ace96383ca62afc109bfca550dc64e59ce99d /lib/cdreader.cpp
parent5695a4b1e91154f8b9bae6d62eb9313b973fc6bd (diff)
Linux ports
Diffstat (limited to 'lib/cdreader.cpp')
-rw-r--r--lib/cdreader.cpp107
1 files changed, 55 insertions, 52 deletions
diff --git a/lib/cdreader.cpp b/lib/cdreader.cpp
index cfe91b3..058dddc 100644
--- a/lib/cdreader.cpp
+++ b/lib/cdreader.cpp
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: cdreader.cpp,v 1.16 2003-12-04 01:47:37 pixel Exp $ */
+/* $Id: cdreader.cpp,v 1.17 2003-12-11 16:53:43 pixel Exp $ */
#include <stdio.h>
#include <string.h>
@@ -191,6 +191,7 @@ void cdreader::introduce(Byte * datas, int n) {
cdreader::cdreader(const String & no) throw (GeneralException) :
Handle(open(no.to_charp(), O_RDONLY)), n(no), sector(0) {
+ int i;
#ifdef DEBUG
printm(M_ERROR, "Opening cdrom device " + no + "\n");
@@ -214,7 +215,9 @@ cdreader::cdreader(const String & no) throw (GeneralException) :
nsectors = 0;
}
-cdreader::cdreader(const cdreader & i) : Handle(i), n(i.n) {
+cdreader::cdreader(const cdreader & inp) : Handle(inp), n(inp.n) {
+ int i;
+
for (i = 0; i < 400000; i++) {
sectors[i] = 0;
}
@@ -271,62 +274,62 @@ void cdreader::close() throw (GeneralException) {
CloseHandle(hFile);
}
-typedef enum _TRACK_MODE_TYPE {
- YellowMode2,
- XAForm2,
- CDDA
-} TRACK_MODE_TYPE, *PTRACK_MODE_TYPE;
+typedef enum _TRACK_MODE_TYPE {
+ YellowMode2,
+ XAForm2,
+ CDDA
+} TRACK_MODE_TYPE, *PTRACK_MODE_TYPE;
-typedef struct _RAW_READ_INFO {
- LARGE_INTEGER DiskOffset;
- ULONG SectorCount;
- TRACK_MODE_TYPE TrackMode;
+typedef struct _RAW_READ_INFO {
+ LARGE_INTEGER DiskOffset;
+ ULONG SectorCount;
+ TRACK_MODE_TYPE TrackMode;
} RAW_READ_INFO, *PRAW_READ_INFO;
void cdreader::getsector(void *buf, int sec, int nb) throw (GeneralException) {
- RAW_READ_INFO rawIOCTL;
- DWORD dwRet;
- BOOL bStat;
- bool done = false;
+ RAW_READ_INFO rawIOCTL;
+ DWORD dwRet;
+ BOOL bStat;
+ bool done = false;
if (sec >= 0)
sector = sec;
-
- rawIOCTL.DiskOffset.QuadPart = sector * 2048;
- rawIOCTL.SectorCount = nb;
- rawIOCTL.TrackMode = YellowMode2;
-
- while (!done) {
- SetLastError(0);
- bStat = DeviceIoControl(hFile, IOCTL_CDROM_RAW_READ,
- &rawIOCTL, sizeof(RAW_READ_INFO),
- buf, 2352 * nb, &dwRet, NULL);
- if (!bStat) {
- DWORD dwErrCode = GetLastError();
- if (dwErrCode == ERROR_INVALID_FUNCTION) {
- if (rawIOCTL.TrackMode == YellowMode2) {
- rawIOCTL.TrackMode = XAForm2;
- continue;
- }
- }
- if (dwErrCode != ERROR_IO_PENDING) {
- LPVOID lpMsgBuf;
- if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf, 0, NULL ))
- throw GeneralException("Gave up on reading CD: unknown error");
- String errmsg = (LPCTSTR) lpMsgBuf;
- LocalFree(lpMsgBuf);
- throw GeneralException("Gave up on reading CD: " + errmsg);
- }
- } else {
- done = true;
- }
- }
-
- sector += nb;
+
+ rawIOCTL.DiskOffset.QuadPart = sector * 2048;
+ rawIOCTL.SectorCount = nb;
+ rawIOCTL.TrackMode = YellowMode2;
+
+ while (!done) {
+ SetLastError(0);
+ bStat = DeviceIoControl(hFile, IOCTL_CDROM_RAW_READ,
+ &rawIOCTL, sizeof(RAW_READ_INFO),
+ buf, 2352 * nb, &dwRet, NULL);
+ if (!bStat) {
+ DWORD dwErrCode = GetLastError();
+ if (dwErrCode == ERROR_INVALID_FUNCTION) {
+ if (rawIOCTL.TrackMode == YellowMode2) {
+ rawIOCTL.TrackMode = XAForm2;
+ continue;
+ }
+ }
+ if (dwErrCode != ERROR_IO_PENDING) {
+ LPVOID lpMsgBuf;
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR) &lpMsgBuf, 0, NULL ))
+ throw GeneralException("Gave up on reading CD: unknown error");
+ String errmsg = (LPCTSTR) lpMsgBuf;
+ LocalFree(lpMsgBuf);
+ throw GeneralException("Gave up on reading CD: " + errmsg);
+ }
+ } else {
+ done = true;
+ }
+ }
+
+ sector += nb;
}
#endif