source: trunk/src/kernel32/initsystem.cpp@ 3461

Last change on this file since 3461 was 3461, checked in by sandervl, 25 years ago

init changes, export for installation program, create additional directories & registry keys, added lvl2 debug log feature, override for windows dir re-added

File size: 13.4 KB
Line 
1/* $Id: initsystem.cpp,v 1.9 2000-04-29 18:26:58 sandervl Exp $ */
2/*
3 * Odin system initialization (registry & directories)
4 *
5 * Called from the WarpIn install program to create the desktop directories and
6 * to setup the registry
7 *
8 * InitSystemAndRegistry creates:
9 * - WINDOWSDIR\SYSTEM
10 * - WINDOWSDIR\AppData
11 * - WINDOWSDIR\Cache
12 * - WINDOWSDIR\Cookies
13 * - WINDOWSDIR\Desktop
14 * - WINDOWSDIR\Favorites
15 * - WINDOWSDIR\Fonts
16 * - WINDOWSDIR\History
17 * - WINDOWSDIR\NetHood
18 * - WINDOWSDIR\My Documents
19 * - WINDOWSDIR\PrintHood
20 * - WINDOWSDIR\Recent
21 * - WINDOWSDIR\SendTo
22 * - WINDOWSDIR\Start Menu
23 * - WINDOWSDIR\Start Menu\Programs
24 * - WINDOWSDIR\Start Menu\Programs\Startup
25 * - WINDOWSDIR\ShellNew
26 * - and a minimal system registry
27 *
28 * NOTE: Most of this has to be moved into the Odin install program!!!!!
29 *
30 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
31 *
32 */
33
34#include <os2win.h>
35#include <ctype.h>
36#include <string.h>
37#include "winreg.h"
38#include "global.h"
39#include "winnt.h"
40#include "winerror.h"
41#include "winreg.h"
42#include "debugtools.h"
43#include "cpuhlp.h"
44#include <odininst.h>
45#include "directory.h"
46#include <versionos2.h>
47
48#define DBG_LOCALLOG DBG_initsystem
49#include "dbglocal.h"
50
51#define DDRAW_CLASSID "{D7B70EE0-4340-11CF-B063-0020AFC2CD35}"
52#define DDRAW_DEFAULT "DirectDraw Object"
53#define DDRAW_CLIPPER_CLASSID "{593817A0-7DB3-11CF-A2DE-00AA00B93356}"
54#define DDRAW_CLIPPER_DEFAULT "DirectDraw Clipper Object"
55#define DDRAW_DLL "ddraw.dll"
56#define DSOUND_CLASSID "{47D4D946-62E8-11cf-93BC-444553540000}"
57#define DSOUND_DEFAULT "DirectSound Object"
58#define DSOUND_DLL "dsound.dll"
59#define COM_CLASS_ID "CLSID"
60#define COM_INPROCSERVER "InprocServer32"
61#define COM_THREADMODEL "ThreadingModel"
62#define THREAD_BOTH "Both"
63#define INITREG_ERROR "InitRegistry: Unable to register system information"
64
65//******************************************************************************
66//******************************************************************************
67//******************************************************************************
68//[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows]
69//"Directory"=hex(2):25,53,79,73,74,65,6d,52,6f,6f,74,25,00
70//"SystemDirectory"=hex(2):25,53,79,73,74,65,6d,52,6f,6f,74,25,5c,73,79,73,74,65,\
71// 6d,33,32,00
72//"ErrorMode"=dword:00000000
73//"NoInteractiveServices"=dword:00000000
74//"CSDVersion"=dword:00000300
75BYTE ShutdownTime[] = {0x44,0x5e,0xf2,0xbb,0x84,0x41,0xbf,0x01};
76//******************************************************************************
77BOOL InitSystemAndRegistry()
78{
79 HKEY hkey, hkey1;
80 char *buf;
81 DWORD val;
82 char digbuf[16];
83
84 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Windows",&hkey)!=ERROR_SUCCESS) {
85 dprintf(("InitRegistry: Unable to register system information\n"));
86 return FALSE;
87 }
88 buf = InternalGetWindowsDirectoryA();
89 RegSetValueExA(hkey,"Directory",0,REG_BINARY, (LPBYTE)buf, strlen(buf)+1);
90 buf = InternalGetSystemDirectoryA();
91 RegSetValueExA(hkey,"SystemDirectory",0,REG_BINARY, (LPBYTE)buf, strlen(buf)+1);
92 val = 0;
93 RegSetValueExA(hkey,"ErrorMode",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
94 val = 0;
95 RegSetValueExA(hkey,"NoInteractiveServices",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
96 val = ODINNT_BUILD_NR;
97 RegSetValueExA(hkey,"CSDVersion",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
98 RegSetValueExA(hkey,"ShutdownTime",0,REG_DWORD, (LPBYTE)ShutdownTime, sizeof(ShutdownTime));
99 RegCloseKey(hkey);
100
101 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",&hkey)!=ERROR_SUCCESS) {
102 dprintf(("InitRegistry: Unable to register system information (2)"));
103 return FALSE;
104 }
105 buf = InternalGetSystemDirectoryA();
106 RegSetValueExA(hkey,"SystemRoot",0,REG_SZ, (LPBYTE)buf, strlen(buf)+1);
107 RegSetValueExA(hkey,"PathName",0,REG_SZ, (LPBYTE)buf, strlen(buf)+1);
108 sprintf(digbuf, "%d", ODINNT_BUILD_NR);
109 RegSetValueExA(hkey,"CurrentBuildNumber",0,REG_SZ, (LPBYTE)digbuf, strlen(digbuf)+1);
110 RegSetValueExA(hkey,"CurrentType",0,REG_SZ, (LPBYTE)ODINNT_OSTYPE_UNI, sizeof(ODINNT_OSTYPE_UNI));
111 RegSetValueExA(hkey,"CSDVersion",0,REG_SZ, (LPBYTE)ODINNT_CSDVERSION, sizeof(ODINNT_CSDVERSION));
112 RegSetValueExA(hkey,"SoftwareType",0,REG_SZ, (LPBYTE)ODINNT_SOFTWARE_TYPE, sizeof(ODINNT_SOFTWARE_TYPE));
113
114 sprintf(digbuf, "%d.%d", ODINNT_MAJOR_VERSION, ODINNT_MINOR_VERSION);
115 RegSetValueExA(hkey,"CurrentVersion",0,REG_SZ, (LPBYTE)digbuf, strlen(digbuf)+1);
116
117 val = (DWORD)time(NULL); //todo: Correct format???
118 RegSetValueExA(hkey,"InstallDate",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
119
120 RegCloseKey(hkey);
121 //todo: productid, registered org/owner, sourcepath,
122
123 //Create Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders keys
124 //"Favorites"="C:\WINDOWS\Favorites"
125 //"StartUp"="C:\WINDOWS\Start Menu\Programs\Startup"
126 //"Desktop"="C:\WINDOWS\Desktop"
127 //"Programs"="C:\WINDOWS\Start Menu\Programs"
128 //"Fonts"="C:\WINDOWS\Fonts"
129 //"SendTo"="C:\WINDOWS\SendTo"
130 //"Start Menu"="C:\WINDOWS\Start Menu"
131 //"Templates"="C:\WINDOWS\ShellNew"
132 //"Recent"="C:\WINDOWS\Recent"
133 //"NetHood"="C:\WINDOWS\NetHood"
134 //"Personal"="C:\My Documents"
135
136 char shellpath[260];
137
138 if(RegCreateKeyA(HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",&hkey)!=ERROR_SUCCESS) {
139 dprintf(("InitRegistry: Unable to register system information (3)"));
140 return FALSE;
141 }
142// if(RegOpenKeyA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hkey) != ERROR_SUCCESS)
143// {
144 //SYSTEM dir
145 strcpy(shellpath, InternalGetWindowsDirectoryA());
146 strcat(shellpath, "\\SYSTEM");
147 CreateDirectoryA(shellpath, NULL);
148
149 //AppData
150 strcpy(shellpath, InternalGetWindowsDirectoryA());
151 strcat(shellpath, "\\Application Data");
152 CreateDirectoryA(shellpath, NULL);
153 RegSetValueExA(hkey,"AppData",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
154 //Cache
155 strcpy(shellpath, InternalGetWindowsDirectoryA());
156 strcat(shellpath, "\\Temporary Internet Files");
157 CreateDirectoryA(shellpath, NULL);
158 RegSetValueExA(hkey,"Cache",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
159 //Cookies
160 strcpy(shellpath, InternalGetWindowsDirectoryA());
161 strcat(shellpath, "\\Cookies");
162 CreateDirectoryA(shellpath, NULL);
163 RegSetValueExA(hkey,"Cookies",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
164 //Desktop
165 strcpy(shellpath, InternalGetWindowsDirectoryA());
166 strcat(shellpath, "\\Desktop");
167 CreateDirectoryA(shellpath, NULL);
168 RegSetValueExA(hkey,"Desktop",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
169 //Favorites
170 strcpy(shellpath, InternalGetWindowsDirectoryA());
171 strcat(shellpath, "\\Favorites");
172 CreateDirectoryA(shellpath, NULL);
173 RegSetValueExA(hkey,"Favorites",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
174 //Fonts
175 strcpy(shellpath, InternalGetWindowsDirectoryA());
176 strcat(shellpath, "\\Fonts");
177 CreateDirectoryA(shellpath, NULL);
178 RegSetValueExA(hkey,"Fonts",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
179 //History
180 strcpy(shellpath, InternalGetWindowsDirectoryA());
181 strcat(shellpath, "\\History");
182 CreateDirectoryA(shellpath, NULL);
183 RegSetValueExA(hkey,"History",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
184 //NetHood
185 strcpy(shellpath, InternalGetWindowsDirectoryA());
186 strcat(shellpath, "\\NetHood");
187 CreateDirectoryA(shellpath, NULL);
188 RegSetValueExA(hkey,"NetHood",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
189 //Personal
190 strcpy(shellpath, InternalGetWindowsDirectoryA());
191 strcat(shellpath, "\\My Documents");
192 CreateDirectoryA(shellpath, NULL);
193 RegSetValueExA(hkey,"Personal",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
194 //PrintHood
195 strcpy(shellpath, InternalGetWindowsDirectoryA());
196 strcat(shellpath, "\\PrintHood");
197 CreateDirectoryA(shellpath, NULL);
198 RegSetValueExA(hkey,"PrintHood",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
199 //Recent
200 strcpy(shellpath, InternalGetWindowsDirectoryA());
201 strcat(shellpath, "\\Recent");
202 CreateDirectoryA(shellpath, NULL);
203 RegSetValueExA(hkey,"Recent",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
204 //SendTo
205 strcpy(shellpath, InternalGetWindowsDirectoryA());
206 strcat(shellpath, "\\SendTo");
207 CreateDirectoryA(shellpath, NULL);
208 RegSetValueExA(hkey,"SendTo",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
209 //Start Menu
210 strcpy(shellpath, InternalGetWindowsDirectoryA());
211 strcat(shellpath, "\\Start Menu");
212 CreateDirectoryA(shellpath, NULL);
213 RegSetValueExA(hkey,"Start Menu",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
214 //Programs
215 strcpy(shellpath, InternalGetWindowsDirectoryA());
216 strcat(shellpath, "\\Start Menu\\Programs");
217 CreateDirectoryA(shellpath, NULL);
218 RegSetValueExA(hkey,"Programs",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
219 //Startup
220 strcat(shellpath, "\\Startup");
221 CreateDirectoryA(shellpath, NULL);
222 RegSetValueExA(hkey,"Startup",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
223 //ShellNew
224 strcpy(shellpath, InternalGetWindowsDirectoryA());
225 strcat(shellpath, "\\ShellNew");
226 CreateDirectoryA(shellpath, NULL);
227 RegSetValueExA(hkey,"Templates",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
228// }
229 RegCloseKey(hkey);
230
231 //Now the Ddraw & dsound registry keys:
232 //HKEY_CLASSES_ROOT\DirectDraw = DirectDraw Object
233 //HKEY_CLASSES_ROOT\DirectDraw\CLSID = {D7B70EE0-4340-11CF-B063-0020AFC2CD35}
234 //HKEY_CLASSES_ROOT\CLSID\{D7B70EE0-4340-11CF-B063-0020AFC2CD35} = DirectDraw Object
235 //HKEY_CLASSES_ROOT\CLSID\{D7B70EE0-4340-11CF-B063-0020AFC2CD35}\InprocServer32 = ddraw.dll
236 if(RegCreateKeyA(HKEY_CLASSES_ROOT,"DirectDraw",&hkey)!=ERROR_SUCCESS) {
237 goto initreg_error;
238 }
239 RegSetValueExA(hkey, "", 0, REG_SZ, (LPBYTE)DDRAW_DEFAULT, sizeof(DDRAW_DEFAULT));
240 if(RegCreateKeyA(hkey,COM_CLASS_ID,&hkey1)!=ERROR_SUCCESS) {
241 RegCloseKey(hkey);
242 goto initreg_error;
243 }
244 RegSetValueExA(hkey1,"",0,REG_SZ, (LPBYTE)DDRAW_CLASSID, sizeof(DDRAW_CLASSID));
245 RegCloseKey(hkey1);
246 RegCloseKey(hkey);
247
248 if(RegCreateKeyA(HKEY_CLASSES_ROOT, COM_CLASS_ID"\\"DDRAW_CLASSID ,&hkey)!=ERROR_SUCCESS) {
249 goto initreg_error;
250 }
251 RegSetValueExA(hkey,"",0,REG_SZ, (LPBYTE)DDRAW_DEFAULT, sizeof(DDRAW_DEFAULT));
252 if(RegCreateKeyA(hkey,COM_INPROCSERVER, &hkey1)!=ERROR_SUCCESS) {
253 RegCloseKey(hkey);
254 goto initreg_error;
255 }
256 RegSetValueExA(hkey1,"",0,REG_SZ, (LPBYTE)DDRAW_DLL, sizeof(DDRAW_DLL));
257 RegSetValueExA(hkey1, COM_THREADMODEL, 0,REG_SZ, (LPBYTE)THREAD_BOTH, sizeof(THREAD_BOTH));
258 RegCloseKey(hkey1);
259 RegCloseKey(hkey);
260
261 //HKEY_CLASSES_ROOT\DirectDrawClipper = DirectDraw Clipper Object
262 //HKEY_CLASSES_ROOT\DirectDrawClipper\CLSID = {593817A0-7DB3-11CF-A2DE-00AA00B93356}
263 //HKEY_CLASSES_ROOT\CLSID\{593817A0-7DB3-11CF-A2DE-00AA00B93356} = DirectDraw Clipper Object
264 //HKEY_CLASSES_ROOT\CLSID\{593817A0-7DB3-11CF-A2DE-00AA00B93356}\InprocServer32 = ddraw.dll
265 if(RegCreateKeyA(HKEY_CLASSES_ROOT,"DirectDrawClipper",&hkey)!=ERROR_SUCCESS) {
266 goto initreg_error;
267 }
268 RegSetValueExA(hkey,"",0,REG_SZ, (LPBYTE)DDRAW_CLIPPER_DEFAULT, sizeof(DDRAW_CLIPPER_DEFAULT));
269 if(RegCreateKeyA(hkey,COM_CLASS_ID,&hkey1)!=ERROR_SUCCESS) {
270 RegCloseKey(hkey);
271 goto initreg_error;
272 }
273 RegSetValueExA(hkey1,"",0,REG_SZ, (LPBYTE)DDRAW_CLIPPER_CLASSID, sizeof(DDRAW_CLIPPER_CLASSID));
274 RegCloseKey(hkey1);
275 RegCloseKey(hkey);
276
277 if(RegCreateKeyA(HKEY_CLASSES_ROOT, COM_CLASS_ID"\\"DDRAW_CLIPPER_CLASSID,&hkey)!=ERROR_SUCCESS) {
278 goto initreg_error;
279 }
280 RegSetValueExA(hkey,"",0,REG_SZ, (LPBYTE)DDRAW_CLIPPER_DEFAULT, sizeof(DDRAW_CLIPPER_DEFAULT));
281 if(RegCreateKeyA(hkey,COM_INPROCSERVER, &hkey1)!=ERROR_SUCCESS) {
282 RegCloseKey(hkey);
283 goto initreg_error;
284 }
285 RegSetValueExA(hkey1,"",0,REG_SZ, (LPBYTE)DDRAW_DLL, sizeof(DDRAW_DLL));
286 RegSetValueExA(hkey1, COM_THREADMODEL, 0,REG_SZ, (LPBYTE)THREAD_BOTH, sizeof(THREAD_BOTH));
287 RegCloseKey(hkey1);
288 RegCloseKey(hkey);
289
290 //HKEY_CLASSES_ROOT\DirectSound = DirectSound Object
291 //HKEY_CLASSES_ROOT\DirectSound\CLSID = {47D4D946-62E8-11cf-93BC-444553540000}
292 //HKEY_CLASSES_ROOT\CLSID\{47D4D946-62E8-11cf-93BC-444553540000} = DirectSound Object
293 //HKEY_CLASSES_ROOT\CLSID\{47D4D946-62E8-11cf-93BC-444553540000}\InprocServer32 = dsound.dll
294 if(RegCreateKeyA(HKEY_CLASSES_ROOT,"DirectSound",&hkey)!=ERROR_SUCCESS) {
295 goto initreg_error;
296 }
297 RegSetValueExA(hkey,"",0,REG_SZ, (LPBYTE)DSOUND_DEFAULT, sizeof(DSOUND_DEFAULT));
298 if(RegCreateKeyA(hkey,COM_CLASS_ID,&hkey1)!=ERROR_SUCCESS) {
299 RegCloseKey(hkey);
300 goto initreg_error;
301 }
302 RegSetValueExA(hkey1,"",0,REG_SZ, (LPBYTE)DSOUND_CLASSID, sizeof(DSOUND_CLASSID));
303 RegCloseKey(hkey1);
304 RegCloseKey(hkey);
305
306 if(RegCreateKeyA(HKEY_CLASSES_ROOT, COM_CLASS_ID"\\"DSOUND_CLASSID ,&hkey)!=ERROR_SUCCESS) {
307 goto initreg_error;
308 }
309 RegSetValueExA(hkey,"",0,REG_SZ, (LPBYTE)DSOUND_DEFAULT, sizeof(DSOUND_DEFAULT));
310 if(RegCreateKeyA(hkey,COM_INPROCSERVER, &hkey1)!=ERROR_SUCCESS) {
311 RegCloseKey(hkey);
312 goto initreg_error;
313 }
314 RegSetValueExA(hkey1,"",0,REG_SZ, (LPBYTE)DSOUND_DLL, sizeof(DSOUND_DLL));
315 RegSetValueExA(hkey1, COM_THREADMODEL, 0,REG_SZ, (LPBYTE)THREAD_BOTH, sizeof(THREAD_BOTH));
316 RegCloseKey(hkey1);
317 RegCloseKey(hkey);
318 return TRUE;
319
320initreg_error:
321 dprintf((INITREG_ERROR));
322 return FALSE;
323}
324//******************************************************************************
325//******************************************************************************
Note: See TracBrowser for help on using the repository browser.