| 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_DOSERRORS
|
|---|
| 22 | #define INCL_DOSDEVICES
|
|---|
| 23 | #define INCL_DOSDEVIOCTL
|
|---|
| 24 | #define INCL_DOSFILEMGR
|
|---|
| 25 |
|
|---|
| 26 | #include <os2.h>
|
|---|
| 27 | #include <stdlib.h>
|
|---|
| 28 | #include <stdio.h>
|
|---|
| 29 | #include <string.h>
|
|---|
| 30 | #include "mediafolderinc.h"
|
|---|
| 31 |
|
|---|
| 32 | #define LVM_IS_HARDDISK 0
|
|---|
| 33 | #define LVM_IS_PRM 1
|
|---|
| 34 | #define LVM_IS_CDROM 2
|
|---|
| 35 | #define LVM_IS_NETWORK 3
|
|---|
| 36 | #define LVM_IS_UNKNOWN 4
|
|---|
| 37 |
|
|---|
| 38 | /* Typedefs for LVM */
|
|---|
| 39 | typedef unsigned long CARDINAL32;
|
|---|
| 40 | typedef unsigned long DoubleWord; /* ULONG */
|
|---|
| 41 | typedef unsigned char BOOLEAN;
|
|---|
| 42 |
|
|---|
| 43 | #define VOLUME_NAME_SIZE 20
|
|---|
| 44 | #define FILESYSTEM_NAME_SIZE 20
|
|---|
| 45 |
|
|---|
| 46 | #ifdef ADDRESS
|
|---|
| 47 | #undef ADDRESS
|
|---|
| 48 | #endif
|
|---|
| 49 | typedef void* ADDRESS;
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | HMODULE hMod=NULLHANDLE;
|
|---|
| 53 |
|
|---|
| 54 | typedef struct _Volume_Control_Record {
|
|---|
| 55 | DoubleWord Volume_Serial_Number;
|
|---|
| 56 | ADDRESS Volume_Handle;
|
|---|
| 57 | BOOLEAN Compatibility_Volume;
|
|---|
| 58 | BYTE Device_Type;
|
|---|
| 59 | BYTE Reserved[2]; /* Padding */
|
|---|
| 60 | } Volume_Control_Record;
|
|---|
| 61 |
|
|---|
| 62 | typedef struct _Volume_Control_Array {
|
|---|
| 63 | Volume_Control_Record* Volume_Control_Data;
|
|---|
| 64 | CARDINAL32 Count;
|
|---|
| 65 | } Volume_Control_Array;
|
|---|
| 66 |
|
|---|
| 67 | typedef struct _Volume_Information_Record {
|
|---|
| 68 | CARDINAL32 Volume_Size;
|
|---|
| 69 | CARDINAL32 Partition_Count;
|
|---|
| 70 | CARDINAL32 Drive_Letter_Conflict;
|
|---|
| 71 | BOOLEAN Compatibility_Volume;
|
|---|
| 72 | BOOLEAN Bootable;
|
|---|
| 73 | char Drive_Letter_Preference;
|
|---|
| 74 | char Current_Drive_Letter;
|
|---|
| 75 | char Initial_Drive_Letter;
|
|---|
| 76 | BOOLEAN New_Volume;
|
|---|
| 77 | BYTE Status;
|
|---|
| 78 | BYTE Reserved_1; /* PAdding */
|
|---|
| 79 | char Volume_Name[VOLUME_NAME_SIZE];
|
|---|
| 80 | char File_System_Name[FILESYSTEM_NAME_SIZE];
|
|---|
| 81 | } Volume_Information_Record;
|
|---|
| 82 |
|
|---|
| 83 | typedef Volume_Control_Array (_System _PFNVCA) ();
|
|---|
| 84 | typedef _PFNVCA *PFNVCA;
|
|---|
| 85 |
|
|---|
| 86 | typedef Volume_Information_Record (_System _PFNVIR) ();
|
|---|
| 87 | typedef _PFNVIR *PFNVIR;
|
|---|
| 88 |
|
|---|
| 89 | PFN pfnOpen_LVM_Engine=NULLHANDLE;
|
|---|
| 90 | PFN pfnClose_LVM_Engine=NULLHANDLE;
|
|---|
| 91 | PFNVCA pfnvcaGet_Volume_Control_Data=NULLHANDLE;
|
|---|
| 92 | PFNVIR pfnvirGet_Volume_Information=NULLHANDLE;
|
|---|
| 93 |
|
|---|
| 94 | BOOL loadLVMFuncs(void)
|
|---|
| 95 | {
|
|---|
| 96 | char chrErrorObject[CCHMAXPATH]={0};
|
|---|
| 97 | ULONG ulCB;
|
|---|
| 98 |
|
|---|
| 99 | /* Try to load LVM */
|
|---|
| 100 | if(DosLoadModule(chrErrorObject, sizeof(chrErrorObject), "LVM.DLL", &hMod)!=NO_ERROR)
|
|---|
| 101 | return FALSE;
|
|---|
| 102 | // printf("Got LVM.DLL\n");
|
|---|
| 103 |
|
|---|
| 104 | for(;;) {
|
|---|
| 105 | /* Get proc addresses */
|
|---|
| 106 | if(DosQueryProcAddr(hMod, 0, "Open_LVM_Engine", &pfnOpen_LVM_Engine)!=NO_ERROR)
|
|---|
| 107 | break;
|
|---|
| 108 | // printf("Got Open_LVM_Engine: %x\n", pfnOpen_LVM_Engine);
|
|---|
| 109 |
|
|---|
| 110 | if(DosQueryProcAddr(hMod, 0, "Close_LVM_Engine", &pfnClose_LVM_Engine)!=NO_ERROR)
|
|---|
| 111 | break;
|
|---|
| 112 | // printf("Got Close_LVM_Engine\n");
|
|---|
| 113 |
|
|---|
| 114 | if(DosQueryProcAddr(hMod, 0, "Get_Volume_Control_Data", (PFN*)&pfnvcaGet_Volume_Control_Data)!=NO_ERROR)
|
|---|
| 115 | break;
|
|---|
| 116 | // printf("Got Get_Volume_Control_Data: %x\n", pfnvcaGet_Volume_Control_Data);
|
|---|
| 117 |
|
|---|
| 118 | if(DosQueryProcAddr(hMod, 0, "Get_Volume_Information", (PFN*)&pfnvirGet_Volume_Information)!=NO_ERROR)
|
|---|
| 119 | break;
|
|---|
| 120 | // printf("Got Get_Volume_Information: %x\n", pfnvirGet_Volume_Information);
|
|---|
| 121 |
|
|---|
| 122 | return TRUE;
|
|---|
| 123 | }
|
|---|
| 124 | DosFreeModule(hMod);
|
|---|
| 125 | return FALSE;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /**************************************************************/
|
|---|
| 129 | /* */
|
|---|
| 130 | /* This funktion returns the CD-Drives in the system */
|
|---|
| 131 | /* */
|
|---|
| 132 | /* iNumCD (output): # of CD-Drives */
|
|---|
| 133 | /* cFirstDrive (output): first cd-Drive letter */
|
|---|
| 134 | /* returns TRUE: We have cd-drives */
|
|---|
| 135 | /* */
|
|---|
| 136 | /**************************************************************/
|
|---|
| 137 | BOOL CDQueryCDDrives(int *iNumCD, char * cFirstDrive)
|
|---|
| 138 | {
|
|---|
| 139 | HFILE hfDevice;
|
|---|
| 140 | ULONG ulAction;
|
|---|
| 141 | ULONG ulLen;
|
|---|
| 142 | static char cFirst=0;
|
|---|
| 143 | static int iNumCDLocal=0;
|
|---|
| 144 | static BOOL haveCD=FALSE;
|
|---|
| 145 | static BOOL done=FALSE;
|
|---|
| 146 | struct
|
|---|
| 147 | {
|
|---|
| 148 | USHORT usCountCD;
|
|---|
| 149 | USHORT usFirstCD;
|
|---|
| 150 | } CDInfo;
|
|---|
| 151 |
|
|---|
| 152 | if(!done){
|
|---|
| 153 | ulLen = sizeof(CDInfo);
|
|---|
| 154 | if(!DosOpen("\\DEV\\CD-ROM2$", &hfDevice, &ulAction, 0,
|
|---|
| 155 | FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
|
|---|
| 156 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL))
|
|---|
| 157 | {
|
|---|
| 158 | if(!DosDevIOCtl(hfDevice, 0x82, 0x60, NULL, 0, NULL, &CDInfo, ulLen, &ulLen))
|
|---|
| 159 | {
|
|---|
| 160 | if(CDInfo.usCountCD) {
|
|---|
| 161 | haveCD=TRUE;
|
|---|
| 162 | iNumCDLocal=CDInfo.usCountCD;
|
|---|
| 163 | cFirst='A'+ CDInfo.usFirstCD;
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 | DosClose(hfDevice);
|
|---|
| 167 | }
|
|---|
| 168 | done=TRUE;
|
|---|
| 169 | }
|
|---|
| 170 | *iNumCD=iNumCDLocal;
|
|---|
| 171 | *cFirstDrive=cFirst;
|
|---|
| 172 | return haveCD;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | int main(void)
|
|---|
| 176 | {
|
|---|
| 177 | CARDINAL32 error;
|
|---|
| 178 | int iNumCD;
|
|---|
| 179 | char cFirst;
|
|---|
| 180 | char setup[100];
|
|---|
| 181 | char name[100];
|
|---|
| 182 | char id[40];
|
|---|
| 183 | int a;
|
|---|
| 184 |
|
|---|
| 185 | if(!CDQueryCDDrives(&iNumCD, &cFirst))
|
|---|
| 186 | exit(1);
|
|---|
| 187 |
|
|---|
| 188 | if(!loadLVMFuncs()) {
|
|---|
| 189 | for(a=0;a<iNumCD;a++) {
|
|---|
| 190 | int b;
|
|---|
| 191 | /* Build folder name */
|
|---|
| 192 | sprintf(name, "CD-Audio^Drive %c:", cFirst+a);
|
|---|
| 193 | /* Build object ID */
|
|---|
| 194 | sprintf(id, CDFLDR_ID, cFirst+a);
|
|---|
| 195 | /* Build setup string */
|
|---|
| 196 | sprintf(setup, "%s=%c:;OBJECTID=%s;", CDFLDR_DRIVE, cFirst+a, id);
|
|---|
| 197 | // DosSleep(1500);
|
|---|
| 198 | for(b=1;b<=5;b++) {
|
|---|
| 199 | /* Wait to let WPS load the class if not yet done. Then retry */
|
|---|
| 200 | if(WinCreateObject(CDFLDR_CLASSNAME, name, setup,CDFLDR_LOCATION, CO_UPDATEIFEXISTS))
|
|---|
| 201 | /*printf("Can't create %s\n", name);*/
|
|---|
| 202 | break;
|
|---|
| 203 | DosSleep(5000);
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 | else {
|
|---|
| 208 | /* LVM system */
|
|---|
| 209 | printf("This is a LVM system\n");
|
|---|
| 210 |
|
|---|
| 211 | pfnOpen_LVM_Engine(TRUE, &error);
|
|---|
| 212 | if(!error) {
|
|---|
| 213 | Volume_Control_Array vca={0};
|
|---|
| 214 | printf("LVM engine opened\n");
|
|---|
| 215 |
|
|---|
| 216 | vca= pfnvcaGet_Volume_Control_Data(&error);
|
|---|
| 217 | if(!error) {
|
|---|
| 218 | int a;
|
|---|
| 219 |
|
|---|
| 220 | printf("Successfully got volume data\n");
|
|---|
| 221 | for(a=0; a<vca.Count; a++) {
|
|---|
| 222 | /* Now check all device types */
|
|---|
| 223 | if(vca.Volume_Control_Data[a].Device_Type==LVM_IS_CDROM) {
|
|---|
| 224 | Volume_Information_Record vir;
|
|---|
| 225 | int b;
|
|---|
| 226 |
|
|---|
| 227 | vir=pfnvirGet_Volume_Information(vca.Volume_Control_Data[a].Volume_Handle, &error);
|
|---|
| 228 | if(!error) {
|
|---|
| 229 | //printf("Device_type: %d, drive letter: %c:\n",
|
|---|
| 230 | // vca.Volume_Control_Data[a].Device_Type, vir.Current_Drive_Letter);
|
|---|
| 231 |
|
|---|
| 232 | /* Build folder name */
|
|---|
| 233 | sprintf(name, "CD-Audio^Drive %c:", vir.Current_Drive_Letter);
|
|---|
| 234 | /* Build object ID */
|
|---|
| 235 | sprintf(id, CDFLDR_ID, vir.Current_Drive_Letter);
|
|---|
| 236 | /* Build setup string */
|
|---|
| 237 | sprintf(setup, "%s=%c:;OBJECTID=%s;", CDFLDR_DRIVE, vir.Current_Drive_Letter, id);
|
|---|
| 238 |
|
|---|
| 239 | for(b=1;b<=5;b++) {
|
|---|
| 240 | /* Wait to let WPS load the class if not yet done. Then retry */
|
|---|
| 241 |
|
|---|
| 242 | if(WinCreateObject(CDFLDR_CLASSNAME, name, setup, CDFLDR_LOCATION, CO_UPDATEIFEXISTS))
|
|---|
| 243 | break;
|
|---|
| 244 |
|
|---|
| 245 | // printf("Found: %s, %s\n", name, setup);
|
|---|
| 246 | DosSleep(5000);
|
|---|
| 247 | } /* for(b)*/
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 | }/* for(a) */
|
|---|
| 251 | }
|
|---|
| 252 | /* Close engine */
|
|---|
| 253 | pfnClose_LVM_Engine();
|
|---|
| 254 | }
|
|---|
| 255 | DosFreeModule(hMod);
|
|---|
| 256 | } /* else */
|
|---|
| 257 | return (0);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|