From ab7e0b08fa8c31cf1d468ab4b3c660e2b1836811 Mon Sep 17 00:00:00 2001 From: Fishbone Date: Sun, 2 Jun 2013 16:19:21 +0000 Subject: Added WhatsApp-protocol git-svn-id: http://svn.miranda-ng.org/main/trunk@4861 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/utils.cpp | 106 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 protocols/WhatsApp/src/utils.cpp (limited to 'protocols/WhatsApp/src/utils.cpp') diff --git a/protocols/WhatsApp/src/utils.cpp b/protocols/WhatsApp/src/utils.cpp new file mode 100644 index 0000000000..c635061994 --- /dev/null +++ b/protocols/WhatsApp/src/utils.cpp @@ -0,0 +1,106 @@ +#include "common.h" + +void UnixTimeToFileTime(time_t t, LPFILETIME pft) +{ + // Note that LONGLONG is a 64-bit value + LONGLONG ll; + + ll = Int32x32To64(t, 10000000) + 116444736000000000; + pft->dwLowDateTime = (DWORD)ll; + pft->dwHighDateTime = ll >> 32; +} + +DWORD utils::conversion::to_timestamp(std::string data) +{ + DWORD timestamp = NULL; + /* + if (!utils::conversion::from_string(timestamp, data, std::dec)) { + timestamp = static_cast(::time(NULL)); + } + */ + return timestamp; +} + +std::string utils::text::source_get_value(std::string* data, unsigned int argument_count, ...) +{ + va_list arg; + std::string ret; + std::string::size_type start = 0, end = 0; + + va_start(arg, argument_count); + + for (unsigned int i = argument_count; i > 0; i--) + { + if (i == 1) + { + end = data->find(va_arg(arg, char*), start); + if (start == std::string::npos || end == std::string::npos) + break; + ret = data->substr(start, end - start); + } else { + std::string term = va_arg(arg, char*); + start = data->find(term, start); + if (start == std::string::npos) + break; + start += term.length(); + } + } + + va_end(arg); + return ret; +} + +std::string getLastErrorMsg() +{ + // Retrieve the system error message for the last-error code + + LPVOID lpMsgBuf; + LPVOID lpDisplayBuf; + DWORD dw = WSAGetLastError(); + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dw, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR) &lpMsgBuf, + 0, NULL ); + + // Display the error message and exit the process + /* + lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, + (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); + StringCchPrintf((LPTSTR)lpDisplayBuf, + LocalSize(lpDisplayBuf) / sizeof(TCHAR), + TEXT("%s"), + lpMsgBuf); + */ + + std::string ret((LPSTR) lpMsgBuf); + LocalFree(lpMsgBuf); + //LocalFree(lpDisplayBuf); + + //return std::string((LPCTSTR)lpDisplayBuf); + return ret; +} + +int utils::debug::log(std::string file_name, std::string text) +{ + char szFile[MAX_PATH]; + GetModuleFileNameA(g_hInstance, szFile, SIZEOF(szFile)); + std::string path = szFile; + path = path.substr(0, path.rfind("\\")); + path = path.substr(0, path.rfind("\\") + 1); + path = path + file_name.c_str() + ".txt"; + + SYSTEMTIME time; + GetLocalTime(&time); + + std::ofstream out(path.c_str(), std::ios_base::out | std::ios_base::app | std::ios_base::ate); + out << "[" << (time.wHour < 10 ? "0" : "") << time.wHour << ":" << (time.wMinute < 10 ? "0" : "") << time.wMinute << ":" << (time.wSecond < 10 ? "0" : "") << time.wSecond << "] " << text << std::endl; + out.close(); + + return EXIT_SUCCESS; +} \ No newline at end of file -- cgit v1.2.3