X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FcreaSystem.cxx;h=1346a08a085d16efc80fe686fde8a6d75f5ab975;hb=6621cea2f494bd58d194e3165a5fdb1981025583;hp=65311afe1e6c9601276b7963c26fbf07065a5883;hpb=f212ff2c82487b560f063b0c1d5951841ffe857e;p=crea.git diff --git a/src/creaSystem.cxx b/src/creaSystem.cxx index 65311af..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,8 +171,94 @@ int System::GetAppPath(char *pname, size_t pathsize) #endif /* MACOSX */ return -1; /* Path Lookup Failed */ -} +} + +std::string System::GetDllAppPath(std::string &nomdll){ + std::string path = "."; +#ifdef WIN32 + char currentPath[_MAX_PATH]; + HMODULE hand = GetModuleHandle(nomdll.c_str()); + GetModuleFileName(hand, currentPath, _MAX_PATH); + + path = currentPath; + + path = path.substr(0,path.find_last_of("\\")); +#endif + 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 "<