summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/WhatsApp/src/utils.cpp')
-rw-r--r--protocols/WhatsApp/src/utils.cpp106
1 files changed, 106 insertions, 0 deletions
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<DWORD>(timestamp, data, std::dec)) {
+ timestamp = static_cast<DWORD>(::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