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.

182 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. inf.c
  5. Abstract:
  6. This module contains function for processing the INF Processing sections of WINBOM.INI
  7. Author:
  8. Stephen Lodwick (stelo) 8/01/2000
  9. Revision History:
  10. --*/
  11. #include "factoryp.h"
  12. #include <setupapi.h>
  13. #include <tchar.h>
  14. //
  15. // Internal Defined Value(s):
  16. //
  17. #define INF_SEC_UPDATESYSTEM _T("UpdateSystem")
  18. //
  19. // Internally defined functions
  20. //
  21. BOOL ProcessInfSection( LPTSTR, LPTSTR );
  22. UINT CALLBACK InfQueueCallback ( PVOID, UINT, UINT, UINT );
  23. /*++
  24. ===============================================================================
  25. Routine Description:
  26. BOOL ProcessInfSection
  27. Given a filename and a section this function will process/install all entries
  28. in an inf section
  29. Arguments:
  30. lpFilename - The name of the inf file to process
  31. lpInfSection - The name of the inf section to process
  32. Return Value:
  33. Boolean on whether or not it was able to process the file
  34. ===============================================================================
  35. --*/
  36. BOOL ProcessInfSection( LPTSTR lpFilename, LPTSTR lpInfSection )
  37. {
  38. HINF hInf = NULL;
  39. PVOID pvContext = NULL;
  40. HSPFILEQ hfq = NULL;
  41. BOOL bReturn = FALSE;
  42. FacLogFileStr(3, _T("ProcessInfSection('%s', '%s')"), lpFilename, lpInfSection);
  43. if ((hInf = SetupOpenInfFile(lpFilename, NULL, INF_STYLE_OLDNT | INF_STYLE_WIN4, NULL)) != INVALID_HANDLE_VALUE)
  44. {
  45. FacLogFileStr(3, _T("ProcessInfSection: Opened '%s'"), lpFilename);
  46. // We must have a valid context and file queue for all operations
  47. //
  48. // ISSUE-2002/02/25-acosma,robertko - The hfq file queue is not needed here. It does not get passed to
  49. // SetupInstallFromInfSection() so there is no way for any files to be in this queue.
  50. // Committing this probably does nothing. SetupInstallFromInfSection does an internal commit of a queue
  51. // that it creates.
  52. //
  53. if ( (NULL != (pvContext = SetupInitDefaultQueueCallback(NULL)) ) &&
  54. (INVALID_HANDLE_VALUE != (hfq = SetupOpenFileQueue()) )
  55. )
  56. {
  57. // Attempt to install the inf section.
  58. //
  59. if ( SetupInstallFromInfSection(NULL, hInf, lpInfSection, SPINST_ALL , NULL, NULL, SP_COPY_NEWER, SetupDefaultQueueCallback, pvContext, NULL, NULL) )
  60. {
  61. // Installation succeeded
  62. //
  63. FacLogFileStr(3, _T("ProcessInfSection: SetupInstallFromInfSection Success"));
  64. // Commit the queue
  65. //
  66. SetupCommitFileQueue(NULL, hfq, SetupDefaultQueueCallback, pvContext);
  67. bReturn = TRUE;
  68. }
  69. else
  70. {
  71. // Installation failed
  72. //
  73. FacLogFileStr(3 | LOG_ERR, _T("ProcessInfSection: Failed SetupInstallFromInfSection (Error: %d)"), GetLastError());
  74. }
  75. // We have a valid queue, lets close it now
  76. //
  77. SetupCloseFileQueue(hfq);
  78. }
  79. // Clean up the memory allocated by the context
  80. //
  81. if ( NULL != pvContext )
  82. {
  83. SetupTermDefaultQueueCallback(pvContext);
  84. }
  85. // Close the Inf file
  86. //
  87. SetupCloseInfFile(hInf);
  88. }
  89. else
  90. {
  91. FacLogFileStr(3 | LOG_ERR, _T("ProcessInfSection: Failed to open '%s'\n"), lpFilename);
  92. bReturn = FALSE;
  93. }
  94. return bReturn;
  95. }
  96. BOOL InfInstall(LPSTATEDATA lpStateData)
  97. {
  98. if ( !DisplayInfInstall(lpStateData) )
  99. {
  100. return TRUE;
  101. }
  102. return ProcessInfSection(lpStateData->lpszWinBOMPath, INF_SEC_UPDATESYSTEM);
  103. }
  104. BOOL DisplayInfInstall(LPSTATEDATA lpStateData)
  105. {
  106. return IniSettingExists(lpStateData->lpszWinBOMPath, INF_SEC_UPDATESYSTEM, NULL, NULL);
  107. }
  108. /*++
  109. ===============================================================================
  110. Routine Description:
  111. UINT CALLBACK InfQueueCallback
  112. This function is required to do file updates when processing an inf file
  113. Arguments:
  114. Context - Context that's currently being used for file queue
  115. Notification - Message
  116. Param1 - Parameter 1
  117. Param2 - Parameter 2
  118. Return Value:
  119. n/a
  120. ===============================================================================
  121. --*/
  122. UINT CALLBACK InfQueueCallback (
  123. PVOID Context,
  124. UINT Notification,
  125. UINT Param1,
  126. UINT Param2
  127. )
  128. {
  129. if (SPFILENOTIFY_DELETEERROR == Notification)
  130. {
  131. // Skip any file delete errors
  132. //
  133. return FILEOP_SKIP;
  134. }
  135. else
  136. {
  137. // Pass all other notifications through without modification
  138. //
  139. return SetupDefaultQueueCallback(Context,
  140. Notification, Param1, Param2);
  141. }
  142. }