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.

130 lines
4.0 KiB

  1. // Upgrade.cpp: implementation of the CUpgrade class.
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "Upgrade.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CUpgrade::CUpgrade(CRequestObject *pObj, IWbemServices *pNamespace,
  12. IWbemContext *pCtx):CGenericClass(pObj, pNamespace, pCtx)
  13. {
  14. }
  15. CUpgrade::~CUpgrade()
  16. {
  17. }
  18. HRESULT CUpgrade::CreateObject(IWbemObjectSink *pHandler, ACTIONTYPE atAction)
  19. {
  20. HRESULT hr = WBEM_S_NO_ERROR;
  21. MSIHANDLE hView = NULL;
  22. MSIHANDLE hRecord = NULL;
  23. int i = -1;
  24. WCHAR wcBuf[BUFF_SIZE];
  25. WCHAR wcProductCode[39];
  26. WCHAR wcQuery[BUFF_SIZE];
  27. DWORD dwBufSize;
  28. bool bMatch;
  29. UINT uiStatus;
  30. //These will change from class to class
  31. bool bUpgradeCode, bProductVersion, bOperator, bProductCode;
  32. wcscpy(wcQuery, L"select distinct `UpgradeCode`, `ProductVersion`, `Operator`, `Features`, `Property` from Upgrade");
  33. while(m_pRequest->Package(++i)){
  34. wcscpy(wcProductCode, m_pRequest->Package(i));
  35. bMatch = false;
  36. //Open our database
  37. try
  38. {
  39. if ( GetView ( &hView, wcProductCode, wcQuery, L"Upgrade", TRUE, FALSE ) )
  40. {
  41. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  42. while(uiStatus != ERROR_NO_MORE_ITEMS){
  43. CheckMSI(uiStatus);
  44. if(FAILED(hr = SpawnAnInstance(m_pNamespace, m_pCtx,
  45. &m_pObj, m_pRequest->m_bstrClass))) throw hr;
  46. //----------------------------------------------------
  47. dwBufSize = BUFF_SIZE;
  48. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 1, wcBuf, &dwBufSize));
  49. PutKeyProperty(m_pObj, pUpgradeCode, wcBuf, &bUpgradeCode, m_pRequest);
  50. dwBufSize = BUFF_SIZE;
  51. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 2, wcBuf, &dwBufSize));
  52. PutKeyProperty(m_pObj, pProductVersion, wcBuf, &bProductVersion, m_pRequest);
  53. PutKeyProperty(m_pObj, pOperator, g_fpMsiRecordGetInteger(hRecord, 3),
  54. &bOperator, m_pRequest);
  55. PutKeyProperty(m_pObj, pProductCode, wcProductCode, &bProductCode, m_pRequest);
  56. //====================================================
  57. dwBufSize = BUFF_SIZE;
  58. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 4, wcBuf, &dwBufSize));
  59. PutProperty(m_pObj, pFeatures, wcBuf);
  60. dwBufSize = BUFF_SIZE;
  61. CheckMSI(g_fpMsiRecordGetStringW(hRecord, 5, wcBuf, &dwBufSize));
  62. PutProperty(m_pObj, pProperty, wcBuf);
  63. //----------------------------------------------------
  64. if(bUpgradeCode && bProductVersion && bOperator && bProductCode) bMatch = true;
  65. if((atAction != ACTIONTYPE_GET) || bMatch) hr = pHandler->Indicate(1, &m_pObj);
  66. m_pObj->Release();
  67. m_pObj = NULL;
  68. if(bMatch){
  69. g_fpMsiViewClose(hView);
  70. g_fpMsiCloseHandle(hView);
  71. g_fpMsiCloseHandle(hRecord);
  72. return hr;
  73. }
  74. uiStatus = g_fpMsiViewFetch(hView, &hRecord);
  75. }
  76. }
  77. }
  78. catch(...)
  79. {
  80. g_fpMsiCloseHandle(hRecord);
  81. g_fpMsiViewClose(hView);
  82. g_fpMsiCloseHandle(hView);
  83. msidata.CloseDatabase ();
  84. if(m_pObj)
  85. {
  86. m_pObj->Release();
  87. m_pObj = NULL;
  88. }
  89. throw;
  90. }
  91. g_fpMsiCloseHandle(hRecord);
  92. g_fpMsiViewClose(hView);
  93. g_fpMsiCloseHandle(hView);
  94. msidata.CloseDatabase ();
  95. }
  96. return hr;
  97. }