X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkUtilities.cxx;h=672dac69d4163cd303253da91b8fbef0c0164791;hb=4d6822024afbbe783cdd620e248184b37d84c540;hp=4bf1689be6aed0a62dee70aa01cc4db48b078df3;hpb=536dfc0a21b307fe5fa18afca108a77a5f79a6f6;p=bbtk.git diff --git a/kernel/src/bbtkUtilities.cxx b/kernel/src/bbtkUtilities.cxx index 4bf1689..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,6 +619,33 @@ 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 // @@ -641,9 +671,10 @@ namespace bbtk #ifdef WIN32 //2018-07-06 mingw64 +//2021-12-12 wchar_t pname2[512]; long result = GetModuleFileName(NULL, pname2, pathsize); -// int ret = wcstombs ( pname, pname2, sizeof(pname) ); + crea::System::wtoc(pname2,pname); // long result = GetModuleFileName(NULL, pname, pathsize); if (result > 0) { @@ -743,7 +774,6 @@ namespace bbtk return status; #endif /* MACOSX */ -printf("EED Utilities get_app_path END\n"); return -1; /* Path Lookup Failed */ } @@ -754,59 +784,28 @@ printf("EED Utilities get_app_path END\n"); //========================================================================= std::string Utilities::GetExecutablePath() { -printf("EED Utilities::GetExecutablePath Start\n"); char name[PATH_MAX]; -printf("EED Utilities::GetExecutablePath 1 \n"); int err = get_app_path(name, PATH_MAX); -printf("EED Utilities::GetExecutablePath 2 \n"); + if (err) - { -printf("EED Utilities::GetExecutablePath 2.1 \n"); -// bbtkGlobalError("Could not determine current executable path ?"); - -/* - -printf("EED Utilities bbtkGlobalError XX Start\n"); - do - { -printf("EED Utilities bbtkGlobalError XX A.1\n"); - std::ostringstream s; -printf("EED Utilities bbtkGlobalError XX A.2\n"); - s << "Could not determine current executable path ?"; -printf("EED Utilities bbtkGlobalError XX A.3\n"); - std::ostringstream f; -printf("EED Utilities bbtkGlobalError XX A.4\n"); - f << __FILE__ << " (l."<<__LINE__<<")"; -printf("EED Utilities bbtkGlobalError XX A.5\n"); -std::string aa=f.str(); -printf("EED Utilities bbtkGlobalError XX A.6\n"); -std::string bb=f.str(); -printf("EED Utilities bbtkGlobalError XX A.7\n"); - bbtk::Exception e( "global scope", - f.str(), - s.str()); - throw e; -printf("EED Utilities bbtkGlobalError XX B\n"); - } - while (0); -printf("EED Utilities bbtkGlobalError XX End\n"); - -*/ - - -printf("EED Utilities::GetExecutablePath 2.2 \n"); - } - + { + try + { + bbtkGlobalError("Could not determine current executable path ?"); + } + catch (bbtk::Exception e) + { + std::cerr << e.GetErrorMessage() << std::endl; + } + } + // remove the exe name char *slash; -printf("EED Utilities::GetExecutablePath 3 >%s<\n",name); slash = strrchr(name, VALID_FILE_SEPARATOR_CHAR); -printf("EED Utilities::GetExecutablePath 4 \n"); if (slash) - { - *slash = 0; - } -printf("EED Utilities::GetExecutablePath END \n"); + { + *slash = 0; + } return name; } //========================================================================= @@ -814,7 +813,9 @@ printf("EED Utilities::GetExecutablePath END \n"); 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) @@ -823,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; }