ReactOS 0.4.15-dev-7677-g8209aa5
CIniPropertyBag Class Reference
Inheritance diagram for CIniPropertyBag:
Collaboration diagram for CIniPropertyBag:

Public Member Functions

 CIniPropertyBag (DWORD dwMode)
 
 ~CIniPropertyBag () override
 
HRESULT Init (LPCWSTR pszIniFile, LPCWSTR pszSection)
 
STDMETHODIMP Read (_In_z_ LPCWSTR pszPropName, _Inout_ VARIANT *pvari, _Inout_opt_ IErrorLog *pErrorLog) override
 
STDMETHODIMP Write (_In_z_ LPCWSTR pszPropName, _In_ VARIANT *pvari) override
 
- Public Member Functions inherited from CBasePropertyBag
 CBasePropertyBag (DWORD dwMode)
 
virtual ~CBasePropertyBag ()
 
STDMETHODIMP QueryInterface (REFIID riid, void **ppvObject) override
 
 STDMETHODIMP_ (ULONG) AddRef() override
 
 STDMETHODIMP_ (ULONG) Release() override
 
- Public Member Functions inherited from IPropertyBag
HRESULT Read ([in] LPCOLESTR pszPropName, [in, out] VARIANT *pVar, [in] IErrorLog *pErrorLog)
 
HRESULT RemoteRead ([in] LPCOLESTR pszPropName, [out] VARIANT *pVar, [in] IErrorLog *pErrorLog, [in] DWORD varType, [in] IUnknown *pUnkObj)
 
HRESULT Write ([in] LPCOLESTR pszPropName, [in] VARIANT *pVar)
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Protected Member Functions

HRESULT _GetSectionAndName (LPCWSTR pszStart, LPWSTR pszSection, UINT cchSectionMax, LPWSTR pszName, UINT cchNameMax)
 

Static Protected Member Functions

static BOOL LooksLikeAnAlternateStream (LPCWSTR pszStart)
 

Protected Attributes

LPWSTR m_pszFileName
 
LPWSTR m_pszSection
 
BOOL m_bAlternateStream
 
- Protected Attributes inherited from CBasePropertyBag
LONG m_cRefs
 
DWORD m_dwMode
 

Additional Inherited Members

- Public Types inherited from IPropertyBag
typedef IPropertyBagLPPROPERTYBAG
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 

Detailed Description

Definition at line 760 of file propbag.cpp.

Constructor & Destructor Documentation

◆ CIniPropertyBag()

CIniPropertyBag::CIniPropertyBag ( DWORD  dwMode)
inline

Definition at line 784 of file propbag.cpp.

785 : CBasePropertyBag(dwMode)
789 {
790 }
LPWSTR m_pszFileName
Definition: propbag.cpp:763
LPWSTR m_pszSection
Definition: propbag.cpp:764
BOOL m_bAlternateStream
Definition: propbag.cpp:765
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117

◆ ~CIniPropertyBag()

CIniPropertyBag::~CIniPropertyBag ( )
inlineoverride

Definition at line 792 of file propbag.cpp.

793 {
796 }
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594

Member Function Documentation

◆ _GetSectionAndName()

HRESULT CIniPropertyBag::_GetSectionAndName ( LPCWSTR  pszStart,
LPWSTR  pszSection,
UINT  cchSectionMax,
LPWSTR  pszName,
UINT  cchNameMax 
)
protected

Definition at line 828 of file propbag.cpp.

834{
835 LPCWSTR pchSep = StrChrW(pszStart, L'\\');
836 if (pchSep)
837 {
838 UINT cchSep = (UINT)(pchSep - pszStart + 1);
839 StrCpyNW(pszSection, pszStart, min(cchSep, cchSectionMax));
840 StrCpyNW(pszName, pchSep + 1, cchNameMax);
841 return S_OK;
842 }
843
844 if (m_pszSection)
845 {
846 StrCpyNW(pszSection, m_pszSection, cchSectionMax);
847 StrCpyNW(pszName, pszStart, cchNameMax);
848 return S_OK;
849 }
850
851 ERR("%p: %s\n", this, debugstr_w(pszStart));
852 return E_INVALIDARG;
853}
#define ERR(fmt,...)
Definition: debug.h:110
#define E_INVALIDARG
Definition: ddrawi.h:101
LPWSTR WINAPI StrChrW(LPCWSTR lpszStr, WCHAR ch)
Definition: string.c:468
LPWSTR WINAPI StrCpyNW(LPWSTR dst, LPCWSTR src, int count)
Definition: string.c:536
#define S_OK
Definition: intsafe.h:52
#define debugstr_w
Definition: kernel32.h:32
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by Read(), and Write().

◆ Init()

HRESULT CIniPropertyBag::Init ( LPCWSTR  pszIniFile,
LPCWSTR  pszSection 
)

Definition at line 808 of file propbag.cpp.

809{
810 m_pszFileName = StrDupW(pszIniFile);
811 if (!m_pszFileName)
812 return E_OUTOFMEMORY;
813
814 // Is it an ADS (Alternate Data Stream) pathname?
816
817 if (pszSection)
818 {
819 m_pszSection = StrDupW(pszSection);
820 if (!m_pszSection)
821 return E_OUTOFMEMORY;
822 }
823
824 return S_OK;
825}
static BOOL LooksLikeAnAlternateStream(LPCWSTR pszStart)
Definition: propbag.cpp:767
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
LPWSTR WINAPI StrDupW(LPCWSTR lpszStr)
Definition: string.c:1089

◆ LooksLikeAnAlternateStream()

static BOOL CIniPropertyBag::LooksLikeAnAlternateStream ( LPCWSTR  pszStart)
inlinestaticprotected

Definition at line 767 of file propbag.cpp.

768 {
769 LPCWSTR pch = StrRChrW(pszStart, NULL, L'\\');
770 if (!pch)
771 pch = pszStart;
772 return StrChrW(pch, L':') != NULL;
773 }
LPWSTR WINAPI StrRChrW(LPCWSTR str, LPCWSTR end, WORD ch)
Definition: string.c:556
#define pch(ap)
Definition: match.c:418

Referenced by Init().

◆ Read()

STDMETHODIMP CIniPropertyBag::Read ( _In_z_ LPCWSTR  pszPropName,
_Inout_ VARIANT pvari,
_Inout_opt_ IErrorLog pErrorLog 
)
override

Definition at line 856 of file propbag.cpp.

860{
861 UNREFERENCED_PARAMETER(pErrorLog);
862
863 TRACE("%p: %s %p %p\n", this, debugstr_w(pszPropName), pvari, pErrorLog);
864
865 VARTYPE vt = V_VT(pvari);
866
867 ::VariantInit(pvari);
868
870 {
871 ERR("%p: 0x%X\n", this, m_dwMode);
872 return E_ACCESSDENIED;
873 }
874
875 WCHAR szSection[64], szName[64];
876 HRESULT hr =
877 _GetSectionAndName(pszPropName, szSection, _countof(szSection), szName, _countof(szName));
878 if (FAILED(hr))
879 return hr;
880
881 const INT cchBuffMax = 4 * MAX_PATH; // UTF-7 needs 4 times length buffer.
882 CComHeapPtr<WCHAR> pszBuff;
883 if (!pszBuff.Allocate(cchBuffMax * sizeof(WCHAR)))
884 return E_OUTOFMEMORY;
885
886 if (!SHGetIniStringUTF7W(szSection, szName, pszBuff, cchBuffMax, m_pszFileName))
887 return E_FAIL;
888
889 BSTR bstr = ::SysAllocString(pszBuff);
890 V_BSTR(pvari) = bstr;
891 if (!bstr)
892 return E_OUTOFMEMORY;
893
894 V_VT(pvari) = VT_BSTR;
895 return ::VariantChangeTypeForRead(pvari, vt);
896}
bool Allocate(_In_ size_t nElements=1)
Definition: atlalloc.h:143
HRESULT _GetSectionAndName(LPCWSTR pszStart, LPWSTR pszSection, UINT cchSectionMax, LPWSTR pszName, UINT cchNameMax)
Definition: propbag.cpp:828
#define E_FAIL
Definition: ddrawi.h:102
OLECHAR * BSTR
Definition: compat.h:2293
#define MAX_PATH
Definition: compat.h:34
unsigned short VARTYPE
Definition: compat.h:2254
@ VT_BSTR
Definition: compat.h:2303
static REFPROPVARIANT PROPVAR_CHANGE_FLAGS VARTYPE vt
Definition: suminfo.c:86
#define FAILED(hr)
Definition: intsafe.h:51
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
#define V_VT(A)
Definition: oleauto.h:211
#define V_BSTR(A)
Definition: oleauto.h:226
static const WCHAR szName[]
Definition: powrprof.c:45
EXTERN_C DWORD WINAPI SHGetIniStringUTF7W(_In_opt_z_ LPCWSTR lpAppName, _In_z_ LPCWSTR lpKeyName, _Out_writes_to_(nSize, return+1) _Post_z_ LPWSTR lpReturnedString, _In_ DWORD nSize, _In_z_ LPCWSTR lpFileName)
Definition: propbag.cpp:722
#define MODE_CAN_READ(dwMode)
Definition: propbag.cpp:22
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:68
#define TRACE(s)
Definition: solgame.cpp:4
int32_t INT
Definition: typedefs.h:58
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:568
#define E_ACCESSDENIED
Definition: winerror.h:2849
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ Write()

STDMETHODIMP CIniPropertyBag::Write ( _In_z_ LPCWSTR  pszPropName,
_In_ VARIANT pvari 
)
override

Definition at line 899 of file propbag.cpp.

900{
901 TRACE("%p: %s %p\n", this, debugstr_w(pszPropName), pvari);
902
904 {
905 ERR("%p: 0x%X\n", this, m_dwMode);
906 return E_ACCESSDENIED;
907 }
908
909 HRESULT hr;
910 BSTR bstr;
911 VARIANTARG vargTemp = { 0 };
912 switch (V_VT(pvari))
913 {
914 case VT_EMPTY:
915 bstr = NULL;
916 break;
917
918 case VT_BSTR:
919 bstr = V_BSTR(pvari);
920 break;
921
922 default:
923 hr = ::VariantChangeType(&vargTemp, pvari, 0, VT_BSTR);
924 if (FAILED(hr))
925 goto Quit;
926
927 bstr = V_BSTR(&vargTemp);
928 break;
929 }
930
931 WCHAR szSection[64], szName[64];
932 hr = _GetSectionAndName(pszPropName, szSection, _countof(szSection), szName, _countof(szName));
933 if (SUCCEEDED(hr))
934 {
935 if (SHSetIniStringUTF7W(szSection, szName, bstr, m_pszFileName))
936 {
939 }
940 else
941 {
942 hr = E_FAIL;
943 }
944 }
945
946Quit:
947 ::VariantClear(&vargTemp);
948 return hr;
949}
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
@ VT_EMPTY
Definition: compat.h:2295
#define SUCCEEDED(hr)
Definition: intsafe.h:50
EXTERN_C BOOL WINAPI SHSetIniStringUTF7W(_In_z_ LPCWSTR lpAppName, _In_z_ LPCWSTR lpKeyName, _In_opt_z_ LPCWSTR lpString, _In_z_ LPCWSTR lpFileName)
Definition: propbag.cpp:748
#define MODE_CAN_WRITE(dwMode)
Definition: propbag.cpp:24
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1821
#define SHCNF_PATHW
Definition: shlobj.h:1843
HRESULT WINAPI DECLSPEC_HOTPATCH VariantChangeType(VARIANTARG *pvargDest, VARIANTARG *pvargSrc, USHORT wFlags, VARTYPE vt)
Definition: variant.c:962
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648

Member Data Documentation

◆ m_bAlternateStream

BOOL CIniPropertyBag::m_bAlternateStream
protected

Definition at line 765 of file propbag.cpp.

Referenced by Init(), and Write().

◆ m_pszFileName

LPWSTR CIniPropertyBag::m_pszFileName
protected

Definition at line 763 of file propbag.cpp.

Referenced by Init(), Read(), Write(), and ~CIniPropertyBag().

◆ m_pszSection

LPWSTR CIniPropertyBag::m_pszSection
protected

Definition at line 764 of file propbag.cpp.

Referenced by _GetSectionAndName(), Init(), and ~CIniPropertyBag().


The documentation for this class was generated from the following file: