3e406f7a6aaa2cee31f37042e7d9ae103abc1151
[reactos.git] / reactos / subsys / system / services / config.c
1 /*
2 * config.c
3 */
4
5 /* INCLUDES *****************************************************************/
6
7 #include "services.h"
8
9 #define NDEBUG
10 #include <debug.h>
11
12 /* FUNCTIONS *****************************************************************/
13
14 DWORD
15 ScmWriteDependencies(HKEY hServiceKey,
16 LPWSTR lpDependencies,
17 DWORD dwDependenciesLength)
18 {
19 DWORD dwError = ERROR_SUCCESS;
20 DWORD dwGroupLength = 0;
21 DWORD dwServiceLength = 0;
22 DWORD dwLength;
23 LPWSTR lpGroupDeps;
24 LPWSTR lpServiceDeps;
25 LPWSTR lpSrc;
26 LPWSTR lpDst;
27
28 if (*lpDependencies == 0)
29 {
30 RegDeleteValue(hServiceKey,
31 L"DependOnService");
32 RegDeleteValue(hServiceKey,
33 L"DependOnGroup");
34 }
35 else
36 {
37 lpGroupDeps = HeapAlloc(GetProcessHeap(),
38 HEAP_ZERO_MEMORY,
39 (dwDependenciesLength + 2) * sizeof(WCHAR));
40 if (lpGroupDeps == NULL)
41 return ERROR_NOT_ENOUGH_MEMORY;
42
43 lpSrc = lpDependencies;
44 lpDst = lpGroupDeps;
45 while (*lpSrc != 0)
46 {
47 dwLength = wcslen(lpSrc);
48 if (*lpSrc == SC_GROUP_IDENTIFIERW)
49 {
50 lpSrc++;
51 dwGroupLength += dwLength;
52 wcscpy(lpDst, lpSrc);
53 lpDst = lpDst + dwLength;
54 }
55
56 lpSrc = lpSrc + dwLength;
57 }
58 *lpDst = 0;
59 lpDst++;
60 dwGroupLength++;
61
62 lpSrc = lpDependencies;
63 lpServiceDeps = lpDst;
64 while (*lpSrc != 0)
65 {
66 dwLength = wcslen(lpSrc) + 1;
67 if (*lpSrc != SC_GROUP_IDENTIFIERW)
68 {
69 dwServiceLength += dwLength;
70 wcscpy(lpDst, lpSrc);
71 lpDst = lpDst + dwLength;
72 }
73
74 lpSrc = lpSrc + dwLength;
75 }
76 *lpDst = 0;
77 dwServiceLength++;
78
79 dwError = RegSetValueExW(hServiceKey,
80 L"DependOnGroup",
81 0,
82 REG_MULTI_SZ,
83 (LPBYTE)lpGroupDeps,
84 dwGroupLength * sizeof(WCHAR));
85
86 if (dwError == ERROR_SUCCESS)
87 {
88 dwError = RegSetValueExW(hServiceKey,
89 L"DependOnService",
90 0,
91 REG_MULTI_SZ,
92 (LPBYTE)lpServiceDeps,
93 dwServiceLength * sizeof(WCHAR));
94 }
95
96 HeapFree(GetProcessHeap(), 0, lpGroupDeps);
97 }
98
99 return dwError;
100 }
101
102 /* EOF */
103