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

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

setcurrentdir fix + create shell dirs + keys during kernel32 init

File size: 8.0 KB
Line 
1/* $Id: initsystem.cpp,v 1.5 2000-03-02 19:17:21 sandervl Exp $ */
2/*
3 * Odin system initialization (registry & directories)
4 *
5 *
6 * NOTE: Most of this has to be moved into the Odin install program!!!!!
7 *
8 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
9 *
10 */
11
12#include <os2win.h>
13#include <ctype.h>
14#include <string.h>
15#include "winreg.h"
16#include "global.h"
17#include "winnt.h"
18#include "winerror.h"
19#include "winreg.h"
20#include "debugtools.h"
21#include "cpuhlp.h"
22#include "initsystem.h"
23#include "directory.h"
24#include <versionos2.h>
25
26#define DBG_LOCALLOG DBG_initsystem
27#include "dbglocal.h"
28
29static HINSTANCE hInstance = 0;
30
31BOOL InitRegistry();
32
33LONG (WIN32API *ADVAPI32_RegCloseKey)(HKEY) = 0;
34LONG (WIN32API *ADVAPI32_RegOpenKeyA)(HKEY,LPCSTR,LPHKEY) = 0;
35LONG (WIN32API *ADVAPI32_RegCreateKeyA)(HKEY,LPCSTR,LPHKEY) = 0;
36LONG (WIN32API *ADVAPI32_RegSetValueExA)(HKEY,LPSTR,DWORD,DWORD,LPBYTE,DWORD) = 0;
37
38//******************************************************************************
39//******************************************************************************
40BOOL InitSystemEnvironment(ULONG nrCPUs)
41{
42 hInstance = LoadLibraryA("ADVAPI32.DLL");
43 if(hInstance) {
44 *(VOID **)&ADVAPI32_RegCloseKey=(void*)GetProcAddress(hInstance, (LPCSTR)"RegCloseKey");
45 *(VOID **)&ADVAPI32_RegOpenKeyA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegOpenKeyA");
46 *(VOID **)&ADVAPI32_RegCreateKeyA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegCreateKeyA");
47 *(VOID **)&ADVAPI32_RegSetValueExA=(void*)GetProcAddress(hInstance, (LPCSTR)"RegSetValueExA");
48 }
49 InitSystemInfo(nrCPUs);
50 return InitRegistry();
51}
52//******************************************************************************
53//[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows]
54//"Directory"=hex(2):25,53,79,73,74,65,6d,52,6f,6f,74,25,00
55//"SystemDirectory"=hex(2):25,53,79,73,74,65,6d,52,6f,6f,74,25,5c,73,79,73,74,65,\
56// 6d,33,32,00
57//"ErrorMode"=dword:00000000
58//"NoInteractiveServices"=dword:00000000
59//"CSDVersion"=dword:00000300
60BYTE ShutdownTime[] = {0x44,0x5e,0xf2,0xbb,0x84,0x41,0xbf,0x01};
61//******************************************************************************
62BOOL InitRegistry()
63{
64 HKEY hkey;
65 char *buf;
66 DWORD val;
67 char digbuf[16];
68
69 if(ADVAPI32_RegCreateKeyA(HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\Windows",&hkey)!=ERROR_SUCCESS) {
70 dprintf(("InitRegistry: Unable to register system information\n"));
71 return FALSE;
72 }
73 buf = InternalGetWindowsDirectoryA();
74 ADVAPI32_RegSetValueExA(hkey,"Directory",0,REG_BINARY, (LPBYTE)buf, strlen(buf)+1);
75 buf = InternalGetSystemDirectoryA();
76 ADVAPI32_RegSetValueExA(hkey,"SystemDirectory",0,REG_BINARY, (LPBYTE)buf, strlen(buf)+1);
77 val = 0;
78 ADVAPI32_RegSetValueExA(hkey,"ErrorMode",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
79 val = 0;
80 ADVAPI32_RegSetValueExA(hkey,"NoInteractiveServices",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
81 val = ODINNT_BUILD_NR;
82 ADVAPI32_RegSetValueExA(hkey,"CSDVersion",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
83 ADVAPI32_RegSetValueExA(hkey,"ShutdownTime",0,REG_DWORD, (LPBYTE)ShutdownTime, sizeof(ShutdownTime));
84 ADVAPI32_RegCloseKey(hkey);
85
86 if(ADVAPI32_RegCreateKeyA(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",&hkey)!=ERROR_SUCCESS) {
87 dprintf(("InitRegistry: Unable to register system information (2)"));
88 return FALSE;
89 }
90 buf = InternalGetSystemDirectoryA();
91 ADVAPI32_RegSetValueExA(hkey,"SystemRoot",0,REG_SZ, (LPBYTE)buf, strlen(buf)+1);
92 ADVAPI32_RegSetValueExA(hkey,"PathName",0,REG_SZ, (LPBYTE)buf, strlen(buf)+1);
93 sprintf(digbuf, "%d", ODINNT_BUILD_NR);
94 ADVAPI32_RegSetValueExA(hkey,"CurrentBuildNumber",0,REG_SZ, (LPBYTE)digbuf, strlen(digbuf)+1);
95 ADVAPI32_RegSetValueExA(hkey,"CurrentType",0,REG_SZ, (LPBYTE)ODINNT_OSTYPE_UNI, sizeof(ODINNT_OSTYPE_UNI));
96 ADVAPI32_RegSetValueExA(hkey,"CSDVersion",0,REG_SZ, (LPBYTE)ODINNT_CSDVERSION, sizeof(ODINNT_CSDVERSION));
97 ADVAPI32_RegSetValueExA(hkey,"SoftwareType",0,REG_SZ, (LPBYTE)ODINNT_SOFTWARE_TYPE, sizeof(ODINNT_SOFTWARE_TYPE));
98
99 sprintf(digbuf, "%d.%d", ODINNT_MAJOR_VERSION, ODINNT_MINOR_VERSION);
100 ADVAPI32_RegSetValueExA(hkey,"CurrentVersion",0,REG_SZ, (LPBYTE)digbuf, strlen(digbuf)+1);
101
102 val = (DWORD)time(NULL); //todo: Correct format???
103 ADVAPI32_RegSetValueExA(hkey,"InstallDate",0,REG_DWORD, (LPBYTE)&val, sizeof(DWORD));
104
105 ADVAPI32_RegCloseKey(hkey);
106 //todo: productid, registered org/owner, sourcepath,
107
108 //Create Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders keys
109 //"Favorites"="C:\WINDOWS\Favorites"
110 //"StartUp"="C:\WINDOWS\Start Menu\Programs\Startup"
111 //"Desktop"="C:\WINDOWS\Desktop"
112 //"Programs"="C:\WINDOWS\Start Menu\Programs"
113 //"Fonts"="C:\WINDOWS\Fonts"
114 //"SendTo"="C:\WINDOWS\SendTo"
115 //"Start Menu"="C:\WINDOWS\Start Menu"
116 //"Templates"="C:\WINDOWS\ShellNew"
117 //"Recent"="C:\WINDOWS\Recent"
118 //"NetHood"="C:\WINDOWS\NetHood"
119 //"Personal"="C:\My Documents"
120
121 char shellpath[260];
122
123 if(ADVAPI32_RegOpenKeyA(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hkey) != ERROR_SUCCESS)
124 {
125 if(ADVAPI32_RegCreateKeyA(HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",&hkey)!=ERROR_SUCCESS) {
126 dprintf(("InitRegistry: Unable to register system information (3)"));
127 return FALSE;
128 }
129 strcpy(shellpath, InternalGetSystemDirectoryA());
130 strcat(shellpath, "\\Favorites");
131 CreateDirectoryA(shellpath, NULL);
132 ADVAPI32_RegSetValueExA(hkey,"Favorites",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
133 strcpy(shellpath, InternalGetSystemDirectoryA());
134 strcat(shellpath, "\\Programs\\Startup");
135 CreateDirectoryA(shellpath, NULL);
136 ADVAPI32_RegSetValueExA(hkey,"Startup",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
137 strcpy(shellpath, InternalGetSystemDirectoryA());
138 strcat(shellpath, "\\Desktop");
139 CreateDirectoryA(shellpath, NULL);
140 ADVAPI32_RegSetValueExA(hkey,"Desktop",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
141 strcpy(shellpath, InternalGetSystemDirectoryA());
142 strcat(shellpath, "\\Start Menu\\Programs");
143 CreateDirectoryA(shellpath, NULL);
144 ADVAPI32_RegSetValueExA(hkey,"Programs",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
145 strcpy(shellpath, InternalGetSystemDirectoryA());
146 strcat(shellpath, "\\Fonts");
147 CreateDirectoryA(shellpath, NULL);
148 ADVAPI32_RegSetValueExA(hkey,"Fonts",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
149 strcpy(shellpath, InternalGetSystemDirectoryA());
150 strcat(shellpath, "\\SendTo");
151 CreateDirectoryA(shellpath, NULL);
152 ADVAPI32_RegSetValueExA(hkey,"SendTo",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
153 strcpy(shellpath, InternalGetSystemDirectoryA());
154 strcat(shellpath, "\\Start Menu");
155 CreateDirectoryA(shellpath, NULL);
156 ADVAPI32_RegSetValueExA(hkey,"Start Menu",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
157 strcpy(shellpath, InternalGetSystemDirectoryA());
158 strcat(shellpath, "\\ShellNew");
159 CreateDirectoryA(shellpath, NULL);
160 ADVAPI32_RegSetValueExA(hkey,"Templates",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
161 strcpy(shellpath, InternalGetSystemDirectoryA());
162 strcat(shellpath, "\\Recent");
163 CreateDirectoryA(shellpath, NULL);
164 ADVAPI32_RegSetValueExA(hkey,"Recent",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
165 strcpy(shellpath, InternalGetSystemDirectoryA());
166 strcat(shellpath, "\\NetHood");
167 CreateDirectoryA(shellpath, NULL);
168 ADVAPI32_RegSetValueExA(hkey,"NetHood",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
169 strcpy(shellpath, InternalGetSystemDirectoryA());
170 strcat(shellpath, "\\My Documents");
171 CreateDirectoryA(shellpath, NULL);
172 ADVAPI32_RegSetValueExA(hkey,"Personal",0,REG_SZ, (LPBYTE)shellpath, strlen(shellpath)+1);
173 }
174 ADVAPI32_RegCloseKey(hkey);
175 return TRUE;
176}
177//******************************************************************************
178//******************************************************************************
Note: See TracBrowser for help on using the repository browser.