7676#include < cstdlib>
7777#include < cstdio>
7878#include < tchar.h>
79+
80+ #include < string>
81+
7982#include " pvengine.h"
8083#include " resource.h"
8184#include " pvdialog.h"
@@ -421,6 +424,16 @@ char *AboutURLs[NUM_ABOUT_LINKS] =
421424 " http://softwarefreedom.org/"
422425 };
423426
427+ const char *CanInheritFromVersions[] =
428+ {
429+ #ifdef POVRAY_IS_BETA
430+ " v" POV_RAY_GENERATION,
431+ #endif
432+ " v3.7" ,
433+ " v3.6" ,
434+ NULL // end of list
435+ };
436+
424437bool handle_main_command (WPARAM wParam, LPARAM lParam) ;
425438void SetStatusPanelItemText (int id, LPCSTR format, ...) ;
426439void ShowAboutBox (void );
@@ -1358,13 +1371,15 @@ bool inferHome (void)
13581371 return (true ) ;
13591372}
13601373
1361- string get36Home ( void )
1374+ string getHome ( const char * ver )
13621375{
13631376 char str[_MAX_PATH];
13641377 HKEY key ;
13651378 DWORD len = sizeof (str);
13661379
1367- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, " Software\\ " REGKEY " \\ v3.6\\ Windows" , 0 , KEY_READ, &key) == ERROR_SUCCESS)
1380+ std::string keyName = std::string (" Software\\ " REGKEY " \\ " ) + ver + " \\ Windows" ;
1381+
1382+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, keyName.c_str (), 0 , KEY_READ, &key) == ERROR_SUCCESS)
13681383 {
13691384 if (RegQueryValueEx (key, " Home" , 0 , NULL , (BYTE *) str, &len) == 0 )
13701385 {
@@ -1374,7 +1389,7 @@ string get36Home(void)
13741389 }
13751390 RegCloseKey (key) ;
13761391 }
1377- if (RegOpenKeyEx (HKEY_CURRENT_USER, " Software \\ " REGKEY " \\ v3.6 \\ Windows " , 0 , KEY_READ, &key) == ERROR_SUCCESS)
1392+ if (RegOpenKeyEx (HKEY_CURRENT_USER, keyName. c_str () , 0 , KEY_READ, &key) == ERROR_SUCCESS)
13781393 {
13791394 if (RegQueryValueEx (key, " Home" , 0 , NULL , (BYTE *) str, &len) == 0 )
13801395 {
@@ -1387,7 +1402,7 @@ string get36Home(void)
13871402 return string ();
13881403}
13891404
1390- bool copy36EditSettings ( void )
1405+ bool copyEditSettings ( const char * ver )
13911406{
13921407 HKEY hKeySrc ;
13931408 HKEY hKeyDst ;
@@ -1404,46 +1419,9 @@ bool copy36EditSettings(void)
14041419 return (false ) ;
14051420 }
14061421
1407- if (RegOpenKeyEx (HKEY_CURRENT_USER, " Software\\ " REGKEY " \\ v3.6" , 0 , KEY_READ, &hKeySrc) != ERROR_SUCCESS)
1408- {
1409- FreeLibrary (hLib) ;
1410- return (false ) ;
1411- }
1412-
1413- if (RegCreateKeyEx (HKEY_CURRENT_USER, " Software\\ " REGKEY " \\ " REGVERKEY " \\ POV-Edit" , 0 , " " , REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL , &hKeyDst, NULL ) != ERROR_SUCCESS)
1414- {
1415- RegCloseKey (hKeySrc) ;
1416- FreeLibrary (hLib) ;
1417- return (false ) ;
1418- }
1419-
1420- result = shCopyKey (hKeySrc, " POV-Edit" , hKeyDst, NULL ) ;
1421- RegCloseKey (hKeySrc) ;
1422- RegCloseKey (hKeyDst) ;
1423- FreeLibrary (hLib) ;
1424-
1425- return (result == ERROR_SUCCESS) ;
1426- }
1422+ std::string keyName = std::string (" Software\\ " REGKEY " \\ " ) + ver;
14271423
1428- #ifdef POVRAY_IS_BETA
1429- bool copy37NoBetaEditSettings (void )
1430- {
1431- HKEY hKeySrc ;
1432- HKEY hKeyDst ;
1433- DWORD result ;
1434- HINSTANCE hLib ;
1435- shCopyType *shCopyKey ;
1436-
1437- if ((hLib = LoadLibrary (" shlwapi.dll" )) == NULL )
1438- return (false ) ;
1439- shCopyKey = (shCopyType *) GetProcAddress (hLib, " SHCopyKeyA" ) ;
1440- if (shCopyKey == NULL )
1441- {
1442- FreeLibrary (hLib) ;
1443- return (false ) ;
1444- }
1445-
1446- if (RegOpenKeyEx (HKEY_CURRENT_USER, " Software\\ " REGKEY " \\ v" POV_RAY_GENERATION, 0 , KEY_READ, &hKeySrc) != ERROR_SUCCESS)
1424+ if (RegOpenKeyEx (HKEY_CURRENT_USER, keyName.c_str (), 0 , KEY_READ, &hKeySrc) != ERROR_SUCCESS)
14471425 {
14481426 FreeLibrary (hLib) ;
14491427 return (false ) ;
@@ -1463,39 +1441,14 @@ bool copy37NoBetaEditSettings(void)
14631441
14641442 return (result == ERROR_SUCCESS) ;
14651443}
1466- #endif
14671444
1468- bool checkEditKey36 ( void )
1445+ bool checkEditKey ( const char * ver )
14691446{
14701447 HKEY key ;
14711448
1472- if (RegOpenKeyEx (HKEY_CURRENT_USER, " Software\\ " REGKEY " \\ v3.6\\ POV-Edit" , 0 , KEY_READ, &key) == ERROR_SUCCESS)
1473- {
1474- RegCloseKey (key) ;
1475- return (true ) ;
1476- }
1477- return (false ) ;
1478- }
1449+ std::string keyName = std::string (" Software\\ " REGKEY " \\ " ) + ver + " \\ POV-Edit" ;
14791450
1480- #ifdef POVRAY_IS_BETA
1481- bool checkEditKey37NoBeta (void )
1482- {
1483- HKEY key ;
1484-
1485- if (RegOpenKeyEx (HKEY_CURRENT_USER, " Software\\ " REGKEY " \\ v" POV_RAY_GENERATION " \\ POV-Edit" , 0 , KEY_READ, &key) == ERROR_SUCCESS)
1486- {
1487- RegCloseKey (key) ;
1488- return (true ) ;
1489- }
1490- return (false ) ;
1491- }
1492- #endif
1493-
1494- bool checkEditKey37 (void )
1495- {
1496- HKEY key ;
1497-
1498- if (RegOpenKeyEx (HKEY_CURRENT_USER, " Software\\ " REGKEY " \\ " REGVERKEY " \\ POV-Edit" , 0 , KEY_READ, &key) == ERROR_SUCCESS)
1451+ if (RegOpenKeyEx (HKEY_CURRENT_USER, keyName.c_str (), 0 , KEY_READ, &key) == ERROR_SUCCESS)
14991452 {
15001453 RegCloseKey (key) ;
15011454 return (true ) ;
@@ -5538,17 +5491,16 @@ int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
55385491 sprintf (ToolIniFileName, " %sini\\ pvtools.ini" , DocumentsPath);
55395492 sprintf (EngineIniFileName, " %sini\\ pvengine.ini" , DocumentsPath);
55405493
5541- if (!checkEditKey37 ( ))
5494+ if (!checkEditKey (REGVERKEY ))
55425495 {
5543- #ifdef POVRAY_IS_BETA
5544- if (checkEditKey37NoBeta ())
5545- copy37NoBetaEditSettings ();
5546- else if (checkEditKey36 ())
5547- copy36EditSettings ();
5548- #else
5549- if (checkEditKey36 ())
5550- copy36EditSettings ();
5551- #endif
5496+ for (const char **oldVer = CanInheritFromVersions; *oldVer != NULL ; ++oldVer)
5497+ {
5498+ if (checkEditKey (*oldVer))
5499+ {
5500+ copyEditSettings (*oldVer);
5501+ break ;
5502+ }
5503+ }
55525504 }
55535505
55545506 if (checkRegKey () == false || FreshInstall == true )
@@ -5570,28 +5522,28 @@ int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
55705522#ifndef MAP_INI_TO_REGISTRY
55715523 if (!fileExists (EngineIniFileName))
55725524 {
5573- // no INI file: see if we can copy the 3.6 INI options, should they exist
5574- if (debugging)
5575- debug_output (" no pvengine.ini: seeing if there is a v3.6 ini\n " ) ;
5576-
5577- string str (get36Home ());
5578- if (str.empty () == false )
5525+ bool foundOld = false ;
5526+ for (const char **oldVer = CanInheritFromVersions; *oldVer != NULL ; ++oldVer)
55795527 {
5580- string oldINIpath = str + " ini\\ pvengine.ini" ;
5581- if (fileExists (oldINIpath.c_str ()))
5528+ // no INI file: see if we can copy an older version's INI options, should they exist
5529+ if (debugging)
5530+ debug_output (" no pvengine.ini: seeing if there is a %s ini\n " , *oldVer) ;
5531+
5532+ string str (getHome (*oldVer));
5533+ if (str.empty () == false )
55825534 {
5535+ string oldINIpath = str + " ini\\ pvengine.ini" ;
5536+ if (!fileExists (oldINIpath.c_str ()))
5537+ continue ;
5538+
55835539 if (debugging)
55845540 debug_output (" cloning INI file %s to %s\n " , oldINIpath.c_str (), EngineIniFileName) ;
55855541 cloneOldIni (str, DocumentsPath);
5586- }
5587- else
5588- {
5589- if (debugging)
5590- debug_output (" creating default INI file %s\n " , EngineIniFileName) ;
5591- cloneOldIni (" " , DocumentsPath);
5542+ foundOld = true ;
5543+ break ;
55925544 }
55935545 }
5594- else
5546+ if (!foundOld)
55955547 {
55965548 if (debugging)
55975549 debug_output (" creating default INI file %s\n " , EngineIniFileName) ;
0 commit comments