1 /*******************************************************************************
3 * This file is part of the Ogg Vorbis DirectShow filter collection *
5 * Copyright (c) 2001, Tobias Waldvogel *
6 * All rights reserved. *
8 * Redistribution and use in source and binary forms, with or without *
9 * modification, are permitted provided that the following conditions are met: *
11 * - Redistributions of source code must retain the above copyright notice, *
12 * this list of conditions and the following disclaimer. *
14 * - Redistributions in binary form must reproduce the above copyright notice, *
15 * this list of conditions and the following disclaimer in the documentation *
16 * and/or other materials provided with the distribution. *
18 * - The names of the contributors may not be used to endorse or promote *
19 * products derived from this software without specific prior written *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE *
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN *
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
32 * POSSIBILITY OF SUCH DAMAGE. *
34 *******************************************************************************/
36 #include "PersistPropertyBag.h"
40 CPersistPropertyBag::CPersistPropertyBag(const char** arProps
, int iProps
, const GUID
* pClsID
)
47 HRESULT STDMETHODCALLTYPE
CPersistPropertyBag::GetClassID(CLSID
* pClsID
)
53 HRESULT STDMETHODCALLTYPE
CPersistPropertyBag::InitNew(void)
58 // Walks through all properties in m_arProps and calls read
59 HRESULT STDMETHODCALLTYPE
CPersistPropertyBag::Load(IPropertyBag
*pPropBag
, IErrorLog
*pErrorLog
)
66 for (int i
=0; i
<m_iProps
; i
++)
68 mbstowcs(wzName
, m_arProps
[i
], 128);
69 if (SUCCEEDED(pPropBag
->Read(wzName
, &V
, NULL
)))
77 // Walks through all properties in m_arProps and calls write
78 HRESULT STDMETHODCALLTYPE
CPersistPropertyBag::Save(IPropertyBag
*pPropBag
, BOOL fClearDirty
,
79 BOOL fSaveAllProperties
)
86 for (int i
=0; i
<m_iProps
; i
++)
88 mbstowcs(wzName
, m_arProps
[i
], 128);
89 if (SUCCEEDED(Read(wzName
, &V
, NULL
)))
90 pPropBag
->Write(wzName
, &V
);
97 CRegistryStuff::CRegistryStuff(const GUID
* pClsID
)
102 // Returns a handle to the registry key HKEY_CLASSES_ROOT, CLSID\<idCLSID>\defaults
103 HKEY
CRegistryStuff::OpenRegistry()
105 OLECHAR szCLSID
[CHARS_IN_GUID
];
106 CHAR chCLSIDEntry
[260];
107 LPDWORD lpdwDisposition
= 0;
111 StringFromGUID2(*m_pClsID
, szCLSID
, CHARS_IN_GUID
);
112 wsprintf(chCLSIDEntry
, "CLSID\\%ls\\Defaults", szCLSID
);
113 result
= RegCreateKeyEx(HKEY_CLASSES_ROOT
, chCLSIDEntry
, 0, "",
114 REG_OPTION_NON_VOLATILE
, KEY_READ
| KEY_WRITE
, NULL
,
115 &hKey
, lpdwDisposition
);
117 return result
== ERROR_SUCCESS
? hKey
: NULL
;
120 HRESULT
CRegistryStuff::SaveToRegistry(const char* szName
, bool bVal
)
122 if (HKEY hKey
= OpenRegistry())
124 DWORD dwData
= bVal
? 1 : 0;
125 RegSetValueEx(hKey
, szName
, 0, REG_DWORD
, (CONST BYTE
*)&dwData
, sizeof(dwData
));
132 HRESULT
CRegistryStuff::SaveToRegistry(const char* szName
, __int32 iVal
)
134 return SaveToRegistry(szName
, (unsigned __int32
)iVal
);
137 HRESULT
CRegistryStuff::SaveToRegistry(const char* szName
, unsigned __int32 iVal
)
139 if (HKEY hKey
= OpenRegistry())
141 RegSetValueEx(hKey
, szName
, 0, REG_DWORD
, (CONST BYTE
*)&iVal
, sizeof(iVal
));
148 HRESULT
CRegistryStuff::SaveToRegistry(const char* szName
, float fVal
)
150 if (HKEY hKey
= OpenRegistry())
153 sprintf(szVal
, "%f", fVal
);
154 RegSetValueEx(hKey
, szName
, 0, REG_SZ
, (CONST BYTE
*)szVal
, strlen(szVal
));
162 HRESULT
CRegistryStuff::SaveToRegistry(const char* szName
, char* szVal
)
164 if (HKEY hKey
= OpenRegistry())
166 RegSetValueEx(hKey
, szName
, 0, REG_SZ
, (CONST BYTE
*)szVal
, strlen(szVal
)+1);
173 HRESULT
CRegistryStuff::SaveToRegistry(const char* szName
, wchar_t* wzVal
)
175 if (HKEY hKey
= OpenRegistry())
179 wcstombs(szValue
, wzVal
, 128);
180 RegSetValueEx(hKey
, szName
, 0, REG_SZ
, (CONST BYTE
*)szValue
, strlen(szValue
)+1);
188 HRESULT
CRegistryStuff::LoadFromRegistry(const char* szName
,
189 bool* pbVal
, bool bDefault
)
191 if (HKEY hKey
= OpenRegistry())
194 DWORD dwSize
= sizeof(dwData
);
196 if (RegQueryValueEx(hKey
, szName
, NULL
, NULL
, (BYTE
*)&dwData
, &dwSize
) == ERROR_SUCCESS
)
197 *pbVal
= dwData
!= 0;
207 HRESULT
CRegistryStuff::LoadFromRegistry(const char* szName
,
208 __int32
* piVal
, __int32 iDefault
)
210 return LoadFromRegistry(szName
, (unsigned __int32
*) piVal
,
211 (unsigned __int32
) iDefault
);
214 HRESULT
CRegistryStuff::LoadFromRegistry(const char* szName
,
215 unsigned __int32
* piVal
, unsigned __int32 iDefault
)
217 if (HKEY hKey
= OpenRegistry())
219 DWORD dwSize
= sizeof(*piVal
);
221 if (RegQueryValueEx(hKey
, szName
, NULL
, NULL
, (BYTE
*)piVal
, &dwSize
) != ERROR_SUCCESS
)
230 HRESULT
CRegistryStuff::LoadFromRegistry(const char* szName
,
231 float* pfVal
, float fDefault
)
233 if (HKEY hKey
= OpenRegistry())
236 DWORD dwSize
= sizeof(szVal
);
238 if (RegQueryValueEx(hKey
, szName
, NULL
, NULL
, (BYTE
*)szVal
, &dwSize
) == ERROR_SUCCESS
)
239 *pfVal
= atof(szVal
);