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.

134 lines
3.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // File: darenum.cpp
  6. //
  7. // The current order of enumeration is Legacy --> Darwin --> SMS
  8. //
  9. // History:
  10. // 2-03-97 by dli
  11. //------------------------------------------------------------------------
  12. #include "priv.h"
  13. // Do not build this file if on Win9X or NT4
  14. #ifndef DOWNLEVEL_PLATFORM
  15. #include "darenum.h"
  16. #include "darapp.h"
  17. #include "util.h"
  18. CDarwinEnumPublishedApps::CDarwinEnumPublishedApps(GUID * pAppCategoryId) : _cRef(1)
  19. {
  20. ASSERT(_bGuidUsed == FALSE);
  21. // Do we have a Catogory GUID?
  22. if (pAppCategoryId)
  23. {
  24. // Yes
  25. _CategoryGUID = *pAppCategoryId;
  26. _bGuidUsed = TRUE;
  27. }
  28. GetManagedApplications(_bGuidUsed ? &_CategoryGUID : NULL, _bGuidUsed ? MANAGED_APPS_FROMCATEGORY : MANAGED_APPS_USERAPPLICATIONS,
  29. MANAGED_APPS_INFOLEVEL_DEFAULT, &_dwNumApps, &_prgApps);
  30. }
  31. CDarwinEnumPublishedApps::~CDarwinEnumPublishedApps()
  32. {
  33. if (_prgApps && (_dwNumApps > 0))
  34. {
  35. LocalFree(_prgApps);
  36. }
  37. }
  38. // IEnumPublishedApps::QueryInterface
  39. HRESULT CDarwinEnumPublishedApps::QueryInterface(REFIID riid, LPVOID * ppvOut)
  40. {
  41. static const QITAB qit[] = {
  42. QITABENT(CDarwinEnumPublishedApps, IEnumPublishedApps), // IID_IEnumPublishedApps
  43. { 0 },
  44. };
  45. return QISearch(this, qit, riid, ppvOut);
  46. }
  47. // IEnumPublishedApps::AddRef
  48. ULONG CDarwinEnumPublishedApps::AddRef()
  49. {
  50. _cRef++;
  51. TraceMsg(TF_OBJLIFE, "CDarwinEnumPublishedApps()::AddRef called, new _cRef=%lX", _cRef);
  52. return _cRef;
  53. }
  54. // IEnumPublishedApps::Release
  55. ULONG CDarwinEnumPublishedApps::Release()
  56. {
  57. _cRef--;
  58. TraceMsg(TF_OBJLIFE, "CDarwinEnumPublishedApps()::Release called, new _cRef=%lX", _cRef);
  59. if (_cRef > 0)
  60. return _cRef;
  61. delete this;
  62. return 0;
  63. }
  64. // IEnumPublishedApps::Next
  65. // PERF: we should do some optimization instead of enumerating these apps
  66. // one by one.
  67. // S_FALSE means end of enumeration
  68. HRESULT CDarwinEnumPublishedApps::Next(IPublishedApp ** ppia)
  69. {
  70. HRESULT hres = S_FALSE;
  71. *ppia = NULL;
  72. if (_prgApps && (_dwNumApps > 0) && (_dwIndex < _dwNumApps))
  73. {
  74. BOOL bContinue = FALSE;
  75. do {
  76. PMANAGEDAPPLICATION pma = &_prgApps[_dwIndex];
  77. // NOTE: no Hydra machines (_bTSSession == TRUE) we filter out all the
  78. // Darwin apps.
  79. if (pma->pszPackageName && pma->pszPackageName[0])
  80. {
  81. CDarwinPublishedApp *pdpa = new CDarwinPublishedApp(pma);
  82. if (pdpa)
  83. {
  84. *ppia = SAFECAST(pdpa, IPublishedApp *);
  85. hres = S_OK;
  86. }
  87. else
  88. hres = E_OUTOFMEMORY;
  89. bContinue = FALSE;
  90. }
  91. else
  92. {
  93. ClearManagedApplication(pma);
  94. bContinue = TRUE;
  95. }
  96. _dwIndex++;
  97. } while (bContinue && (_dwIndex < _dwNumApps));
  98. }
  99. return hres;
  100. }
  101. // IEnumPublishedApps::Reset
  102. HRESULT CDarwinEnumPublishedApps::Reset(void)
  103. {
  104. if (_prgApps && (_dwNumApps > 0))
  105. {
  106. LocalFree(_prgApps);
  107. }
  108. GetManagedApplications(_bGuidUsed ? &_CategoryGUID : NULL, MANAGED_APPS_USERAPPLICATIONS,
  109. _bGuidUsed ? MANAGED_APPS_FROMCATEGORY : MANAGED_APPS_INFOLEVEL_DEFAULT, &_dwNumApps, &_prgApps);
  110. _dwIndex = 0;
  111. return S_OK;
  112. }
  113. #endif //DOWNLEVEL_PLATFORM