|
8 | 8 | #include <Windows.h> |
9 | 9 | #endif |
10 | 10 |
|
| 11 | +#ifdef _WIN32 |
| 12 | + |
| 13 | +std::string getRegKey(const std::string& location, const std::string& name, bool system) |
| 14 | + { |
| 15 | + HKEY key; |
| 16 | + TCHAR value[1024]; |
| 17 | + DWORD bufLen = 1024*sizeof(TCHAR); |
| 18 | + long ret; |
| 19 | + ret = RegOpenKeyExA(system?HKEY_LOCAL_MACHINE:HKEY_CURRENT_USER, location.c_str(), 0, KEY_QUERY_VALUE, &key); |
| 20 | + if( ret != ERROR_SUCCESS ){ |
| 21 | + return std::string(); |
| 22 | + } |
| 23 | + ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen); |
| 24 | + RegCloseKey(key); |
| 25 | + if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){ |
| 26 | + return std::string(); |
| 27 | + } |
| 28 | + std::string stringValue = std::string(value, (size_t)bufLen - 1); |
| 29 | + size_t i = stringValue.length(); |
| 30 | + while( i > 0 && stringValue[i-1] == '\0' ){ |
| 31 | + --i; |
| 32 | + } |
| 33 | + return stringValue.substr(0,i); |
| 34 | + } |
| 35 | + |
| 36 | +#endif |
| 37 | + |
11 | 38 | // Run a simple Cadabra server on a local port. |
12 | 39 |
|
13 | 40 | int main() |
14 | 41 | { |
15 | 42 | #ifdef _WIN32 |
16 | 43 | // The Anaconda people _really_ do not understand packaging... |
| 44 | + // We are going to find out the installation path for Anaconda/Miniconda |
| 45 | + // by querying a registry key. |
17 | 46 | std::string pythonhome=Glib::getenv("PYTHONHOME"); |
18 | | - std::string pythonpath=Glib::getenv("PYTHONPATH"); |
19 | | - Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + Glib::get_home_dir()+"/Anaconda3"); |
20 | | - Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + Glib::get_home_dir()+"/Anaconda3"); |
| 47 | + std::string pythonpath=Glib::getenv("PYTHONPATH"); |
| 48 | + |
| 49 | + std::string s = getRegKey("SOFTWARE\\Python\\PythonCore\\3.7", "", false); |
| 50 | + if(s=="") |
| 51 | + s = getRegKey("SOFTWARE\\Python\\PythonCore\\3.7", "", true); |
| 52 | + |
| 53 | +// Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + Glib::get_home_dir()+"/Anaconda3"); |
| 54 | +// Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + Glib::get_home_dir()+"/Anaconda3"); |
| 55 | + Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + s); |
| 56 | + Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + s); |
21 | 57 | // std::cerr << "Server::init: using PYTHONPATH = " << Glib::getenv("PYTHONPATH") |
22 | 58 | // << " and PYTHONHOME = " << Glib::getenv("PYTHONHOME") << "." << std::endl; |
23 | 59 | #endif |
|
0 commit comments