source: branches/v2.9/mediafolder/c/createcd/_createcd.c

Last change on this file was 2, checked in by stevenhl, 8 years ago

Import sources from cwmm-full.zip dated 2005-03-21

File size: 3.3 KB
Line 
1/*
2 * This file is (C) Chris Wohlgemuth 1999-2002
3 */
4/*
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#define INCL_DOS
21#define INCL_DOSDEVICES
22#define INCL_DOSDEVIOCTL
23#define INCL_DOSFILEMGR
24
25#include <os2.h>
26#include <stdlib.h>
27#include <stdio.h>
28#include <string.h>
29#include "mediafolderinc.h"
30
31
32
33/**************************************************************/
34/* */
35/* This funktion returns the CD-Drives in the system */
36/* */
37/* iNumCD (output): # of CD-Drives */
38/* cFirstDrive (output): first cd-Drive letter */
39/* returns TRUE: We have cd-drives */
40/* */
41/**************************************************************/
42BOOL CDQueryCDDrives(int *iNumCD, char * cFirstDrive)
43{
44 HFILE hfDevice;
45 ULONG ulAction;
46 ULONG ulLen;
47 static char cFirst=0;
48 static int iNumCDLocal=0;
49 static BOOL haveCD=FALSE;
50 static BOOL done=FALSE;
51 struct
52 {
53 USHORT usCountCD;
54 USHORT usFirstCD;
55 } CDInfo;
56
57 if(!done){
58 ulLen = sizeof(CDInfo);
59 if(!DosOpen("\\DEV\\CD-ROM2$", &hfDevice, &ulAction, 0,
60 FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
61 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL))
62 {
63 if(!DosDevIOCtl(hfDevice, 0x82, 0x60, NULL, 0, NULL, &CDInfo, ulLen, &ulLen))
64 {
65 if(CDInfo.usCountCD) {
66 haveCD=TRUE;
67 iNumCDLocal=CDInfo.usCountCD;
68 cFirst='A'+ CDInfo.usFirstCD;
69 }
70 }
71 DosClose(hfDevice);
72 }
73 done=TRUE;
74 }
75 *iNumCD=iNumCDLocal;
76 *cFirstDrive=cFirst;
77 return haveCD;
78}
79
80int main(void)
81{
82 int iNumCD;
83 char cFirst;
84 char setup[100];
85 char name[100];
86 char id[40];
87 int a;
88
89 if(!CDQueryCDDrives(&iNumCD, &cFirst))
90 exit(1);
91 for(a=0;a<iNumCD;a++) {
92 int b;
93 /* Build folder name */
94 sprintf(name, "CD-Audio^Drive %c:", cFirst+a);
95 /* Build object ID */
96 sprintf(id, CDFLDR_ID, cFirst+a);
97 /* Build setup string */
98 sprintf(setup, "%s=%c:;OBJECTID=%s;", CDFLDR_DRIVE, cFirst+a, id);
99 // DosSleep(1500);
100 for(b=1;b<=5;b++) {
101 /* Wait to let WPS load the class if not yet done. Then retry */
102 if(!WinCreateObject(CDFLDR_CLASSNAME, name, setup,CDFLDR_LOCATION, CO_UPDATEIFEXISTS))
103 printf("Can't create %s\n", name);
104 else
105 break;
106 DosSleep(1000);
107 }
108 }
109 exit(0);
110}
Note: See TracBrowser for help on using the repository browser.