X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FcreaSystem.cxx;h=1346a08a085d16efc80fe686fde8a6d75f5ab975;hb=6621cea2f494bd58d194e3165a5fdb1981025583;hp=460bb7fb53c5756fbb966d11d4f912dc982c9d9e;hpb=a92a4d8ae0373b7e45cba62c8f84c2196030a269;p=crea.git diff --git a/src/creaSystem.cxx b/src/creaSystem.cxx index 460bb7f..1346a08 100644 --- a/src/creaSystem.cxx +++ b/src/creaSystem.cxx @@ -4,10 +4,17 @@ #include #ifdef WIN32 -#include /* GetModuleFileName */ -#include + #include /* GetModuleFileName */ + #include + #endif /* WIN32 */ +#ifdef LINUX + #include + #include + #include +#endif + #ifdef __APPLE__ /* assume this is OSX */ #include #include /* _NSGetExecutablePath : must add -framework @@ -43,12 +50,7 @@ namespace crea return isatty(fileno(stdin)); } #endif -std::string System::GetDllAppPath(std::string nom){ - std::string path = "."; -#ifdef WIN32 -#endif - return path; -} + int System::GetAppPath(char *pname, size_t pathsize) { #ifdef LINUX @@ -169,9 +171,9 @@ int System::GetAppPath(char *pname, size_t pathsize) #endif /* MACOSX */ return -1; /* Path Lookup Failed */ -} +} -std::string System::GetDllAppPath(std::string nomdll){ +std::string System::GetDllAppPath(std::string &nomdll){ std::string path = "."; #ifdef WIN32 char currentPath[_MAX_PATH]; @@ -185,4 +187,78 @@ std::string System::GetDllAppPath(std::string nomdll){ return path; } + +std::string System::GetDllAppPath(const char *nomdll){ + std::string path = "."; +#ifdef WIN32 + char currentPath[_MAX_PATH]; + HMODULE hand = GetModuleHandle(nomdll); + GetModuleFileName(hand, currentPath, _MAX_PATH); + + path = currentPath; + + path = path.substr(0,path.find_last_of("\\")); +#endif + return path; +} + + +#if defined(_WIN32) +#define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '\\' +#else +#define CREACONTOUR_VALID_FILE_SEPARATOR_CHAR '/' +#endif + + //========================================================================= +std::string System::GetExecutablePath(){ + char name[PATH_MAX]; + //EED int err = get_app_path(name, PATH_MAX); + int err = System::GetAppPath(name,PATH_MAX); + if (err) + { + printf("Could not determine current executable path ? "); + } + // remove the exe name + char *slash; + slash = strrchr(name, CREACONTOUR_VALID_FILE_SEPARATOR_CHAR); + if (slash) + { + *slash = 0; + } + return name; + } + + void System::createDirectory(const char* directorypath){ + #ifdef WIN32 + if (CreateDirectory(directorypath, NULL) == ERROR_ALREADY_EXISTS) + { + std::cout<<"directory already exists "<