acea97fb1d560c6f220c102ce5438c2921d3f0b2
[reactos.git] / reactos / tools / mkhive / mkhive.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
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.
14 *
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
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: mkhive.c,v 1.5 2004/11/15 19:20:23 gdalsnes Exp $
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS hive maker
22 * FILE: tools/mkhive/mkhive.c
23 * PURPOSE: Hive maker
24 * PROGRAMMER: Eric Kohl
25 */
26
27 #include <limits.h>
28 #include <string.h>
29 #include <stdio.h>
30
31 #include "mkhive.h"
32 #include "registry.h"
33 #include "reginf.h"
34 #include "binhive.h"
35
36 #ifndef WIN32
37 #ifndef PATH_MAX
38 #define PATH_MAX 260
39 #endif
40 #define DIR_SEPARATOR_CHAR '/'
41 #define DIR_SEPARATOR_STRING "/"
42 #else
43 #define DIR_SEPARATOR_CHAR '\\'
44 #define DIR_SEPARATOR_STRING "\\"
45 #endif
46
47
48 void usage (void)
49 {
50 printf ("Usage: mkhive <srcdir> <dstdir> <addinf>\n\n");
51 printf (" srcdir - inf files are read from this directory\n");
52 printf (" dstdir - binary hive files are created in this directory\n");
53 printf (" addinf - additional inf files with full path\n");
54 }
55
56 void convert_path(char *dst, char *src)
57 {
58 int i;
59
60 i = 0;
61 while (src[i] != 0)
62 {
63 #ifdef WIN32
64 if (src[i] == '/')
65 {
66 dst[i] = '\\';
67 }
68 #else
69 if (src[i] == '\\')
70 {
71 dst[i] = '/';
72 }
73 #endif
74 else
75 {
76 dst[i] = src[i];
77 }
78
79 i++;
80 }
81 dst[i] = 0;
82 }
83
84
85 int main (int argc, char *argv[])
86 {
87 char FileName[PATH_MAX];
88 int Param;
89
90 printf ("Binary hive maker\n");
91
92 if (argc < 3)
93 {
94 usage ();
95 return 1;
96 }
97
98 RegInitializeRegistry ();
99
100 convert_path (FileName, argv[1]);
101 strcat (FileName, DIR_SEPARATOR_STRING);
102 strcat (FileName, "hivesys.inf");
103 ImportRegistryFile (FileName, "AddReg", FALSE);
104
105 convert_path (FileName, argv[1]);
106 strcat (FileName, DIR_SEPARATOR_STRING);
107 strcat (FileName, "hivecls.inf");
108 ImportRegistryFile (FileName, "AddReg", FALSE);
109
110 convert_path (FileName, argv[1]);
111 strcat (FileName, DIR_SEPARATOR_STRING);
112 strcat (FileName, "hivesft.inf");
113 ImportRegistryFile (FileName, "AddReg", FALSE);
114
115 convert_path (FileName, argv[1]);
116 strcat (FileName, DIR_SEPARATOR_STRING);
117 strcat (FileName, "hivedef.inf");
118 ImportRegistryFile (FileName, "AddReg", FALSE);
119
120 for (Param = 3; Param < argc; Param++)
121 {
122 convert_path (FileName, argv[Param]);
123 ImportRegistryFile (FileName, "AddReg", FALSE);
124 }
125
126 convert_path (FileName, argv[2]);
127 strcat (FileName, DIR_SEPARATOR_STRING);
128 strcat (FileName, "system");
129 if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SYSTEM"))
130 {
131 return 1;
132 }
133
134 convert_path (FileName, argv[2]);
135 strcat (FileName, DIR_SEPARATOR_STRING);
136 strcat (FileName, "software");
137 if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SOFTWARE"))
138 {
139 return 1;
140 }
141
142 convert_path (FileName, argv[2]);
143 strcat (FileName, DIR_SEPARATOR_STRING);
144 strcat (FileName, "sam");
145 if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SAM"))
146 {
147 return 1;
148 }
149
150 convert_path (FileName, argv[2]);
151 strcat (FileName, DIR_SEPARATOR_STRING);
152 strcat (FileName, "security");
153 if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SECURITY"))
154 {
155 return 1;
156 }
157
158 convert_path (FileName, argv[2]);
159 strcat (FileName, DIR_SEPARATOR_STRING);
160 strcat (FileName, "default");
161 if (!ExportBinaryHive (FileName, "\\Registry\\User\\.DEFAULT"))
162 {
163 return 1;
164 }
165
166 // RegShutdownRegistry ();
167
168 printf (" Done.\n");
169
170 return 0;
171 }
172
173 /* EOF */