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
29 /* INCLUDES *****************************************************************/
39 #define PATH_MAX _MAX_PATH
46 #define DIR_SEPARATOR_CHAR '/'
47 #define DIR_SEPARATOR_STRING "/"
49 #define DIR_SEPARATOR_CHAR '\\'
50 #define DIR_SEPARATOR_STRING "\\"
53 /* FUNCTIONS ****************************************************************/
57 printf("Usage: mkhive [-?] -h:hive1[,hiveN...] [-u] -d:<dstdir> <inffiles>\n\n"
58 " -h:hiveN - Comma-separated list of hives to create. Possible values are:\n"
59 " SETUPREG, SYSTEM, SOFTWARE, DEFAULT, SAM, SECURITY, BCD.\n"
60 " -u - Generate file names in uppercase (default: lowercase) (TEMPORARY FLAG!).\n"
61 " -d:dstdir - The binary hive files are created in this directory.\n"
62 " inffiles - List of INF files with full path.\n"
63 " -? - Displays this help screen.\n");
66 void convert_path(char *dst
, char *src
)
94 int main(int argc
, char *argv
[])
99 BOOL UpperCaseFileName
= FALSE
;
100 PCSTR HiveList
= NULL
;
101 CHAR DestPath
[PATH_MAX
] = "";
102 CHAR FileName
[PATH_MAX
];
110 printf("Binary hive maker\n");
112 /* Read the options */
113 for (i
= 1; i
< argc
&& *argv
[i
] == '-'; i
++)
115 if (argv
[i
][1] == '?' && argv
[i
][2] == 0)
121 if (argv
[i
][1] == 'u' && argv
[i
][2] == 0)
123 UpperCaseFileName
= TRUE
;
126 if (argv
[i
][1] == 'h' && (argv
[i
][2] == ':' || argv
[i
][2] == '='))
128 HiveList
= argv
[i
] + 3;
130 else if (argv
[i
][1] == 'd' && (argv
[i
][2] == ':' || argv
[i
][2] == '='))
132 convert_path(DestPath
, argv
[i
] + 3);
136 fprintf(stderr
, "Unrecognized option: %s\n", argv
[i
]);
141 /* Check whether we have all the parameters needed */
142 if (!HiveList
|| !*HiveList
)
144 fprintf(stderr
, "The mandatory list of hives is missing.\n");
149 fprintf(stderr
, "The mandatory output directory is missing.\n");
154 fprintf(stderr
, "Not enough parameters, or the list of INF files is missing.\n");
158 /* Initialize the registry */
159 RegInitializeRegistry(HiveList
);
161 /* Default to failure */
164 /* Now we should have the list of INF files: parse it */
165 for (; i
< argc
; ++i
)
167 convert_path(FileName
, argv
[i
]);
168 if (!ImportRegistryFile(FileName
))
172 for (i
= 0; i
< MAX_NUMBER_OF_REGISTRY_HIVES
; ++i
)
174 /* Skip this registry hive if it's not in the list */
175 if (!strstr(HiveList
, RegistryHives
[i
].HiveName
))
178 strcpy(FileName
, DestPath
);
179 strcat(FileName
, DIR_SEPARATOR_STRING
);
181 ptr
= FileName
+ strlen(FileName
);
183 strcat(FileName
, RegistryHives
[i
].HiveName
);
185 /* Exception for the special setup registry hive */
186 // if (strcmp(RegistryHives[i].HiveName, "SETUPREG") == 0)
188 strcat(FileName
, ".HIV");
190 /* Adjust file name case if needed */
191 if (UpperCaseFileName
)
194 *ptr
= toupper(*ptr
);
199 *ptr
= tolower(*ptr
);
202 if (!ExportBinaryHive(FileName
, RegistryHives
[i
].CmHive
))
205 /* If we happen to deal with the special setup registry hive, stop there */
206 // if (strcmp(RegistryHives[i].HiveName, "SETUPREG") == 0)
215 /* Shut down the registry */
216 RegShutdownRegistry();