36 #define DBG_PROGNAME "INSTCBM.EXE"
43 static BOOL CbmCheckCorrectInstallation(BOOL HaveAdminRights);
57 OutputPathString(IN PCHAR Text, IN PCHAR Path)
62 printf(
"%s%s\n", Text, Path);
79 OutputVersionString(IN PCHAR Text, IN ULONG Version, IN ULONG VersionEx)
88 char patchlevelVersion[] =
"pl0";
92 patchlevelVersion[2] =
97 patchlevelVersion[0] = 0;
100 _snprintf(buffer2,
sizeof(buffer)-1,
109 _snprintf(buffer,
sizeof(buffer)-1,
111 ?
"%s%s (Development)"
118 _snprintf(buffer,
sizeof(buffer)-1,
"COULD NOT DETERMINE VERSION");
120 buffer[
sizeof(buffer)-1] = 0;
122 OutputPathString(Text, buffer);
155 ReadDriverData(
char *DriverPath, ULONG DriverPathLen, DWORD *StartMode, DWORD *LptPort, DWORD *LptLocking, DWORD *CableType)
167 char driverPathFromRegistry[MAX_PATH];
170 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
178 fprintf(stderr,
"Could not open registry key\n");
185 regLength =
sizeof(driverPathFromRegistry);
187 regReturn = RegQueryValueEx(regKey,
"ImagePath", NULL, ®Type,
188 (LPBYTE)driverPathFromRegistry, ®Length);
190 if (regReturn != ERROR_SUCCESS)
203 driverPathFromRegistry[
sizeof(driverPathFromRegistry)-1] = 0;
207 pColon = strchr(driverPathFromRegistry,
':');
213 if (strncmp(driverPathFromRegistry,
"\\??\\",
sizeof(
"\\??\\")-1) == 0)
217 strncpy(DriverPath, &driverPathFromRegistry[
sizeof(
"\\??\\")-1],
222 strncpy(DriverPath, driverPathFromRegistry, DriverPathLen);
232 lengthString = GetWindowsDirectory(DriverPath, DriverPathLen);
234 if ((lengthString != 0) && (lengthString < DriverPathLen))
236 strncat(&DriverPath[lengthString],
"\\", DriverPathLen-lengthString);
239 strncat(&DriverPath[lengthString], driverPathFromRegistry,
240 DriverPathLen-lengthString);
270 if (regKey != NULL) {
300 getVersionInfoOfFile(
char * Filename, ULONG *VersionNumber, ULONG *PatchLevelNumber)
304 DWORD versionInfoSize;
311 *PatchLevelNumber = 0;
313 versionInfoSize = GetFileVersionInfoSize(Filename, &dummyhandle);
315 if (versionInfoSize > 0)
317 void *versionInfo = malloc(versionInfoSize);
319 if (versionInfo && GetFileVersionInfo(Filename, 0, versionInfoSize, versionInfo))
321 VS_FIXEDFILEINFO *fileInfo;
322 DWORD fileInfoSize = 0;
323 TCHAR *versionInfoText = 0;
325 if (VerQueryValue(versionInfo, TEXT(
"\\"), &fileInfo, &fileInfoSize))
327 *VersionNumber = ((fileInfo->dwFileVersionMS & 0x00FF0000) >> 8) | fileInfo->dwFileVersionMS & 0xFF;
328 *VersionNumber <<= 16;
329 *VersionNumber |= ((fileInfo->dwFileVersionLS & 0x00FF0000) >> 8) | fileInfo->dwFileVersionLS & 0xFF;
336 if (VerQueryValue(versionInfo, TEXT(
"\\StringFileInfo\\000004B0\\FileVersion"), &versionInfoText, &fileInfoSize))
338 char *patch_level = strstr(versionInfoText,
"pl");
342 *PatchLevelNumber = atoi(patch_level + 2);
348 if (strcmp(versionInfoText, TEXT(
"0.1.0a")) == 0)
349 *PatchLevelNumber = 1;
386 ReadDllVersion(
char * Filename,
char * Path, ULONG PathLen, ULONG * VersionNumber, ULONG * VersionNumberEx)
397 handleDll = LoadLibrary(Filename);
403 length = GetModuleFileName(handleDll, Path, PathLen);
405 if (length >= PathLen)
410 error = getVersionInfoOfFile(Path, VersionNumber, VersionNumberEx);
412 FreeLibrary(handleDll);
431 CompleteDriverInstallation(HMODULE HandleDll)
437 cbm_install_complete_t * p_cbm_install_complete;
442 memset(&dllInstallOutBuffer, 0,
sizeof(dllInstallOutBuffer));
444 p_cbm_install_complete =
445 (cbm_install_complete_t *) GetProcAddress(HandleDll,
"cbm_install_complete");
447 if (p_cbm_install_complete) {
448 error = p_cbm_install_complete((PULONG) &dllInstallOutBuffer,
sizeof(dllInstallOutBuffer));
472 printf(
"Checking configuration for OpenCBM\n");
474 if (CbmCheckCorrectInstallation(TRUE ))
477 "Please fix them before trying to use the driver!"));
478 fprintf(stderr,
"*** There were errors in the current configuration.\n"
479 "*** Please fix them before trying to use the driver!\n");
486 printf(
"No problems found in current configuration\n\n");
507 checkIfDifferentVersions(Version1, VersionEx1, Version2, VersionEx2)
509 return ((Version1 != Version2) || (VersionEx1 != VersionEx2)) ? TRUE : FALSE;
513 get_plugin_filename(
char *PluginName)
519 filename = malloc(
sizeof(
"opencbm-.dll") + strlen(PluginName));
522 sprintf(filename,
"opencbm-%s.dll", PluginName);
548 ULONG instcbmVersion;
549 ULONG instcbmVersionEx;
554 char dllPath[MAX_PATH] =
"<unknown>";
555 char driverPath[MAX_PATH] =
"<unknown>";
557 BOOL differentVersion = FALSE;
558 char **PluginNames = NULL;
573 error = ReadDllVersion(
"OPENCBM.DLL", dllPath,
sizeof(dllPath),
578 error = ReadDriverData(driverPath,
sizeof(driverPath), &startMode, &lptPort, &lptLocking, &cableType);
582 printf(
"\n\nThe following configuration is used:\n\n");
586 OPENCBM_VERSION_MINOR,
587 OPENCBM_VERSION_SUBMINOR,
588 OPENCBM_VERSION_DEVEL);
593 OutputVersionString(
"INSTCBM version: ", instcbmVersion, instcbmVersionEx);
595 OutputVersionString(
"Driver version: ", InstallOutBuffer->
DriverVersion,
597 OutputPathString (
"Driver path: ", driverPath);
598 differentVersion |= checkIfDifferentVersions(instcbmVersion, instcbmVersionEx,
601 OutputVersionString(
"DLL version: ", InstallOutBuffer->
DllVersion,
603 OutputPathString (
"DLL path: ", dllPath);
604 differentVersion |= checkIfDifferentVersions(instcbmVersion, instcbmVersionEx,
609 ULONG dllVersionVdd = 0;
610 ULONG dllVersionVddEx = 0;
614 ReadDllVersion(
"opencbmvdd.dll", dllPath,
sizeof(dllPath),
615 &dllVersionVdd, &dllVersionVddEx);
617 OutputVersionString(
"VDD version: ", dllVersionVdd, dllVersionVddEx);
618 OutputPathString (
"VDD path: ", dllPath);
619 differentVersion |= checkIfDifferentVersions(instcbmVersion, instcbmVersionEx,
620 dllVersionVdd, dllVersionVddEx);
622 #endif // #ifdef _X86_
628 for (i = 0; PluginNames[i] != NULL; i++)
630 ULONG dllVersionPlugin = 0;
631 ULONG dllVersionPluginEx = 0;
633 char *filename = get_plugin_filename(PluginNames[i]);
643 error = ReadDllVersion(filename, dllPath,
sizeof(dllPath),
644 &dllVersionPlugin, &dllVersionPluginEx);
648 printf(
"\nPlugin '%s':\n", PluginNames[i]);
649 OutputVersionString(
"Plugin version: ", dllVersionPlugin, dllVersionPluginEx);
650 OutputPathString (
"Plugin path: ", dllPath);
661 if (differentVersion)
664 printf(
"There are mixed versions, THIS IS NOT RECOMMENDED!\n\n");
667 printf(
"Driver configuration:\n");
670 printf(
" Default port: ........ LPT%i\n", lptPort ? lptPort : 1);
674 const char *startModeName;
679 startModeName =
"NO ENTRY FOUND!";
682 case SERVICE_BOOT_START:
683 startModeName =
"boot";
686 case SERVICE_SYSTEM_START:
687 startModeName =
"system";
690 case SERVICE_AUTO_START:
691 startModeName =
"auto";
694 case SERVICE_DEMAND_START:
695 startModeName =
"demand";
698 case SERVICE_DISABLED:
699 startModeName =
"disabled";
703 startModeName =
"<UNKNOWN>";
707 printf(
" Driver start mode: ... %s (%i)\n", startModeName, startMode);
712 printf(
" LPT port locking: .... %s\n", lptLocking ?
"yes" :
"no");
716 const char *cableTypeName;
721 cableTypeName =
"auto";
725 cableTypeName =
"xm1541";
729 cableTypeName =
"xa1541";
733 cableTypeName =
"<UNKNOWN>";
737 printf(
" Cable type: .......... %s (%i)\n\n", cableTypeName, cableType);
767 CbmCheckCorrectInstallation(BOOL HaveAdminRights)
771 BOOL driverAlreadyStarted = FALSE;
776 memset(&outBuffer, 0,
sizeof(outBuffer));
778 for (tries = 1; tries >= 0; --tries)
780 if (driverAlreadyStarted) {
788 driverAlreadyStarted = TRUE;
793 printf(
"Driver or DLL not correctly installed.\n");
800 outBuffer.DllVersion = 0;
805 printf(
"Driver problem: Could not check install.\n");
820 driverAlreadyStarted = FALSE;
826 printf(
"Please wait some seconds...\n");
833 printf(
"\n*** Could not get an interrupt. Please try again after a reboot.\n");
860 if (CheckVersions(&outBuffer))
#define CBMT_I_INSTALL_OUT_GET_VERSION_SUBMINOR(_x)
#define FUNC_LEAVE_INT(_xxx)
Define makros for debugging purposes.
int CbmCheckDriver(void)
Check for the correct installation.
#define CBM_REGKEY_SERVICE
LONG RegGetDWORD(IN HKEY RegKey, IN char *SubKey, OUT LPDWORD Value)
Get a DWORD value from the registry.
#define CBM_REGKEY_SERVICE_IECCABLE
Define the IOCTL codes for the opencbm driver.
#define FUNC_LEAVE_ULONG(_xxx)
#define CBM_REGKEY_SERVICE_DEFAULTLPT
#define CBM_REGKEY_SERVICE_PERMLOCK
#define CBMT_I_INSTALL_OUT_GET_VERSION_MAJOR(_x)
BOOL cbm_driver_install(OUT PULONG Buffer, IN ULONG BufferLen)
Complete driver installation, "direct version".
#define CBMT_I_INSTALL_OUT_GET_VERSION_EX_BUGFIX(_x)
#define CBMT_I_INSTALL_OUT_MAKE_VERSION(_x, _y, _z, _w)
#define FUNC_LEAVE_BOOL(_xxx)
#define CBMT_I_INSTALL_OUT_GET_VERSION_MINOR(_x)
#define CBMT_I_INSTALL_OUT_MAKE_VERSION_EX(_w)
Defining OpenCBM version.
#define CBM_I_DRIVER_INSTALL_0M_NO_INTERRUPT
CBMCTRL_I_INSTALL: No interrupt available.
#define FUNC_LEAVE_STRING(_xxx)
VOID CbmParportRestart(VOID)
Restart the parallel port.
BOOL cbm_driver_stop(VOID)
Stop a device driver.
#define CBMT_I_INSTALL_OUT_GET_VERSION_DEVEL(_x)
BOOL cbm_driver_start(VOID)
Start a device driver.
Internal API for opencbm installation.
Some functions for string handling.
BOOL IsDriverStartedAutomatically(VOID)
Is the driver started automatically?