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.

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