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.

225 lines
7.3 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: Bookmark.h */
  4. /* Description: Implementation of Bookmark API */
  5. /* Author: Steve Rowe */
  6. /* Modified: David Janecek */
  7. /*************************************************************************/
  8. #include "stdafx.h"
  9. #include "msvidctl.h"
  10. #include "msvidwebdvd.h"
  11. #include "msviddvdadm.h"
  12. #include "msviddvdBookmark.h"
  13. #include "perfcntr.h"
  14. /*************************************************************************/
  15. /* Global consts. */
  16. /*************************************************************************/
  17. static const TCHAR g_szBookmark[] = TEXT("DVD.bookmark");
  18. /*************************************************************************/
  19. /* Outgoing interaface implementation. */
  20. /*************************************************************************/
  21. /*************************************************************************/
  22. /* Function: SaveBookmark */
  23. /*************************************************************************/
  24. STDMETHODIMP CMSVidWebDVD::SaveBookmark(){
  25. HRESULT hr = S_OK;
  26. try {
  27. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  28. PQDVDInfo2 pDvdInfo2 = GetDVDInfo2();
  29. if(!pDvdInfo2){
  30. throw(E_UNEXPECTED);
  31. }/* end of if statement */
  32. CComPtr<IDvdState> pBookmark;
  33. hr = pDvdInfo2->GetState(&pBookmark);
  34. if(FAILED(hr)){
  35. throw(hr);
  36. }/* end of if statement */
  37. hr = CBookmark::SaveToRegistry(pBookmark);
  38. }/* end of try statement */
  39. catch(HRESULT hrTmp){
  40. hr = hrTmp;
  41. }/* end of catch statement */
  42. catch(...){
  43. hr = E_UNEXPECTED;
  44. }/* end of catch statement */
  45. return HandleError(hr);
  46. }/* end of function SaveBookmark */
  47. /*************************************************************************/
  48. /* Function: RestoreBookmark */
  49. /* Description: Restores the state by loading the bookmark stream */
  50. /*************************************************************************/
  51. STDMETHODIMP CMSVidWebDVD::RestoreBookmark(){
  52. VIDPERF_FUNC;
  53. HRESULT hr = S_OK;
  54. CComQIPtr<IDvdCmd>IDCmd;
  55. try {
  56. CComPtr<IDvdState> pBookmark;
  57. HRESULT hrTemp = CBookmark::LoadFromRegistry(&pBookmark);
  58. DeleteBookmark();
  59. if(SUCCEEDED(hrTemp)){
  60. INITIALIZE_GRAPH_IF_NEEDS_TO_BE
  61. if(!m_pDVDControl2){
  62. throw(E_UNEXPECTED);
  63. }/* end of if statement */
  64. hr = m_pDVDControl2->SetState(pBookmark, DVD_CMD_FLAG_Flush|DVD_CMD_FLAG_Block, 0);
  65. if(IDCmd){
  66. IDCmd->WaitForEnd();
  67. }
  68. }
  69. }/* end of try statement */
  70. catch(HRESULT hrTmp){
  71. DeleteBookmark();
  72. hr = hrTmp;
  73. }/* end of catch statement */
  74. catch(...){
  75. DeleteBookmark();
  76. hr = E_UNEXPECTED;
  77. }/* end of catch statement */
  78. return HandleError(hr);
  79. }/* end of function RestoreBookmark */
  80. /*************************************************************************/
  81. /* Function: DeleteBookmark */
  82. /* Description: Blasts the bookmark file away. */
  83. /*************************************************************************/
  84. STDMETHODIMP CMSVidWebDVD::DeleteBookmark(){
  85. HRESULT hr = S_OK;
  86. try {
  87. hr = CBookmark::DeleteFromRegistry();
  88. }/* end of try statement */
  89. catch(HRESULT hrTmp){
  90. hr = hrTmp;
  91. }/* end of catch statement */
  92. catch(...){
  93. hr = E_UNEXPECTED;
  94. }/* end of catch statement */
  95. return HandleError(hr);
  96. }/* end of function DeleteBookmark */
  97. /*************************************************************/
  98. /* Name: SaveToRegistry
  99. /* Description: Save the bookmark to registry
  100. /*************************************************************/
  101. HRESULT CBookmark::SaveToRegistry(IDvdState *pbookmark)
  102. {
  103. IPersistMemory* pPersistMemory;
  104. HRESULT hr = pbookmark->QueryInterface(IID_IPersistMemory, (void **) &pPersistMemory );
  105. if (SUCCEEDED(hr)) {
  106. ULONG ulMax;
  107. hr = pPersistMemory->GetSizeMax( &ulMax );
  108. if( SUCCEEDED( hr )) {
  109. BYTE *buffer = new BYTE[ulMax];
  110. hr = pPersistMemory->Save( buffer, TRUE, ulMax );
  111. DWORD dwLen = ulMax;
  112. if (SUCCEEDED(hr)) {
  113. BOOL bSuccess = SetRegistryBytesCU(g_szBookmark, buffer, dwLen);
  114. if (!bSuccess)
  115. hr = E_FAIL;
  116. }
  117. delete[] buffer;
  118. }
  119. pPersistMemory->Release();
  120. }
  121. return hr;
  122. }
  123. /*************************************************************/
  124. /* Name: LoadFromRegistry
  125. /* Description: load the bookmark from registry
  126. /*************************************************************/
  127. HRESULT CBookmark::LoadFromRegistry(IDvdState **ppBookmark)
  128. {
  129. HRESULT hr = CoCreateInstance( CLSID_DVDState, NULL, CLSCTX_INPROC_SERVER, IID_IDvdState, (LPVOID*) ppBookmark );
  130. if( SUCCEEDED( hr )) {
  131. IPersistMemory* pPersistMemory;
  132. hr = (*ppBookmark)->QueryInterface(IID_IPersistMemory, (void **) &pPersistMemory );
  133. if( SUCCEEDED( hr )) {
  134. ULONG ulMax;
  135. hr = pPersistMemory->GetSizeMax( &ulMax );
  136. if (SUCCEEDED(hr)) {
  137. BYTE *buffer = new BYTE[ulMax];
  138. DWORD dwLen = ulMax;
  139. BOOL bFound = GetRegistryBytesCU(g_szBookmark, buffer, &dwLen);
  140. if (bFound && dwLen != 0){
  141. hr = pPersistMemory->Load( buffer, dwLen);
  142. }
  143. else{
  144. dwLen = ulMax;
  145. bFound = GetRegistryBytes(g_szBookmark, buffer, &dwLen);
  146. if (bFound && dwLen != 0){
  147. hr = pPersistMemory->Load( buffer, dwLen);
  148. if(SUCCEEDED(hr)){
  149. SetRegistryBytes(g_szBookmark, NULL, 0);
  150. }
  151. }
  152. else{
  153. hr = E_FAIL;
  154. }
  155. }
  156. delete[] buffer;
  157. }
  158. pPersistMemory->Release();
  159. }
  160. }
  161. return hr;
  162. }
  163. /*************************************************************/
  164. /* Name: DeleteFromRegistry
  165. /* Description: load the bookmark from registry
  166. /*************************************************************/
  167. HRESULT CBookmark::DeleteFromRegistry()
  168. {
  169. HRESULT hr = S_OK;
  170. BOOL bSuccess = SetRegistryBytesCU(g_szBookmark, NULL, 0);
  171. if (!bSuccess)
  172. hr = E_FAIL;
  173. return hr;
  174. }
  175. /*************************************************************************/
  176. /* End of file: Bookmark.cpp */
  177. /*************************************************************************/