1 | /*
|
---|
2 | * (C) Chris Wohlgemuth 2002-2003
|
---|
3 | *
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2, or (at your option)
|
---|
9 | * any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; see the file COPYING. If not, write to
|
---|
18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | */
|
---|
20 | /*
|
---|
21 | * If you need another license for your project/product contact me at
|
---|
22 | *
|
---|
23 | * http://www.os2world.com/cdwriting
|
---|
24 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
---|
25 | */
|
---|
26 |
|
---|
27 | #define INCL_DOSDEVIOCTL
|
---|
28 | #define INCL_DOS
|
---|
29 | #include <os2.h>
|
---|
30 |
|
---|
31 | /**************************************************************/
|
---|
32 | /* */
|
---|
33 | /* This funktion returns the CD-Drives in the system */
|
---|
34 | /* */
|
---|
35 | /* iNumCD (output): # of CD-Drives */
|
---|
36 | /* iFirstDrive (output): first cd-Drive */
|
---|
37 | /* returns TRUE: We have cd-drives */
|
---|
38 | /* */
|
---|
39 | /**************************************************************/
|
---|
40 | BOOL cwQueryCDDrives(int *iNumCD, int * iFirstDrive)
|
---|
41 | {
|
---|
42 | HFILE hfDevice;
|
---|
43 | ULONG ulAction;
|
---|
44 | ULONG ulLen;
|
---|
45 | static int iFirst=0;
|
---|
46 | static int iNumCDLocal=0;
|
---|
47 | static BOOL haveCD=FALSE;
|
---|
48 | static BOOL done=FALSE;
|
---|
49 | struct
|
---|
50 | {
|
---|
51 | USHORT usCountCD;
|
---|
52 | USHORT usFirstCD;
|
---|
53 | } CDInfo;
|
---|
54 |
|
---|
55 | if(!done){
|
---|
56 | ulLen = sizeof(CDInfo);
|
---|
57 | if(!DosOpen("\\DEV\\CD-ROM2$", &hfDevice, &ulAction, 0,
|
---|
58 | FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
59 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL))
|
---|
60 | {
|
---|
61 | if(!DosDevIOCtl(hfDevice, 0x82, 0x60, NULL, 0, NULL, &CDInfo, ulLen, &ulLen))
|
---|
62 | {
|
---|
63 | if(CDInfo.usCountCD) {
|
---|
64 | haveCD=TRUE;
|
---|
65 | iNumCDLocal=CDInfo.usCountCD;
|
---|
66 | iFirst=1+CDInfo.usFirstCD;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | DosClose(hfDevice);
|
---|
70 | }
|
---|
71 | done=TRUE;
|
---|
72 | }
|
---|
73 | *iNumCD=iNumCDLocal;
|
---|
74 | *iFirstDrive=iFirst;
|
---|
75 | return haveCD;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /****************************************/
|
---|
79 | /* Input: drive (e.g. o:) */
|
---|
80 | /****************************************/
|
---|
81 | HFILE openDrive(char* drive)
|
---|
82 | {
|
---|
83 | HFILE hfDrive = 0;
|
---|
84 | ULONG ulAction;
|
---|
85 | ULONG rc;
|
---|
86 |
|
---|
87 | rc = DosOpen(drive, &hfDrive, &ulAction, 0,
|
---|
88 | FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
89 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY |
|
---|
90 | OPEN_FLAGS_DASD|OPEN_FLAGS_FAIL_ON_ERROR, NULL);
|
---|
91 |
|
---|
92 | if(rc)
|
---|
93 | return NULLHANDLE;//Error
|
---|
94 |
|
---|
95 | return hfDrive;
|
---|
96 | }
|
---|
97 |
|
---|
98 | void closeDrive(HFILE hfDrive)
|
---|
99 | {
|
---|
100 | DosClose(hfDrive);
|
---|
101 | }
|
---|
102 |
|
---|
103 | #pragma pack(1)
|
---|
104 |
|
---|
105 | typedef struct{
|
---|
106 | UCHAR ucFirstTrack;
|
---|
107 | UCHAR ucLastTrack;
|
---|
108 | ULONG ulLeadOut;
|
---|
109 | }CDINFO;
|
---|
110 |
|
---|
111 | typedef struct
|
---|
112 | {
|
---|
113 | UCHAR signature[4];
|
---|
114 | UCHAR ucTrackNum;
|
---|
115 | }TINFOPARAM;
|
---|
116 |
|
---|
117 | typedef struct
|
---|
118 | {
|
---|
119 | ULONG ulTrackAddress;
|
---|
120 | UCHAR ucTCInfo;
|
---|
121 | }CDTRACKINFO;
|
---|
122 |
|
---|
123 | #pragma pack()
|
---|
124 |
|
---|
125 | /******************************************/
|
---|
126 | /* Result:
|
---|
127 | 0: Error
|
---|
128 | -1: CD is Data Disk
|
---|
129 | other: # Audio tracks */
|
---|
130 | /******************************************/
|
---|
131 | int CDQueryAudioCDTracks(HFILE hfDrive)
|
---|
132 | {
|
---|
133 | ULONG ulParamLen;
|
---|
134 | ULONG ulDataLen;
|
---|
135 | ULONG rc;
|
---|
136 | CDINFO cdInfo;
|
---|
137 | TINFOPARAM tip;
|
---|
138 | CDTRACKINFO trackInfo;
|
---|
139 | //char text[100];
|
---|
140 |
|
---|
141 | ulDataLen=sizeof(cdInfo);
|
---|
142 | ulParamLen=4;
|
---|
143 |
|
---|
144 | if(!hfDrive)
|
---|
145 | return 0;
|
---|
146 |
|
---|
147 | rc = DosDevIOCtl(hfDrive, IOCTL_CDROMAUDIO, CDROMAUDIO_GETAUDIODISK,
|
---|
148 | "CD01", 4, &ulParamLen, &cdInfo,
|
---|
149 | sizeof(cdInfo), &ulDataLen);
|
---|
150 |
|
---|
151 | if(rc) {
|
---|
152 | return 0;//Error
|
---|
153 | }
|
---|
154 |
|
---|
155 | ulDataLen=sizeof(trackInfo);
|
---|
156 | ulParamLen=sizeof(TINFOPARAM);
|
---|
157 | tip.signature[0]='C';
|
---|
158 | tip.signature[1]='D';
|
---|
159 | tip.signature[2]='0';
|
---|
160 | tip.signature[3]='1';
|
---|
161 | tip.ucTrackNum=1;
|
---|
162 |
|
---|
163 | /* We have a disc. Check if it's audio */
|
---|
164 | rc = DosDevIOCtl(hfDrive, IOCTL_CDROMAUDIO, CDROMAUDIO_GETAUDIOTRACK,
|
---|
165 | &tip, sizeof(tip), &ulParamLen, &trackInfo,
|
---|
166 | sizeof(trackInfo), &ulDataLen);
|
---|
167 |
|
---|
168 | if(rc) {
|
---|
169 | return 0;//Error
|
---|
170 | }
|
---|
171 |
|
---|
172 | if(trackInfo.ucTCInfo & 0x40) {
|
---|
173 | return -1;//It's a data track
|
---|
174 | }
|
---|
175 | return cdInfo.ucLastTrack-cdInfo.ucFirstTrack+1;
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|