Create the AHCI branch for Aman's work
[reactos.git] / 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 ImportRegistryFile (FileName);
105 }
106
107 convert_path (FileName, argv[1]);
108 strcat (FileName, DIR_SEPARATOR_STRING);
109 strcat (FileName, "default");
110 if (!ExportBinaryHive (FileName, &DefaultHive))
111 {
112 return 1;
113 }
114
115 convert_path (FileName, argv[1]);
116 strcat (FileName, DIR_SEPARATOR_STRING);
117 strcat (FileName, "sam");
118 if (!ExportBinaryHive (FileName, &SamHive))
119 {
120 return 1;
121 }
122
123 convert_path (FileName, argv[1]);
124 strcat (FileName, DIR_SEPARATOR_STRING);
125 strcat (FileName, "security");
126 if (!ExportBinaryHive (FileName, &SecurityHive))
127 {
128 return 1;
129 }
130
131 convert_path (FileName, argv[1]);
132 strcat (FileName, DIR_SEPARATOR_STRING);
133 strcat (FileName, "software");
134 if (!ExportBinaryHive (FileName, &SoftwareHive))
135 {
136 return 1;
137 }
138
139 convert_path (FileName, argv[1]);
140 strcat (FileName, DIR_SEPARATOR_STRING);
141 strcat (FileName, "system");
142 if (!ExportBinaryHive (FileName, &SystemHive))
143 {
144 return 1;
145 }
146
147 convert_path (FileName, argv[1]);
148 strcat (FileName, DIR_SEPARATOR_STRING);
149 strcat (FileName, "BCD");
150 if (!ExportBinaryHive (FileName, &BcdHive))
151 {
152 return 1;
153 }
154
155 RegShutdownRegistry ();
156
157 printf (" Done.\n");
158
159 return 0;
160 }
161
162 /* EOF */