From 9587d2fff6264b2f45e271f372a5c1dfbfc49c47 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Fri, 2 May 2014 17:03:16 +0200 Subject: [PATCH] Improved Windows compatiblity --- lib/config.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/config.cpp b/lib/config.cpp index 65c5bdb2..4ea1b31b 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -9,6 +9,10 @@ #include #include +#ifdef __CYGWIN__ +#include +#endif + #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__MACH__) #include #else @@ -511,18 +515,22 @@ void Util::Config::addBasicConnectorOptions(JSON::Value & capabilities){ /// Gets directory the current executable is stored in. std::string Util::getMyPath(){ char mypath[500]; -#ifdef __APPLE__ + #ifdef __CYGWIN__ + GetModuleFileName(0, mypath, 500); + #else + #ifdef __APPLE__ memset( mypath, 0, 500); unsigned int refSize = 500; int ret = _NSGetExecutablePath(mypath,&refSize); -#else + #else int ret = readlink("/proc/self/exe", mypath, 500); if (ret != -1){ mypath[ret] = 0; }else{ mypath[0] = 0; } -#endif + #endif + #endif std::string tPath = mypath; size_t slash = tPath.rfind('/'); if (slash == std::string::npos){ @@ -538,6 +546,18 @@ std::string Util::getMyPath(){ /// Gets all executables in getMyPath that start with "Mist". void Util::getMyExec(std::deque & execs){ std::string path = Util::getMyPath(); + #ifdef __CYGWIN__ + path += "\\Mist*"; + WIN32_FIND_DATA FindFileData; + HANDLE hdl = FindFirstFile(path.c_str(), &FindFileData); + while (hdl != INVALID_HANDLE_VALUE){ + execs.push_back(FindFileData.cFileName); + if (!FindNextFile(hdl, &FindFileData)){ + FindClose(hdl); + hdl = INVALID_HANDLE_VALUE; + } + } + #else DIR * d = opendir(path.c_str()); if (!d){return;} struct dirent *dp; @@ -550,6 +570,7 @@ void Util::getMyExec(std::deque & execs){ } } while (dp != NULL); closedir(d); + #endif } /// Sets the current process' running user