Check registry for location of Cantera data files

This commit is contained in:
Ray Speth 2012-01-05 22:22:19 +00:00
parent 89a405006b
commit f40e5e352e
2 changed files with 54 additions and 20 deletions

View file

@ -39,6 +39,8 @@
#include <algorithm>
#include <functional>
#include <new>
#include <windows.h>
#pragma comment(lib, "advapi32")
#endif
using namespace std;
@ -764,6 +766,11 @@ namespace Cantera {
* @param msg c++ string to be written to the screen
* @ingroup textlogs
*/
#ifdef WIN32
long int readStringRegistryKey(const std::string& keyName, const std::string& valueName,
std::string& value, const std::string& defaultValue);
#endif
void writelog(const std::string& msg) { pMessenger->writelog(msg); }
@ -1148,6 +1155,26 @@ protected:
}
}
#ifdef WIN32
long int Application::readStringRegistryKey(const std::string& keyName, const std::string& valueName,
std::string& value, const std::string& defaultValue) {
HKEY key;
long open_error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName.c_str(), 0, KEY_READ, &key);
value = defaultValue;
CHAR buffer[1024];
DWORD bufferSize = sizeof(buffer);
ULONG error;
error = RegQueryValueEx(key, valueName.c_str(), 0, NULL, (LPBYTE) buffer, &bufferSize);
if (ERROR_SUCCESS == error) {
value = buffer;
}
RegCloseKey(key);
return error;
}
#endif
void setTmpDir(std::string tmp) { app()->setTmpDir(tmp); }
void Application::setTmpDir(std::string tmp) {
APP_LOCK();
@ -1343,27 +1370,15 @@ protected:
#ifdef WIN32
//
// Under Windows, the Cantera setup utility puts data files in
// a directory 'Cantera\data' below the one the environment
// variable COMMONPROGRAMFILES points to. (This is usually
// C:\Program Files\Common Files.) If this environment
// variable is defined, then this directory is assumed to
// exist and is added to the search path.
//
const char* comfiles = getenv("COMMONPROGRAMFILES");
if (comfiles != 0) {
string cfiles = string(comfiles);
// Under Windows, the Cantera setup utility records the installation
// directory in the registry. Data files are stored in the 'data' and
// 'templates' subdirectories of the main installation directory.
// remove quotes if necessary
if (cfiles[0] == '\'')
cfiles = cfiles.substr(1,1000);
if (cfiles[cfiles.size()-1] == '\'') cfiles[cfiles.size()-1] = '\n';
string datadir = string(comfiles) + "/Cantera/data";
string tmpldir = string(comfiles) + "/Cantera/templates";
dirs.push_back(datadir);
dirs.push_back(tmpldir);
std::string installDir;
readStringRegistryKey("SOFTWARE\\Cantera\\Cantera 2.0", "InstallDir", installDir, "");
if (installDir != "") {
dirs.push_back(installDir + "data");
dirs.push_back(installDir + "templates");
}
#endif

View file

@ -129,6 +129,14 @@ class WxsGenerator(object):
templates_dir = self.addDirectoryContents('templates', instdir, extras)
tutorials_dir = self.addDirectoryContents('tutorials', instdir, extras)
# Registry entries
reg_key = self.addRegistryKey(core, product, Id='CanteraRegRoot', Root='HKLM',
Key='Software\\Cantera\\Cantera 2.0',
Action='createAndRemoveOnUninstall')
et.SubElement(reg_key, 'RegistryValue', dict(Type='string',
Name='InstallDir',
Value='[INSTALLDIR]'))
# Wix UI
et.SubElement(product, 'UIRef', dict(Id='WixUI_FeatureTree'))
et.SubElement(product, 'UIRef', dict(Id='WixUI_ErrorProgressText'))
@ -144,6 +152,17 @@ class WxsGenerator(object):
tree = et.ElementTree(wix)
tree.write(outFile)
def addRegistryKey(self, feature, parent, Id, Root, Key, Action):
guid = str(uuid.uuid5(self.CANTERA_UUID, Id))
fields = {'Win64': 'yes'} if self.x64 else {}
dr = et.SubElement(parent, "DirectoryRef", dict(Id="TARGETDIR"))
c = et.SubElement(dr, "Component",
dict(Id=Id, Guid=guid, **fields))
r = et.SubElement(c, "RegistryKey", dict(Id=Id, Root=Root, Key=Key, Action=Action))
et.SubElement(feature, 'ComponentRef', dict(Id=Id))
return r
def indent(elem, level=0):
""" in-place prettyprint formatter (from lxml) """