1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006,2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 //////////////////////////////////////////////////////////////////////////////////////////////
29 CRegBase::CRegBase (const CString
& key
, bool force
, HKEY base
)
30 : CRegBaseCommon
<CString
> (key
, force
, base
)
32 m_key
.TrimLeft(_T("\\"));
33 int backslashpos
= m_key
.ReverseFind('\\');
34 m_path
= m_key
.Left(backslashpos
);
35 m_path
.TrimRight(_T("\\"));
36 m_key
= m_key
.Mid(backslashpos
);
41 //////////////////////////////////////////////////////////////////////////////////////////////
43 CRegStdBase::CRegStdBase()
47 CRegStdBase::CRegStdBase (const stdstring
& key
, bool force
, HKEY base
)
48 : CRegBaseCommon
<stdstring
> (key
, force
, base
)
50 stdstring::size_type pos
= key
.find_last_of(_T('\\'));
51 m_path
= key
.substr(0, pos
);
52 m_key
= key
.substr(pos
+ 1);
55 //////////////////////////////////////////////////////////////////////////////////////////////
57 #ifdef __ATLTYPES_H__ // defines CRect
58 CRegRect::CRegRect(void)
59 : CRegTypedBase
<CRect
, CRegBase
>(CRect(0,0,0,0))
63 CRegRect::CRegRect(const CString
& key
, const CRect
& def
, bool force
, HKEY base
)
64 : CRegTypedBase
<CRect
, CRegBase
> (key
, def
, force
, base
)
69 void CRegRect::InternalRead (HKEY hKey
, CRect
& value
)
73 RegQueryValueEx(hKey
, m_key
, NULL
, &type
, NULL
, (LPDWORD
) &size
);
75 std::auto_ptr
<char> buffer (new char[size
]);
76 if ((LastError
= RegQueryValueEx(hKey
, m_key
, NULL
, &type
, (BYTE
*) buffer
.get(), &size
))==ERROR_SUCCESS
)
78 ASSERT(type
==REG_BINARY
);
79 value
= CRect((LPRECT
)buffer
.get());
83 void CRegRect::InternalWrite (HKEY hKey
, const CRect
& value
)
85 LastError
= RegSetValueEx(hKey
, m_key
, 0, REG_BINARY
, (BYTE
*)(LPCRECT
)value
, sizeof(value
));
90 //////////////////////////////////////////////////////////////////////////////////////////////
92 #ifdef __ATLTYPES_H__ // defines CPoint
93 CRegPoint::CRegPoint(void)
94 : CRegTypedBase
<CPoint
, CRegBase
>(CPoint(0,0))
98 CRegPoint::CRegPoint(const CString
& key
, const CPoint
& def
, bool force
, HKEY base
)
99 : CRegTypedBase
<CPoint
, CRegBase
> (key
, def
, force
, base
)
104 void CRegPoint::InternalRead (HKEY hKey
, CPoint
& value
)
108 RegQueryValueEx(hKey
, m_key
, NULL
, &type
, NULL
, (LPDWORD
) &size
);
110 std::auto_ptr
<char> buffer(new char[size
]);
111 if ((LastError
= RegQueryValueEx(hKey
, m_key
, NULL
, &type
, (BYTE
*) buffer
.get(), &size
))==ERROR_SUCCESS
)
113 ASSERT(type
==REG_BINARY
);
114 value
= CPoint(*(POINT
*)buffer
.get());
118 void CRegPoint::InternalWrite (HKEY hKey
, const CPoint
& value
)
120 LastError
= RegSetValueEx(hKey
, m_key
, 0, REG_BINARY
, (BYTE
*)&value
, sizeof(value
));
124 /////////////////////////////////////////////////////////////////////
126 #ifdef __AFXCOLL_H__ // defines CStringList
127 CRegistryKey::CRegistryKey(const CString
& key
, HKEY base
)
132 m_path
.TrimLeft(_T("\\"));
135 CRegistryKey::~CRegistryKey()
141 DWORD
CRegistryKey::createKey()
144 DWORD rc
= RegCreateKeyEx(m_base
, m_path
, 0, _T(""), REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &m_hKey
, &disp
);
145 if (rc
!= ERROR_SUCCESS
)
149 return RegCloseKey(m_hKey
);
152 DWORD
CRegistryKey::removeKey()
154 RegOpenKeyEx(m_base
, m_path
, 0, KEY_WRITE
, &m_hKey
);
155 return SHDeleteKey(m_base
, (LPCTSTR
)m_path
);
158 bool CRegistryKey::getValues(CStringList
& values
)
162 if (RegOpenKeyEx(m_base
, m_path
, 0, KEY_EXECUTE
, &m_hKey
)==ERROR_SUCCESS
)
164 for (int i
= 0, rc
= ERROR_SUCCESS
; rc
== ERROR_SUCCESS
; i
++)
167 DWORD size
= sizeof value
/ sizeof TCHAR
;
168 rc
= RegEnumValue(m_hKey
, i
, value
, &size
, NULL
, NULL
, NULL
, NULL
);
169 if (rc
== ERROR_SUCCESS
)
171 values
.AddTail(value
);
176 return values
.GetCount() > 0;
179 bool CRegistryKey::getSubKeys(CStringList
& subkeys
)
183 if (RegOpenKeyEx(m_base
, m_path
, 0, KEY_EXECUTE
, &m_hKey
)==ERROR_SUCCESS
)
185 for (int i
= 0, rc
= ERROR_SUCCESS
; rc
== ERROR_SUCCESS
; i
++)
188 DWORD size
= sizeof value
/ sizeof TCHAR
;
189 FILETIME last_write_time
;
190 rc
= RegEnumKeyEx(m_hKey
, i
, value
, &size
, NULL
, NULL
, NULL
, &last_write_time
);
191 if (rc
== ERROR_SUCCESS
)
193 subkeys
.AddTail(value
);
198 return subkeys
.GetCount() > 0;