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.

214 lines
5.6 KiB

  1. // parser.cpp : Defines the entry point for the DLL application.
  2. #include "precomp.h"
  3. #include "..\mcinc.h"
  4. #include "marsload.h"
  5. #include "xmlparser.h"
  6. #include "..\marswin.h"
  7. #include "..\panel.h"
  8. #include "..\place.h"
  9. #include <strsafe.h>
  10. HRESULT CMMFParser::DoPlace( BYTE*& rgBuffer )
  11. {
  12. MarsAppDef_Place pPlace; Extract( rgBuffer, pPlace );
  13. CComBSTR bstrName( pPlace.szName );
  14. HRESULT hr;
  15. m_pMarsDocument->MarsWindow()->SetFirstPlace( bstrName );
  16. if(bstrName)
  17. {
  18. CPlaceCollection* pPlaceCollection = m_pMarsDocument->GetPlaces(); if(!pPlaceCollection) return E_FAIL;
  19. CComClassPtr<CMarsPlace> spPlace;
  20. if(SUCCEEDED(hr = pPlaceCollection->AddPlace( bstrName, &spPlace )))
  21. {
  22. ATLASSERT(spPlace);
  23. for(DWORD u = 0; u < pPlace.dwPlacePanelCount; ++u)
  24. {
  25. MarsAppDef_PlacePanel pPPanel; Extract( rgBuffer, pPPanel );
  26. CComBSTR bstrPanel( pPPanel.szName );
  27. if(bstrPanel)
  28. {
  29. CPlacePanel *pPlacePanel = new CPlacePanel( &pPPanel );
  30. if(pPlacePanel)
  31. {
  32. hr = spPlace->AddPanel( pPlacePanel );
  33. }
  34. else
  35. {
  36. hr = E_OUTOFMEMORY;
  37. }
  38. }
  39. else
  40. {
  41. hr = E_OUTOFMEMORY;
  42. }
  43. if(FAILED(hr)) break;
  44. }
  45. }
  46. }
  47. else
  48. {
  49. hr = E_OUTOFMEMORY;
  50. }
  51. return hr;
  52. }
  53. HRESULT CMMFParser::DoPlaces( BYTE*& rgBuffer )
  54. {
  55. HRESULT hr;
  56. MarsAppDef_Places pPlaces; Extract( rgBuffer, pPlaces );
  57. for(DWORD i = 0; i < pPlaces.dwPlacesCount; i++)
  58. {
  59. if(FAILED(hr = DoPlace( rgBuffer ))) return hr;
  60. }
  61. return S_OK;
  62. }
  63. HRESULT CMMFParser::DoPanel( BYTE*& rgBuffer )
  64. {
  65. MarsAppDef_Panel pLayout; Extract( rgBuffer, pLayout );
  66. CPanelCollection* pPanelCollection = m_pMarsDocument->GetPanels(); if(!pPanelCollection) return E_FAIL;
  67. CComPtr<IMarsPanel> spPanel;
  68. WCHAR wszStartUrl[MAX_PATH];
  69. HRESULT hr;
  70. ExpandEnvironmentStringsW( pLayout.szUrl, wszStartUrl, ARRAYSIZE(wszStartUrl ) );
  71. StringCchCopyW( pLayout.szUrl, ARRAYSIZE(pLayout.szUrl), wszStartUrl );
  72. hr = pPanelCollection->AddPanel( &pLayout, &spPanel );
  73. return hr;
  74. }
  75. HRESULT CMMFParser::DoPanels( BYTE*& rgBuffer )
  76. {
  77. HRESULT hr;
  78. MarsAppDef_Panels pPanels; Extract( rgBuffer, pPanels );
  79. for(DWORD i = 0; i < pPanels.dwPanelsCount; i++)
  80. {
  81. if(FAILED(hr = DoPanel( rgBuffer ))) return hr;
  82. }
  83. return S_OK;
  84. }
  85. HRESULT CMMFParser::DoMarsApp( BYTE* rgBuffer )
  86. {
  87. HRESULT hr;
  88. MarsAppDef pMarsApp; Extract( rgBuffer, pMarsApp );
  89. if(pMarsApp.dwVersion == XML_FILE_FORMAT_CURRENT_VERSION)
  90. {
  91. if(SUCCEEDED(hr = DoPanels( rgBuffer )) &&
  92. SUCCEEDED(hr = DoPlaces( rgBuffer )) )
  93. {
  94. if(pMarsApp.fTitleBar == FALSE)
  95. {
  96. m_pMarsDocument->MarsWindow()->ShowTitleBar( FALSE );
  97. }
  98. }
  99. }
  100. else
  101. {
  102. hr = E_FAIL;
  103. }
  104. return hr;
  105. }
  106. ////////////////////////////////////////////////////////////////////////////////
  107. HRESULT CMMFParser::ReadFile( const CComPtr<IStream>& spStream )
  108. {
  109. HRESULT hr;
  110. if(SUCCEEDED(hr = ReadMMFStreamCookie( spStream )))
  111. {
  112. STATSTG stat;
  113. if(SUCCEEDED(hr = spStream->Stat( &stat, STATFLAG_NONAME )))
  114. {
  115. m_dwDocSize = stat.cbSize.LowPart - MMF_FILE_COOKIELEN;
  116. m_rgDocBuff = (BYTE*)LocalAlloc( LPTR, m_dwDocSize );
  117. if(m_rgDocBuff)
  118. {
  119. ULONG cbRead = 0;
  120. hr = spStream->Read( m_rgDocBuff, m_dwDocSize, &cbRead );
  121. if(cbRead != m_dwDocSize)
  122. {
  123. hr = E_FAIL;
  124. }
  125. if(SUCCEEDED(hr))
  126. {
  127. hr = DoMarsApp( m_rgDocBuff );
  128. }
  129. }
  130. else
  131. {
  132. hr = E_OUTOFMEMORY;
  133. }
  134. }
  135. }
  136. return hr;
  137. }
  138. HRESULT CMMFParser::ReadMMFStreamCookie( const CComPtr<IStream>& spStream )
  139. {
  140. HRESULT hr;
  141. char szFileCookie[MMF_FILE_COOKIELEN];
  142. ULONG cbRead = 0;
  143. if(SUCCEEDED(hr = spStream->Read( szFileCookie, MMF_FILE_COOKIELEN, &cbRead )))
  144. {
  145. if((cbRead == (MMF_FILE_COOKIELEN)) && (!memcmp( szFileCookie, g_szMMFCookie, MMF_FILE_COOKIELEN )))
  146. {
  147. hr = S_OK;
  148. }
  149. else
  150. {
  151. hr = E_INVALIDARG;
  152. }
  153. }
  154. return hr;
  155. }
  156. CMMFParser::CMMFParser( CMarsDocument *pMarsDocument )
  157. {
  158. m_pMarsDocument = pMarsDocument; // class CMarsDocument* m_pMarsDocument;
  159. m_dwDocSize = 0; // DWORD m_dwDocSize;
  160. m_rgDocBuff = NULL; // BYTE* m_rgDocBuff;
  161. // CComBSTR m_bstrFirstPlace;
  162. }
  163. HRESULT CMMFParser::MMFToMars( LPCWSTR pwszMMFUrl, CMarsDocument* pMarsDocument )
  164. {
  165. HRESULT hr;
  166. CComPtr<IStream> spStream;
  167. if(SUCCEEDED(hr = URLOpenBlockingStream( NULL, pwszMMFUrl, &spStream, 0, NULL )))
  168. {
  169. CMMFParser mmfParser( pMarsDocument );
  170. hr = mmfParser.ReadFile( spStream );
  171. }
  172. return hr;
  173. }