X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=kernel%2Fsrc%2FbbtkUtilities.cxx;h=672dac69d4163cd303253da91b8fbef0c0164791;hb=4f67d228a6c8207e7dda7623a1bf664dac01b378;hp=a7285fed13e6e80efd8b93cdba1d9e3747f26acb;hpb=feaad5f26780e5ea143af6da2e000e7058336b36;p=bbtk.git diff --git a/kernel/src/bbtkUtilities.cxx b/kernel/src/bbtkUtilities.cxx index a7285fe..672dac6 100644 --- a/kernel/src/bbtkUtilities.cxx +++ b/kernel/src/bbtkUtilities.cxx @@ -36,6 +36,7 @@ +#include "creaSystem.h" #include "bbtkUtilities.h" #include "bbtkMessageManager.h" @@ -287,8 +288,10 @@ namespace bbtk libname += pkgname; #if defined(MACOSX) libname += ".dylib"; -#else - libname += ".so"; +#elif defined(WIN32) // mingw + libname += ".dll"; +#else // Linux + libname += ".so"; #endif #elif defined(_WIN32) @@ -616,11 +619,39 @@ namespace bbtk } //========================================================================= + + + +//===================================================================================== +/* http://forums.codeguru.com/showthread.php?336106-WCHAR*-to-CHAR* +|| ::DESCRIPTION:: +|| This function will convert a WCHAR string to a CHAR string. +|| +|| Param 1 :: Pointer to a buffer that will contain the converted string. Ensure this +|| buffer is large enough; if not, buffer overrun errors will occur. +|| Param 2 :: Constant pointer to a source WCHAR string to be converted to CHAR +*/ +/* +void wtoc(const WCHAR* Source,CHAR* Dest) +{ + int i = 0; + while(Source[i] != '\0') + { + Dest[i] = (CHAR)Source[i]; + ++i; + } // while +} +*/ + + + + //========================================================================= // From http://www.fltk.org/newsgroups.php?gfltk.general+v:22083 // int get_app_path (char *pname, size_t pathsize) { + #ifdef LINUX /* Oddly, the readlink(2) man page says no NULL is appended. */ /* So you have to do it yourself, based on the return value: */ @@ -638,10 +669,12 @@ namespace bbtk #endif /* LINUX */ #ifdef WIN32 + //2018-07-06 mingw64 +//2021-12-12 wchar_t pname2[512]; - mbstowcs(pname2,pname,strlen(pname)+1); long result = GetModuleFileName(NULL, pname2, pathsize); + crea::System::wtoc(pname2,pname); // long result = GetModuleFileName(NULL, pname, pathsize); if (result > 0) { @@ -740,6 +773,7 @@ namespace bbtk free (given_path); return status; #endif /* MACOSX */ + return -1; /* Path Lookup Failed */ } @@ -752,18 +786,26 @@ namespace bbtk { char name[PATH_MAX]; int err = get_app_path(name, PATH_MAX); + if (err) - { - bbtkGlobalError("Could not determine current executable path ?"); - } - + { + try + { + bbtkGlobalError("Could not determine current executable path ?"); + } + catch (bbtk::Exception e) + { + std::cerr << e.GetErrorMessage() << std::endl; + } + } + // remove the exe name char *slash; slash = strrchr(name, VALID_FILE_SEPARATOR_CHAR); if (slash) - { - *slash = 0; - } + { + *slash = 0; + } return name; } //========================================================================= @@ -771,7 +813,9 @@ namespace bbtk std::string Utilities::GetEnvHome() { -#if defined(__GNUC__) +#if defined(_WIN32) + std::string strHome( getenv("USERPROFILE") ); +#elif defined(__GNUC__) std::string strHome; char *envHome=getenv("HOME"); if (envHome!=NULL) @@ -780,8 +824,6 @@ std::string Utilities::GetEnvHome() } else { strHome = "/var/www/testwtdbg/docroot"; } // if -#elif defined(_WIN32) - std::string strHome( getenv("USERPROFILE") ); #endif return strHome; }