From: rnv Date: Tue, 5 Mar 2019 08:36:02 +0000 (+0300) Subject: Run SALOME on Windows with unicode path. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c0db13accd1ab68409866ac471123b0d2c5ff22d;p=modules%2Fgeom.git Run SALOME on Windows with unicode path. --- diff --git a/src/GEOMUtils/GEOMUtils_XmlHandler.cxx b/src/GEOMUtils/GEOMUtils_XmlHandler.cxx index 46ea3a8f9..cc1212654 100644 --- a/src/GEOMUtils/GEOMUtils_XmlHandler.cxx +++ b/src/GEOMUtils/GEOMUtils_XmlHandler.cxx @@ -18,12 +18,14 @@ // #include "GEOMUtils_XmlHandler.hxx" +#include #include #include #ifdef WIN32 #include +#include #else #include #endif @@ -75,91 +77,113 @@ namespace std::list getPluginXMLFiles() { - std::list xmlPaths; + std::list xmlPaths; #ifdef WIN32 - std::string sep = "\\"; +#ifdef UNICODE + std::wstring sep = L"\\"; +#else + std::string sep = "\\"; +#endif #else - std::string sep = "/"; + std::string sep = "/"; #endif - if ( const char* var = getenv( env_var ) ) - { - std::string plugins = var; +#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)) + { + std::string plugins = var; +#endif + std::string::size_type from = 0, pos; + while (from < plugins.size()) + { +#if defined(WIN32) && defined(UNICODE) + pos = plugins.find(L':', from); + std::wstring plugin; +#else + pos = plugins.find(':', from); + std::string plugin; +#endif + if (pos != std::string::npos) + plugin = plugins.substr(from, pos - from); + else + plugin = plugins.substr(from), pos = plugins.size(); + from = pos + 1; - std::string::size_type from = 0, pos; - while ( from < plugins.size() ) - { - pos = plugins.find( ':', from ); - std::string plugin; - if ( pos != std::string::npos ) - plugin = plugins.substr( from, pos-from ); - else - plugin = plugins.substr( from ), pos = plugins.size(); - from = pos + 1; - - if ( plugin.size() == 0 ) continue; - - std::string pluginRoot = toUpper( plugin+"_ROOT_DIR" ); + 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"); - const char* rootDirGeom = getenv( "GEOM_ROOT_DIR" ); - const char* rootDirPlugin = getenv( pluginRoot.c_str() ); + const char* rootDirGeom = getenv("GEOM_ROOT_DIR"); + const char* rootDirPlugin = getenv(pluginRoot.c_str()); +#endif - bool fileOK = false; - if ( rootDirGeom ) { - std::string xmlPath = rootDirGeom; - if ( xmlPath[ xmlPath.size()-1 ] != sep[0] ) - xmlPath += sep; - xmlPath += "share" + sep + "salome" + sep + "resources" + sep + "geom" + sep + plugin + ".xml"; -#ifdef WIN32 + bool fileOK = false; + if (rootDirGeom) { -#ifdef UNICODE - //RNV: this is workaround for providing compilation, - // 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); +#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 - const char* aPath = xmlPath.c_str(); + std::string xmlPath = rootDirGeom; + if (xmlPath[xmlPath.size() - 1] != sep[0]) + xmlPath += sep; + xmlPath += "share" + sep + "salome" + sep + "resources" + sep + "geom" + sep + plugin + ".xml"; #endif - fileOK = (GetFileAttributes(aPath) != INVALID_FILE_ATTRIBUTES); -#if UNICODE - delete aPath; + +#ifdef WIN32 + fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES); +#else + fileOK = (access(xmlPath.c_str(), F_OK) == 0); #endif + if (fileOK) +#if defined(WIN32) && defined(UNICODE) + xmlPaths.push_back(Kernel_Utils::utf8_encode_s(xmlPath)); #else - fileOK = (access(xmlPath.c_str(), F_OK) == 0); + xmlPaths.push_back(xmlPath); #endif - if ( fileOK ) - xmlPaths.push_back( xmlPath ); - } - if ( !fileOK && rootDirPlugin ) { - std::string xmlPath = rootDirPlugin; - if ( xmlPath[ xmlPath.size()-1 ] != sep[0] ) - xmlPath += sep; - xmlPath += "share" + sep + "salome" + sep + "resources" + sep + toLower(plugin) + sep + plugin + ".xml"; -#ifdef WIN32 -#ifdef UNICODE - 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); + } + 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 - const char* aPath = xmlPath.c_str(); + std::string xmlPath = rootDirPlugin; + if (xmlPath[xmlPath.size() - 1] != sep[0]) + xmlPath += sep; + xmlPath += "share" + sep + "salome" + sep + "resources" + sep + toLower(plugin) + sep + plugin + ".xml"; #endif - fileOK = (GetFileAttributes(aPath) != INVALID_FILE_ATTRIBUTES); -#if UNICODE - delete aPath; + +#ifdef WIN32 + fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES); +#else + fileOK = (access(xmlPath.c_str(), F_OK) == 0); #endif +#if defined(WIN32) && defined(UNICODE) + xmlPaths.push_back(Kernel_Utils::utf8_encode_s(xmlPath)); #else - fileOK = (access(xmlPath.c_str(), F_OK) == 0); + xmlPaths.push_back(xmlPath); #endif - if ( fileOK ) - xmlPaths.push_back( xmlPath ); - } - } - } - return xmlPaths; + } + } + return xmlPaths; + } } #ifdef MYDEBUG diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index d9cbf08c7..69985856d 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -2532,21 +2532,14 @@ void GEOM_Gen_i::LoadPlugin(const std::string& theLibName) // check, if corresponding operations are already created if (myOpCreatorMap.find(theLibName) == myOpCreatorMap.end()) { #if WIN32 - #if UNICODE - //RNV: this is workaround for providing compilation, - // path should be processed as unicode string. - 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); + #if UNICODE + std::wstring strL = Kernel_Utils::utf8_decode_s(aPlatformLibName); + const wchar_t* aPath = strL.c_str(); #else const char* aPath = aPlatformLibName.c_str(); #endif // load plugin library LibHandle libHandle = LoadLib(aPath); - #if UNICODE - delete aPath; - #endif #else LibHandle libHandle = LoadLib(aPlatformLibName.c_str()); #endif