// // changes some definitions in spinf // #include #include #include "prsinf.h" #include "spinf.h" #include #define CBMAXSECTION 256 #define SZLANGSECTION "OptionsText" // // BUGBUG I don't know what is supposed to happen with this. // #define DWLANGMAX 4 PCHAR rgszLangs[DWLANGMAX] = {"ENG", "GER", "FREN", "SPAN"}; #define ENGLISH 0 #define GERMAN 1 #define FRENCH 2 #define SPANISH 3 PCHAR GetKeyOrValue( HANDLE, PCHAR, ULONG ); // // Device Type to INF filename mapping in the system directory // typedef struct _DeviceTypeToInf { PCHAR szDeviceType; PCHAR szSystemInf; PCHAR szOemInfPrefix; } DEVICETYPETOINF, *pDEVICETYPETOINF; DEVICETYPETOINF DeviceTypeToInfList[] = { { "Computer" , "COMPUTER.INF" , "OEMCPT" }, { "Video" , "VIDEO.INF" , "OEMVIO" }, { "Pointer" , "POINTER.INF" , "OEMPTR" }, { "Keyboard" , "KEYBOARD.INF" , "OEMKBD" }, { "Layout" , "LAYOUT.INF" , "OEMLAY" }, { "Language" , "LANGUAGE.INF" , "OEMLNG" }, { "Printer" , "PRINTER.INF" , "OEMPRN" }, { "Scsi" , "SCSI.INF" , "OEMSCS" }, { "Tape" , "TAPE.INF" , "OEMTAP" }, { "Sound" , "SOUND.INF" , "OEMSND" }, { "Driver" , "DRIVER.INF" , "OEMDRV" }, { NULL , NULL , NULL } }; BOOLEAN GetFullInfName( IN PCHAR szInfName, IN ULONG cb, OUT PCHAR pszFullInfName ) /*++ Routine Description: This routine takes non-qualified inf file name and inserts the directory where inf files are kept in front. Arguments: szInfName - Unqualified inf file name cb - number of bytes in Full Inf name buffer pszFullInfName - Pointer to buffer to hold name Return Value: True of name could fit and there is a location for inf files --*/ { ULONG cbFullName; // // Currently all inf's are stored in system directory // cbFullName = GetSystemDirectory(pszFullInfName, cb); if (cbFullName == 0) { return( FALSE ); } if ((cbFullName + strlen( szInfName) + 0) > cb) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); return( FALSE ); } strcat(pszFullInfName, szInfName); return( TRUE ); } PCHAR GetInfFileList ( ) /*++ Routine Description: Locates all OEM INF files in the system directory. This function fills a string buffer with a double 0 terminated list of filenames. Each filename in the buffer is separated from the next by a single 0 termination char. Each filename is relative to the directory where OEM inf files are stored. Arguments: szInfType - String to match in Identification section. Return Value: A NULL is returned on error or no files found. Use GetLastError to determine exact error. NOTE: The returned buffer is allocated with LocalAlloc. It MUST be freed with LocalFree by the caller. --*/ { PCHAR psz, pszT; ULONG obBuff, cbBuffMax; ULONG cbPath; HANDLE hndFind; CHAR szSearchPath[MAX_PATH]; WIN32_FIND_DATA ffd; // // Fully Qualify the file masm first. // if (!GetFullInfName( "\\*.inf",MAX_PATH, szSearchPath)) { return( NULL ); } hndFind = FindFirstFile(szSearchPath, &ffd); if (hndFind == BADHANDLE) { return( NULL ); } // // Use an initial guess to start out buffer // cbBuffMax = 12 * MAX_PATH; if ((psz = LocalAlloc(LPTR, cbBuffMax)) == NULL) { return( NULL ); } strcpy(psz, ffd.cFileName); obBuff = strlen(psz) + 1; // // Locate all inf files and see if they are of the correct type. // // while ( FindNextFile(hndFind, &ffd) ) { cbPath = strlen( ffd.cFileName ); // // compute spaced needed plus 2 for string and buffer terminatation // if (cbBuffMax <= (cbPath + obBuff + 2)) { cbBuffMax += cbPath + MAX_PATH; pszT = LocalReAlloc(psz, cbBuffMax, LMEM_ZEROINIT | LMEM_MOVEABLE); if (pszT == NULL) { LocalFree( psz ); return( NULL ); } psz = pszT; } strcpy(psz + obBuff, ffd.cFileName); obBuff += cbPath + 1; } // // Terminate buffer // psz[obBuff] = 0; // // realloc down to exact size. plus buffer for terminator // LocalReAlloc(psz, obBuff + 1, LMEM_ZEROINIT); return( psz ); } HANDLE OpenInfFile ( IN PCHAR szFileName, IN PCHAR szInfType ) /*++ Routine Description: Opens an INF file of the specified type and returns an open handle to it. szInfType should match the string in the OptionType value in the Identification section of the INF file. if szFileName is a simple filename with no path information the directory where all OEM files are kept is prepended. If szFileName contains any path information it should contain a full path. Arguments: szFileName - File name to locate. szInfType - String to match in Identification section. Return Value: Returns a Bad handle (-1) if szInfType does not match or the file could not be opened. --*/ { CHAR szPath[MAX_PATH]; PCHAR szTypeCur; ULONG cbPath; HANDLE hndInf; // // Check to see if file name has any path characters. // If not then get the standard location for all OEM // files. If it does then assume a full path name. // szPath[0] = 0; cbPath = 0; if (!strpbrk( szFileName, "\\:") ) { // // This can only fail if buffer too small, but a path cannot // be greater then MAX_PATH. // cbPath = GetSystemDirectory(szPath, MAX_PATH); strcat(szPath, "\\"); } if ((cbPath + strlen(szFileName)) < MAX_PATH - 2) { strcat(szPath, szFileName); } else { SetLastError( ERROR_INVALID_PARAMETER ); return( BADHANDLE ); } // // Open the file, load and parse it // hndInf = SpInitINFBuffer(szPath); if (hndInf == BADHANDLE) { return( BADHANDLE); } // // [Identification] // OptionType =