1 // msvc6chk.cpp : Defines the entry point for the console application.
16 static char * dinkumwareCopyright
=
17 "The files presented here are copyright © 1995-2000 by P.J. Plauger.\n"
18 "All rights reserved. They are for use only in conjunction with a valid\n"
19 "license for Microsoft Visual C++ V5.0 or V6.0. Microsoft Corporation is in\n"
20 "no way involved with the production or release of these files. The files are\n"
21 "offered on an `as is' basis. DINKUMWARE, LTD. AND P.J. PLAUGER MAKE NO\n"
22 "REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THESE FILES, EITHER\n"
23 "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF\n"
24 "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.\n"
25 "DINKUMWARE, LTD. AND P.J. PLAUGER SHALL NOT BE LIABLE FOR ANY DAMAGES\n"
26 "SUFFERED BY LICENSEE AS A RESULT OF USING THESE FILES.";
30 static struct FileUpgradeInfo
{
32 const char * registryBase
;
33 const char * registryKey
;
34 const char * filename
;
37 const char * newFilename
;
43 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
45 "INCLUDE\\DEQUE", 0x4229bfd5,
46 "UPGRADES/DEQUE", 0x11539af7,
51 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
53 "INCLUDE\\FSTREAM", 0x28f76291,
54 "UPGRADES/FSTREAM", 0xb9a507b4,
59 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
61 "INCLUDE\\LIST", 0x64487361,
62 "UPGRADES/LIST", 0xa97cc61b,
67 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
69 "INCLUDE\\VECTOR", 0x26ba0df5,
70 "UPGRADES/VECTOR", 0x35a94c52,
75 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
77 "INCLUDE\\XMEMORY", 0xa6ac2fb8,
78 "UPGRADES/XMEMORY", 0x52936ff7,
83 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
85 "INCLUDE\\XSTRING", 0x705ce397,
86 "UPGRADES/XSTRING", 0x6215f086,
91 "SOFTWARE\\Microsoft\\VisualStudio\\6.0\\Setup\\Microsoft Visual C++",
93 "INCLUDE\\XTREE", 0xe64c6f6e,
94 "UPGRADES/XTREE", 0x07972076,
101 static unsigned long crc_table
[256];
103 void gen_crc32_table(void) /* build the crc table */
105 unsigned long crc
, poly
;
109 for (i
= 0; i
< 256; i
++) {
111 for (j
= 8; j
> 0; j
--) {
113 crc
= (crc
>> 1) ^ poly
;
121 void init_crc32(unsigned long & crc
)
127 void add_to_crc32(unsigned long & crc
, unsigned char value
)
129 crc
= (crc
>> 8) ^ crc_table
[(crc
^value
) & 0xFF];
130 crc
= crc
^ 0xFFFFFFFF;
133 bool CalculateCRCOfFile(const std::string
& fn
, unsigned long & crc32
)
135 int file
= ::open(fn
.c_str(), O_RDONLY
| O_BINARY
);
141 while (read(file
, &ch
, 1))
142 add_to_crc32(crc32
, ch
);
165 int main(int argc
, char * argv
[])
167 cout
<< "PWLIB File Upgrader v" << VERSION
<< "\n"
168 << "Copyright (C) 2004 by Post Increment" << endl
;
172 bool testFiles
= false;
173 bool doUpgrade
= false;
177 if (strcmpi(argv
[1], "test") == 0)
179 else if (strcmpi(argv
[1], "upgrade") == 0)
181 else if (strcmpi(argv
[1], "force") == 0) {
190 for (i
= 0; fileInfo
[i
].filename
!= NULL
; ++i
) {
191 FileUpgradeInfo
& info
= fileInfo
[i
];
193 char * infoKeyName
= "(unknown)";
194 if (info
.key
== HKEY_CLASSES_ROOT
)
195 infoKeyName
= "HKEY_CLASSES_ROOT";
197 else if (info
.key
== HKEY_CURRENT_USER
)
198 infoKeyName
= "HKEY_CURRENT_USER";
200 else if (info
.key
== HKEY_LOCAL_MACHINE
)
201 infoKeyName
= "HKEY_LOCAL_MACHINE";
203 else if (info
.key
== HKEY_USERS
)
204 infoKeyName
= "HKEY_USERS";
208 LONG stat
= RegOpenKeyEx(info
.key
,
212 if (stat
!= ERROR_SUCCESS
) {
213 cout
<< "Registry entry " << infoKeyName
<< "\\" << info
.registryBase
<< " not found - error = " << stat
<< endl
;
219 DWORD keyLen
= sizeof(keyData
);
220 if (RegQueryValueEx(key
.key
,
224 (BYTE
*)keyData
, &keyLen
) != ERROR_SUCCESS
) {
225 cout
<< "Registry key " << infoKeyName
<< "\\" << info
.registryBase
<< "\\" << info
.registryKey
<< " not found" << endl
;
229 std::string
fn(keyData
);
234 if (!CalculateCRCOfFile(fn
, crc32
)) {
235 cout
<< fn
.c_str() << "does not exist" << endl
;
240 unsigned long newcrc
;
241 if (!CalculateCRCOfFile(info
.newFilename
, newcrc
))
242 cout
<< info
.newFilename
<< "does not exist" << endl
;
244 cout
<< hex
<< crc32
<< dec
<< " = " << fn
.c_str() << "\n"
245 << hex
<< newcrc
<< dec
<< " = " << info
.newFilename
<< "\n"
250 else if (crc32
== info
.newcrc
) {
251 cout
<< fn
.c_str() << " already upgraded" << endl
;
255 if (crc32
!= info
.oldcrc
) {
256 cout
<< "WARNING: " << fn
.c_str() << " has unknown CRC " << hex
<< crc32
<< dec
257 << ", assuming it does NOT need upgrade." << endl
;
261 // create name of backup file
262 std::string backupFn
= fn
+ ".backup";
266 if (::access(backupFn
.c_str(), 0) != 0)
268 sprintf(buffer
, "_%i.backup", count
++);
269 backupFn
= fn
+ std::string(buffer
);
273 cout
<< "\nWARNING: the following file requires upgrading:\n"
274 << fn
.c_str() << endl
;
275 std::string cmd
= argv
[0];
276 int pos
= cmd
.rfind('\\');
277 if (pos
!= std::string::npos
)
279 pos
= cmd
.rfind('.');
280 if (pos
!= std::string::npos
)
282 cout
<< "Please run \"" << cmd
.c_str() << " upgrade\" to upgrade this file" << endl
;
287 cout
<< "\nWARNING: the following file requires upgrading:\n"
288 << fn
.c_str() << endl
;
290 if (info
.copyright
!= NULL
)
291 cout
<< "\n" << info
.copyright
<< "\n" << endl
;
294 cout
<< "Upgrade file (y/n) ? " << flush
;
299 cout
<< "Aborting upgrade." << endl
;
304 // check that replacement file exists
305 if (::access(info
.newFilename
, 0) != 0) {
306 cout
<< "ERROR: new file " << info
.newFilename
<< "not found - aborting upgrade" << endl
;
311 // rename existing file
312 if (::rename(fn
.c_str(), backupFn
.c_str()) != 0) {
313 cout
<< "ERROR: rename of " << fn
.c_str() << " to " << backupFn
.c_str() << " failed" << endl
;
319 if (!CopyFile(info
.newFilename
, fn
.c_str(), true)) {
320 cout
<< "ERROR: copy of " << info
.newFilename
<< " to " << fn
.c_str() << " failed\n"
321 << " reverting " << backupFn
.c_str() << " to " << fn
.c_str() << endl
;
322 ::unlink(fn
.c_str());
323 ::rename(backupFn
.c_str(), fn
.c_str());
329 cout
<< "The following files have been upgraded\n"
330 << " " << fn
.c_str() << "\n"
331 << "The previous version of the file has been renamed to\n"
332 << " " << backupFn
.c_str() << endl
;