3232#include " ../utilities/install/install_nt.h"
3333#include " ../utilities/install/install_proto.h"
3434
35- const DWORD GDSVER_MAJOR = 6 ;
36- const DWORD GDSVER_MINOR = 3 ;
35+ constexpr DWORD GDSVER_MAJOR = 6 ;
36+ constexpr DWORD GDSVER_MINOR = 3 ;
3737
38- const char * SHARED_KEY = " SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ SharedDLLs" ;
38+ constexpr const char * SHARED_KEY = " SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ SharedDLLs" ;
3939
4040namespace
4141{
@@ -78,7 +78,7 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
7878
7979 // Get Windows System Directory
8080 TEXT sysdir[MAXPATHLEN];
81- int len = GetSystemDirectory (sysdir, sizeof (sysdir));
81+ const int len = GetSystemDirectory (sysdir, sizeof (sysdir));
8282 if (len == 0 )
8383 return (*err_handler) (GetLastError (), " GetSystemDirectory()" );
8484
@@ -172,12 +172,14 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
172172 // Move _FBCLIENT.DLL as the final target
173173 if (MoveFile (workfile, target) == 0 )
174174 {
175- // MoveFile failed, this is expected if target already exists
176- ULONG werr = GetLastError ();
177- if (werr != ERROR_ALREADY_EXISTS)
178175 {
179- DeleteFile (workfile);
180- return (*err_handler) (werr, " MoveFile(_FBCLIENT.DLL, 'target')" );
176+ // MoveFile failed, this is expected if target already exists
177+ const ULONG werr = GetLastError ();
178+ if (werr != ERROR_ALREADY_EXISTS)
179+ {
180+ DeleteFile (workfile);
181+ return (*err_handler) (werr, " MoveFile(_FBCLIENT.DLL, 'target')" );
182+ }
181183 }
182184
183185 // Failed moving because a destination target file already exists
@@ -207,15 +209,15 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
207209
208210 if ((*ntmove) (target, 0 , MOVEFILE_DELAY_UNTIL_REBOOT) == 0 )
209211 {
210- ULONG werr = GetLastError ();
212+ const ULONG werr = GetLastError ();
211213 FreeLibrary (kernel32);
212214 DeleteFile (workfile);
213215 return (*err_handler) (werr, " MoveFileEx(delete 'target')" );
214216 }
215217
216218 if ((*ntmove) (workfile, target, MOVEFILE_DELAY_UNTIL_REBOOT) == 0 )
217219 {
218- ULONG werr = GetLastError ();
220+ const ULONG werr = GetLastError ();
219221 FreeLibrary (kernel32);
220222 DeleteFile (workfile);
221223 return (*err_handler) (werr, " MoveFileEx(replace 'target')" );
@@ -250,15 +252,15 @@ USHORT CLIENT_install(const TEXT * rootdir, USHORT client, bool sw_force, err_ha
250252 if (WritePrivateProfileString (" rename" , " NUL" , starget,
251253 " WININIT.INI" ) == 0 )
252254 {
253- ULONG werr = GetLastError ();
255+ const ULONG werr = GetLastError ();
254256 DeleteFile (workfile);
255257 return (*err_handler) (werr, " WritePrivateProfileString(delete 'target')" );
256258 }
257259
258260 if (WritePrivateProfileString (" rename" , starget, sworkfile,
259261 " WININIT.INI" ) == 0 )
260262 {
261- ULONG werr = GetLastError ();
263+ const ULONG werr = GetLastError ();
262264 DeleteFile (workfile);
263265 return (*err_handler) (werr, " WritePrivateProfileString(replace 'target')" );
264266 }
@@ -301,7 +303,7 @@ USHORT CLIENT_remove(const TEXT* rootdir, USHORT client, bool sw_force, err_hand
301303
302304 // Get Windows System Directory
303305 TEXT sysdir[MAXPATHLEN];
304- int len = GetSystemDirectory (sysdir, sizeof (sysdir));
306+ const int len = GetSystemDirectory (sysdir, sizeof (sysdir));
305307 if (len == 0 )
306308 return (*err_handler) (GetLastError (), " GetSystemDirectory()" );
307309
@@ -370,7 +372,7 @@ USHORT CLIENT_query(USHORT client, ULONG& verMS, ULONG& verLS, ULONG& sharedCoun
370372
371373 // Get Windows System Directory
372374 TEXT sysdir[MAXPATHLEN];
373- int len = GetSystemDirectory (sysdir, sizeof (sysdir));
375+ const int len = GetSystemDirectory (sysdir, sizeof (sysdir));
374376 if (len == 0 )
375377 return (*err_handler) (GetLastError (), " GetSystemDirectory()" );
376378
@@ -380,13 +382,12 @@ USHORT CLIENT_query(USHORT client, ULONG& verMS, ULONG& verLS, ULONG& sharedCoun
380382 lstrcat (target, client == CLIENT_GDS ? GDS32_NAME : FBCLIENT_NAME);
381383
382384 verMS = verLS = sharedCount = 0 ;
383- USHORT status = GetVersion (target, verMS, verLS, err_handler);
385+ const USHORT status = GetVersion (target, verMS, verLS, err_handler);
384386 if (status != FB_SUCCESS)
385387 return status; // FB_FAILURE or FB_INSTALL_FILE_NOT_FOUND
386388
387389 HKEY hkey;
388- LONG keystatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE, SHARED_KEY, 0 ,
389- KEY_READ, &hkey);
390+ const LONG keystatus = RegOpenKeyEx (HKEY_LOCAL_MACHINE, SHARED_KEY, 0 , KEY_READ, &hkey);
390391 if (keystatus != ERROR_SUCCESS)
391392 return (*err_handler) (keystatus, " RegOpenKeyEx" );
392393
@@ -428,18 +429,18 @@ USHORT GetVersion(const TEXT* filename, DWORD& verMS, DWORD& verLS, err_handler_
428429 // can't be deleted between check for existence and version read.
429430
430431 DWORD dwUnused;
431- DWORD rsize = GetFileVersionInfoSize (const_cast <TEXT*>( filename) , &dwUnused);
432+ const DWORD rsize = GetFileVersionInfoSize (filename, &dwUnused);
432433 if (rsize == 0 )
433434 {
434- ULONG werr = GetLastError ();
435+ const ULONG werr = GetLastError ();
435436 CloseHandle (hfile);
436437 return (*err_handler) (werr, " GetFileVersionInfoSize()" );
437438 }
438439
439440 BYTE* hver = new BYTE[rsize];
440- if (! GetFileVersionInfo (const_cast <TEXT*>( filename) , 0 , rsize, hver))
441+ if (!GetFileVersionInfo (filename, 0 , rsize, hver))
441442 {
442- ULONG werr = GetLastError ();
443+ const ULONG werr = GetLastError ();
443444 delete[] hver;
444445 CloseHandle (hfile);
445446 return (*err_handler) (werr, " GetFileVersionInfo()" );
@@ -450,7 +451,7 @@ USHORT GetVersion(const TEXT* filename, DWORD& verMS, DWORD& verLS, err_handler_
450451 UINT uiUnused;
451452 if (! VerQueryValue (hver, " \\ " , (void **)&ffi, &uiUnused))
452453 {
453- ULONG werr = GetLastError ();
454+ const ULONG werr = GetLastError ();
454455 delete[] hver;
455456 return (*err_handler) (werr, " VerQueryValue()" );
456457 }
@@ -495,13 +496,13 @@ USHORT PatchVersion(const TEXT* filename, DWORD verMS, err_handler_t err_handler
495496 if (hfile == INVALID_HANDLE_VALUE)
496497 return (*err_handler) (GetLastError (), " CreateFile()" );
497498
498- DWORD fsize = GetFileSize (hfile, 0 );
499+ const DWORD fsize = GetFileSize (hfile, 0 );
499500
500501 HANDLE hmap = CreateFileMapping (hfile, 0 ,
501502 PAGE_READWRITE | SEC_COMMIT, 0 , 0 , 0 );
502503 if (hmap == 0 )
503504 {
504- ULONG werr = GetLastError ();
505+ const ULONG werr = GetLastError ();
505506 CloseHandle (hfile);
506507 return (*err_handler) (werr, " CreateFileMapping()" );
507508 }
@@ -510,22 +511,22 @@ USHORT PatchVersion(const TEXT* filename, DWORD verMS, err_handler_t err_handler
510511 FILE_MAP_WRITE, 0 , 0 , 0 ));
511512 if (mem == 0 )
512513 {
513- ULONG werr = GetLastError ();
514+ const ULONG werr = GetLastError ();
514515 CloseHandle (hmap);
515516 CloseHandle (hfile);
516517 return (*err_handler) (werr, " MapViewOfFile()" );
517518 }
518519
519520 // This is a "magic value" that will allow locating the version info.
520521 // Windows itself does something equivalent internally.
521- const BYTE lookup[] =
522+ constexpr BYTE lookup[] =
522523 {
523524 ' V' , 0 , ' S' , 0 , ' _' , 0 ,
524525 ' V' , 0 , ' E' , 0 , ' R' , 0 , ' S' , 0 , ' I' , 0 , ' O' , 0 , ' N' , 0 , ' _' , 0 ,
525526 ' I' , 0 , ' N' , 0 , ' F' , 0 , ' O' , 0 , 0 , 0 , 0 , 0 , 0xbd , 0x04 , 0xef , 0xfe
526527 };
527- BYTE* p = mem; // First byte of mapped file
528- BYTE* end = mem + fsize; // Last byte + 1 of mapped file
528+ BYTE* p = mem; // First byte of mapped file
529+ const BYTE* end = mem + fsize; // Last byte + 1 of mapped file
529530
530531 int i = 0 ;
531532 while (p < end)
0 commit comments