From 7d79bf582d1b34e2bfd56f66b3a9ccfcb4353961 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Thu, 24 Mar 2016 03:47:06 +0300 Subject: [PATCH] Trying to proccess .app references correctly --- src/ipcollector.cpp | 55 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/ipcollector.cpp b/src/ipcollector.cpp index 85fe44a..30014fd 100644 --- a/src/ipcollector.cpp +++ b/src/ipcollector.cpp @@ -34,34 +34,55 @@ bool AddPeer(std::string &strIpAddr) { if (it != vAddedNodes.end()) return false; + printf("Adding node %s\n", strIpAddr.c_str()); vAddedNodes.push_back(strIpAddr); + return true; } - void ThreadIPCollector(void* parg) { printf("ThreadIPCollector started\n"); vnThreadsRunning[THREAD_IPCOLLECTOR]++; - while(!fShutdown) { - if (fServer) { - // If RPC server is enabled then we don't have to parse anything. - std::string strCollectorOutput = exec(strCollectorCommand.c_str()); - printf("Peer collector output: %s\n", strCollectorOutput.c_str()); - } else { - // Otherwise, there is a work to be done. - std::string strCollectorOutput = exec((strCollectorCommand + " norpc").c_str()); - std::istringstream collectorStream(strCollectorOutput); + std::string strExecutableFilePath = ""; +#ifdef MAC_OSX + size_t nameEnd = strCollectorCommand.rfind(".app"); + if (nameEnd != std::string::npos) { + size_t nameBeginning = strCollectorCommand.rfind("/"); + if (nameBeginning == std::string::npos) + nameBeginning = 0; - std::string strIpAddr; - while (std::getline(collectorStream, strIpAddr)) { - AddPeer(strIpAddr); + std::string strFileName = strCollectorCommand.substr(nameBeginning, nameEnd - nameBeginning); + strExecutableFilePath = strCollectorCommand + "/Contents/MacOS/" + strFileName; + } + else + strExecutableFilePath = strCollectorCommand; +#else + strExecutableFilePath = strCollectorCommand; +#endif + + if (strExecutableFilePath != "") + { + while(!fShutdown) { + if (fServer) { + // If RPC server is enabled then we don't have to parse anything. + std::string strCollectorOutput = exec(strExecutableFilePath.c_str()); + printf("Peer collector output: %s\n", strCollectorOutput.c_str()); + } else { + // Otherwise, there is a work to be done. + std::string strCollectorOutput = exec((strExecutableFilePath + " norpc").c_str()); + std::istringstream collectorStream(strCollectorOutput); + + std::string strIpAddr; + while (std::getline(collectorStream, strIpAddr)) { + AddPeer(strIpAddr); + } } - } - int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours. - for (int i = 0; i < nSleepHours * 3600 && !fShutdown; i++) - Sleep(1000); + int nSleepHours = 1 + GetRandInt(5); // Sleep for 1-6 hours. + for (int i = 0; i < nSleepHours * 3600 && !fShutdown; i++) + Sleep(1000); + } } printf("ThreadIPCollector stopped\n"); -- 1.7.1