Run SALOME on Windows with unicode path.

This commit is contained in:
rnv 2019-03-05 11:36:02 +03:00
parent 88dc4db51c
commit c0db13accd
2 changed files with 100 additions and 83 deletions

View File

@ -18,12 +18,14 @@
// //
#include "GEOMUtils_XmlHandler.hxx" #include "GEOMUtils_XmlHandler.hxx"
#include <Basics_Utils.hxx>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <algorithm> #include <algorithm>
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#include <algorithm>
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -78,20 +80,35 @@ namespace
std::list<std::string> xmlPaths; std::list<std::string> xmlPaths;
#ifdef WIN32 #ifdef WIN32
#ifdef UNICODE
std::wstring sep = L"\\";
#else
std::string sep = "\\"; std::string sep = "\\";
#endif
#else #else
std::string sep = "/"; std::string sep = "/";
#endif #endif
#if defined(WIN32) && defined(UNICODE)
std::wstring wenv_var = Kernel_Utils::utf8_decode_s(env_var);
if (const wchar_t* var = _wgetenv(wenv_var.c_str()))
{
std::wstring plugins = var;
#else
if (const char* var = getenv(env_var)) if (const char* var = getenv(env_var))
{ {
std::string plugins = var; std::string plugins = var;
#endif
std::string::size_type from = 0, pos; std::string::size_type from = 0, pos;
while (from < plugins.size()) while (from < plugins.size())
{ {
#if defined(WIN32) && defined(UNICODE)
pos = plugins.find(L':', from);
std::wstring plugin;
#else
pos = plugins.find(':', from); pos = plugins.find(':', from);
std::string plugin; std::string plugin;
#endif
if (pos != std::string::npos) if (pos != std::string::npos)
plugin = plugins.substr(from, pos - from); plugin = plugins.substr(from, pos - from);
else else
@ -99,68 +116,75 @@ namespace
from = pos + 1; from = pos + 1;
if (plugin.size() == 0) continue; if (plugin.size() == 0) continue;
#if defined(WIN32) && defined(UNICODE)
std::wstring pluginRoot = plugin + L"_ROOT_DIR";
std::transform(pluginRoot.begin(), pluginRoot.end(), pluginRoot.begin(), ::toupper);
const wchar_t* rootDirGeom = _wgetenv(L"GEOM_ROOT_DIR");
const wchar_t* rootDirPlugin = _wgetenv(pluginRoot.c_str());
#else
std::string pluginRoot = toUpper(plugin + "_ROOT_DIR"); std::string pluginRoot = toUpper(plugin + "_ROOT_DIR");
const char* rootDirGeom = getenv("GEOM_ROOT_DIR"); const char* rootDirGeom = getenv("GEOM_ROOT_DIR");
const char* rootDirPlugin = getenv(pluginRoot.c_str()); const char* rootDirPlugin = getenv(pluginRoot.c_str());
#endif
bool fileOK = false; bool fileOK = false;
if (rootDirGeom) { if (rootDirGeom) {
#if defined(WIN32) && defined(UNICODE)
std::wstring xmlPath = rootDirGeom;
if (xmlPath[xmlPath.size() - 1] != sep[0])
xmlPath += sep;
xmlPath += L"share" + sep + L"salome" + sep + L"resources" + sep + L"geom" + sep + plugin + L".xml";
#else
std::string xmlPath = rootDirGeom; std::string xmlPath = rootDirGeom;
if (xmlPath[xmlPath.size() - 1] != sep[0]) if (xmlPath[xmlPath.size() - 1] != sep[0])
xmlPath += sep; xmlPath += sep;
xmlPath += "share" + sep + "salome" + sep + "resources" + sep + "geom" + sep + plugin + ".xml"; xmlPath += "share" + sep + "salome" + sep + "resources" + sep + "geom" + sep + plugin + ".xml";
#ifdef WIN32 #endif
#ifdef UNICODE #ifdef WIN32
//RNV: this is workaround for providing compilation, fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
// path should be processed as unicode string.
size_t length = strlen(xmlPath.c_str()) + sizeof(char);
wchar_t* aPath = new wchar_t[length + 1];
memset(aPath, '\0', length);
mbstowcs(aPath, xmlPath.c_str(), length);
#else
const char* aPath = xmlPath.c_str();
#endif
fileOK = (GetFileAttributes(aPath) != INVALID_FILE_ATTRIBUTES);
#if UNICODE
delete aPath;
#endif
#else #else
fileOK = (access(xmlPath.c_str(), F_OK) == 0); fileOK = (access(xmlPath.c_str(), F_OK) == 0);
#endif #endif
if (fileOK) if (fileOK)
#if defined(WIN32) && defined(UNICODE)
xmlPaths.push_back(Kernel_Utils::utf8_encode_s(xmlPath));
#else
xmlPaths.push_back(xmlPath); xmlPaths.push_back(xmlPath);
#endif
} }
if (!fileOK && rootDirPlugin) { if (!fileOK && rootDirPlugin) {
#if defined(WIN32) && defined(UNICODE)
std::wstring xmlPath = rootDirPlugin;
if (xmlPath[xmlPath.size() - 1] != sep[0])
xmlPath += sep;
std::transform(plugin.begin(), plugin.end(), plugin.begin(), ::tolower);
xmlPath += L"share" + sep + L"salome" + sep + L"resources" + sep + plugin + sep + plugin + L".xml";
#else
std::string xmlPath = rootDirPlugin; std::string xmlPath = rootDirPlugin;
if (xmlPath[xmlPath.size() - 1] != sep[0]) if (xmlPath[xmlPath.size() - 1] != sep[0])
xmlPath += sep; xmlPath += sep;
xmlPath += "share" + sep + "salome" + sep + "resources" + sep + toLower(plugin) + sep + plugin + ".xml"; xmlPath += "share" + sep + "salome" + sep + "resources" + sep + toLower(plugin) + sep + plugin + ".xml";
#endif
#ifdef WIN32 #ifdef WIN32
#ifdef UNICODE fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
size_t length = strlen(xmlPath.c_str()) + sizeof(char);
wchar_t* aPath = new wchar_t[length+1];
memset(aPath, '\0', length);
mbstowcs(aPath, xmlPath.c_str(), length);
#else
const char* aPath = xmlPath.c_str();
#endif
fileOK = (GetFileAttributes(aPath) != INVALID_FILE_ATTRIBUTES);
#if UNICODE
delete aPath;
#endif
#else #else
fileOK = (access(xmlPath.c_str(), F_OK) == 0); fileOK = (access(xmlPath.c_str(), F_OK) == 0);
#endif #endif
if ( fileOK ) #if defined(WIN32) && defined(UNICODE)
xmlPaths.push_back(Kernel_Utils::utf8_encode_s(xmlPath));
#else
xmlPaths.push_back(xmlPath); xmlPaths.push_back(xmlPath);
} #endif
} }
} }
return xmlPaths; return xmlPaths;
} }
}
#ifdef MYDEBUG #ifdef MYDEBUG
void dumpinfo(const GEOMUtils::PluginInfo& info) void dumpinfo(const GEOMUtils::PluginInfo& info)

View File

@ -2533,20 +2533,13 @@ void GEOM_Gen_i::LoadPlugin(const std::string& theLibName)
if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) { if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) {
#if WIN32 #if WIN32
#if UNICODE #if UNICODE
//RNV: this is workaround for providing compilation, std::wstring strL = Kernel_Utils::utf8_decode_s(aPlatformLibName);
// path should be processed as unicode string. const wchar_t* aPath = strL.c_str();
size_t length = strlen(aPlatformLibName.c_str()) + sizeof(char);
wchar_t* aPath = new wchar_t[length + 1];
memset(aPath, '\0', length);
mbstowcs(aPath, aPlatformLibName.c_str(), length);
#else #else
const char* aPath = aPlatformLibName.c_str(); const char* aPath = aPlatformLibName.c_str();
#endif #endif
// load plugin library // load plugin library
LibHandle libHandle = LoadLib(aPath); LibHandle libHandle = LoadLib(aPath);
#if UNICODE
delete aPath;
#endif
#else #else
LibHandle libHandle = LoadLib(aPlatformLibName.c_str()); LibHandle libHandle = LoadLib(aPlatformLibName.c_str());
#endif #endif