update for HEAD-2003091401
[reactos.git] / 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$
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
30 #include "mkhive.h"
31 #include "registry.h"
32 #include "reginf.h"
33 #include "binhive.h"
34
35 #ifndef WIN32
36 #ifndef PATH_MAX
37 #define PATH_MAX 260
38 #endif
39 #define DIR_SEPARATOR_CHAR '/'
40 #define DIR_SEPARATOR_STRING "/"
41 #else
42 #define DIR_SEPARATOR_CHAR '\\'
43 #define DIR_SEPARATOR_STRING "\\"
44 #endif
45
46
47 void usage (void)
48 {
49   printf ("Usage: mkhive <srcdir> <dstdir>\n\n");
50   printf ("  srcdir  - inf files are read from this directory\n");
51   printf ("  dstdir  - binary hive files are created in this directory\n");
52 }
53
54 void convert_path(char *dst, char *src)
55 {
56   int i;
57
58   i = 0;
59   while (src[i] != 0)
60     {
61 #ifdef WIN32
62       if (src[i] == '/')
63         {
64           dst[i] = '\\';
65         }
66 #else
67       if (src[i] == '\\')
68         {
69           dst[i] = '/';
70         }
71 #endif
72       else
73         {
74           dst[i] = src[i];
75         }
76
77       i++;
78     }
79   dst[i] = 0;
80 }
81
82
83 int main (int argc, char *argv[])
84 {
85   char FileName[PATH_MAX];
86
87   printf ("Binary hive maker\n");
88
89   if (argc < 3)
90     {
91       usage ();
92       return 1;
93     }
94
95   RegInitializeRegistry ();
96
97   convert_path (FileName, argv[1]);
98   strcat (FileName, DIR_SEPARATOR_STRING);
99   strcat (FileName, "hivesys.inf");
100   ImportRegistryFile (FileName, "AddReg", FALSE);
101
102   convert_path (FileName, argv[1]);
103   strcat (FileName, DIR_SEPARATOR_STRING);
104   strcat (FileName, "hivecls.inf");
105   ImportRegistryFile (FileName, "AddReg", FALSE);
106
107   convert_path (FileName, argv[1]);
108   strcat (FileName, DIR_SEPARATOR_STRING);
109   strcat (FileName, "hivesft.inf");
110   ImportRegistryFile (FileName, "AddReg", FALSE);
111
112   convert_path (FileName, argv[1]);
113   strcat (FileName, DIR_SEPARATOR_STRING);
114   strcat (FileName, "hivedef.inf");
115   ImportRegistryFile (FileName, "AddReg", FALSE);
116
117   convert_path (FileName, argv[2]);
118   strcat (FileName, DIR_SEPARATOR_STRING);
119   strcat (FileName, "system");
120   ExportBinaryHive (FileName, "\\Registry\\Machine\\SYSTEM");
121
122   convert_path (FileName, argv[2]);
123   strcat (FileName, DIR_SEPARATOR_STRING);
124   strcat (FileName, "software");
125   ExportBinaryHive (FileName, "\\Registry\\Machine\\SOFTWARE");
126
127   convert_path (FileName, argv[2]);
128   strcat (FileName, DIR_SEPARATOR_STRING);
129   strcat (FileName, "sam");
130   ExportBinaryHive (FileName, "\\Registry\\Machine\\SAM");
131
132   convert_path (FileName, argv[2]);
133   strcat (FileName, DIR_SEPARATOR_STRING);
134   strcat (FileName, "security");
135   ExportBinaryHive (FileName, "\\Registry\\Machine\\SECURITY");
136
137   convert_path (FileName, argv[2]);
138   strcat (FileName, DIR_SEPARATOR_STRING);
139   strcat (FileName, "default");
140   ExportBinaryHive (FileName, "\\Registry\\User\\.DEFAULT");
141
142 //  RegShutdownRegistry ();
143
144   printf ("  Done.\n");
145
146   return 0;
147 }
148
149 /* EOF */