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.

372 lines
9.4 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. // subcomp.cpp
  3. // implementation a default sub component
  4. #include "stdafx.h"
  5. #include "subcomp.h"
  6. OCMSubComp::OCMSubComp ()
  7. {
  8. m_lTicks = 0;
  9. }
  10. BOOL OCMSubComp::Initialize ()
  11. {
  12. return TRUE;
  13. }
  14. BOOL OCMSubComp::GetCurrentSubCompState () const
  15. {
  16. return GetHelperRoutines().QuerySelectionState(
  17. GetHelperRoutines().OcManagerContext,
  18. GetSubCompID(),
  19. OCSELSTATETYPE_CURRENT);
  20. }
  21. BOOL OCMSubComp::GetOriginalSubCompState () const
  22. {
  23. return GetHelperRoutines().QuerySelectionState(
  24. GetHelperRoutines().OcManagerContext,
  25. GetSubCompID(),
  26. OCSELSTATETYPE_ORIGINAL);
  27. }
  28. BOOL OCMSubComp::HasStateChanged () const
  29. {
  30. //
  31. // returns true if current selection state is different from previous.
  32. //
  33. return GetCurrentSubCompState() != GetOriginalSubCompState();
  34. }
  35. //
  36. // this functions ticks the gauge for the specified count
  37. // keep traks of the count reported to the OC_QUERY_STEP_COUNT
  38. //
  39. void OCMSubComp::Tick (DWORD dwTickCount /* = 1 */)
  40. {
  41. if (m_lTicks > 0)
  42. {
  43. m_lTicks -= dwTickCount;
  44. while(dwTickCount--)
  45. GetHelperRoutines().TickGauge( GetHelperRoutines().OcManagerContext );
  46. }
  47. else
  48. {
  49. m_lTicks = 0;
  50. }
  51. }
  52. //
  53. // completes the remaining ticks.
  54. //
  55. void OCMSubComp::TickComplete ()
  56. {
  57. ASSERT(m_lTicks >= 0);
  58. while (m_lTicks--)
  59. GetHelperRoutines().TickGauge( GetHelperRoutines().OcManagerContext );
  60. }
  61. DWORD OCMSubComp::OnQueryStepCount()
  62. {
  63. m_lTicks = GetStepCount() + 2;
  64. return m_lTicks;
  65. }
  66. DWORD OCMSubComp::GetStepCount () const
  67. {
  68. return 0;
  69. }
  70. DWORD OCMSubComp::OnQueryState ( UINT uiWhichState ) const
  71. {
  72. LOGMESSAGE1(_T("In OCMSubComp::OnQueryState for %s"), GetSubCompID());
  73. ASSERT(OCSELSTATETYPE_ORIGINAL == uiWhichState ||
  74. OCSELSTATETYPE_CURRENT == uiWhichState ||
  75. OCSELSTATETYPE_FINAL == uiWhichState );
  76. return SubcompUseOcManagerDefault;
  77. }
  78. DWORD OCMSubComp::OnQuerySelStateChange (BOOL /* bNewState */, BOOL /* bDirectSelection */) const
  79. {
  80. return TRUE;
  81. }
  82. DWORD OCMSubComp::LookupTargetSection(LPTSTR szTargetSection, DWORD dwSize, LPCTSTR lookupSection)
  83. {
  84. DWORD dwError = GetStringValue(GetComponentInfHandle(), GetSubCompID(), lookupSection, szTargetSection, dwSize);
  85. if (dwError == ERROR_SUCCESS)
  86. {
  87. LOGMESSAGE2(_T("sectionname = <%s>, actual section = <%s>"), lookupSection, szTargetSection);
  88. }
  89. else
  90. {
  91. AssertFalse();
  92. LOGMESSAGE1(_T("ERROR:GetSectionToBeProcess:GetStringValue failed GetLastError() = %lu"), dwError);
  93. }
  94. return dwError;
  95. }
  96. DWORD OCMSubComp::GetTargetSection(LPTSTR szTargetSection, DWORD dwSize, ESections eSectionType, BOOL *pbNoSection)
  97. {
  98. ASSERT(szTargetSection);
  99. ASSERT(pbNoSection);
  100. //
  101. // get section to be processed
  102. //
  103. LPCTSTR szSection = GetSectionToBeProcessed( eSectionType );
  104. if (szSection == NULL)
  105. {
  106. *pbNoSection = TRUE;
  107. return NO_ERROR;
  108. }
  109. else
  110. {
  111. //
  112. // there is a section to be processed.
  113. //
  114. *pbNoSection = FALSE;
  115. }
  116. //
  117. // look for the target section
  118. //
  119. return LookupTargetSection(szTargetSection, dwSize, szSection);
  120. }
  121. DWORD OCMSubComp::OnCalcDiskSpace ( DWORD addComponent, HDSKSPC dspace )
  122. {
  123. LOGMESSAGE1(_T("In OCMSubComp::OnCalcDiskSpace for %s"), GetSubCompID());
  124. TCHAR TargetSection[S_SIZE];
  125. BOOL bNoSection = FALSE;
  126. DWORD rc = GetTargetSection(TargetSection, S_SIZE, kDiskSpaceAddSection, &bNoSection);
  127. //
  128. // if there is no section to be processed. just return success.
  129. //
  130. if (bNoSection)
  131. {
  132. return NO_ERROR;
  133. }
  134. if (rc == NO_ERROR)
  135. {
  136. if (addComponent)
  137. {
  138. LOGMESSAGE1(_T("Calculating disk space for add section = %s"), TargetSection);
  139. rc = SetupAddInstallSectionToDiskSpaceList(
  140. dspace,
  141. GetComponentInfHandle(),
  142. NULL,
  143. TargetSection,
  144. 0,
  145. 0);
  146. }
  147. else
  148. {
  149. LOGMESSAGE1(_T("Calculating disk space for remove section = %s"), TargetSection);
  150. rc = SetupRemoveInstallSectionFromDiskSpaceList(
  151. dspace,
  152. GetComponentInfHandle(),
  153. NULL,
  154. TargetSection,
  155. 0,
  156. 0);
  157. }
  158. if (!rc)
  159. rc = GetLastError();
  160. else
  161. rc = NO_ERROR;
  162. }
  163. return rc;
  164. }
  165. DWORD OCMSubComp::OnQueueFiles ( HSPFILEQ queue )
  166. {
  167. LOGMESSAGE1(_T("In OCMSubComp::OnQueueFiles for %s"), GetSubCompID());
  168. TCHAR TargetSection[S_SIZE];
  169. BOOL bNoSection = FALSE;
  170. DWORD rc = GetTargetSection(TargetSection, S_SIZE, kFileSection, &bNoSection);
  171. //
  172. // if there is no section to be processed. just return success.
  173. //
  174. if (bNoSection)
  175. {
  176. return NO_ERROR;
  177. }
  178. if (rc == NO_ERROR)
  179. {
  180. LOGMESSAGE1(_T("Queuing Files from Section = %s"), TargetSection);
  181. if (!SetupInstallFilesFromInfSection(
  182. GetComponentInfHandle(),
  183. NULL,
  184. queue,
  185. TargetSection,
  186. NULL,
  187. 0 // this should eliminate the warning about overwriting newer file.
  188. ))
  189. {
  190. rc = GetLastError();
  191. LOGMESSAGE2(_T("ERROR:OnQueueFileOps::SetupInstallFilesFromInfSection <%s> failed.GetLastError() = <%ul)"), TargetSection, rc);
  192. }
  193. else
  194. {
  195. return NO_ERROR;
  196. }
  197. }
  198. return rc;
  199. }
  200. DWORD OCMSubComp::OnCompleteInstall ()
  201. {
  202. LOGMESSAGE1(_T("In OCMSubComp::OnCompleteInstall for %s"), GetSubCompID());
  203. if (!BeforeCompleteInstall ())
  204. {
  205. LOGMESSAGE0(_T("ERROR:BeforeCompleteInstall failed!"));
  206. }
  207. TCHAR TargetSection[S_SIZE];
  208. BOOL bNoSection = FALSE;
  209. DWORD dwError = GetTargetSection(TargetSection, S_SIZE, kRegistrySection, &bNoSection);
  210. //
  211. // if there is no section to be processed. just go ahead.
  212. //
  213. if (!bNoSection)
  214. {
  215. LOGMESSAGE1(_T("Setting up Registry/Links/RegSvrs from section = %s"), TargetSection);
  216. dwError = SetupInstallFromInfSection(
  217. NULL, // hwndOwner
  218. GetComponentInfHandle(), // inf handle
  219. TargetSection, //
  220. SPINST_ALL & ~SPINST_FILES, // operation flags
  221. NULL, // relative key root
  222. NULL, // source root path
  223. 0, // copy flags
  224. NULL, // callback routine
  225. NULL, // callback routine context
  226. NULL, // device info set
  227. NULL // device info struct
  228. );
  229. if (dwError == 0)
  230. LOGMESSAGE1(_T("ERROR:while installating section <%lu>"), GetLastError());
  231. }
  232. Tick();
  233. if (!AfterCompleteInstall ())
  234. {
  235. LOGMESSAGE0(_T("ERROR:AfterCompleteInstall failed!"));
  236. }
  237. TickComplete();
  238. return NO_ERROR;
  239. }
  240. BOOL OCMSubComp::BeforeCompleteInstall ()
  241. {
  242. return TRUE;
  243. }
  244. BOOL OCMSubComp::AfterCompleteInstall ()
  245. {
  246. return TRUE;
  247. }
  248. DWORD OCMSubComp::OnAboutToCommitQueue ()
  249. {
  250. return NO_ERROR;
  251. }
  252. void
  253. OCMSubComp::SetupRunOnce( HINF hInf, LPCTSTR SectionName )
  254. {
  255. INFCONTEXT sic;
  256. TCHAR CommandLine[ RUNONCE_CMDBUFSIZE ];
  257. BOOL b;
  258. STARTUPINFO startupinfo;
  259. PROCESS_INFORMATION process_information;
  260. DWORD dwErr;
  261. if (!SetupFindFirstLine( hInf, SectionName, NULL , &sic))
  262. {
  263. LOGMESSAGE1(_T("WARNING: nothing in %s to be processed."), SectionName);
  264. }
  265. else
  266. {
  267. do {
  268. if (!SetupGetStringField(&sic, 1, CommandLine, RUNONCE_CMDBUFSIZE, NULL))
  269. {
  270. LOGMESSAGE1(_T("WARNING: No command to be processed."), SectionName);
  271. break;
  272. }
  273. LOGMESSAGE1(_T("RunOnce: spawning process %s"), CommandLine);
  274. ZeroMemory( &startupinfo, sizeof(startupinfo) );
  275. startupinfo.cb = sizeof(startupinfo);
  276. startupinfo.dwFlags = STARTF_USESHOWWINDOW;
  277. startupinfo.wShowWindow = SW_HIDE | SW_SHOWMINNOACTIVE;
  278. b = CreateProcess( NULL,
  279. CommandLine,
  280. NULL,
  281. NULL,
  282. FALSE,
  283. CREATE_DEFAULT_ERROR_MODE,
  284. NULL,
  285. NULL,
  286. &startupinfo,
  287. &process_information );
  288. if ( !b )
  289. {
  290. LOGMESSAGE1(_T("ERROR: failed to spawn %s process."), CommandLine);
  291. continue;
  292. }
  293. dwErr = WaitForSingleObject( process_information.hProcess, RUNONCE_DEFAULTWAIT );
  294. if ( dwErr != NO_ERROR )
  295. {
  296. LOGMESSAGE1(_T("ERROR: process %s failed to complete in time."), CommandLine);
  297. // Don't terminate process, just go on to next one.
  298. }
  299. else
  300. {
  301. LOGMESSAGE1(_T("INFO: process %s completed successfully."), CommandLine);
  302. }
  303. CloseHandle( process_information.hProcess );
  304. CloseHandle( process_information.hThread );
  305. } while ( SetupFindNextLine( &sic, &sic ) );
  306. }
  307. return;
  308. }