summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-03-15 16:02:47 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-03-15 16:02:47 +0000
commit91243d1c1d3b2360aab5b134c74dcb279a9136d7 (patch)
tree0d3944785bce7dba47545d384e5f061c025e7616 /plugins/HistoryStats
parent9487c9cfe6ab1572444fed37d234a4abfd18f3fb (diff)
crash fix for time handling in HistoryStats 64 bits (thx to white_tiger)
git-svn-id: http://svn.miranda-ng.org/main/trunk@8623 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/HistoryStats')
-rw-r--r--plugins/HistoryStats/src/column_split.cpp6
-rw-r--r--plugins/HistoryStats/src/column_splittimeline.cpp6
-rw-r--r--plugins/HistoryStats/src/optionsctrlimpl.h16
-rw-r--r--plugins/HistoryStats/src/optionsctrlimpl_datetime.cpp41
-rw-r--r--plugins/HistoryStats/src/settings.cpp14
-rw-r--r--plugins/HistoryStats/src/utils.cpp50
-rw-r--r--plugins/HistoryStats/src/utils.h8
-rw-r--r--plugins/HistoryStats/src/version.h2
8 files changed, 70 insertions, 73 deletions
diff --git a/plugins/HistoryStats/src/column_split.cpp b/plugins/HistoryStats/src/column_split.cpp
index fd48189c48..48d47b579f 100644
--- a/plugins/HistoryStats/src/column_split.cpp
+++ b/plugins/HistoryStats/src/column_split.cpp
@@ -156,10 +156,10 @@ void ColSplit::impl_contactDataBeginAcquire()
if (params.alignment == 1)
{
- DWORD dwOffset = 0;
- tm offsetTM = *gmtime(reinterpret_cast<const time_t*>(&dwOffset));
+ time_t offset = 0;
+ struct tm* offsetTM = gmtime(&offset);
- m_nTimeOffset = 86400 * ((offsetTM.tm_wday + 6) % 7);
+ m_nTimeOffset = 86400 * ((offsetTM->tm_wday + 6) % 7);
}
else
{
diff --git a/plugins/HistoryStats/src/column_splittimeline.cpp b/plugins/HistoryStats/src/column_splittimeline.cpp
index 986c48e6e2..f28bc6cb6d 100644
--- a/plugins/HistoryStats/src/column_splittimeline.cpp
+++ b/plugins/HistoryStats/src/column_splittimeline.cpp
@@ -176,10 +176,10 @@ void ColSplitTimeline::impl_contactDataBeginAcquire()
if (params.alignment == 1)
{
- DWORD dwOffset = 0;
- tm offsetTM = *gmtime(reinterpret_cast<const time_t*>(&dwOffset));
+ time_t offset = 0;
+ struct tm* offsetTM = gmtime(&offset);
- m_nTimeOffset = 86400 * ((offsetTM.tm_wday + 6) % 7);
+ m_nTimeOffset = 86400 * ((offsetTM->tm_wday + 6) % 7);
}
else
{
diff --git a/plugins/HistoryStats/src/optionsctrlimpl.h b/plugins/HistoryStats/src/optionsctrlimpl.h
index 9ee6474022..218a28718a 100644
--- a/plugins/HistoryStats/src/optionsctrlimpl.h
+++ b/plugins/HistoryStats/src/optionsctrlimpl.h
@@ -274,8 +274,8 @@ private:
{
public:
static ext::string getDTFormatString(const ext::string& strFormat);
- static SYSTEMTIME toSystemTime(DWORD dwTimestamp);
- static DWORD fromSystemTime(const SYSTEMTIME& st);
+ static SYSTEMTIME toSystemTime(time_t timestamp);
+ static time_t fromSystemTime(const SYSTEMTIME& st);
public:
bool m_bDisableChildsOnNone;
@@ -283,18 +283,18 @@ private:
ext::string m_strFormat;
ext::string m_strFormatDT;
bool m_bNone;
- DWORD m_dwTimestamp;
+ time_t m_timestamp;
HWND m_hDateTimeWnd;
private:
void enableChildsDateTime();
bool getChildEnable();
- DWORD getTimestampValue();
+ time_t getTimestampValue();
bool getTimestampNone();
ext::string getCombinedText();
public:
- explicit DateTime(OptionsCtrlImpl* pCtrl, Item* pParent, const TCHAR* szLabel, const TCHAR* szFormat, DWORD dwTimestamp, DWORD dwFlags, INT_PTR dwData);
+ explicit DateTime(OptionsCtrlImpl* pCtrl, Item* pParent, const TCHAR* szLabel, const TCHAR* szFormat, time_t timestamp, DWORD dwFlags, INT_PTR dwData);
virtual void onToggle() { onActivate(); }
virtual void onSelect();
@@ -308,8 +308,8 @@ private:
bool isNone();
void setNone();
- DWORD getTimestamp();
- void setTimestamp(DWORD dwTimestamp);
+ time_t getTimestamp();
+ void setTimestamp(time_t timestamp);
void onDateTimeChange();
bool isMonthCalVisible();
};
@@ -444,4 +444,4 @@ private:
bool getItemFreeRect(HTREEITEM hItem, RECT& outRect);
};
-#endif // HISTORYSTATS_GUARD_OPTIONSCTRLIMPL_H \ No newline at end of file
+#endif // HISTORYSTATS_GUARD_OPTIONSCTRLIMPL_H
diff --git a/plugins/HistoryStats/src/optionsctrlimpl_datetime.cpp b/plugins/HistoryStats/src/optionsctrlimpl_datetime.cpp
index ee71a916e1..0f56c8e5a4 100644
--- a/plugins/HistoryStats/src/optionsctrlimpl_datetime.cpp
+++ b/plugins/HistoryStats/src/optionsctrlimpl_datetime.cpp
@@ -103,11 +103,11 @@ ext::string OptionsCtrlImpl::DateTime::getDTFormatString(const ext::string& strF
return strOut;
}
-SYSTEMTIME OptionsCtrlImpl::DateTime::toSystemTime(DWORD dwTimestamp)
+SYSTEMTIME OptionsCtrlImpl::DateTime::toSystemTime(time_t timestamp)
{
SYSTEMTIME st;
FILETIME ft;
- LONGLONG ll = Int32x32To64(dwTimestamp, 10000000) + 116444736000000000;
+ LONGLONG ll = Int32x32To64(timestamp, 10000000) + 116444736000000000;
ft.dwLowDateTime = static_cast<DWORD>(ll);
ft.dwHighDateTime = static_cast<DWORD>(ll >> 32);
@@ -117,19 +117,16 @@ SYSTEMTIME OptionsCtrlImpl::DateTime::toSystemTime(DWORD dwTimestamp)
return st;
}
-DWORD OptionsCtrlImpl::DateTime::fromSystemTime(const SYSTEMTIME& st)
+time_t OptionsCtrlImpl::DateTime::fromSystemTime(const SYSTEMTIME& st)
{
FILETIME ft;
LONGLONG ll;
- DWORD dwTimestamp;
SystemTimeToFileTime(&st, &ft);
ll = (static_cast<LONGLONG>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
- dwTimestamp = static_cast<DWORD>((ll - 116444736000000000) / 10000000);
-
- return dwTimestamp;
+ return static_cast<time_t>((ll - 116444736000000000) / 10000000);
}
void OptionsCtrlImpl::DateTime::enableChildsDateTime()
@@ -146,7 +143,7 @@ bool OptionsCtrlImpl::DateTime::getChildEnable()
m_bDisableChildsOnNone && !m_bNone && (!m_bDisableChilds || m_bEnabled);
}
-DWORD OptionsCtrlImpl::DateTime::getTimestampValue()
+time_t OptionsCtrlImpl::DateTime::getTimestampValue()
{
SYSTEMTIME st;
@@ -178,13 +175,13 @@ ext::string OptionsCtrlImpl::DateTime::getCombinedText()
if (m_bNone)
strTemp += TranslateT("none");
else
- strTemp += utils::timestampToString(m_dwTimestamp, m_strFormat.c_str());
+ strTemp += utils::timestampToString(m_timestamp, m_strFormat.c_str());
return strTemp;
}
-OptionsCtrlImpl::DateTime::DateTime(OptionsCtrlImpl* pCtrl, Item* pParent, const TCHAR* szLabel, const TCHAR* szFormat, DWORD dwTimestamp, DWORD dwFlags, INT_PTR dwData)
-: Item(pCtrl, itDateTime, szLabel, dwFlags, dwData), m_hDateTimeWnd(NULL), m_strFormat(szFormat), m_dwTimestamp(dwTimestamp)
+OptionsCtrlImpl::DateTime::DateTime(OptionsCtrlImpl* pCtrl, Item* pParent, const TCHAR* szLabel, const TCHAR* szFormat, time_t timestamp, DWORD dwFlags, INT_PTR dwData)
+: Item(pCtrl, itDateTime, szLabel, dwFlags, dwData), m_hDateTimeWnd(NULL), m_strFormat(szFormat), m_timestamp(timestamp)
{
m_bDisableChildsOnNone = bool_(dwFlags & OCF_DISABLECHILDSONNONE);
m_bAllowNone = bool_(dwFlags & OCF_ALLOWNONE);
@@ -238,7 +235,7 @@ void OptionsCtrlImpl::DateTime::onSelect()
SendMessage(hTempWnd, DTM_SETSYSTEMTIME, GDT_NONE, 0);
}
else {
- SYSTEMTIME st = toSystemTime(m_dwTimestamp);
+ SYSTEMTIME st = toSystemTime(m_timestamp);
SendMessage(hTempWnd, DTM_SETSYSTEMTIME, GDT_VALID, reinterpret_cast<LPARAM>(&st));
}
@@ -263,7 +260,7 @@ void OptionsCtrlImpl::DateTime::onDeselect()
bValidRect = true;
}
- m_dwTimestamp = getTimestampValue();
+ m_timestamp = getTimestampValue();
m_bNone = getTimestampNone();
m_pCtrl->setNodeText(m_hItem, getCombinedText().c_str());
@@ -292,7 +289,7 @@ void OptionsCtrlImpl::DateTime::onActivate()
void OptionsCtrlImpl::DateTime::onDateTimeChange()
{
if (m_hDateTimeWnd) {
- m_dwTimestamp = getTimestampValue();
+ m_timestamp = getTimestampValue();
m_bNone = getTimestampNone();
// enable childs?
@@ -329,7 +326,7 @@ void OptionsCtrlImpl::DateTime::setLabel(const TCHAR* szLabel)
bool OptionsCtrlImpl::DateTime::isNone()
{
if (m_hDateTimeWnd) {
- m_dwTimestamp = getTimestampValue();
+ m_timestamp = getTimestampValue();
m_bNone = getTimestampNone();
}
@@ -355,23 +352,23 @@ void OptionsCtrlImpl::DateTime::setNone()
enableChildsDateTime();
}
-DWORD OptionsCtrlImpl::DateTime::getTimestamp()
+time_t OptionsCtrlImpl::DateTime::getTimestamp()
{
if (m_hDateTimeWnd) {
- m_dwTimestamp = getTimestampValue();
- m_bNone = getTimestampNone();
+ m_timestamp = getTimestampValue();
+ //m_bNone = getTimestampNone();/// @note : what was this supposed to be?
}
- return m_dwTimestamp;
+ return m_timestamp;
}
-void OptionsCtrlImpl::DateTime::setTimestamp(DWORD dwTimestamp)
+void OptionsCtrlImpl::DateTime::setTimestamp(time_t timestamp)
{
m_bNone = false;
- m_dwTimestamp = dwTimestamp;
+ m_timestamp = timestamp;
if (m_hDateTimeWnd) {
- SYSTEMTIME st = toSystemTime(dwTimestamp);
+ SYSTEMTIME st = toSystemTime(timestamp);
SendMessage(m_hDateTimeWnd, DTM_SETSYSTEMTIME, GDT_VALID, reinterpret_cast<LPARAM>(&st));
}
diff --git a/plugins/HistoryStats/src/settings.cpp b/plugins/HistoryStats/src/settings.cpp
index 207af935ae..bd591b231c 100644
--- a/plugins/HistoryStats/src/settings.cpp
+++ b/plugins/HistoryStats/src/settings.cpp
@@ -47,19 +47,19 @@ Settings::Filter::Filter(const ext::string& strID)
: m_strID(strID), m_nMode(fwmWordsMatching), m_nRef(0)
{
time_t curTime = time(NULL);
- struct tm curTM = *localtime(&curTime);
+ struct tm* curTM = localtime(&curTime);
- m_strName += utils::intToPadded(1900 + curTM.tm_year, 4);
+ m_strName += utils::intToPadded(1900 + curTM->tm_year, 4);
m_strName += _T("-");
- m_strName += utils::intToPadded(1 + curTM.tm_mon, 2);
+ m_strName += utils::intToPadded(1 + curTM->tm_mon, 2);
m_strName += _T("-");
- m_strName += utils::intToPadded(curTM.tm_mday, 2);
+ m_strName += utils::intToPadded(curTM->tm_mday, 2);
m_strName += _T(" ");
- m_strName += utils::intToPadded(curTM.tm_hour, 2);
+ m_strName += utils::intToPadded(curTM->tm_hour, 2);
m_strName += _T(":");
- m_strName += utils::intToPadded(curTM.tm_min, 2);
+ m_strName += utils::intToPadded(curTM->tm_min, 2);
m_strName += _T(":");
- m_strName += utils::intToPadded(curTM.tm_sec, 2);
+ m_strName += utils::intToPadded(curTM->tm_sec, 2);
m_strName += _T(".");
m_strName += utils::intToPadded(GetTickCount() % 1000, 3);
}
diff --git a/plugins/HistoryStats/src/utils.cpp b/plugins/HistoryStats/src/utils.cpp
index c73b8d941d..0d7d617a34 100644
--- a/plugins/HistoryStats/src/utils.cpp
+++ b/plugins/HistoryStats/src/utils.cpp
@@ -12,11 +12,11 @@
namespace utils
{
- ext::string timestampToString(DWORD value, const TCHAR* format)
+ ext::string timestampToString(time_t value, const TCHAR* format)
{
TCHAR temp[100] = { 0 };
- return (ext::strfunc::ftime(temp, 100, format, gmtime(reinterpret_cast<time_t*>(&value))) > 0) ? temp : _T("");
+ return (ext::strfunc::ftime(temp, 100, format, gmtime(&value)) > 0) ? temp : _T("");
}
ext::string tmStructToString(const tm& value, const TCHAR* format)
@@ -199,7 +199,7 @@ namespace utils
return szText;
}
- ext::string replaceVariables(const ext::string& strFormat, DWORD timeValue, const TCHAR* szNick /* = _T("") */)
+ ext::string replaceVariables(const ext::string& strFormat, time_t timeValue, const TCHAR* szNick /* = _T("") */)
{
static const TCHAR* szMonthName[][2] = {
{ LPGENT("month3:Jan"), LPGENT("monthF:January") },
@@ -226,7 +226,7 @@ namespace utils
{ LPGENT("wday2:Su"), LPGENT("wday3:Sun"), LPGENT("wdayF:Sunday") },
};
- struct tm timeTM = *gmtime(reinterpret_cast<time_t*>(&timeValue));
+ struct tm* timeTM = gmtime(&timeValue);
ext::string strOut = strFormat;
ext::string::size_type posOpen = strOut.find('%');
@@ -240,67 +240,67 @@ namespace utils
// match variable and generate substitution
if (strVar == _T("h")) {
- strSubst = intToString(timeTM.tm_hour % 12 + (timeTM.tm_hour % 12 == 0 ? 12 : 0));
+ strSubst = intToString(timeTM->tm_hour % 12 + (timeTM->tm_hour % 12 == 0 ? 12 : 0));
}
else if (strVar == _T("hh")) {
- strSubst = intToPadded(timeTM.tm_hour % 12 + (timeTM.tm_hour % 12 == 0 ? 12 : 0), 2);
+ strSubst = intToPadded(timeTM->tm_hour % 12 + (timeTM->tm_hour % 12 == 0 ? 12 : 0), 2);
}
else if (strVar == _T("H")) {
- strSubst = intToString(timeTM.tm_hour);
+ strSubst = intToString(timeTM->tm_hour);
}
else if (strVar == _T("HH")) {
- strSubst = intToPadded(timeTM.tm_hour, 2);
+ strSubst = intToPadded(timeTM->tm_hour, 2);
}
else if (strVar == _T("m")) {
- strSubst = intToString(timeTM.tm_min);
+ strSubst = intToString(timeTM->tm_min);
}
else if (strVar == _T("mm")) {
- strSubst = intToPadded(timeTM.tm_min, 2);
+ strSubst = intToPadded(timeTM->tm_min, 2);
}
else if (strVar == _T("s")) {
- strSubst = intToString(timeTM.tm_sec);
+ strSubst = intToString(timeTM->tm_sec);
}
else if (strVar == _T("ss")) {
- strSubst = intToPadded(timeTM.tm_sec, 2);
+ strSubst = intToPadded(timeTM->tm_sec, 2);
}
else if (strVar == _T("tt")) {
- strSubst = timeTM.tm_hour / 12 ? TranslateT("pm") : TranslateT("am");
+ strSubst = timeTM->tm_hour / 12 ? TranslateT("pm") : TranslateT("am");
}
else if (strVar == _T("TT")) {
- strSubst = timeTM.tm_hour / 12 ? TranslateT("PM") : TranslateT("AM");
+ strSubst = timeTM->tm_hour / 12 ? TranslateT("PM") : TranslateT("AM");
}
else if (strVar == _T("yy")) {
- strSubst = intToPadded((timeTM.tm_year + 1900) % 100, 2);
+ strSubst = intToPadded((timeTM->tm_year + 1900) % 100, 2);
}
else if (strVar == _T("yyyy")) {
- strSubst = intToPadded(timeTM.tm_year + 1900, 4);
+ strSubst = intToPadded(timeTM->tm_year + 1900, 4);
}
else if (strVar == _T("M")) {
- strSubst = intToString(timeTM.tm_mon + 1);
+ strSubst = intToString(timeTM->tm_mon + 1);
}
else if (strVar == _T("MM")) {
- strSubst = intToPadded(timeTM.tm_mon + 1, 2);
+ strSubst = intToPadded(timeTM->tm_mon + 1, 2);
}
else if (strVar == _T("MMM")) {
- strSubst = stripPrefix(_T("month3:"), TranslateTS(szMonthName[timeTM.tm_mon % 12][0]));
+ strSubst = stripPrefix(_T("month3:"), TranslateTS(szMonthName[timeTM->tm_mon % 12][0]));
}
else if (strVar == _T("MMMM")) {
- strSubst = stripPrefix(_T("monthF:"), TranslateTS(szMonthName[timeTM.tm_mon % 12][1]));
+ strSubst = stripPrefix(_T("monthF:"), TranslateTS(szMonthName[timeTM->tm_mon % 12][1]));
}
else if (strVar == _T("d")) {
- strSubst = intToString(timeTM.tm_mday);
+ strSubst = intToString(timeTM->tm_mday);
}
else if (strVar == _T("dd")) {
- strSubst = intToPadded(timeTM.tm_mday, 2);
+ strSubst = intToPadded(timeTM->tm_mday, 2);
}
else if (strVar == _T("ww")) {
- strSubst = stripPrefix(_T("wday2:"), TranslateTS(szWDayName[(timeTM.tm_wday + 6) % 7][0]));
+ strSubst = stripPrefix(_T("wday2:"), TranslateTS(szWDayName[(timeTM->tm_wday + 6) % 7][0]));
}
else if (strVar == _T("www")) {
- strSubst = stripPrefix(_T("wday3:"), TranslateTS(szWDayName[(timeTM.tm_wday + 6) % 7][1]));
+ strSubst = stripPrefix(_T("wday3:"), TranslateTS(szWDayName[(timeTM->tm_wday + 6) % 7][1]));
}
else if (strVar == _T("wwww")) {
- strSubst = stripPrefix(_T("wdayF:"), TranslateTS(szWDayName[(timeTM.tm_wday + 6) % 7][2]));
+ strSubst = stripPrefix(_T("wdayF:"), TranslateTS(szWDayName[(timeTM->tm_wday + 6) % 7][2]));
}
else if (strVar == _T("miranda_path")) {
strSubst = getMirandaPath();
diff --git a/plugins/HistoryStats/src/utils.h b/plugins/HistoryStats/src/utils.h
index 49cab7f9be..c68d124b45 100644
--- a/plugins/HistoryStats/src/utils.h
+++ b/plugins/HistoryStats/src/utils.h
@@ -7,14 +7,14 @@
namespace utils
{
// time formatting
- ext::string timestampToString(DWORD value, const TCHAR* format);
+ ext::string timestampToString(time_t value, const TCHAR* format);
ext::string tmStructToString(const tm& value, const TCHAR* format);
inline ext::string timestampToDateTime(DWORD value) { return timestampToString(value, _T("%c")); }
inline ext::string timestampToDate(DWORD value) { return timestampToString(value, _T("%x")); }
inline ext::string timestampToTime(DWORD value) { return timestampToString(value, _T("%X")); }
ext::string durationToString(DWORD value);
DWORD parseDate(const ext::string& date);
- inline ext::string formatDate(DWORD dwTimestamp) { return timestampToString(dwTimestamp, _T("%Y-%m-%d")); }
+ inline ext::string formatDate(time_t timeValue) { return timestampToString(timeValue, _T("%Y-%m-%d")); }
// number formatting
ext::string intToString(int value);
@@ -32,7 +32,7 @@ namespace utils
inline ext::string replaceAll(ext::string text, const TCHAR* find, const TCHAR* replace) { replaceAllInPlace(text, find, replace); return text; }
inline ext::string htmlEscape(ext::string text) { htmlEscapeInPlace(text); return text; }
const TCHAR* stripPrefix(const TCHAR* szPrefix, const TCHAR* szText);
- ext::string replaceVariables(const ext::string& strFormat, DWORD timeValue, const TCHAR* szNick = _T(""));
+ ext::string replaceVariables(const ext::string& strFormat, time_t timeValue, const TCHAR* szNick = _T(""));
// case conversion
ext::string toLowerCase(const ext::string& text);
@@ -176,4 +176,4 @@ public:
static ext::t::string filter(const ext::t::string& str);
};
-#endif // HISTORYSTATS_GUARD_UTILS_H \ No newline at end of file
+#endif // HISTORYSTATS_GUARD_UTILS_H
diff --git a/plugins/HistoryStats/src/version.h b/plugins/HistoryStats/src/version.h
index f038e8a7f3..1e4d087498 100644
--- a/plugins/HistoryStats/src/version.h
+++ b/plugins/HistoryStats/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 0
-#define __BUILD_NUM 2
+#define __BUILD_NUM 3
#include <stdver.h>