Improved Windows compatiblity

This commit is contained in:
Thulinma 2014-05-02 17:03:16 +02:00
parent b460321e3c
commit 9587d2fff6

View file

@ -9,6 +9,10 @@
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#ifdef __CYGWIN__
#include <windows.h>
#endif
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__MACH__) #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__MACH__)
#include <sys/wait.h> #include <sys/wait.h>
#else #else
@ -511,6 +515,9 @@ void Util::Config::addBasicConnectorOptions(JSON::Value & capabilities){
/// Gets directory the current executable is stored in. /// Gets directory the current executable is stored in.
std::string Util::getMyPath(){ std::string Util::getMyPath(){
char mypath[500]; char mypath[500];
#ifdef __CYGWIN__
GetModuleFileName(0, mypath, 500);
#else
#ifdef __APPLE__ #ifdef __APPLE__
memset( mypath, 0, 500); memset( mypath, 0, 500);
unsigned int refSize = 500; unsigned int refSize = 500;
@ -523,6 +530,7 @@ std::string Util::getMyPath(){
mypath[0] = 0; mypath[0] = 0;
} }
#endif #endif
#endif
std::string tPath = mypath; std::string tPath = mypath;
size_t slash = tPath.rfind('/'); size_t slash = tPath.rfind('/');
if (slash == std::string::npos){ if (slash == std::string::npos){
@ -538,6 +546,18 @@ std::string Util::getMyPath(){
/// Gets all executables in getMyPath that start with "Mist". /// Gets all executables in getMyPath that start with "Mist".
void Util::getMyExec(std::deque<std::string> & execs){ void Util::getMyExec(std::deque<std::string> & execs){
std::string path = Util::getMyPath(); 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()); DIR * d = opendir(path.c_str());
if (!d){return;} if (!d){return;}
struct dirent *dp; struct dirent *dp;
@ -550,6 +570,7 @@ void Util::getMyExec(std::deque<std::string> & execs){
} }
} while (dp != NULL); } while (dp != NULL);
closedir(d); closedir(d);
#endif
} }
/// Sets the current process' running user /// Sets the current process' running user