3 * Copyright (C) 2003, 2006 ReactOS Team
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.
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.
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.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS hive maker
22 * FILE: tools/mkhive/mkhive.c
24 * PROGRAMMERS: Eric Kohl
26 * Hermès Bélusca-Maïto
37 #define PATH_MAX _MAX_PATH
44 #define DIR_SEPARATOR_CHAR '/'
45 #define DIR_SEPARATOR_STRING "/"
47 #define DIR_SEPARATOR_CHAR '\\'
48 #define DIR_SEPARATOR_STRING "\\"
54 printf("Usage: mkhive [-?] -h:hive1[,hiveN...] [-u] -d:<dstdir> <inffiles>\n\n"
55 " -h:hiveN - Comma-separated list of hives to create. Possible values are:\n"
56 " SETUPREG, SYSTEM, SOFTWARE, DEFAULT, SAM, SECURITY, BCD.\n"
57 " -u - Generate file names in uppercase (default: lowercase) (TEMPORARY FLAG!).\n"
58 " -d:dstdir - The binary hive files are created in this directory.\n"
59 " inffiles - List of INF files with full path.\n"
60 " -? - Displays this help screen.\n");
63 void convert_path(char *dst
, char *src
)
91 int main(int argc
, char *argv
[])
95 BOOL UpperCaseFileName
= FALSE
;
96 PCSTR HiveList
= NULL
;
97 CHAR DestPath
[PATH_MAX
] = "";
98 CHAR FileName
[PATH_MAX
];
106 printf("Binary hive maker\n");
108 /* Read the options */
109 for (i
= 1; i
< argc
&& *argv
[i
] == '-'; i
++)
111 if (argv
[i
][1] == '?' && argv
[i
][1] == 0)
117 if (argv
[i
][1] == 'u' && argv
[i
][1] == 0)
119 UpperCaseFileName
= TRUE
;
122 if (argv
[i
][1] == 'h' && (argv
[i
][2] == ':' || argv
[i
][2] == '='))
124 HiveList
= argv
[i
] + 3;
126 else if (argv
[i
][1] == 'd' && (argv
[i
][2] == ':' || argv
[i
][2] == '='))
128 convert_path(DestPath
, argv
[i
] + 3);
132 fprintf(stderr
, "Unrecognized option: %s\n", argv
[i
]);
137 /* Check whether we have all the parameters needed */
138 if (!HiveList
|| !*HiveList
)
140 fprintf(stderr
, "The mandatory list of hives is missing.\n");
145 fprintf(stderr
, "The mandatory output directory is missing.\n");
150 fprintf(stderr
, "Not enough parameters, or the list of INF files is missing.\n");
154 /* Initialize the registry */
155 RegInitializeRegistry(HiveList
);
157 /* Default to failure */
160 /* Now we should have the list of INF files: parse it */
161 for (; i
< argc
; ++i
)
163 convert_path(FileName
, argv
[i
]);
164 if (!ImportRegistryFile(FileName
))
168 for (i
= 0; i
< MAX_NUMBER_OF_REGISTRY_HIVES
; ++i
)
170 /* Skip this registry hive if it's not in the list */
171 if (!strstr(HiveList
, RegistryHives
[i
].HiveName
))
174 strcpy(FileName
, DestPath
);
175 strcat(FileName
, DIR_SEPARATOR_STRING
);
176 strcat(FileName
, RegistryHives
[i
].HiveName
);
178 /* Exception for the special setup registry hive */
179 // if (strcmp(RegistryHives[i].HiveName, "SETUPREG") == 0)
181 strcat(FileName
, ".HIV");
183 /* Adjust file name case if needed */
184 if (UpperCaseFileName
)
188 *ptr
++ = toupper(*ptr
);
194 *ptr
++ = tolower(*ptr
);
197 if (!ExportBinaryHive(FileName
, RegistryHives
[i
].CmHive
))
200 /* If we happen to deal with the special setup registry hive, stop there */
201 // if (strcmp(RegistryHives[i].HiveName, "SETUPREG") == 0)
210 /* Shut down the registry */
211 RegShutdownRegistry();