Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. class.c
  5. Abstract:
  6. This file implements the modem co-class
  7. installer for fax.
  8. Environment:
  9. WIN32 User Mode
  10. Author:
  11. Wesley Witt (wesw) 31-Jul-1997
  12. --*/
  13. #include "faxocm.h"
  14. #pragma hdrstop
  15. #if DBG
  16. typedef struct _DIF_DEBUG {
  17. DWORD DifValue;
  18. LPTSTR DifString;
  19. } DIF_DEBUG, *PDIF_DEBUG;
  20. DIF_DEBUG DifDebug[] =
  21. {
  22. { 0, L"" }, // 0x00000000
  23. { DIF_SELECTDEVICE, L"DIF_SELECTDEVICE" }, // 0x00000001
  24. { DIF_INSTALLDEVICE, L"DIF_INSTALLDEVICE" }, // 0x00000002
  25. { DIF_ASSIGNRESOURCES, L"DIF_ASSIGNRESOURCES" }, // 0x00000003
  26. { DIF_PROPERTIES, L"DIF_PROPERTIES" }, // 0x00000004
  27. { DIF_REMOVE, L"DIF_REMOVE" }, // 0x00000005
  28. { DIF_FIRSTTIMESETUP, L"DIF_FIRSTTIMESETUP" }, // 0x00000006
  29. { DIF_FOUNDDEVICE, L"DIF_FOUNDDEVICE" }, // 0x00000007
  30. { DIF_SELECTCLASSDRIVERS, L"DIF_SELECTCLASSDRIVERS" }, // 0x00000008
  31. { DIF_VALIDATECLASSDRIVERS, L"DIF_VALIDATECLASSDRIVERS" }, // 0x00000009
  32. { DIF_INSTALLCLASSDRIVERS, L"DIF_INSTALLCLASSDRIVERS" }, // 0x0000000A
  33. { DIF_CALCDISKSPACE, L"DIF_CALCDISKSPACE" }, // 0x0000000B
  34. { DIF_DESTROYPRIVATEDATA, L"DIF_DESTROYPRIVATEDATA" }, // 0x0000000C
  35. { DIF_VALIDATEDRIVER, L"DIF_VALIDATEDRIVER" }, // 0x0000000D
  36. { DIF_MOVEDEVICE, L"DIF_MOVEDEVICE" }, // 0x0000000E
  37. { DIF_DETECT, L"DIF_DETECT" }, // 0x0000000F
  38. { DIF_INSTALLWIZARD, L"DIF_INSTALLWIZARD" }, // 0x00000010
  39. { DIF_DESTROYWIZARDDATA, L"DIF_DESTROYWIZARDDATA" }, // 0x00000011
  40. { DIF_PROPERTYCHANGE, L"DIF_PROPERTYCHANGE" }, // 0x00000012
  41. { DIF_ENABLECLASS, L"DIF_ENABLECLASS" }, // 0x00000013
  42. { DIF_DETECTVERIFY, L"DIF_DETECTVERIFY" }, // 0x00000014
  43. { DIF_INSTALLDEVICEFILES, L"DIF_INSTALLDEVICEFILES" }, // 0x00000015
  44. { DIF_UNREMOVE, L"DIF_UNREMOVE" }, // 0x00000016
  45. { DIF_SELECTBESTCOMPATDRV, L"DIF_SELECTBESTCOMPATDRV" }, // 0x00000017
  46. { DIF_ALLOW_INSTALL, L"DIF_ALLOW_INSTALL" }, // 0x00000018
  47. { DIF_REGISTERDEVICE, L"DIF_REGISTERDEVICE" }, // 0x00000019
  48. { 0, L"" }, // 0x0000001A
  49. { 0, L"" }, // 0x0000001B
  50. { 0, L"" }, // 0x0000001C
  51. { 0, L"" }, // 0x0000001D
  52. { 0, L"" }, // 0x0000001E
  53. { 0, L"" }, // 0x0000001F
  54. { DIF_INSTALLINTERFACES, L"DIF_INSTALLINTERFACES" }, // 0x00000020
  55. { DIF_DETECTCANCEL, L"DIF_DETECTCANCEL" }, // 0x00000021
  56. { DIF_REGISTER_COINSTALLERS, L"DIF_REGISTER_COINSTALLERS" }, // 0x00000022
  57. { 0, L"" } // 0x00000023
  58. };
  59. #endif
  60. VOID
  61. StartSystray(
  62. VOID
  63. )
  64. {
  65. STARTUPINFO si;
  66. PROCESS_INFORMATION pi;
  67. LPWSTR szSystray = ExpandEnvironmentString( L"%systemroot%\\system32\\systray.exe" );
  68. GetStartupInfo(&si);
  69. if ( CreateProcess(NULL,szSystray,NULL,NULL,FALSE,DETACHED_PROCESS,NULL,NULL,&si,&pi) ) {
  70. CloseHandle( pi.hProcess );
  71. CloseHandle( pi.hThread );
  72. }
  73. MemFree( szSystray );
  74. }
  75. DWORD
  76. CALLBACK
  77. FaxModemCoClassInstaller(
  78. IN DI_FUNCTION InstallFunction,
  79. IN HDEVINFO DeviceInfoSet,
  80. IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
  81. IN OUT PCOINSTALLER_CONTEXT_DATA Context
  82. )
  83. {
  84. __try {
  85. DebugPrint(( L"FaxModemCoClassInstaller: processing %s request", DifDebug[InstallFunction].DifString ));
  86. if (InstallFunction == DIF_FIRSTTIMESETUP) {
  87. NtGuiMode = TRUE;
  88. return Context->InstallResult;
  89. }
  90. if (InstallFunction == DIF_INSTALLDEVICE) {
  91. if (!Context->PostProcessing) {
  92. DebugPrint(( L"FaxModemCoClassInstaller: pre-installation, waiting for post-installation call" ));
  93. return ERROR_DI_POSTPROCESSING_REQUIRED;
  94. }
  95. if (Context->InstallResult != NO_ERROR) {
  96. DebugPrint(( L"FaxModemCoClassInstaller: previous error causing installation failure, 0x%08x", Context->InstallResult ));
  97. return Context->InstallResult;
  98. }
  99. if (!NtGuiMode) {
  100. //
  101. // check if we have a fax printer
  102. //
  103. PPRINTER_INFO_2 pPrinterInfo;
  104. DWORD dwPrinters, i;
  105. //
  106. // note: if this call returns NULL, assume this means that there are zero printers installed,
  107. // not a spooler errror
  108. //
  109. pPrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters(NULL,2,&dwPrinters,PRINTER_ENUM_LOCAL);
  110. if (pPrinterInfo) {
  111. for (i=0;i<dwPrinters;i++) {
  112. if (wcscmp(pPrinterInfo[i].pDriverName,FAX_DRIVER_NAME) == 0) {
  113. DebugPrint(( L"Fax printer %s already installed, exiting co-class installer", pPrinterInfo[i].pPrinterName ));
  114. MemFree( pPrinterInfo );
  115. return NO_ERROR;
  116. }
  117. }
  118. MemFree( pPrinterInfo );
  119. }
  120. //
  121. // create a fax printer
  122. //
  123. WCHAR PrinterName[64];
  124. LoadString( hInstance, IDS_DEFAULT_PRINTER_NAME, PrinterName, sizeof(PrinterName)/sizeof(WCHAR) );
  125. if (!CreateLocalFaxPrinter( PrinterName )) {
  126. DebugPrint(( L"CreateLocalFaxPrinter() failed" ));
  127. }
  128. //
  129. // start the fax service
  130. //
  131. StartFaxService();
  132. //
  133. // put the control panel back in place so the user sees it
  134. //
  135. LPTSTR dstFile = ExpandEnvironmentString( TEXT("%systemroot%\\system32\\fax.cpl") );
  136. LPTSTR srcFile = ExpandEnvironmentString( TEXT("%systemroot%\\system32\\fax.cpk") );
  137. if (!MoveFileEx(srcFile, dstFile, MOVEFILE_REPLACE_EXISTING)) {
  138. MoveFileEx(srcFile, dstFile, MOVEFILE_REPLACE_EXISTING | MOVEFILE_DELAY_UNTIL_REBOOT);
  139. }
  140. //
  141. // create the program groups
  142. //
  143. CreateGroupItems( NULL );
  144. //
  145. // restart systray so that we get the fax icon
  146. //
  147. // StartSystray();
  148. }
  149. return NO_ERROR;
  150. }
  151. } __except (EXCEPTION_EXECUTE_HANDLER) {
  152. DebugPrint(( TEXT("FaxModemCoClassInstaller crashed: 0x%08x"), GetExceptionCode() ));
  153. }
  154. return Context->InstallResult;
  155. }