[FORMATTING] No code changes!
[reactos.git] / reactos / dll / win32 / advapi32 / misc / hwprofiles.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/advapi32/misc/hwprofiles.c
6 * PURPOSE: advapi32.dll Hardware Functions
7 * PROGRAMMER: Steven Edwards
8 * UPDATE HISTORY:
9 * 20042502
10 */
11
12 #include <advapi32.h>
13 #include <wine/debug.h>
14 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
15
16 /******************************************************************************
17 * GetCurrentHwProfileA [ADVAPI32.@]
18 *
19 * Get the current hardware profile.
20 *
21 * PARAMS
22 * lpHwProfileInfo [O] Destination for hardware profile information.
23 *
24 * RETURNS
25 * Success: TRUE. lpHwProfileInfo is updated with the hardware profile details.
26 * Failure: FALSE.
27 *
28 * @implemented
29 */
30 BOOL STDCALL
31 GetCurrentHwProfileA(LPHW_PROFILE_INFOA lpHwProfileInfo)
32 {
33 HW_PROFILE_INFOW ProfileInfo;
34 UNICODE_STRING StringU;
35 ANSI_STRING StringA;
36 BOOL bResult;
37 NTSTATUS Status;
38
39 TRACE("GetCurrentHwProfileA() called\n");
40
41 bResult = GetCurrentHwProfileW(&ProfileInfo);
42 if (bResult == FALSE)
43 return FALSE;
44
45 lpHwProfileInfo->dwDockInfo = ProfileInfo.dwDockInfo;
46
47 /* Convert the profile GUID to ANSI */
48 StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileGuid;
49 StringU.Length = wcslen(ProfileInfo.szHwProfileGuid) * sizeof(WCHAR);
50 StringU.MaximumLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
51 StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileGuid;
52 StringA.Length = 0;
53 StringA.MaximumLength = HW_PROFILE_GUIDLEN;
54 Status = RtlUnicodeStringToAnsiString(&StringA,
55 &StringU,
56 FALSE);
57 if (!NT_SUCCESS(Status))
58 {
59 SetLastError(RtlNtStatusToDosError(Status));
60 return FALSE;
61 }
62
63 /* Convert the profile name to ANSI */
64 StringU.Buffer = (PWCHAR)ProfileInfo.szHwProfileName;
65 StringU.Length = wcslen(ProfileInfo.szHwProfileName) * sizeof(WCHAR);
66 StringU.MaximumLength = MAX_PROFILE_LEN * sizeof(WCHAR);
67 StringA.Buffer = (PCHAR)&lpHwProfileInfo->szHwProfileName;
68 StringA.Length = 0;
69 StringA.MaximumLength = MAX_PROFILE_LEN;
70 Status = RtlUnicodeStringToAnsiString(&StringA,
71 &StringU,
72 FALSE);
73 if (!NT_SUCCESS(Status))
74 {
75 SetLastError(RtlNtStatusToDosError(Status));
76 return FALSE;
77 }
78
79 return TRUE;
80 }
81
82
83 /*
84 * @implemented
85 */
86 BOOL STDCALL
87 GetCurrentHwProfileW(LPHW_PROFILE_INFOW lpHwProfileInfo)
88 {
89 WCHAR szKeyName[256];
90 HKEY hDbKey;
91 HKEY hProfileKey;
92 DWORD dwLength;
93 DWORD dwConfigId;
94
95 TRACE("GetCurrentHwProfileW() called\n");
96
97 if (lpHwProfileInfo == NULL)
98 {
99 SetLastError(ERROR_INVALID_PARAMETER);
100 return FALSE;
101 }
102
103 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
104 L"System\\CurrentControlSet\\Control\\IDConfigDB",
105 0,
106 KEY_QUERY_VALUE,
107 &hDbKey))
108 {
109 SetLastError(ERROR_REGISTRY_CORRUPT);
110 return FALSE;
111 }
112
113 dwLength = sizeof(DWORD);
114 if (RegQueryValueExW(hDbKey,
115 L"CurrentConfig",
116 0,
117 NULL,
118 (LPBYTE)&dwConfigId,
119 &dwLength))
120 {
121 RegCloseKey(hDbKey);
122 SetLastError(ERROR_REGISTRY_CORRUPT);
123 return FALSE;
124 }
125
126 swprintf(szKeyName,
127 L"Hardware Profile\\%04lu",
128 dwConfigId);
129
130 if (RegOpenKeyExW(hDbKey,
131 szKeyName,
132 0,
133 KEY_QUERY_VALUE | KEY_SET_VALUE,
134 &hProfileKey))
135 {
136 RegCloseKey(hDbKey);
137 SetLastError(ERROR_REGISTRY_CORRUPT);
138 return FALSE;
139 }
140
141 dwLength = sizeof(DWORD);
142 if (RegQueryValueExW(hProfileKey,
143 L"DockState",
144 0,
145 NULL,
146 (LPBYTE)&lpHwProfileInfo->dwDockInfo,
147 &dwLength))
148 {
149 lpHwProfileInfo->dwDockInfo =
150 DOCKINFO_DOCKED | DOCKINFO_UNDOCKED | DOCKINFO_USER_SUPPLIED;
151 }
152
153 dwLength = HW_PROFILE_GUIDLEN * sizeof(WCHAR);
154 if (RegQueryValueExW(hProfileKey,
155 L"HwProfileGuid",
156 0,
157 NULL,
158 (LPBYTE)&lpHwProfileInfo->szHwProfileGuid,
159 &dwLength))
160 {
161 /* FIXME: Create a new GUID */
162 wcscpy(lpHwProfileInfo->szHwProfileGuid,
163 L"{00000000-0000-0000-0000-000000000000}");
164
165 dwLength = (wcslen(lpHwProfileInfo->szHwProfileGuid) + 1) * sizeof(WCHAR);
166 RegSetValueExW(hProfileKey,
167 L"HwProfileGuid",
168 0,
169 REG_SZ,
170 (LPBYTE)lpHwProfileInfo->szHwProfileGuid,
171 dwLength);
172 }
173
174 dwLength = MAX_PROFILE_LEN * sizeof(WCHAR);
175 if (RegQueryValueExW(hProfileKey,
176 L"FriendlyName",
177 0,
178 NULL,
179 (LPBYTE)&lpHwProfileInfo->szHwProfileName,
180 &dwLength))
181 {
182 wcscpy(lpHwProfileInfo->szHwProfileName,
183 L"Noname Hardware Profile");
184 dwLength = (wcslen(lpHwProfileInfo->szHwProfileName) + 1) * sizeof(WCHAR);
185 RegSetValueExW(hProfileKey,
186 L"FriendlyName",
187 0,
188 REG_SZ,
189 (LPBYTE)lpHwProfileInfo->szHwProfileName,
190 dwLength);
191 }
192
193 RegCloseKey(hProfileKey);
194 RegCloseKey(hDbKey);
195
196 return TRUE;
197 }
198
199 /* EOF */