Leaked source code of windows server 2003
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.

91 lines
2.1 KiB

  1. #include <windows.h>
  2. #include <setupapi.h>
  3. #include "globals.h"
  4. #include "advpack.h"
  5. //
  6. // Note that the global context is initialized to all zeros.
  7. //
  8. ADVCONTEXT ctx = {
  9. 0, // wOSVer
  10. 0, // wQuietMode
  11. 0, // bUpdHlpDlls
  12. NULL, // hSetupLibrary
  13. FALSE, // fOSSupportsINFInstalls
  14. NULL, // lpszTitle
  15. NULL, // hWnd
  16. ENGINE_SETUPAPI, // dwSetupEngine
  17. FALSE, // bCompressed
  18. { 0 }, // szBrowsePath
  19. NULL, // hInf
  20. FALSE, // bHiveLoaded
  21. { 0 } // szRegHiveKey
  22. };
  23. DWORD cctxSaved = 0;
  24. PADVCONTEXT pctxSave = NULL;
  25. HINSTANCE g_hInst = NULL;
  26. HANDLE g_hAdvLogFile = INVALID_HANDLE_VALUE;
  27. BOOL SaveGlobalContext()
  28. {
  29. if (pctxSave)
  30. {
  31. PADVCONTEXT pctxNew = LocalReAlloc(pctxSave, (cctxSaved + 1) * sizeof(ADVCONTEXT), LMEM_MOVEABLE | LMEM_ZEROINIT);
  32. if (!pctxNew)
  33. {
  34. return FALSE;
  35. }
  36. pctxSave = pctxNew;
  37. }
  38. else
  39. {
  40. pctxSave = LocalAlloc(LPTR, sizeof(ADVCONTEXT));
  41. if (!pctxSave)
  42. {
  43. return FALSE;
  44. }
  45. }
  46. pctxSave[cctxSaved++] = ctx;
  47. //
  48. // Note that the global context is initialized to all zeros except the HINSTANCE
  49. // of this module
  50. //
  51. memset(&ctx, 0, sizeof(ADVCONTEXT));
  52. return TRUE;
  53. }
  54. BOOL RestoreGlobalContext()
  55. {
  56. if (!cctxSaved)
  57. {
  58. return FALSE;
  59. }
  60. // before we release the current contex:ctx to make sure there is no opened handle not being released
  61. if (ctx.hSetupLibrary)
  62. {
  63. CommonInstallCleanup();
  64. }
  65. cctxSaved--;
  66. ctx = pctxSave[cctxSaved];
  67. if (cctxSaved)
  68. {
  69. PADVCONTEXT pctxNew = LocalReAlloc(pctxSave, cctxSaved * sizeof(ADVCONTEXT), LMEM_MOVEABLE | LMEM_ZEROINIT);
  70. if (pctxNew)
  71. {
  72. pctxSave = pctxNew;
  73. }
  74. }
  75. else
  76. {
  77. LocalFree(pctxSave);
  78. pctxSave = NULL;
  79. }
  80. return TRUE;
  81. }