]> git.sesse.net Git - vlc/blob - projects/activex/persiststorage.cpp
Merge branch 'master' into lpcm_encoder
[vlc] / projects / activex / persiststorage.cpp
1 /*****************************************************************************
2  * persiststorage.cpp: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #include "plugin.h"
24 #include "persiststorage.h"
25
26 using namespace std;
27
28 STDMETHODIMP VLCPersistStorage::GetClassID(LPCLSID pClsID)
29 {
30     if( NULL == pClsID )
31         return E_POINTER;
32
33     *pClsID = _p_instance->getClassID();
34
35     return S_OK;
36 };
37
38 STDMETHODIMP VLCPersistStorage::IsDirty(void)
39 {
40     return _p_instance->isDirty() ? S_OK : S_FALSE;
41 };
42
43 STDMETHODIMP VLCPersistStorage::InitNew(LPSTORAGE pStg)
44 {
45     return _p_instance->onInit();
46 };
47
48 STDMETHODIMP VLCPersistStorage::Load(LPSTORAGE pStg)
49 {
50     if( NULL == pStg )
51         return E_INVALIDARG;
52
53     LPSTREAM pStm = NULL;
54     HRESULT result = pStg->OpenStream(L"VideoLAN ActiveX Plugin Data", NULL,
55                         STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &pStm);
56
57     if( FAILED(result) )
58         return result;
59
60     LPPERSISTSTREAMINIT pPersistStreamInit;
61     if( SUCCEEDED(QueryInterface(IID_IPersistStreamInit, (void **)&pPersistStreamInit)) )
62     {
63         result = pPersistStreamInit->Load(pStm);
64         pPersistStreamInit->Release();
65     }
66
67     pStm->Release();
68
69     return result;
70 };
71
72 STDMETHODIMP VLCPersistStorage::Save(LPSTORAGE pStg, BOOL fSameAsLoad)
73 {
74     if( NULL == pStg )
75         return E_INVALIDARG;
76
77     if( fSameAsLoad && (S_FALSE == IsDirty()) )
78         return S_OK;
79
80     LPSTREAM pStm = NULL;
81     HRESULT result = pStg->CreateStream(L"VideoLAN ActiveX Plugin Data",
82                         STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &pStm);
83
84     if( FAILED(result) )
85         return result;
86
87     LPPERSISTSTREAMINIT pPersistStreamInit;
88     if( SUCCEEDED(QueryInterface(IID_IPersistStreamInit, (void **)&pPersistStreamInit)) )
89     {
90         result = pPersistStreamInit->Save(pStm, fSameAsLoad);
91         pPersistStreamInit->Release();
92     }
93
94     pStm->Release();
95
96     return result;
97 };
98
99 STDMETHODIMP VLCPersistStorage::SaveCompleted(IStorage *pStg)
100 {
101     return S_OK;
102 };
103
104 STDMETHODIMP VLCPersistStorage::HandsOffStorage(void)
105 {
106     return S_OK;
107 };
108