[MKHIVE]
[reactos.git] / reactos / sdk / tools / mkhive / mkhive.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2003, 2006 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
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 * Hervé Poussineau
26 */
27
28 #include <limits.h>
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "mkhive.h"
33
34 #ifdef _MSC_VER
35 #include <stdlib.h>
36 #define PATH_MAX _MAX_PATH
37 #endif // _MSC_VER
38
39 #ifndef _WIN32
40 #ifndef PATH_MAX
41 #define PATH_MAX 260
42 #endif
43 #define DIR_SEPARATOR_CHAR '/'
44 #define DIR_SEPARATOR_STRING "/"
45 #else
46 #define DIR_SEPARATOR_CHAR '\\'
47 #define DIR_SEPARATOR_STRING "\\"
48 #endif
49
50
51 void usage (void)
52 {
53 printf ("Usage: mkhive <dstdir> <inffiles>\n\n");
54 printf (" dstdir - binary hive files are created in this directory\n");
55 printf (" inffiles - inf files with full path\n");
56 }
57
58 void convert_path(char *dst, char *src)
59 {
60 int i;
61
62 i = 0;
63 while (src[i] != 0)
64 {
65 #ifdef _WIN32
66 if (src[i] == '/')
67 {
68 dst[i] = '\\';
69 }
70 #else
71 if (src[i] == '\\')
72 {
73 dst[i] = '/';
74 }
75 #endif
76 else
77 {
78 dst[i] = src[i];
79 }
80
81 i++;
82 }
83 dst[i] = 0;
84 }
85
86 int main (int argc, char *argv[])
87 {
88 char FileName[PATH_MAX];
89 int i;
90
91 if (argc < 3)
92 {
93 usage ();
94 return 1;
95 }
96
97 printf ("Binary hive maker\n");
98
99 RegInitializeRegistry ();
100
101 for (i = 2; i < argc; i++)
102 {
103 convert_path (FileName, argv[i]);
104 if (!ImportRegistryFile (FileName))
105 {
106 return 1;
107 }
108 }
109
110 convert_path (FileName, argv[1]);
111 strcat (FileName, DIR_SEPARATOR_STRING);
112 strcat (FileName, "default");
113 if (!ExportBinaryHive (FileName, &DefaultHive))
114 {
115 return 1;
116 }
117
118 convert_path (FileName, argv[1]);
119 strcat (FileName, DIR_SEPARATOR_STRING);
120 strcat (FileName, "sam");
121 if (!ExportBinaryHive (FileName, &SamHive))
122 {
123 return 1;
124 }
125
126 convert_path (FileName, argv[1]);
127 strcat (FileName, DIR_SEPARATOR_STRING);
128 strcat (FileName, "security");
129 if (!ExportBinaryHive (FileName, &SecurityHive))
130 {
131 return 1;
132 }
133
134 convert_path (FileName, argv[1]);
135 strcat (FileName, DIR_SEPARATOR_STRING);
136 strcat (FileName, "software");
137 if (!ExportBinaryHive (FileName, &SoftwareHive))
138 {
139 return 1;
140 }
141
142 convert_path (FileName, argv[1]);
143 strcat (FileName, DIR_SEPARATOR_STRING);
144 strcat (FileName, "system");
145 if (!ExportBinaryHive (FileName, &SystemHive))
146 {
147 return 1;
148 }
149
150 convert_path (FileName, argv[1]);
151 strcat (FileName, DIR_SEPARATOR_STRING);
152 strcat (FileName, "BCD");
153 if (!ExportBinaryHive (FileName, &BcdHive))
154 {
155 return 1;
156 }
157
158 RegShutdownRegistry ();
159
160 printf (" Done.\n");
161
162 return 0;
163 }
164
165 /* EOF */