From bf37d6655a27cc3ea5af5412c9717596c9d1c30f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 19 Jun 2015 18:18:13 +0000 Subject: timezone api migrated to mir_core git-svn-id: http://svn.miranda-ng.org/main/trunk@14266 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- bin10/lib/mir_core.lib | Bin 292608 -> 296626 bytes bin10/lib/mir_core64.lib | Bin 294440 -> 298108 bytes bin12/lib/mir_core.lib | Bin 292608 -> 296626 bytes bin12/lib/mir_core64.lib | Bin 294440 -> 298108 bytes include/delphi/m_timezones.inc | 39 -- include/m_database.h | 53 -- include/m_timezones.h | 125 +++-- plugins/AvatarHistory/src/AvatarDlg.cpp | 6 +- plugins/AvatarHistory/src/stdafx.h | 1 + plugins/BasicHistory/src/BasicHistory.cpp | 5 +- plugins/BasicHistory/src/EventList.cpp | 2 +- plugins/BasicHistory/src/ExportManager.cpp | 4 +- plugins/BasicHistory/src/HistoryWindow.cpp | 4 +- plugins/Clist_modern/src/init.cpp | 3 - plugins/Clist_modern/src/modern_cachefuncs.cpp | 4 +- plugins/Clist_modern/src/modern_clcpaint.cpp | 14 +- .../Clist_modern/src/modern_rowheight_funcs.cpp | 2 +- plugins/Clist_nicer/src/clcitems.cpp | 2 +- plugins/Clist_nicer/src/clcpaint.cpp | 2 +- plugins/Clist_nicer/src/init.cpp | 3 - plugins/CmdLine/src/mimcmd_handlers.cpp | 6 +- plugins/CmdLine/src/stdafx.h | 1 + plugins/Exchange/src/utils.cpp | 4 +- plugins/HistoryLinkListPlus/src/linklist.h | 1 + plugins/HistoryLinkListPlus/src/linklist_fct.cpp | 7 +- plugins/HistoryStats/src/mu_common.cpp | 8 - plugins/HistoryStats/src/mu_common.h | 9 - plugins/HistoryStats/src/statistic.cpp | 4 +- plugins/HistoryStats/src/stdafx.h | 1 + plugins/HistoryStats/src/utils.h | 3 - plugins/IEView/src/HistoryHTMLBuilder.cpp | 7 +- plugins/IEView/src/MUCCHTMLBuilder.cpp | 36 +- plugins/IEView/src/ScriverHTMLBuilder.cpp | 20 +- plugins/IEView/src/TabSRMMHTMLBuilder.cpp | 18 +- plugins/IEView/src/TemplateHTMLBuilder.cpp | 21 +- plugins/IEView/src/ieview_common.h | 2 +- plugins/Msg_Export/src/Glob.h | 1 + plugins/Msg_Export/src/utils.cpp | 7 +- plugins/Popup/src/headers.h | 1 + plugins/Popup/src/popup_wnd2.cpp | 12 +- plugins/Scriver/src/msgdialog.cpp | 4 +- plugins/Scriver/src/msglog.cpp | 2 +- plugins/Scriver/src/srmm.cpp | 2 - plugins/SeenPlugin/src/seen.h | 1 + plugins/SeenPlugin/src/utils.cpp | 6 +- plugins/Spamotron/src/spamotron.cpp | 1 - plugins/TabSRMM/src/generic_msghandlers.cpp | 4 +- plugins/TabSRMM/src/infopanel.cpp | 2 +- plugins/TabSRMM/src/msgdlgutils.cpp | 2 +- plugins/TabSRMM/src/msglog.cpp | 4 +- plugins/TabSRMM/src/srmm.cpp | 2 - plugins/TipperYM/src/subst.cpp | 8 +- plugins/TipperYM/src/tipper.cpp | 2 - plugins/TipperYM/src/translations.cpp | 50 +- plugins/UserInfoEx/src/commonheaders.cpp | 7 +- plugins/UserInfoEx/src/ctrl_tzcombo.cpp | 82 +-- plugins/UserInfoEx/src/init.cpp | 5 +- plugins/UserInfoEx/src/psp_options.cpp | 14 +- plugins/UserInfoEx/src/svc_contactinfo.cpp | 29 +- plugins/UserInfoEx/src/svc_timezone.cpp | 4 +- plugins/UserInfoEx/src/svc_timezone_old.cpp | 13 - plugins/UserInfoEx/src/svc_timezone_old.h | 1 - plugins/Utils/mir_buffer.h | 7 +- plugins/Variables/src/parse_miranda.cpp | 9 +- plugins/Variables/src/variables.h | 1 + plugins/YAMN/src/browser/mailbrowser.cpp | 2 +- plugins/YAMN/src/yamn.h | 1 + protocols/ICQCorp/src/corp.h | 1 + protocols/ICQCorp/src/protocol.cpp | 4 +- protocols/ICQCorp/src/transfer.cpp | 2 +- protocols/IcqOscarJ/src/dlgproc.cpp | 4 +- protocols/IcqOscarJ/src/editlist.cpp | 4 +- protocols/IcqOscarJ/src/init.cpp | 2 - protocols/JabberG/src/jabber.cpp | 2 - protocols/JabberG/src/jabber_iq_handlers.cpp | 6 +- protocols/MSN/src/msn.cpp | 2 - protocols/MSN/src/msn_auth.cpp | 4 +- protocols/SkypeWeb/src/main.cpp | 2 - src/core/stdfile/src/filerecvdlg.cpp | 2 +- src/core/stdfile/src/main.cpp | 2 - src/core/stdhelp/src/main.cpp | 2 - src/core/stdidle/src/main.cpp | 2 - src/core/stdmsg/src/msgdialog.cpp | 10 +- src/core/stdmsg/src/msglog.cpp | 2 +- src/core/stdmsg/src/srmm.cpp | 3 - src/core/stduihist/src/history.cpp | 2 +- src/core/stduihist/src/main.cpp | 2 - src/core/stdurl/main.cpp | 2 - src/core/stdurl/urldialogs.cpp | 2 +- src/core/stduserinfo/src/main.cpp | 2 - src/core/stduserinfo/src/stdinfo.cpp | 6 +- src/mir_app/src/contacts.cpp | 4 +- src/mir_app/src/mir_app.def | 1 - src/mir_app/src/mir_app64.def | 1 - src/mir_app/src/timeutils.cpp | 103 ---- src/mir_app/src/timezones.cpp | 557 ------------------- src/mir_app/src/utils.cpp | 3 - src/mir_core/src/mir_core.def | 16 + src/mir_core/src/mir_core64.def | 16 + src/mir_core/src/miranda.cpp | 14 +- src/mir_core/src/stdafx.h | 2 + src/mir_core/src/timezones.cpp | 587 +++++++++++++++++++++ 102 files changed, 869 insertions(+), 1210 deletions(-) delete mode 100644 src/mir_app/src/timeutils.cpp delete mode 100644 src/mir_app/src/timezones.cpp create mode 100644 src/mir_core/src/timezones.cpp diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib index da108db614..ed84fedca4 100644 Binary files a/bin10/lib/mir_core.lib and b/bin10/lib/mir_core.lib differ diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib index 4234167f2d..f7a21f3e17 100644 Binary files a/bin10/lib/mir_core64.lib and b/bin10/lib/mir_core64.lib differ diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib index da108db614..ed84fedca4 100644 Binary files a/bin12/lib/mir_core.lib and b/bin12/lib/mir_core.lib differ diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib index 4234167f2d..f7a21f3e17 100644 Binary files a/bin12/lib/mir_core64.lib and b/bin12/lib/mir_core64.lib differ diff --git a/include/delphi/m_timezones.inc b/include/delphi/m_timezones.inc index 9ac1c775d0..95e99f7413 100644 --- a/include/delphi/m_timezones.inc +++ b/include/delphi/m_timezones.inc @@ -38,43 +38,4 @@ const type mir_time = int_ptr; -type - TTIME_API = record - cbSize:size_t; - - createByName :function (tszName:TChar; dwFlags:dword):THANDLE; cdecl; - createByContact:function (hContact:TMCONTACT; szModule:PAnsiChar; dwFlags:dword):THANDLE; - storeByContact :procedure(hContact:TMCONTACT; szModule:PAnsiChar; hTZ:THANDLE); cdecl; - - printDateTime:function(hTZ:THANDLE; szFormat:TChar; szDest:TChar; - cbDest:int; dwFlags:dword):int; cdecl; - printTimeStamp:function(hTZ:THANDLE; ts:mir_time; szFormat:TChar; szDest:TChar; - cbDest:int; dwFlags:dword):int; cdecl; - - prepareList :function (hContact:TMCONTACT; szModule:PAnsiChar; hWnd:HWND; dwFlags:dword):int; cdecl; - selectListItem :function (hContact:TMCONTACT; szModule:PAnsiChar; hWnd:HWND; dwFlags:dword):int; cdecl; - storeListResults:procedure(hContact:TMCONTACT; szModule:PAnsiChar; hWnd:HWND; dwFlags:dword); cdecl; - - getTimeZoneTime:function(hTZ:THANDLE; var st:SYSTEMTIME):int; cdecl; - timeStampToTimeZoneTimeStamp:function(hTZ:THANDLE; ts:mir_time):time_t; cdecl; - - getTzi :function(hTZ:THANDLE):PTimeZoneInformation; cdecl; - getTzName :function(hTZ:THANDLE):TChar; cdecl; - getTzDescription:function(TZName:TChar):TChar; cdecl; - end; - -// every protocol should declare this variable to use the Time API -//extern TIME_API tmi; - -{ -a service to obtain the Time API - -wParam = 0; -lParam = (LPARAM)(TIME_API*). - -returns TRUE if all is Ok, and FALSE otherwise -} -const - MS_SYSTEM_GET_TMI:PAnsiChar = 'Miranda/System/GetTimeApi'; - {$ENDIF} diff --git a/include/m_database.h b/include/m_database.h index 5b9f3a5407..9fb0cf23df 100644 --- a/include/m_database.h +++ b/include/m_database.h @@ -592,59 +592,6 @@ __forceinline TCHAR* DbGetEventStringT(DBEVENTINFO* dbei, const char* str) return (TCHAR*)CallService(MS_DB_EVENT_GETSTRINGT, (WPARAM)dbei, (LPARAM)str); } -///////////////////////////////////////////////////////////////////////////////////////// -// Time services - -/* DB/Time/TimestampToLocal -Converts a GMT timestamp into local time - wParam = (WPARAM)(DWORD)timestamp - lParam = 0 -Returns the converted value -Timestamps have zero at midnight 1/1/1970 GMT, this service converts such a -value to be based at midnight 1/1/1970 local time. -This service does not use a simple conversion based on the current offset -between GMT and local. Rather, it figures out whether daylight savings time -would have been in place at the time of the stamp and gives the local time as -it would have been at the time and date the stamp contains. -This service isn't nearly as useful as db/time/TimestampToString below and I -recommend avoiding its use when possible so that you don't get your timezones -mixed up (like I did. Living at GMT makes things easier for me, but has certain -disadvantages :-)). -*/ -#define MS_DB_TIME_TIMESTAMPTOLOCAL "DB/Time/TimestampToLocal" - -/* DB/Time/TimestampToString -Converts a GMT timestamp into a customisable local time string - wParam = (WPARAM)(DWORD)timestamp - lParam = (LPARAM)(DBTIMETOSTRING*)&tts -Returns 0 always -Uses db/time/timestamptolocal for the conversion so read that description to -see what's going on. -The string is formatted according to the current user's locale, language and -preferences. -szFormat can have the following special characters: - t Time without seconds, eg hh:mm - s Time with seconds, eg hh:mm:ss - m Time without minutes, eg hh - d Short date, eg dd/mm/yyyy - D Long date, eg d mmmm yyyy - I ISO 8061 Time yyyy-mm-ddThh:mm:ssZ -All other characters are copied across to szDest as-is -*/ -typedef struct { - char *szFormat; // format string, as above - char *szDest; // place to put the output string - int cbDest; // maximum number of bytes to put in szDest -} DBTIMETOSTRING; -#define MS_DB_TIME_TIMESTAMPTOSTRING "DB/Time/TimestampToString" - -typedef struct { - TCHAR *szFormat; // format string, as above - TCHAR *szDest; // place to put the output string - int cbDest; // maximum number of bytes to put in szDest -} DBTIMETOSTRINGT; -#define MS_DB_TIME_TIMESTAMPTOSTRINGT "DB/Time/TimestampToStringT" - ///////////////////////////////////////////////////////////////////////////////////////// // Random services diff --git a/include/m_timezones.h b/include/m_timezones.h index afdfea6fff..41354f4561 100644 --- a/include/m_timezones.h +++ b/include/m_timezones.h @@ -25,7 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef __M_TIMEZONES_H #define __M_TIMEZONES_H +#ifndef M_CORE_H__ #include +#endif #define MIM_TZ_NAMELEN 64 @@ -39,66 +41,93 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef INT_PTR mir_time; -typedef struct -{ - size_t cbSize; +EXTERN_C MIR_CORE_DLL(HANDLE) TimeZone_CreateByName(LPCTSTR tszName, DWORD dwFlags); +EXTERN_C MIR_CORE_DLL(HANDLE) TimeZone_CreateByContact(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags); - HANDLE (*createByName)(LPCTSTR tszName, DWORD dwFlags); - HANDLE (*createByContact)(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags); - void (*storeByContact)(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ); +EXTERN_C MIR_CORE_DLL(void) TimeZone_StoreByContact(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ); +EXTERN_C MIR_CORE_DLL(void) TimeZone_StoreListResult(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags); - int (*printDateTime)(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags); - int (*printTimeStamp)(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags); +EXTERN_C MIR_CORE_DLL(int) TimeZone_PrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags); +EXTERN_C MIR_CORE_DLL(int) TimeZone_PrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags); - int (*prepareList)(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags); - int (*selectListItem)(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags); - void (*storeListResults)(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags); +EXTERN_C MIR_CORE_DLL(int) TimeZone_PrepareList(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags); +EXTERN_C MIR_CORE_DLL(int) TimeZone_SelectListItem(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags); - int (*getTimeZoneTime)(HANDLE hTZ, SYSTEMTIME *st); - mir_time (*timeStampToTimeZoneTimeStamp)(HANDLE hTZ, mir_time ts); +EXTERN_C MIR_CORE_DLL(int) TimeZone_GetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st); +EXTERN_C MIR_CORE_DLL(mir_time) TimeZone_UtcToLocal(HANDLE hTZ, mir_time ts); - LPTIME_ZONE_INFORMATION (*getTzi)(HANDLE hTZ); - LPCTSTR (*getTzName)(HANDLE hTZ); - LPCTSTR (*getTzDescription)(LPCTSTR TZname); +EXTERN_C MIR_CORE_DLL(LPTIME_ZONE_INFORMATION) TimeZone_GetInfo(HANDLE hTZ); +EXTERN_C MIR_CORE_DLL(LPCTSTR) TimeZone_GetName(HANDLE hTZ); +EXTERN_C MIR_CORE_DLL(LPCTSTR) TimeZone_GetDescription(LPCTSTR TZname); #ifdef __cplusplus - int printDateTimeByContact (MCONTACT hContact, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) - { return printDateTime(createByContact(hContact, 0, dwFlags), szFormat, szDest, cbDest, dwFlags); } - - int printTimeStampByContact(MCONTACT hContact, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) - { return printTimeStamp(createByContact(hContact, 0, dwFlags), ts, szFormat, szDest, cbDest, dwFlags); - } - - LPTIME_ZONE_INFORMATION getTziByContact(MCONTACT hContact) - { return getTzi(createByContact(hContact, 0, 0)); } - - int getTimeZoneTimeByContact(MCONTACT hContact, SYSTEMTIME *st) - { return getTimeZoneTime(createByContact(hContact, 0, 0), st); } - - mir_time timeStampToTimeZoneTimeStampByContact(MCONTACT hContact, mir_time ts) - { return timeStampToTimeZoneTimeStamp(createByContact(hContact, 0, 0), ts); } -#endif - -} TIME_API; - -/* every protocol should declare this variable to use the Time API */ -extern TIME_API tmi; - -/* -a service to obtain the Time API + +__forceinline int printDateTimeByContact (MCONTACT hContact, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) +{ + return TimeZone_PrintDateTime(TimeZone_CreateByContact(hContact, 0, dwFlags), szFormat, szDest, cbDest, dwFlags); +} -wParam = 0; -lParam = (LPARAM)(TIME_API*). +__forceinline int printTimeStampByContact(MCONTACT hContact, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) +{ + return TimeZone_PrintTimeStamp(TimeZone_CreateByContact(hContact, 0, dwFlags), ts, szFormat, szDest, cbDest, dwFlags); +} -returns TRUE if all is Ok, and FALSE otherwise -*/ +__forceinline LPTIME_ZONE_INFORMATION getTziByContact(MCONTACT hContact) +{ + return TimeZone_GetInfo(TimeZone_CreateByContact(hContact, 0, 0)); +} -#define MS_SYSTEM_GET_TMI "Miranda/System/GetTimeApi" +__forceinline int getTimeZoneTimeByContact(MCONTACT hContact, SYSTEMTIME *st) +{ + return TimeZone_GetTimeZoneTime(TimeZone_CreateByContact(hContact, 0, 0), st); +} -__forceinline int mir_getTMI(TIME_API* dest) +__forceinline mir_time timeStampToTimeZoneTimeStampByContact(MCONTACT hContact, mir_time ts) { - dest->cbSize = sizeof(*dest); - return CallService(MS_SYSTEM_GET_TMI, 0, (LPARAM)dest); + return TimeZone_UtcToLocal(TimeZone_CreateByContact(hContact, 0, 0), ts); } +#endif + +///////////////////////////////////////////////////////////////////////////////////////// +// Time services +// +// Converts a GMT timestamp into local time +// Returns the converted value +// +// Timestamps have zero at midnight 1/1/1970 GMT, this service converts such a +// value to be based at midnight 1/1/1970 local time. +// This service does not use a simple conversion based on the current offset +// between GMT and local. Rather, it figures out whether daylight savings time +// would have been in place at the time of the stamp and gives the local time as +// it would have been at the time and date the stamp contains. +// This service isn't nearly as useful as db/time/TimestampToString below and I +// recommend avoiding its use when possible so that you don't get your timezones +// mixed up (like I did. Living at GMT makes things easier for me, but has certain +// disadvantages :-)). + +EXTERN_C MIR_CORE_DLL(DWORD) TimeZone_ToLocal(DWORD); + +///////////////////////////////////////////////////////////////////////////////////////// +// Converts a GMT timestamp into a customisable local time string +// Returns the destination buffer +// +// Uses db/time/timestamptolocal for the conversion so read that description to +// see what's going on. +// The string is formatted according to the current user's locale, language and +// preferences. +// szFormat can have the following special characters: +// t Time without seconds, eg hh:mm +// s Time with seconds, eg hh:mm:ss +// m Time without minutes, eg hh +// d Short date, eg dd/mm/yyyy +// D Long date, eg d mmmm yyyy +// I ISO 8061 Time yyyy-mm-ddThh:mm:ssZ +// All other characters are copied across to szDest as-is + +EXTERN_C MIR_CORE_DLL(char*) TimeZone_ToString(mir_time timeVal, const char *szFormat, char *szDest, size_t cchDest); +EXTERN_C MIR_CORE_DLL(wchar_t*) TimeZone_ToStringW(mir_time timeVal, const wchar_t *wszFormat, wchar_t *wszDest, size_t cchDest); + +#define TimeZone_ToStringT TimeZone_ToStringW + #endif /* __M_TIMEZONES_H */ diff --git a/plugins/AvatarHistory/src/AvatarDlg.cpp b/plugins/AvatarHistory/src/AvatarDlg.cpp index dd425345d6..3a791498cc 100644 --- a/plugins/AvatarHistory/src/AvatarDlg.cpp +++ b/plugins/AvatarHistory/src/AvatarDlg.cpp @@ -438,11 +438,7 @@ int FillAvatarListFromDB(HWND list, MCONTACT hContact) // Get time TCHAR date[64]; - DBTIMETOSTRINGT tts = {0}; - tts.szFormat = _T("d s"); - tts.szDest = date; - tts.cbDest = SIZEOF(date); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)dbei.timestamp, (LPARAM)&tts); + TimeZone_ToStringT(dbei.timestamp, _T("d s"), date, SIZEOF(date)); // Get file in disk TCHAR path[MAX_PATH]; diff --git a/plugins/AvatarHistory/src/stdafx.h b/plugins/AvatarHistory/src/stdafx.h index 4bf6f2395f..27a584f5a1 100644 --- a/plugins/AvatarHistory/src/stdafx.h +++ b/plugins/AvatarHistory/src/stdafx.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/plugins/BasicHistory/src/BasicHistory.cpp b/plugins/BasicHistory/src/BasicHistory.cpp index a52f719a5b..c3cd59d45b 100644 --- a/plugins/BasicHistory/src/BasicHistory.cpp +++ b/plugins/BasicHistory/src/BasicHistory.cpp @@ -59,7 +59,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) return TRUE; } -TIME_API tmi = { 0 }; int hLangpack = 0; extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) @@ -256,10 +255,10 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) extern "C" int __declspec(dllexport) Load(void) { + mir_getLP(&pluginInfo); + hTaskMainMenu = NULL; DuplicateHandle(GetCurrentProcess(),GetCurrentThread(),GetCurrentProcess(),&g_hMainThread,0,FALSE,DUPLICATE_SAME_ACCESS); - mir_getTMI(&tmi); - mir_getLP(&pluginInfo); hCurSplitNS = LoadCursor(NULL, IDC_SIZENS); hCurSplitWE = LoadCursor(NULL, IDC_SIZEWE); diff --git a/plugins/BasicHistory/src/EventList.cpp b/plugins/BasicHistory/src/EventList.cpp index c1c707561e..9bbd8ab243 100644 --- a/plugins/BasicHistory/src/EventList.cpp +++ b/plugins/BasicHistory/src/EventList.cpp @@ -366,7 +366,7 @@ void EventList::AddGroup(const EventIndex& ev) TCHAR eventText[256]; int i; eventText[0] = 0; - tmi.printTimeStamp(NULL, data.timestamp, _T("d t"), eventText, 64, 0); + TimeZone_PrintTimeStamp(NULL, data.timestamp, _T("d t"), eventText, 64, 0); std::wstring time = eventText; std::wstring user; if (data.isMe) diff --git a/plugins/BasicHistory/src/ExportManager.cpp b/plugins/BasicHistory/src/ExportManager.cpp index 36fc670db7..a1049d87d7 100644 --- a/plugins/BasicHistory/src/ExportManager.cpp +++ b/plugins/BasicHistory/src/ExportManager.cpp @@ -333,9 +333,9 @@ void ExportManager::AddGroup(bool isMe, const std::wstring &time, const std::wst } } - tmi.printTimeStamp(NULL, data.timestamp, longFormatDate, str , MAXSELECTSTR, 0); + TimeZone_PrintTimeStamp(NULL, data.timestamp, longFormatDate, str , MAXSELECTSTR, 0); std::wstring longDate = str; - tmi.printTimeStamp(NULL, data.timestamp, formatDate, str , MAXSELECTSTR, 0); + TimeZone_PrintTimeStamp(NULL, data.timestamp, formatDate, str , MAXSELECTSTR, 0); std::wstring shortDate = str; std::wstring user; diff --git a/plugins/BasicHistory/src/HistoryWindow.cpp b/plugins/BasicHistory/src/HistoryWindow.cpp index e01294de40..5fe89953f7 100644 --- a/plugins/BasicHistory/src/HistoryWindow.cpp +++ b/plugins/BasicHistory/src/HistoryWindow.cpp @@ -1487,7 +1487,7 @@ void HistoryWindow::SelectEventGroup(int sel) } } - tmi.printTimeStamp(NULL, data.timestamp, formatDate, str, MAXSELECTSTR, 0); + TimeZone_PrintTimeStamp(NULL, data.timestamp, formatDate, str, MAXSELECTSTR, 0); *strLen = (unsigned int)mir_tstrlen(str) * sizeof(TCHAR); TextSelection->SetStart(MAXLONG); TextSelection->GetFont(&TextFont); @@ -2147,7 +2147,7 @@ void HistoryWindow::FormatQuote(std::wstring& quote, const MessageData& md, cons else quote += contactName; TCHAR str[32]; - tmi.printTimeStamp(NULL, md.timestamp, _T("d t"), str, 32, 0); + TimeZone_PrintTimeStamp(NULL, md.timestamp, _T("d t"), str, 32, 0); quote += _T(", "); quote += str; quote += _T("\n"); diff --git a/plugins/Clist_modern/src/init.cpp b/plugins/Clist_modern/src/init.cpp index a676957105..87d62a98b8 100644 --- a/plugins/Clist_modern/src/init.cpp +++ b/plugins/Clist_modern/src/init.cpp @@ -40,8 +40,6 @@ CLIST_INTERFACE corecli = { 0 }; CLUIDATA g_CluiData = { 0 }; int hLangpack; -TIME_API tmi; - static HRESULT SubclassClistInterface(); static HRESULT CreateHookableEvents(); int EventArea_UnloadModule(); @@ -77,7 +75,6 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) extern "C" __declspec(dllexport) int CListInitialise() { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); g_dwMainThreadID = GetCurrentThreadId(); g_hMirApp = GetModuleHandleA("mir_app.dll"); diff --git a/plugins/Clist_modern/src/modern_cachefuncs.cpp b/plugins/Clist_modern/src/modern_cachefuncs.cpp index 218618edc2..f5128356ef 100644 --- a/plugins/Clist_modern/src/modern_cachefuncs.cpp +++ b/plugins/Clist_modern/src/modern_cachefuncs.cpp @@ -58,7 +58,7 @@ void Cache_GetTimezone(ClcData *dat, MCONTACT hContact) if (dat && dat->hWnd == pcli->hwndContactTree) { DWORD flags = dat->contact_time_show_only_if_different ? TZF_DIFONLY : 0; - pdnce->hTimeZone = tmi.createByContact(hContact, 0, flags); + pdnce->hTimeZone = TimeZone_CreateByContact(hContact, 0, flags); } } @@ -496,7 +496,7 @@ int Cache_GetLineText( if (pdnce->hTimeZone) { // Get pdnce time text[0] = 0; - tmi.printDateTime(pdnce->hTimeZone, _T("t"), text, text_size, 0); + TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), text, text_size, 0); } return TEXT_CONTACT_TIME; diff --git a/plugins/Clist_modern/src/modern_clcpaint.cpp b/plugins/Clist_modern/src/modern_clcpaint.cpp index 7c707492fe..a621838d29 100644 --- a/plugins/Clist_modern/src/modern_clcpaint.cpp +++ b/plugins/Clist_modern/src/modern_clcpaint.cpp @@ -1108,7 +1108,7 @@ void CLCPaint::_PaintRowItemsEx(HWND hwnd, HDC hdcMem, ClcData *dat, ClcContact TCHAR buf[70] = _T(""); mir_free_and_nil(pdnce->szSecondLineText); - tmi.printDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); + TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); pdnce->szSecondLineText = mir_tstrdup(buf); } @@ -1136,7 +1136,7 @@ void CLCPaint::_PaintRowItemsEx(HWND hwnd, HDC hdcMem, ClcData *dat, ClcContact TCHAR buf[70] = _T(""); mir_free(pdnce->szThirdLineText); - tmi.printDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); + TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); pdnce->szThirdLineText = mir_tstrdup(buf); } @@ -1417,7 +1417,7 @@ void CLCPaint::_PaintRowItemsEx(HWND hwnd, HDC hdcMem, ClcData *dat, ClcContact case TC_TIME: TCHAR szResult[80]; - if (!tmi.printDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { + if (!TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { // Select font ChangeToFont(hdcMem, dat, FONTID_CONTACT_TIME, NULL); ske_DrawText(hdcMem, szResult, (int)mir_tstrlen(szResult), &p_rect, DT_NOPREFIX | DT_SINGLELINE | (dat->text_rtl ? DT_RTLREADING : 0)); @@ -2163,7 +2163,7 @@ void CLCPaint::_CalcItemsPos(HDC hdcMem, ClcData *dat, ClcContact *Drawing, RECT if (Drawing->type == CLCIT_CONTACT && dat->contact_time_show && pdnce->hTimeZone) { TCHAR szResult[80]; - if (!tmi.printDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { + if (!TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { SIZE text_size; RECT rc; @@ -2351,7 +2351,7 @@ void CLCPaint::_CalcItemsPos(HDC hdcMem, ClcData *dat, ClcContact *Drawing, RECT if (dat->second_line_type == TEXT_CONTACT_TIME && pdnce->hTimeZone) { // Get contact time TCHAR buf[70] = _T(""); - tmi.printDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); + TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); mir_free(pdnce->szSecondLineText); pdnce->szSecondLineText = mir_tstrdup(buf); } @@ -2385,7 +2385,7 @@ void CLCPaint::_CalcItemsPos(HDC hdcMem, ClcData *dat, ClcContact *Drawing, RECT if (dat->third_line_type == TEXT_CONTACT_TIME && pdnce->hTimeZone) { // Get contact time TCHAR buf[70] = _T(""); - tmi.printDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); + TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); mir_free(pdnce->szThirdLineText); pdnce->szThirdLineText = mir_tstrdup(buf); } @@ -2818,7 +2818,7 @@ void CLCPaint::_DrawContactTime(HDC hdcMem, ClcData *dat, ClcContact *Drawing, R if (!pdnce) return; - if (!tmi.printDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { + if (!TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { // Select font ChangeToFont(hdcMem, dat, FONTID_CONTACT_TIME, NULL); ske_DrawText(hdcMem, szResult, (int)mir_tstrlen(szResult), prcItem, DT_NOPREFIX | DT_SINGLELINE); diff --git a/plugins/Clist_modern/src/modern_rowheight_funcs.cpp b/plugins/Clist_modern/src/modern_rowheight_funcs.cpp index bc2aee1df6..5766aa8e08 100644 --- a/plugins/Clist_modern/src/modern_rowheight_funcs.cpp +++ b/plugins/Clist_modern/src/modern_rowheight_funcs.cpp @@ -288,7 +288,7 @@ int mod_CalcRowHeight_worker(ClcData *dat, HWND hwnd, ClcContact *contact, int i if (item == -1) { TCHAR szResult[80]; - if (!tmi.printDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { + if (!TimeZone_PrintDateTime(pdnce->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) { SIZE text_size = { 0 }; RECT rc = { 0 }; // Select font diff --git a/plugins/Clist_nicer/src/clcitems.cpp b/plugins/Clist_nicer/src/clcitems.cpp index c171a09813..332632a305 100644 --- a/plugins/Clist_nicer/src/clcitems.cpp +++ b/plugins/Clist_nicer/src/clcitems.cpp @@ -38,7 +38,7 @@ static void TZ_LoadTimeZone(MCONTACT hContact, struct TExtraCache *c) DWORD flags = 0; if (cfg::dat.bShowLocalTimeSelective) flags |= TZF_DIFONLY; - c->hTimeZone = tmi.createByContact(hContact, 0, flags); + c->hTimeZone = TimeZone_CreateByContact(hContact, 0, flags); } //routines for managing adding/removal of items in the list, including sorting diff --git a/plugins/Clist_nicer/src/clcpaint.cpp b/plugins/Clist_nicer/src/clcpaint.cpp index 9d5e5946b3..6f8ee502a7 100644 --- a/plugins/Clist_nicer/src/clcpaint.cpp +++ b/plugins/Clist_nicer/src/clcpaint.cpp @@ -1110,7 +1110,7 @@ bgskipped: int fHeight = 0; TCHAR szResult[80]; - if (tmi.printDateTime(cEntry->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) + if (TimeZone_PrintDateTime(cEntry->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0)) goto nodisplay; COLORREF oldColor = GetTextColor(hdcMem); diff --git a/plugins/Clist_nicer/src/init.cpp b/plugins/Clist_nicer/src/init.cpp index 4545f578bb..8cf100d225 100644 --- a/plugins/Clist_nicer/src/init.cpp +++ b/plugins/Clist_nicer/src/init.cpp @@ -37,8 +37,6 @@ extern HICON overlayicons[10]; extern int Docking_ProcessWindowMessage(WPARAM wParam, LPARAM lParam); extern int SetHideOffline(WPARAM wParam, LPARAM lParam); -TIME_API tmi; - HMENU BuildGroupPopupMenu(ClcGroup *group); ClcContact *CreateClcContact(void); CListEvent *fnCreateEvent(void); @@ -126,7 +124,6 @@ static int fnIconFromStatusMode(const char *szProto, int status, MCONTACT hConta extern "C" int __declspec(dllexport) CListInitialise() { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); coreCli = *pcli; diff --git a/plugins/CmdLine/src/mimcmd_handlers.cpp b/plugins/CmdLine/src/mimcmd_handlers.cpp index 6931db6137..7c18db81fd 100644 --- a/plugins/CmdLine/src/mimcmd_handlers.cpp +++ b/plugins/CmdLine/src/mimcmd_handlers.cpp @@ -1458,11 +1458,7 @@ void HandleContactsCommand(PCommand command, TArgument *argv, int argc, PReply r void AddHistoryEvent(DBEVENTINFO *dbEvent, char *contact, PReply reply) { char timestamp[256]; - DBTIMETOSTRING tts = {0}; - tts.szDest = timestamp; - tts.cbDest = sizeof(timestamp); - tts.szFormat = "D, s"; - CallService(MS_DB_TIME_TIMESTAMPTOSTRING, dbEvent->timestamp,(LPARAM) &tts); + TimeZone_ToString(dbEvent->timestamp, "D, s", timestamp, sizeof(timestamp)); char *sender = (dbEvent->flags & DBEF_SENT) ? Translate("[me]") : contact; char *message = DbGetEventTextA(dbEvent,CP_ACP); diff --git a/plugins/CmdLine/src/stdafx.h b/plugins/CmdLine/src/stdafx.h index bc9af0e5ea..58df317ad2 100644 --- a/plugins/CmdLine/src/stdafx.h +++ b/plugins/CmdLine/src/stdafx.h @@ -37,6 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "m_message.h" #include "m_ignore.h" #include "m_string.h" +#include "m_timezones.h" #include "m_crashdumper.h" #include "m_statusplugins.h" diff --git a/plugins/Exchange/src/utils.cpp b/plugins/Exchange/src/utils.cpp index e89a170732..2344840601 100644 --- a/plugins/Exchange/src/utils.cpp +++ b/plugins/Exchange/src/utils.cpp @@ -116,7 +116,7 @@ int GetStringFromDatabase(char *szSettingName, TCHAR *szError, TCHAR *szResult, dbv.type = DBVT_ASCIIZ; if (db_get_ts(NULL, ModuleName, szSettingName, &dbv) == 0) { res = 0; - int tmp = mir_tstrlen(dbv.ptszVal); + size_t tmp = mir_tstrlen(dbv.ptszVal); len = (tmp < size - 1) ? tmp : size - 1; _tcsncpy(szResult, dbv.ptszVal, len); szResult[len] = '\0'; @@ -124,7 +124,7 @@ int GetStringFromDatabase(char *szSettingName, TCHAR *szError, TCHAR *szResult, } else { res = 1; - int tmp = mir_tstrlen(szError); + size_t tmp = mir_tstrlen(szError); len = (tmp < size - 1) ? tmp : size - 1; _tcsncpy(szResult, szError, len); szResult[len] = '\0'; diff --git a/plugins/HistoryLinkListPlus/src/linklist.h b/plugins/HistoryLinkListPlus/src/linklist.h index 6bd8bdde50..867e5a8e7d 100644 --- a/plugins/HistoryLinkListPlus/src/linklist.h +++ b/plugins/HistoryLinkListPlus/src/linklist.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include diff --git a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp index b2524bb251..8948ececc7 100644 --- a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp @@ -41,7 +41,7 @@ int ExtractURI(DBEVENTINFO *dbei, MEVENT hEvent, LISTELEMENT *listStart) static LPCTSTR hyperlinkSubstrings[] = { _T(".com"),_T(".net"),_T(".org"),_T(".co.uk"),_T(".ru") }; - DBTIMETOSTRINGT dbtimestring; + LISTELEMENT *newElement, *actualElement; BYTE type = LINK_UNKNOWN; int direction, isLink, linkFound = 0; @@ -149,10 +149,7 @@ int ExtractURI(DBEVENTINFO *dbei, MEVENT hEvent, LISTELEMENT *listStart) _tcsncpy_s(link, word, ((wordlen > LINK_MAX) ? LINK_MAX : wordlen)); } - dbtimestring.szFormat = _T("d-t"); - dbtimestring.szDest = dbdate; - dbtimestring.cbDest = SIZEOF(dbdate); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT,(WPARAM)dbei->timestamp, (LPARAM)&dbtimestring); + TimeZone_ToStringT(dbei->timestamp, _T("d-t"), dbdate, SIZEOF(dbdate)); date_ptr = _tcstok_s(dbdate, _T("-"), &tok_ctx); time_ptr = _tcstok_s(NULL, _T("-"), &tok_ctx); _tcsncpy_s(date, date_ptr, _TRUNCATE); diff --git a/plugins/HistoryStats/src/mu_common.cpp b/plugins/HistoryStats/src/mu_common.cpp index 971a525ae3..5e435604ac 100644 --- a/plugins/HistoryStats/src/mu_common.cpp +++ b/plugins/HistoryStats/src/mu_common.cpp @@ -104,14 +104,6 @@ namespace mu } } - namespace db_time - { - DWORD timestampToLocal(DWORD timestamp) - { - return static_cast(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, static_cast(timestamp), 0)); - } - } - /* * icolib */ diff --git a/plugins/HistoryStats/src/mu_common.h b/plugins/HistoryStats/src/mu_common.h index 6786201805..99f4c6985b 100644 --- a/plugins/HistoryStats/src/mu_common.h +++ b/plugins/HistoryStats/src/mu_common.h @@ -41,15 +41,6 @@ namespace mu int getCount(); } - /* - * db_time - */ - - namespace db_time - { - DWORD timestampToLocal(DWORD timestamp); - } - /* * icolib */ diff --git a/plugins/HistoryStats/src/statistic.cpp b/plugins/HistoryStats/src/statistic.cpp index f2a5fceaf3..c0207baac8 100644 --- a/plugins/HistoryStats/src/statistic.cpp +++ b/plugins/HistoryStats/src/statistic.cpp @@ -434,7 +434,7 @@ bool Statistic::stepReadDB() // filter logged status messages from tabSRMM if (dbei.eventType == etMessage) { // convert to local time (everything in this plugin is done in local time) - DWORD localTimestamp = utils::toLocalTime(dbei.timestamp); + DWORD localTimestamp = TimeZone_ToLocal(dbei.timestamp); if (localTimestamp >= m_TimeMin && localTimestamp <= m_TimeMax) { if (dbei.flags & DBEF_UTF) { @@ -1235,7 +1235,7 @@ Statistic::Statistic(const Settings& settings, InvocationSource invokedFrom, HIN m_nFirstTime(0), m_nLastTime(0) { - m_TimeStarted = utils::toLocalTime(time(NULL)); + m_TimeStarted = TimeZone_ToLocal(time(NULL)); m_MSecStarted = GetTickCount(); m_AverageMinTime = settings.m_AverageMinTime * 24 * 60 * 60; // calculate seconds from days } diff --git a/plugins/HistoryStats/src/stdafx.h b/plugins/HistoryStats/src/stdafx.h index 0b8e3d16c6..4b623bc649 100644 --- a/plugins/HistoryStats/src/stdafx.h +++ b/plugins/HistoryStats/src/stdafx.h @@ -66,6 +66,7 @@ #include // not used #include #include +#include #include // not used, depends on m_protosvc.h #include // depends on m_protosvc.h diff --git a/plugins/HistoryStats/src/utils.h b/plugins/HistoryStats/src/utils.h index 8c2160dee6..cbd42f240b 100644 --- a/plugins/HistoryStats/src/utils.h +++ b/plugins/HistoryStats/src/utils.h @@ -38,9 +38,6 @@ namespace utils ext::string toLowerCase(const ext::string& text); ext::string toUpperCase(const ext::string& text); - // time conversion - inline DWORD toLocalTime(DWORD gmtTimestamp) { return mu::db_time::timestampToLocal(gmtTimestamp); } - // version conversion DWORD dottedToVersion(ext::string version); ext::string versionToDotted(DWORD version); diff --git a/plugins/IEView/src/HistoryHTMLBuilder.cpp b/plugins/IEView/src/HistoryHTMLBuilder.cpp index 513e8eb9ae..7938502f89 100644 --- a/plugins/IEView/src/HistoryHTMLBuilder.cpp +++ b/plugins/IEView/src/HistoryHTMLBuilder.cpp @@ -83,12 +83,7 @@ char *HistoryHTMLBuilder::timestampToString(time_t check) { static char szResult[512]; char str[80]; - DBTIMETOSTRING dbtts; - dbtts.cbDest = 70; - dbtts.szDest = str; - szResult[0] = '\0'; - dbtts.szFormat = (char *)"d t"; - CallService(MS_DB_TIME_TIMESTAMPTOSTRING, check, (LPARAM)& dbtts); + TimeZone_ToString(check, "d t", str, SIZEOF(str)); mir_strncat(szResult, str, SIZEOF(szResult) - mir_strlen(szResult)); mir_strncpy(szResult, ptrA(mir_utf8encode(szResult)), 500); return szResult; diff --git a/plugins/IEView/src/MUCCHTMLBuilder.cpp b/plugins/IEView/src/MUCCHTMLBuilder.cpp index c34e794f41..7ac74ea989 100644 --- a/plugins/IEView/src/MUCCHTMLBuilder.cpp +++ b/plugins/IEView/src/MUCCHTMLBuilder.cpp @@ -82,11 +82,7 @@ char *MUCCHTMLBuilder::timestampToString(DWORD dwData, time_t check) { static char szResult[512]; char str[80]; - - DBTIMETOSTRING dbtts; - - dbtts.cbDest = 70; - dbtts.szDest = str; + const char *szFormat; szResult[0] = '\0'; struct tm tm_now, tm_today; @@ -96,24 +92,20 @@ char *MUCCHTMLBuilder::timestampToString(DWORD dwData, time_t check) tm_today = tm_now; tm_today.tm_hour = tm_today.tm_min = tm_today.tm_sec = 0; today = mktime(&tm_today); - if (dwData&IEEDD_MUCC_SHOW_DATE && dwData&IEEDD_MUCC_SHOW_TIME) { - if (dwData&IEEDD_MUCC_LONG_DATE) { - dbtts.szFormat = dwData&IEEDD_MUCC_SECONDS ? (char *)"D s" : (char *)"D t"; - } - else { - dbtts.szFormat = dwData&IEEDD_MUCC_SECONDS ? (char *)"d s" : (char *)"d t"; - } - } - else if (dwData&IEEDD_MUCC_SHOW_DATE) { - dbtts.szFormat = dwData&IEEDD_MUCC_LONG_DATE ? (char *)"D" : (char *)"d"; - } - else if (dwData&IEEDD_MUCC_SHOW_TIME) { - dbtts.szFormat = dwData&IEEDD_MUCC_SECONDS ? (char *)"s" : (char *)"t"; - } - else { - dbtts.szFormat = (char *)""; + if (dwData & IEEDD_MUCC_SHOW_DATE && dwData & IEEDD_MUCC_SHOW_TIME) { + if (dwData & IEEDD_MUCC_LONG_DATE) + szFormat = (dwData & IEEDD_MUCC_SECONDS) ? "D s" : "D t"; + else + szFormat = (dwData & IEEDD_MUCC_SECONDS) ? "d s" : "d t"; } - CallService(MS_DB_TIME_TIMESTAMPTOSTRING, check, (LPARAM)& dbtts); + else if (dwData & IEEDD_MUCC_SHOW_DATE) + szFormat = dwData & IEEDD_MUCC_LONG_DATE ? "D" : "d"; + else if (dwData & IEEDD_MUCC_SHOW_TIME) + szFormat = dwData & IEEDD_MUCC_SECONDS ? "s" : "t"; + else + szFormat = (char *)""; + + TimeZone_ToString(check, szFormat, str, SIZEOF(str)); mir_strncat(szResult, str, SIZEOF(szResult) - mir_strlen(szResult)); mir_strncpy(szResult, ptrA(mir_utf8encode(szResult)), 500); return szResult; diff --git a/plugins/IEView/src/ScriverHTMLBuilder.cpp b/plugins/IEView/src/ScriverHTMLBuilder.cpp index 7e98f6a877..7143720889 100644 --- a/plugins/IEView/src/ScriverHTMLBuilder.cpp +++ b/plugins/IEView/src/ScriverHTMLBuilder.cpp @@ -120,19 +120,11 @@ void ScriverHTMLBuilder::loadMsgDlgFont(int i, LOGFONTA * lf, COLORREF * colour) } } -char *ScriverHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) +char* ScriverHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) { - static char szResult[512]; + static char szResult[512]; szResult[0] = '\0'; char str[80]; - char format[20]; - DBTIMETOSTRING dbtts; - - szResult[0] = '\0'; - format[0] = '\0'; - - dbtts.cbDest = 70; - dbtts.szDest = str; - dbtts.szFormat = format; + char format[20]; format[0] = '\0'; if ((mode == 0 || mode == 1) && (dwFlags & SMF_LOG_SHOWDATE)) { struct tm tm_now, tm_today; @@ -163,13 +155,13 @@ char *ScriverHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mod } } if (mode == 0 || mode == 2) { - if (mode == 0 && (dwFlags & SMF_LOG_SHOWDATE)) { + if (mode == 0 && (dwFlags & SMF_LOG_SHOWDATE)) mir_strcat(format, " "); - } + mir_strcat(format, (dwFlags & SMF_LOG_SHOWSECONDS) ? "s" : "t"); } if (format[0] != '\0') { - CallService(MS_DB_TIME_TIMESTAMPTOSTRING, check, (LPARAM)& dbtts); + TimeZone_ToString(check, format, str, SIZEOF(str)); mir_strncat(szResult, str, SIZEOF(szResult) - mir_strlen(szResult)); } mir_strncpy(szResult, ptrA(mir_utf8encode(szResult)), 500); diff --git a/plugins/IEView/src/TabSRMMHTMLBuilder.cpp b/plugins/IEView/src/TabSRMMHTMLBuilder.cpp index aa08a7b73a..5f02f33da0 100644 --- a/plugins/IEView/src/TabSRMMHTMLBuilder.cpp +++ b/plugins/IEView/src/TabSRMMHTMLBuilder.cpp @@ -155,18 +155,14 @@ char* TabSRMMHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int isG { static char szResult[512]; char str[80]; - - DBTIMETOSTRING dbtts; + const char *szFormat; struct tm tm_now, tm_today; time_t now = time(NULL); time_t today; - dbtts.cbDest = 70; - dbtts.szDest = str; - if (!isGroupBreak || !(dwFlags & MWF_LOG_SHOWDATES)) { - dbtts.szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? (char *)"s" : (char *)"t"; + szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? "s" : "t"; szResult[0] = '\0'; } else { @@ -176,24 +172,24 @@ char* TabSRMMHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int isG today = mktime(&tm_today); if (dwFlags & MWF_LOG_USERELATIVEDATES && check >= today) { - dbtts.szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? (char *)"s" : (char *)"t"; + szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? "s" : "t"; mir_strcpy(szResult, Translate("Today")); mir_strcat(szResult, ", "); } else if (dwFlags & MWF_LOG_USERELATIVEDATES && check > (today - 86400)) { - dbtts.szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? (char *)"s" : (char *)"t"; + szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? "s" : "t"; mir_strcpy(szResult, Translate("Yesterday")); mir_strcat(szResult, ", "); } else { if (dwFlags & MWF_LOG_LONGDATES) - dbtts.szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? (char *)"D s" : (char *)"D t"; + szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? "D s" : "D t"; else - dbtts.szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? (char *)"d s" : (char *)"d t"; + szFormat = (dwFlags & MWF_LOG_SHOWSECONDS) ? "d s" : "d t"; szResult[0] = '\0'; } } - CallService(MS_DB_TIME_TIMESTAMPTOSTRING, check, (LPARAM)& dbtts); + TimeZone_ToString(check, szFormat, str, SIZEOF(str)); mir_strncat(szResult, str, SIZEOF(szResult) - mir_strlen(szResult)); mir_strncpy(szResult, ptrA(mir_utf8encode(szResult)), 500); return szResult; diff --git a/plugins/IEView/src/TemplateHTMLBuilder.cpp b/plugins/IEView/src/TemplateHTMLBuilder.cpp index e63cfd2203..d7f5ecc85c 100644 --- a/plugins/IEView/src/TemplateHTMLBuilder.cpp +++ b/plugins/IEView/src/TemplateHTMLBuilder.cpp @@ -118,17 +118,12 @@ int TemplateHTMLBuilder::getFlags(ProtocolSettings * protoSettings) char *TemplateHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mode) { - static char szResult[512]; + static char szResult[512]; szResult[0] = '\0'; TCHAR str[300]; - DBTIMETOSTRINGT dbtts; - dbtts.cbDest = 70; - dbtts.szDest = str; - szResult[0] = '\0'; - if (mode) { //time - dbtts.szFormat = (dwFlags & Options::LOG_SHOW_SECONDS) ? _T("s") : _T("t"); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, check, (LPARAM)&dbtts); - } - else {//date + + if (mode) // time + TimeZone_ToStringT(check, (dwFlags & Options::LOG_SHOW_SECONDS) ? _T("s") : _T("t"), str, SIZEOF(str)); + else { // date struct tm tm_now, tm_today; time_t now = time(NULL); time_t today; @@ -140,10 +135,8 @@ char *TemplateHTMLBuilder::timestampToString(DWORD dwFlags, time_t check, int mo _tcsncpy(str, TranslateT("Today"), SIZEOF(str)); else if (dwFlags & Options::LOG_RELATIVE_DATE && check > (today - 86400)) _tcsncpy(str, TranslateT("Yesterday"), SIZEOF(str)); - else { - dbtts.szFormat = (dwFlags & Options::LOG_LONG_DATE) ? _T("D") : _T("d"); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, check, (LPARAM)& dbtts); - } + else + TimeZone_ToStringT(check, (dwFlags & Options::LOG_LONG_DATE) ? _T("D") : _T("d"), str, SIZEOF(str)); } mir_strncpy(szResult, T2Utf(str), 500); diff --git a/plugins/IEView/src/ieview_common.h b/plugins/IEView/src/ieview_common.h index 0edf01a964..2149316aa4 100644 --- a/plugins/IEView/src/ieview_common.h +++ b/plugins/IEView/src/ieview_common.h @@ -52,7 +52,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include - +#include #include #include #include diff --git a/plugins/Msg_Export/src/Glob.h b/plugins/Msg_Export/src/Glob.h index 1f59deeb5f..3d21adb29e 100755 --- a/plugins/Msg_Export/src/Glob.h +++ b/plugins/Msg_Export/src/Glob.h @@ -38,6 +38,7 @@ using namespace std; #include #include #include +#include #include #include diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 755193bddd..65b86fc401 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -1134,12 +1134,7 @@ void ExportDBEventInfo(MCONTACT hContact, DBEVENTINFO &dbei) nFirstColumnWidth, dbei.flags & DBEF_SENT ? sLocalUser.c_str() : sRemoteUser.c_str()); - DBTIMETOSTRINGT dbtts; - dbtts.cbDest = SIZEOF(szTemp) - nIndent - 2; - dbtts.szDest = &szTemp[nIndent]; - dbtts.szFormat = (TCHAR*)sTimeFormat.c_str(); - - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, dbei.timestamp, (LPARAM)&dbtts); + TimeZone_ToStringT(dbei.timestamp, sTimeFormat.c_str(), &szTemp[nIndent], SIZEOF(szTemp) - nIndent - 2); nIndent = (int)mir_tstrlen(szTemp); szTemp[nIndent++] = ' '; diff --git a/plugins/Popup/src/headers.h b/plugins/Popup/src/headers.h index ce6142318a..56b8d1b625 100644 --- a/plugins/Popup/src/headers.h +++ b/plugins/Popup/src/headers.h @@ -83,6 +83,7 @@ http://miranda-ng.org/distr/ #include #include #include +#include #include #include diff --git a/plugins/Popup/src/popup_wnd2.cpp b/plugins/Popup/src/popup_wnd2.cpp index 2d45ac3553..f1183f6dd4 100644 --- a/plugins/Popup/src/popup_wnd2.cpp +++ b/plugins/Popup/src/popup_wnd2.cpp @@ -751,16 +751,10 @@ void PopupWnd2::updateData(POPUPDATA2 *ppd) m_lpzSkin = mir_a2t(ppd->lpzSkin); if (m_options->DisplayTime) { - if (ppd->dwTimestamp) { - DBTIMETOSTRINGT dbtts; - dbtts.szFormat = _T("t"); - dbtts.szDest = m_time; - dbtts.cbDest = SIZEOF(m_time); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ppd->dwTimestamp, (LPARAM)&dbtts); - } - else { + if (ppd->dwTimestamp) + TimeZone_ToStringT(ppd->dwTimestamp, _T("t"), m_time, SIZEOF(m_time)); + else GetTimeFormat(LOCALE_USER_DEFAULT, 0, NULL, _T("HH':'mm"), m_time, SIZEOF(m_time)); - } } else m_time[0] = 0; diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index c0f45ade83..995921af6d 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -1367,8 +1367,8 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP } else if (dat->lastMessage) { TCHAR date[64], time[64]; - tmi.printTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); - tmi.printTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); + TimeZone_PrintTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); + TimeZone_PrintTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); mir_sntprintf(szText, TranslateT("Last message received on %s at %s."), date, time); sbd.pszText = szText; } diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index 86a2751f2c..537673b5a2 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -425,7 +425,7 @@ TCHAR* TimestampToString(DWORD dwFlags, time_t check, int mode) mir_tstrcat(format, (dwFlags & SMF_SHOWSECONDS) ? _T("s") : _T("t")); } if (format[0] != '\0') { - tmi.printTimeStamp(NULL, check, format, str, SIZEOF(str), 0); + TimeZone_PrintTimeStamp(NULL, check, format, str, SIZEOF(str), 0); mir_tstrncat(szResult, str, SIZEOF(szResult) - mir_tstrlen(szResult)); } return szResult; diff --git a/plugins/Scriver/src/srmm.cpp b/plugins/Scriver/src/srmm.cpp index 33d51c4722..371dccf22e 100644 --- a/plugins/Scriver/src/srmm.cpp +++ b/plugins/Scriver/src/srmm.cpp @@ -27,7 +27,6 @@ int OnLoadModule(void); int OnUnloadModule(void); int hLangpack; -TIME_API tmi; HINSTANCE g_hInst; CLIST_INTERFACE *pcli; @@ -63,7 +62,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRMM, extern "C" __declspec(dllexport) int Load(void) { // set the memory manager - mir_getTMI(&tmi); mir_getLP(&pluginInfo); mir_getCLI(); diff --git a/plugins/SeenPlugin/src/seen.h b/plugins/SeenPlugin/src/seen.h index 6f2273546b..4a83833fe6 100644 --- a/plugins/SeenPlugin/src/seen.h +++ b/plugins/SeenPlugin/src/seen.h @@ -41,6 +41,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include #include diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index ea0df3cb61..6a1818d295 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -105,7 +105,7 @@ DWORD isSeen(MCONTACT hcontact, SYSTEMTIME *st) DWORD res = db_get_dw(hcontact, S_MOD, "seenTS", 0); if (res) { if (st) { - ll = UInt32x32To64(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, res, 0), 10000000) + NUM100NANOSEC; + ll = UInt32x32To64(TimeZone_ToLocal(res), 10000000) + NUM100NANOSEC; ft.dwLowDateTime = (DWORD)ll; ft.dwHighDateTime = (DWORD)(ll >> 32); FileTimeToSystemTime(&ft, st); @@ -127,7 +127,7 @@ DWORD isSeen(MCONTACT hcontact, SYSTEMTIME *st) ll -= NUM100NANOSEC; ll /= 10000000; //perform LOCALTOTIMESTAMP - res = (DWORD)ll - CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, 0, 0); + res = (DWORD)ll - TimeZone_ToLocal(0); //nevel look for Year/Month/Day/Hour/Minute/Second again db_set_dw(hcontact, S_MOD, "seenTS", res); } @@ -406,7 +406,7 @@ void DBWriteTimeTS(DWORD t, MCONTACT hcontact) { SYSTEMTIME st; FILETIME ft; - ULONGLONG ll = UInt32x32To64(CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, t, 0), 10000000) + NUM100NANOSEC; + ULONGLONG ll = UInt32x32To64(TimeZone_ToLocal(t), 10000000) + NUM100NANOSEC; ft.dwLowDateTime = (DWORD)ll; ft.dwHighDateTime = (DWORD)(ll >> 32); FileTimeToSystemTime(&ft, &st); diff --git a/plugins/Spamotron/src/spamotron.cpp b/plugins/Spamotron/src/spamotron.cpp index 87172f6092..89f62764ce 100644 --- a/plugins/Spamotron/src/spamotron.cpp +++ b/plugins/Spamotron/src/spamotron.cpp @@ -54,7 +54,6 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; char *msgblob; POPUPDATAT ppdp = {0}; - DBTIMETOSTRING tts = {0}; char protoOption[256] = {0}; int buflen = MAX_BUFFER_LENGTH; TCHAR buf[MAX_BUFFER_LENGTH]; diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index bd339bb0eb..13e8eaa563 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -1053,10 +1053,10 @@ void TSAPI DM_UpdateLastMessage(const TWindowData *dat) mir_sntprintf(szBuf, SIZEOF(szBuf), _T("UID: %s"), dat->cache->getUIN()); else if (dat->lastMessage) { TCHAR date[64], time[64]; - tmi.printTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); + TimeZone_PrintTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); if (dat->pContainer->dwFlags & CNT_UINSTATUSBAR && mir_tstrlen(date) > 6) date[mir_tstrlen(date) - 5] = 0; - tmi.printTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); + TimeZone_PrintTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); mir_sntprintf(szBuf, SIZEOF(szBuf), TranslateT("Last received: %s at %s"), date, time); } else szBuf[0] = 0; diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index 345b527901..747e5682bf 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -543,7 +543,7 @@ void CInfoPanel::RenderIPStatus(const HDC hdc, RECT& rcItem) TCHAR szResult[80]; szResult[0] = 0; if (m_dat->hTimeZone) { - tmi.printDateTime(m_dat->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0); + TimeZone_PrintDateTime(m_dat->hTimeZone, _T("t"), szResult, SIZEOF(szResult), 0); GetTextExtentPoint32(hdc, szResult, (int)mir_tstrlen(szResult), &sTime); } diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index 62c18f8d36..8da7eac733 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -1383,7 +1383,7 @@ void TSAPI LoadOwnAvatar(TWindowData *dat) void TSAPI LoadTimeZone(TWindowData *dat) { if (dat) - dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY); + dat->hTimeZone = TimeZone_CreateByContact(dat->hContact, 0, TZF_KNOWNONLY); } // paste contents of the clipboard into the message input area and send it immediately diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index dc39ec3eed..a04ee564cd 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -367,7 +367,7 @@ static TCHAR* Template_MakeRelativeDate(HANDLE hTimeZone, time_t check, TCHAR co else szFormat = _T("d"); - tmi.printTimeStamp(hTimeZone, check, szFormat, szResult, SIZEOF(szResult), 0); + TimeZone_PrintTimeStamp(hTimeZone, check, szFormat, szResult, SIZEOF(szResult), 0); } return szResult; } @@ -496,7 +496,7 @@ static char* Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, // templated code starts here if (dwEffectiveFlags & MWF_LOG_SHOWTIME) { hTimeZone = ((dat->dwFlags & MWF_LOG_LOCALTIME) && !isSent) ? dat->hTimeZone : NULL; - time_t local_time = tmi.timeStampToTimeZoneTimeStamp(hTimeZone, dbei.timestamp); + time_t local_time = TimeZone_UtcToLocal(hTimeZone, dbei.timestamp); event_time = *gmtime(&local_time); } diff --git a/plugins/TabSRMM/src/srmm.cpp b/plugins/TabSRMM/src/srmm.cpp index dc4c16ab31..cd460b4856 100644 --- a/plugins/TabSRMM/src/srmm.cpp +++ b/plugins/TabSRMM/src/srmm.cpp @@ -36,7 +36,6 @@ LOGFONT lfDefault = { 0 }; */ int hLangpack; -TIME_API tmi = { 0 }; CLIST_INTERFACE *pcli; PLUGININFOEX pluginInfo = { @@ -74,7 +73,6 @@ extern "C" int __declspec(dllexport) Load(void) } mir_getCLI(); - mir_getTMI(&tmi); mir_getLP(&pluginInfo); SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfDefault), &lfDefault, FALSE); diff --git a/plugins/TipperYM/src/subst.cpp b/plugins/TipperYM/src/subst.cpp index 15310e474d..0d97d50af1 100644 --- a/plugins/TipperYM/src/subst.cpp +++ b/plugins/TipperYM/src/subst.cpp @@ -134,12 +134,8 @@ DWORD LastMessageTimestamp(MCONTACT hContact, bool received) void FormatTimestamp(DWORD ts, char *szFormat, TCHAR *buff, int bufflen) { TCHAR swzForm[16]; - DBTIMETOSTRINGT dbt = {0}; - dbt.cbDest = bufflen; - dbt.szDest = buff; a2t(szFormat, swzForm, 16); - dbt.szFormat = swzForm; - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ts, (LPARAM)&dbt); + TimeZone_ToStringT(ts, swzForm, buff, bufflen); } bool Uid(MCONTACT hContact, char *szProto, TCHAR *buff, int bufflen) @@ -280,7 +276,7 @@ bool GetSysSubstText(MCONTACT hContact, TCHAR *swzRawSpec, TCHAR *buff, int buff } } else if (!mir_tstrcmp(swzRawSpec, _T("time"))) { - if (tmi.printDateTime && !tmi.printDateTimeByContact(hContact, _T("t"), buff, bufflen, TZF_KNOWNONLY)) + if (!printDateTimeByContact(hContact, _T("t"), buff, bufflen, TZF_KNOWNONLY)) return true; } else if (!mir_tstrcmp(swzRawSpec, _T("uidname"))) { diff --git a/plugins/TipperYM/src/tipper.cpp b/plugins/TipperYM/src/tipper.cpp index a8c6e68194..bc94a4a38c 100644 --- a/plugins/TipperYM/src/tipper.cpp +++ b/plugins/TipperYM/src/tipper.cpp @@ -37,7 +37,6 @@ TCHAR SKIN_FOLDER[256]; CLIST_INTERFACE *pcli = NULL; FI_INTERFACE *fii = NULL; -TIME_API tmi; int hLangpack; PLUGININFOEX pluginInfoEx = @@ -299,7 +298,6 @@ extern "C" int __declspec(dllexport) Load(void) CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fii); mir_getLP(&pluginInfoEx); mir_getCLI(); - mir_getTMI(&tmi); iCodePage = Langpack_GetDefaultCodePage(); diff --git a/plugins/TipperYM/src/translations.cpp b/plugins/TipperYM/src/translations.cpp index 12ac692831..e492d4bbf8 100644 --- a/plugins/TipperYM/src/translations.cpp +++ b/plugins/TipperYM/src/translations.cpp @@ -70,59 +70,43 @@ TCHAR *NullTranslation(MCONTACT hContact, const char *szModuleName, const char * return NULL; } -TCHAR *TimestampToShortDate(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) +TCHAR* TimestampToShortDate(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) { DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0); - if (ts == 0) return 0; + if (ts == 0) + return 0; - DBTIMETOSTRINGT dbt = {0}; - dbt.cbDest = bufflen; - dbt.szDest = buff; - dbt.szFormat = _T("d"); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ts, (LPARAM)&dbt); - return buff; + return TimeZone_ToStringT(ts, _T("d"), buff, bufflen); } -TCHAR *TimestampToLongDate(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) +TCHAR* TimestampToLongDate(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) { DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0); - if (ts == 0) return 0; + if (ts == 0) + return 0; - DBTIMETOSTRINGT dbt = {0}; - dbt.cbDest = bufflen; - dbt.szDest = buff; - dbt.szFormat = _T("D"); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ts, (LPARAM)&dbt); - return buff; + return TimeZone_ToStringT(ts, _T("D"), buff, bufflen); } -TCHAR *TimestampToTime(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) +TCHAR* TimestampToTime(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) { DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0); - if (ts == 0) return 0; + if (ts == 0) + return 0; - DBTIMETOSTRINGT dbt = {0}; - dbt.cbDest = bufflen; - dbt.szDest = buff; - dbt.szFormat = _T("s"); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ts, (LPARAM)&dbt); - return buff; + return TimeZone_ToStringT(ts, _T("s"), buff, bufflen); } -TCHAR *TimestampToTimeNoSecs(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) +TCHAR* TimestampToTimeNoSecs(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) { DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0); - if (ts == 0) return 0; + if (ts == 0) + return 0; - DBTIMETOSTRINGT dbt = {0}; - dbt.cbDest = bufflen; - dbt.szDest = buff; - dbt.szFormat = _T("t"); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ts, (LPARAM)&dbt); - return buff; + return TimeZone_ToStringT(ts, _T("t"), buff, bufflen); } -TCHAR *TimestampToTimeDifference(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) +TCHAR* TimestampToTimeDifference(MCONTACT hContact, const char *szModuleName, const char *szSettingName, TCHAR *buff, int bufflen) { DWORD ts = db_get_dw(hContact, szModuleName, szSettingName, 0); DWORD t = (DWORD)time(0); diff --git a/plugins/UserInfoEx/src/commonheaders.cpp b/plugins/UserInfoEx/src/commonheaders.cpp index 8eb7699f3a..9b4d77bff0 100644 --- a/plugins/UserInfoEx/src/commonheaders.cpp +++ b/plugins/UserInfoEx/src/commonheaders.cpp @@ -22,10 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" // global: -HINSTANCE ghInst = NULL; -TIME_API tmi; //timezone interface -FI_INTERFACE *FIP = NULL; //freeimage interface -CLIST_INTERFACE *pcli = NULL; +HINSTANCE ghInst = NULL; +FI_INTERFACE *FIP = NULL; //freeimage interface +CLIST_INTERFACE *pcli = NULL; MGLOBAL myGlobals; pfnDwmIsCompositionEnabled dwmIsCompositionEnabled; diff --git a/plugins/UserInfoEx/src/ctrl_tzcombo.cpp b/plugins/UserInfoEx/src/ctrl_tzcombo.cpp index 7159718a51..52dd6b0d1b 100644 --- a/plugins/UserInfoEx/src/ctrl_tzcombo.cpp +++ b/plugins/UserInfoEx/src/ctrl_tzcombo.cpp @@ -49,27 +49,14 @@ static INT_PTR EnumNamesProc(CTimeZone *pTimeZone, int index, LPARAM lParam) **/ CBaseCtrl* CTzCombo::CreateObj(HWND hDlg, WORD idCtrl, LPCSTR pszSetting) { - CTzCombo *ctrl = NULL; HWND hCtrl = GetDlgItem(hDlg, idCtrl); - ctrl = new CTzCombo(hDlg, idCtrl, pszSetting); + CTzCombo *ctrl = new CTzCombo(hDlg, idCtrl, pszSetting); if (ctrl) { - //use new core tz interface - if (tmi.prepareList) { - //set the adress of our timezone handle as itemdata - //caller can obtain the handle htz to extract all relevant information - ctrl->_curSel = 0; - tmi.prepareList(NULL, NULL, hCtrl, TZF_PLF_CB); - } - //fallback use old UIEX method - else { - ctrl->_curSel = ComboBox_AddString(hCtrl, TranslateT("")); - if (SUCCEEDED(ctrl->_curSel)) { - ComboBox_SetItemData(hCtrl, ctrl->_curSel, NULL); - } - ComboBox_SetCurSel(hCtrl, ctrl->_curSel); - EnumTimeZones(EnumNamesProc, (LPARAM)hCtrl); - } + //set the adress of our timezone handle as itemdata + //caller can obtain the handle htz to extract all relevant information + ctrl->_curSel = 0; + TimeZone_PrepareList(NULL, NULL, hCtrl, TZF_PLF_CB); } return (ctrl); } @@ -130,7 +117,7 @@ int CTzCombo::Find(LPTIME_ZONE_INFORMATION pTimeZone) const int nItemCount = ComboBox_GetCount(_hwnd); for (nItemIndex = 0; nItemIndex < nItemCount; nItemIndex++) { - if (pTimeZone == tmi.getTzi((HANDLE)ComboBox_GetItemData(_hwnd, nItemIndex))) + if (pTimeZone == TimeZone_GetInfo((HANDLE)ComboBox_GetItemData(_hwnd, nItemIndex))) return nItemIndex; } return CB_ERR; @@ -160,31 +147,10 @@ void CTzCombo::Release() BOOL CTzCombo::OnInfoChanged(MCONTACT hContact, LPCSTR pszProto) { if (!_Flags.B.hasChanged) { - //use new core tz interface to change the cbbox - if (tmi.storeListResults) { - _curSel = CB_ERR; -// _curSel = tmi.selectListItem(hContact, _hwnd, TZF_PLF_CB); - //dident work well, coz no fallback to proto setting. - //we use saver way by getTziByContact - LPTIME_ZONE_INFORMATION pTimeZone; - pTimeZone = tmi.getTziByContact(hContact); - ComboBox_SetCurSel(_hwnd, Find(pTimeZone)); - _curSel = ComboBox_GetCurSel(_hwnd); - } - //fallback use old UIEX method - else { - CTimeZone *pTimeZone; - _curSel = CB_ERR; - _Flags.W = GetContactTimeZoneCtrl(hContact, pszProto, &pTimeZone); - if (_Flags.W) { - ComboBox_SetCurSel(_hwnd, Find(pTimeZone)); - _curSel = ComboBox_GetCurSel(_hwnd); - } - if (_curSel == CB_ERR) { - ComboBox_SetCurSel(_hwnd, NULL); - _curSel = ComboBox_GetCurSel(_hwnd); - } - } + LPTIME_ZONE_INFORMATION pTimeZone; + pTimeZone = getTziByContact(hContact); + ComboBox_SetCurSel(_hwnd, Find(pTimeZone)); + _curSel = ComboBox_GetCurSel(_hwnd); SendMessage(GetParent(_hwnd), WM_TIMER, 0, 0); } return _Flags.B.hasChanged; @@ -205,28 +171,12 @@ void CTzCombo::OnApply(MCONTACT hContact, LPCSTR pszProto) const char* pszModule = hContact ? USERINFO : pszProto; if (_Flags.B.hasCustom || !hContact) { //use new core tz interface - if (tmi.storeListResults) { - tmi.storeListResults(hContact, NULL, _hwnd, TZF_PLF_CB); - if (!hContact) { - _Flags.B.hasCustom = 0; - _Flags.B.hasProto = 1; - } - _Flags.B.hasChanged = 0; - } - //fallback use old UIEX method - else { - const CTimeZone* pTimeZone = (CTimeZone*)ComboBox_GetItemData(_hwnd, _curSel); - if (PtrIsValid(pTimeZone)) { - db_set_ts(hContact, USERINFO, SET_CONTACT_TIMEZONENAME, pTimeZone->ptszName); - db_set_b(hContact, pszModule, SET_CONTACT_TIMEZONE, pTimeZone->ToMirandaTimezone()); - - if (!hContact) { - _Flags.B.hasCustom = 0; - _Flags.B.hasProto = 1; - } - _Flags.B.hasChanged = 0; - } + TimeZone_StoreListResult(hContact, NULL, _hwnd, TZF_PLF_CB); + if (!hContact) { + _Flags.B.hasCustom = 0; + _Flags.B.hasProto = 1; } + _Flags.B.hasChanged = 0; } if (_Flags.B.hasChanged) @@ -275,5 +225,5 @@ void CTzCombo::OnChangedByUser(WORD wChangedMsg) **/ void CTzCombo::GetTime(LPTSTR szTime, int cchTime) { - tmi.printDateTime((HANDLE)ComboBox_GetItemData(_hwnd, _curSel), _T("t"), szTime, cchTime, 0); + TimeZone_PrintDateTime((HANDLE)ComboBox_GetItemData(_hwnd, _curSel), _T("t"), szTime, cchTime, 0); } diff --git a/plugins/UserInfoEx/src/init.cpp b/plugins/UserInfoEx/src/init.cpp index ab35aa96e5..77324e2eee 100644 --- a/plugins/UserInfoEx/src/init.cpp +++ b/plugins/UserInfoEx/src/init.cpp @@ -170,9 +170,6 @@ extern "C" int __declspec(dllexport) Load(void) // init clist interface mir_getCLI(); - // init new miranda timezone interface - mir_getTMI(&tmi); - // init freeimage interface INT_PTR result = CALLSERVICE_NOTFOUND; if (ServiceExists(MS_IMG_GETINTERFACE)) @@ -196,7 +193,7 @@ extern "C" int __declspec(dllexport) Load(void) IcoLib_LoadModule(); SvcFlagsLoadModule(); - tmi.getTimeZoneTime ? SvcTimezoneLoadModule() : SvcTimezoneLoadModule_old(); + SvcTimezoneLoadModule(); SvcContactInfoLoadModule(); SvcEMailLoadModule(); SvcRefreshContactInfoLoadModule(); diff --git a/plugins/UserInfoEx/src/psp_options.cpp b/plugins/UserInfoEx/src/psp_options.cpp index 2d0b2c20c0..4c71f2c8e2 100644 --- a/plugins/UserInfoEx/src/psp_options.cpp +++ b/plugins/UserInfoEx/src/psp_options.cpp @@ -418,13 +418,8 @@ static INT_PTR CALLBACK DlgProc_AdvancedOpts(HWND hDlg, UINT uMsg, WPARAM wParam DBGetCheckBtn(hDlg, CHECK_OPT_BUTTONICONS, SET_ICONS_BUTTONS, TRUE); DBGetCheckBtn(hDlg, CHECK_OPT_METASCAN, SET_META_SCAN, TRUE); DBGetCheckBtn(hDlg, CHECK_OPT_SREMAIL_ENABLED, SET_EXTENDED_EMAILSERVICE, TRUE); - if (tmi.getTimeZoneTime) { - CheckDlgButton(hDlg, CHECK_OPT_AUTOTIMEZONE, BST_CHECKED); - EnableWindow(GetDlgItem(hDlg, CHECK_OPT_AUTOTIMEZONE), FALSE); - } - else { - DBGetCheckBtn(hDlg, CHECK_OPT_AUTOTIMEZONE, SET_OPT_AUTOTIMEZONE, TRUE); - } + CheckDlgButton(hDlg, CHECK_OPT_AUTOTIMEZONE, BST_CHECKED); + EnableWindow(GetDlgItem(hDlg, CHECK_OPT_AUTOTIMEZONE), FALSE); bInitialized = 1; break; @@ -435,11 +430,6 @@ static INT_PTR CALLBACK DlgProc_AdvancedOpts(HWND hDlg, UINT uMsg, WPARAM wParam DBWriteCheckBtn(hDlg, CHECK_OPT_METASCAN, SET_META_SCAN); DBWriteCheckBtn(hDlg, CHECK_OPT_SREMAIL_ENABLED, SET_EXTENDED_EMAILSERVICE); - if (!tmi.getTimeZoneTime) { - DBWriteCheckBtn(hDlg, CHECK_OPT_AUTOTIMEZONE, SET_OPT_AUTOTIMEZONE); - if (IsDlgButtonChecked(hDlg, CHECK_OPT_AUTOTIMEZONE)) - SvcTimezoneSyncWithWindows(); - } } break; diff --git a/plugins/UserInfoEx/src/svc_contactinfo.cpp b/plugins/UserInfoEx/src/svc_contactinfo.cpp index 3c53c8e23e..662d300256 100644 --- a/plugins/UserInfoEx/src/svc_contactinfo.cpp +++ b/plugins/UserInfoEx/src/svc_contactinfo.cpp @@ -563,11 +563,10 @@ INT_PTR GetContactInfo(WPARAM wParam, LPARAM lParam) break; case CNF_TIMEZONE: - //use new core tz interface - if (tmi.prepareList) { - HANDLE hTz = tmi.createByContact(ci->hContact, 0, TZF_KNOWNONLY); + { + HANDLE hTz = TimeZone_CreateByContact(ci->hContact, 0, TZF_KNOWNONLY); if (hTz) { - LPTIME_ZONE_INFORMATION tzi = tmi.getTzi(hTz); + LPTIME_ZONE_INFORMATION tzi = TimeZone_GetInfo(hTz); int offset = tzi->Bias + tzi->StandardBias; char str[80]; @@ -577,27 +576,9 @@ INT_PTR GetContactInfo(WPARAM wParam, LPARAM lParam) return 0; } ci->pszVal = NULL; + ci->type = (ci->pszVal != NULL) ? CNFT_ASCIIZ : 0; + result = ci->type == 0; } - //fallback use old UIEX method - else { - CTimeZone* ptz = GetContactTimeZone(ci->hContact, ci->szProto); - if (ptz) { - if (ci->dwFlag & CNF_UNICODE) - ci->pszVal = (LPTSTR)mir_t2u(ptz->ptszDisplay); - else - ci->pszVal = (LPTSTR)mir_t2a(ptz->ptszDisplay); - } - else { - /* If a timezone does not exist in CTzMgr, it is a invalid timezone, - because Windows and CTzMgr know all existing timezones and it - would not be shown anywhere anyway as UserInfoEx displays only - known windows timezones in the details dialog! - */ - ci->pszVal = NULL; - } - } - ci->type = (ci->pszVal != NULL) ? CNFT_ASCIIZ : 0; - result = ci->type == 0; break; // diff --git a/plugins/UserInfoEx/src/svc_timezone.cpp b/plugins/UserInfoEx/src/svc_timezone.cpp index 4b4ccd4053..29605c9c1d 100644 --- a/plugins/UserInfoEx/src/svc_timezone.cpp +++ b/plugins/UserInfoEx/src/svc_timezone.cpp @@ -42,7 +42,7 @@ INT_PTR GetContactTimeZoneInformation(WPARAM wParam, LPARAM lParam) if (lParam == NULL) return (1); //use new core tz interface - LPTIME_ZONE_INFORMATION pTimeZoneInformation = tmi.getTzi(tmi.createByContact(wParam, 0, 0)); + LPTIME_ZONE_INFORMATION pTimeZoneInformation = TimeZone_GetInfo(TimeZone_CreateByContact(wParam, 0, 0)); if (pTimeZoneInformation == NULL) return (1); memcpy((void *)lParam, pTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION)); @@ -62,7 +62,7 @@ INT_PTR GetContactLocalTime(WPARAM wParam, LPARAM lParam) { //use new core tz interface LPSYSTEMTIME pSystemTime = (LPSYSTEMTIME)lParam; - return (INT_PTR)tmi.getTimeZoneTimeByContact(wParam, pSystemTime); + return (INT_PTR)getTimeZoneTimeByContact(wParam, pSystemTime); } /*********************************************************************************************************** diff --git a/plugins/UserInfoEx/src/svc_timezone_old.cpp b/plugins/UserInfoEx/src/svc_timezone_old.cpp index b859507240..05809e970b 100644 --- a/plugins/UserInfoEx/src/svc_timezone_old.cpp +++ b/plugins/UserInfoEx/src/svc_timezone_old.cpp @@ -590,16 +590,3 @@ INT_PTR GetContactLocalTime_old(WPARAM wParam, LPARAM lParam) /*********************************************************************************************************** * initialization ***********************************************************************************************************/ - -/** -* This function initially loads the module upon startup. -**/ - -void SvcTimezoneLoadModule_old() -{ - TzMgr.Init(); - CreateServiceFunction(MS_USERINFO_TIMEZONEINFO, GetContactTimeZoneInformation); - CreateServiceFunction(MS_USERINFO_LOCALTIME, GetContactLocalTime); - if (db_get_b(NULL, MODNAME, SET_OPT_AUTOTIMEZONE, TRUE)) - SvcTimezoneSyncWithWindows(); -} diff --git a/plugins/UserInfoEx/src/svc_timezone_old.h b/plugins/UserInfoEx/src/svc_timezone_old.h index 040f272ec6..a28e16a071 100644 --- a/plugins/UserInfoEx/src/svc_timezone_old.h +++ b/plugins/UserInfoEx/src/svc_timezone_old.h @@ -88,6 +88,5 @@ INT_PTR GetContactTimeZoneInformation_old(WPARAM wParam, LPARAM lParam); INT_PTR GetContactLocalTime_old(WPARAM wParam, LPARAM lParam); void SvcTimezoneSyncWithWindows(); -void SvcTimezoneLoadModule_old(); #endif /* _SVC_TIMEZONE_H_OLD */ \ No newline at end of file diff --git a/plugins/Utils/mir_buffer.h b/plugins/Utils/mir_buffer.h index eb7b084579..4aa0a2602e 100644 --- a/plugins/Utils/mir_buffer.h +++ b/plugins/Utils/mir_buffer.h @@ -24,6 +24,7 @@ Boston, MA 02111-1307, USA. #include #include +#include template static inline size_t __blen(const T *str) @@ -467,11 +468,7 @@ static void ReplaceVars(Buffer *buffer, MCONTACT hContact, TCHAR **variab else if (foundLen == 6 && _tcsncmp(&buffer->str[j], _T("%date%"), 6) == 0) { TCHAR tmp[128]; - DBTIMETOSTRINGT tst = {0}; - tst.szFormat = _T("d s"); - tst.szDest = tmp; - tst.cbDest = SIZEOF(tmp); - CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM) time(NULL), (LPARAM) &tst); + TimeZone_ToStringT(time(NULL), _T("d s"), tmp, SIZEOF(tmp)); buffer->replace(j, i + 1, tmp); } else diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index 2710effbf0..bd07c2c23d 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -712,14 +712,7 @@ static TCHAR *parseMirDateString(ARGUMENTSINFO *ai) ai->flags |= AIF_DONTPARSE; TCHAR ret[128]; - DBTIMETOSTRINGT tst = { 0 }; - tst.szFormat = _T("d s"); - tst.szDest = ret; - tst.cbDest = SIZEOF(ret); - if (CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)time(NULL), (LPARAM)&tst)) - return NULL; - - return mir_tstrdup(ret); + return mir_tstrdup(TimeZone_ToStringT(time(NULL), _T("d s"), ret, SIZEOF(ret))); } static TCHAR *parseMirandaCoreVar(ARGUMENTSINFO *ai) diff --git a/plugins/Variables/src/variables.h b/plugins/Variables/src/variables.h index 4d65579e74..49b4bbba01 100644 --- a/plugins/Variables/src/variables.h +++ b/plugins/Variables/src/variables.h @@ -44,6 +44,7 @@ #include #include #include +#include #include diff --git a/plugins/YAMN/src/browser/mailbrowser.cpp b/plugins/YAMN/src/browser/mailbrowser.cpp index 590dc5a25b..5aeb0eda6c 100644 --- a/plugins/YAMN/src/browser/mailbrowser.cpp +++ b/plugins/YAMN/src/browser/mailbrowser.cpp @@ -1063,7 +1063,7 @@ ULONGLONG MimeDateToFileTime(char *datein) char *day = 0, *month = 0, *year = 0, *time = 0, *shift = 0; SYSTEMTIME st; ULONGLONG res = 0; - int wShiftSeconds = CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, 0, 0); + int wShiftSeconds = TimeZone_ToLocal(0); GetLocalTime(&st); //datein = "Xxx, 1 Jan 2060 5:29:1 +0530 XXX"; //datein = "Xxx, 1 Jan 2060 05:29:10 "; diff --git a/plugins/YAMN/src/yamn.h b/plugins/YAMN/src/yamn.h index 29955fcc7c..11f8ae0569 100644 --- a/plugins/YAMN/src/yamn.h +++ b/plugins/YAMN/src/yamn.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/protocols/ICQCorp/src/corp.h b/protocols/ICQCorp/src/corp.h index c703ee04ea..999ccaed64 100644 --- a/protocols/ICQCorp/src/corp.h +++ b/protocols/ICQCorp/src/corp.h @@ -39,6 +39,7 @@ #include #include #include +#include #include "user.h" #include "transfer.h" diff --git a/protocols/ICQCorp/src/protocol.cpp b/protocols/ICQCorp/src/protocol.cpp index 8a4967f5f1..76350c4f18 100644 --- a/protocols/ICQCorp/src/protocol.cpp +++ b/protocols/ICQCorp/src/protocol.cpp @@ -719,7 +719,7 @@ unsigned short ICQ::processUdpPacket(Packet &packet) >> newCommand; timeStampLastMessage = timedataStamp; - timedataStamp = CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, timedataStamp, 0); + timedataStamp = TimeZone_ToLocal(timedataStamp); processSystemMessage(packet, checkUin, newCommand, timedataStamp); break; @@ -806,7 +806,7 @@ unsigned short ICQ::processUdpPacket(Packet &packet) >> newCommand; db_set_dw(NULL, protoName, "LastBroadcastTime", timedataStamp); - timedataStamp = CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, timedataStamp, 0); + timedataStamp = TimeZone_ToLocal(timedataStamp); processSystemMessage(packet, checkUin, newCommand, timedataStamp); break; diff --git a/protocols/ICQCorp/src/transfer.cpp b/protocols/ICQCorp/src/transfer.cpp index c864c6b3e9..32058cc1f9 100644 --- a/protocols/ICQCorp/src/transfer.cpp +++ b/protocols/ICQCorp/src/transfer.cpp @@ -326,7 +326,7 @@ void ICQTransfer::ack(unsigned int result) fts.szCurrentFile = fileName; fts.currentFileSize = fileSize; fts.currentFileProgress = fileProgress; - fts.currentFileTime = CallService(MS_DB_TIME_TIMESTAMPTOLOCAL, fileDate, 0); + fts.currentFileTime = TimeZone_ToLocal(fileDate); /* switch (session->status) { diff --git a/protocols/IcqOscarJ/src/dlgproc.cpp b/protocols/IcqOscarJ/src/dlgproc.cpp index 517463bfd8..704764c848 100644 --- a/protocols/IcqOscarJ/src/dlgproc.cpp +++ b/protocols/IcqOscarJ/src/dlgproc.cpp @@ -77,8 +77,8 @@ char* ChangeInfoData::GetItemSettingText(int i, char *buf, size_t bufsize) FieldNamesItem *list = (FieldNamesItem*)si.pList; if (list == timezonesField) { - HANDLE tz = tmi.createByContact(NULL, ppro->m_szModuleName, 0); - text = make_utf8_string_static(tmi.getTzDescription(tmi.getTzName(tz)), buf, bufsize); + HANDLE tz = TimeZone_CreateByContact(NULL, ppro->m_szModuleName, 0); + text = make_utf8_string_static(TimeZone_GetDescription(TimeZone_GetName(tz)), buf, bufsize); break; } diff --git a/protocols/IcqOscarJ/src/editlist.cpp b/protocols/IcqOscarJ/src/editlist.cpp index da04c5efc1..df632256d5 100644 --- a/protocols/IcqOscarJ/src/editlist.cpp +++ b/protocols/IcqOscarJ/src/editlist.cpp @@ -99,7 +99,7 @@ void ChangeInfoData::BeginListEdit(int iItem, RECT *rc, int iSetting, WORD wVKey } if (list == timezonesField) { - tmi.prepareList(NULL, ppro->m_szModuleName, hwndListEdit, TZF_PLF_LB); + TimeZone_PrepareList(NULL, ppro->m_szModuleName, hwndListEdit, TZF_PLF_LB); } else { int j, n = ListBoxAddStringUtf(hwndListEdit, "Unspecified"); @@ -149,7 +149,7 @@ void ChangeInfoData::EndListEdit(int save) if (iItem != -1 && i != -1) { FieldNamesItem *list = (FieldNamesItem*)si.pList; if (list == timezonesField) { - tmi.storeListResults(NULL, ppro->m_szModuleName, hwndListEdit, TZF_PLF_LB); + TimeZone_StoreListResult(NULL, ppro->m_szModuleName, hwndListEdit, TZF_PLF_LB); list[i = 0].code = ppro->getDword("Timezone", 0); } diff --git a/protocols/IcqOscarJ/src/init.cpp b/protocols/IcqOscarJ/src/init.cpp index ddaec0e16c..e922d09cfa 100644 --- a/protocols/IcqOscarJ/src/init.cpp +++ b/protocols/IcqOscarJ/src/init.cpp @@ -30,7 +30,6 @@ HINSTANCE hInst; int hLangpack; -TIME_API tmi; CLIST_INTERFACE *pcli; bool g_bTerminated; @@ -96,7 +95,6 @@ extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); mir_getCLI(); - mir_getTMI(&tmi); srand(time(NULL)); _tzset(); diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp index caedaddab5..697dcfa3da 100644 --- a/protocols/JabberG/src/jabber.cpp +++ b/protocols/JabberG/src/jabber.cpp @@ -59,7 +59,6 @@ PLUGININFOEX pluginInfo = { }; XML_API xi; -TIME_API tmi; CLIST_INTERFACE* pcli; FI_INTERFACE *FIP = NULL; @@ -184,7 +183,6 @@ extern "C" int __declspec(dllexport) Load() { // set the memory, lists & utf8 managers mir_getXI(&xi); - mir_getTMI(&tmi); mir_getLP(&pluginInfo); mir_getCLI(); diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index d239ae052c..c2b6dc5c67 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -393,7 +393,7 @@ BOOL CJabberProto::OnIqRequestTime(HXML, CJabberIqInfo *pInfo) TCHAR stime[100]; TCHAR szTZ[10]; - tmi.printDateTime(UTC_TIME_HANDLE, _T("I"), stime, SIZEOF(stime), 0); + TimeZone_PrintDateTime(UTC_TIME_HANDLE, _T("I"), stime, SIZEOF(stime), 0); int nGmtOffset = GetGMTOffset(); mir_sntprintf(szTZ, SIZEOF(szTZ), _T("%+03d:%02d"), nGmtOffset / 60, nGmtOffset % 60); @@ -401,7 +401,7 @@ BOOL CJabberProto::OnIqRequestTime(HXML, CJabberIqInfo *pInfo) XmlNodeIq iq(_T("result"), pInfo); HXML timeNode = iq << XCHILDNS(_T("time"), JABBER_FEAT_ENTITY_TIME); timeNode << XCHILD(_T("utc"), stime); timeNode << XCHILD(_T("tzo"), szTZ); - LPCTSTR szTZName = tmi.getTzName(NULL); + LPCTSTR szTZName = TimeZone_GetName(NULL); if (szTZName) timeNode << XCHILD(_T("tz"), szTZName); m_ThreadInfo->send(iq); @@ -426,7 +426,7 @@ BOOL CJabberProto::OnIqProcessIqOldTime(HXML, CJabberIqInfo *pInfo) XmlNodeIq iq(_T("result"), pInfo); HXML queryNode = iq << XQUERY(JABBER_FEAT_ENTITY_TIME_OLD); queryNode << XCHILD(_T("utc"), stime); - LPCTSTR szTZName = tmi.getTzName(NULL); + LPCTSTR szTZName = TimeZone_GetName(NULL); if (szTZName) queryNode << XCHILD(_T("tz"), szTZName); queryNode << XCHILD(_T("display"), dtime); diff --git a/protocols/MSN/src/msn.cpp b/protocols/MSN/src/msn.cpp index ec7f204449..1b0f0b43a6 100644 --- a/protocols/MSN/src/msn.cpp +++ b/protocols/MSN/src/msn.cpp @@ -27,7 +27,6 @@ along with this program. If not, see . HINSTANCE hInst; int hLangpack; -TIME_API tmi; ///////////////////////////////////////////////////////////////////////////////////////// // Initialization routines @@ -111,7 +110,6 @@ static int msnProtoUninit(CMsnProto* ppro) extern "C" int __declspec(dllexport) Load(void) { - mir_getTMI(&tmi); mir_getLP(&pluginInfo); HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index 4dbd10237a..c6c9209b89 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -153,8 +153,8 @@ int CMsnProto::MSN_GetPassportAuth(void) time_t ts = time(NULL); TCHAR szTs1[64], szTs2[64]; - tmi.printTimeStamp(UTC_TIME_HANDLE, ts, _T("I"), szTs1, SIZEOF(szTs1), 0); - tmi.printTimeStamp(UTC_TIME_HANDLE, ts + 20 * 60, _T("I"), szTs2, SIZEOF(szTs2), 0); + TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, ts, _T("I"), szTs1, SIZEOF(szTs1), 0); + TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, ts + 20 * 60, _T("I"), szTs2, SIZEOF(szTs2), 0); CMStringA szAuthInfo(FORMAT, authPacket, int(ts), MyOptions.szEmail, ptrA(HtmlEncode(szPassword)), szTs1, szTs2); diff --git a/protocols/SkypeWeb/src/main.cpp b/protocols/SkypeWeb/src/main.cpp index 103306d981..0d09d03e32 100644 --- a/protocols/SkypeWeb/src/main.cpp +++ b/protocols/SkypeWeb/src/main.cpp @@ -19,7 +19,6 @@ along with this program. If not, see . int hLangpack; XML_API xi; -TIME_API tmi = { 0 }; HINSTANCE g_hInstance; CLIST_INTERFACE *pcli; char g_szMirVer[100]; @@ -55,7 +54,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC extern "C" int __declspec(dllexport) Load(void) { - mir_getTMI(&tmi); mir_getLP(&pluginInfo); mir_getXI(&xi); mir_getCLI(); diff --git a/src/core/stdfile/src/filerecvdlg.cpp b/src/core/stdfile/src/filerecvdlg.cpp index a092b1449f..16edf1c4a0 100644 --- a/src/core/stdfile/src/filerecvdlg.cpp +++ b/src/core/stdfile/src/filerecvdlg.cpp @@ -254,7 +254,7 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l else DestroyWindow(hwndDlg); TCHAR datetimestr[64]; - tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0); + TimeZone_PrintTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0); SetDlgItemText(hwndDlg, IDC_DATE, datetimestr); char* szProto = GetContactProto(dat->hContact); diff --git a/src/core/stdfile/src/main.cpp b/src/core/stdfile/src/main.cpp index cd849b43b6..b49d593f10 100644 --- a/src/core/stdfile/src/main.cpp +++ b/src/core/stdfile/src/main.cpp @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., int LoadSendRecvFileModule(void); CLIST_INTERFACE* pcli; -TIME_API tmi; HINSTANCE hInst; int hLangpack; @@ -60,7 +59,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRFILE extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); if ( IsWinVer7Plus()) diff --git a/src/core/stdhelp/src/main.cpp b/src/core/stdhelp/src/main.cpp index bd42b15c6d..d1a4729250 100644 --- a/src/core/stdhelp/src/main.cpp +++ b/src/core/stdhelp/src/main.cpp @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., int LoadHelpModule(void); CLIST_INTERFACE* pcli; -TIME_API tmi; HINSTANCE hInst; int hLangpack; @@ -58,7 +57,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_UIHELP extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); LoadHelpModule(); diff --git a/src/core/stdidle/src/main.cpp b/src/core/stdidle/src/main.cpp index 6c06ad4be3..2f21ff9097 100644 --- a/src/core/stdidle/src/main.cpp +++ b/src/core/stdidle/src/main.cpp @@ -25,7 +25,6 @@ int LoadIdleModule(void); void UnloadIdleModule(void); CLIST_INTERFACE* pcli; -TIME_API tmi; HINSTANCE hInst; int hLangpack; @@ -59,7 +58,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_IDLE, extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); LoadIdleModule(); diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index b3a9bc050a..c4ca134216 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -136,7 +136,7 @@ static void ShowTime(SrmmWindowData *dat) TCHAR buf[32]; unsigned i = (g_dat.flags & SMF_SHOWREADCHAR) ? 2 : 1; - tmi.printDateTime(dat->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); + TimeZone_PrintDateTime(dat->hTimeZone, _T("t"), buf, SIZEOF(buf), 0); SendMessage(dat->hwndStatus, SB_SETTEXT, i, (LPARAM)buf); dat->wMinute = st.wMinute; } @@ -618,7 +618,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP dat->hContact = newData->hContact; dat->bIsMeta = db_mc_isMeta(dat->hContact) != 0; - dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY); + dat->hTimeZone = TimeZone_CreateByContact(dat->hContact, 0, TZF_KNOWNONLY); dat->wMinute = 61; NotifyLocalWinEvent(dat->hContact, hwndDlg, MSG_WINDOW_EVT_OPENING); @@ -957,8 +957,8 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (dat->lastMessage) { TCHAR date[64], time[64], fmt[128]; - tmi.printTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); - tmi.printTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); + TimeZone_PrintTimeStamp(NULL, dat->lastMessage, _T("d"), date, SIZEOF(date), 0); + TimeZone_PrintTimeStamp(NULL, dat->lastMessage, _T("t"), time, SIZEOF(time), 0); mir_sntprintf(fmt, SIZEOF(fmt), TranslateT("Last message received on %s at %s."), date, time); SendMessage(dat->hwndStatus, SB_SETTEXT, 0, (LPARAM)fmt); } @@ -1080,7 +1080,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; case DM_NEWTIMEZONE: - dat->hTimeZone = tmi.createByContact(dat->hContact, 0, TZF_KNOWNONLY); + dat->hTimeZone = TimeZone_CreateByContact(dat->hContact, 0, TZF_KNOWNONLY); dat->wMinute = 61; SendMessage(hwndDlg, WM_SIZE, 0, 0); break; diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 22fd62bf67..aa214357fc 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -293,7 +293,7 @@ static char *CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, MEVENT else szFormat = g_dat.flags & SMF_SHOWDATE ? _T("d t") : _T("t"); - tmi.printTimeStamp(NULL, dbei.timestamp, szFormat, str, SIZEOF(str), 0); + TimeZone_PrintTimeStamp(NULL, dbei.timestamp, szFormat, str, SIZEOF(str), 0); AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); AppendToBufferWithRTF(buffer, bufferEnd, bufferAlloced, str); diff --git a/src/core/stdmsg/src/srmm.cpp b/src/core/stdmsg/src/srmm.cpp index b629c3598f..8136de9f46 100644 --- a/src/core/stdmsg/src/srmm.cpp +++ b/src/core/stdmsg/src/srmm.cpp @@ -28,8 +28,6 @@ CLIST_INTERFACE *pcli; HINSTANCE g_hInst; int hLangpack; -TIME_API tmi; - PLUGININFOEX pluginInfo = { sizeof(PLUGININFOEX), __PLUGIN_NAME, @@ -58,7 +56,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_SRMM, M extern "C" int __declspec(dllexport) Load(void) { - mir_getTMI(&tmi); mir_getLP(&pluginInfo); mir_getCLI(); diff --git a/src/core/stduihist/src/history.cpp b/src/core/stduihist/src/history.cpp index 0297875807..0748d76e54 100644 --- a/src/core/stduihist/src/history.cpp +++ b/src/core/stduihist/src/history.cpp @@ -164,7 +164,7 @@ static void FillHistoryThread(void* param) TCHAR str[200], eventText[256], strdatetime[64]; GetObjectSummary(&dbei, str, SIZEOF(str)); if (str[0]) { - tmi.printTimeStamp(NULL, dbei.timestamp, _T("d t"), strdatetime, SIZEOF(strdatetime), 0); + TimeZone_PrintTimeStamp(NULL, dbei.timestamp, _T("d t"), strdatetime, SIZEOF(strdatetime), 0); mir_sntprintf(eventText, SIZEOF(eventText), _T("%s: %s"), strdatetime, str); i = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)eventText); SendMessage(hwndList, LB_SETITEMDATA, i, (LPARAM)hDbEvent); diff --git a/src/core/stduihist/src/main.cpp b/src/core/stduihist/src/main.cpp index 76562307c3..dfb8a0d36a 100644 --- a/src/core/stduihist/src/main.cpp +++ b/src/core/stduihist/src/main.cpp @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., int LoadHistoryModule(void); CLIST_INTERFACE* pcli; -TIME_API tmi; HINSTANCE hInst; int hLangpack; @@ -58,7 +57,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_UIHIST extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); LoadHistoryModule(); diff --git a/src/core/stdurl/main.cpp b/src/core/stdurl/main.cpp index 16caf83712..4351ea95c3 100644 --- a/src/core/stdurl/main.cpp +++ b/src/core/stdurl/main.cpp @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., int LoadSendRecvUrlModule(void); CLIST_INTERFACE* pcli; -TIME_API tmi; HINSTANCE hInst; int hLangpack; @@ -58,7 +57,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRURL, extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); LoadSendRecvUrlModule(); diff --git a/src/core/stdurl/urldialogs.cpp b/src/core/stdurl/urldialogs.cpp index f65bf202b9..157725362b 100644 --- a/src/core/stdurl/urldialogs.cpp +++ b/src/core/stdurl/urldialogs.cpp @@ -114,7 +114,7 @@ INT_PTR CALLBACK DlgProcUrlRecv(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP SendDlgItemMessage(hwndDlg, IDOK, BUTTONSETARROW, 1, 0); TCHAR str[128]; - tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), str, SIZEOF(str), 0); + TimeZone_PrintTimeStamp(NULL, dbei.timestamp, _T("t d"), str, SIZEOF(str), 0); SetDlgItemText(hwndDlg, IDC_DATE, str); } diff --git a/src/core/stduserinfo/src/main.cpp b/src/core/stduserinfo/src/main.cpp index ea49811c26..6289d9b209 100644 --- a/src/core/stduserinfo/src/main.cpp +++ b/src/core/stduserinfo/src/main.cpp @@ -24,7 +24,6 @@ with this program; if not, write to the Free Software Foundation, Inc., int LoadUserInfoModule(void); CLIST_INTERFACE* pcli; -TIME_API tmi; HINSTANCE hInst; int hLangpack; @@ -58,7 +57,6 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_UIUSERI extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); - mir_getTMI(&tmi); mir_getCLI(); LoadUserInfoModule(); diff --git a/src/core/stduserinfo/src/stdinfo.cpp b/src/core/stduserinfo/src/stdinfo.cpp index 197d24440c..3ad3f9432c 100644 --- a/src/core/stduserinfo/src/stdinfo.cpp +++ b/src/core/stduserinfo/src/stdinfo.cpp @@ -241,7 +241,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L TranslateDialogDefault(hwndDlg); SetTimer(hwndDlg, 1, 1000, NULL); - tmi.prepareList(lParam, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB); + TimeZone_PrepareList(lParam, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB); SendMessage(hwndDlg, WM_TIMER, 0, 0); break; @@ -250,7 +250,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (hContact != NULL) { TCHAR szTime[80]; - if (tmi.printDateTimeByContact(hContact, _T("s"), szTime, SIZEOF(szTime), TZF_KNOWNONLY)) { + if (printDateTimeByContact(hContact, _T("s"), szTime, SIZEOF(szTime), TZF_KNOWNONLY)) { EnableWindow(GetDlgItem(hwndDlg, IDC_LOCALTIME), FALSE); SetDlgItemText(hwndDlg, IDC_LOCALTIME, TranslateT("")); } @@ -297,7 +297,7 @@ static INT_PTR CALLBACK LocationDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - tmi.storeListResults(hContact, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB); + TimeZone_StoreListResult(hContact, NULL, GetDlgItem(hwndDlg, IDC_TIMEZONESELECT), TZF_PLF_CB); } } break; diff --git a/src/mir_app/src/contacts.cpp b/src/mir_app/src/contacts.cpp index 90ee313f47..b20b201228 100644 --- a/src/mir_app/src/contacts.cpp +++ b/src/mir_app/src/contacts.cpp @@ -344,9 +344,9 @@ static INT_PTR GetContactInfo(WPARAM, LPARAM lParam) case CNF_TIMEZONE: { - HANDLE hTz = tmi.createByContact(ci->hContact, 0, TZF_KNOWNONLY); + HANDLE hTz = TimeZone_CreateByContact(ci->hContact, 0, TZF_KNOWNONLY); if (hTz) { - LPTIME_ZONE_INFORMATION tzi = tmi.getTzi(hTz); + LPTIME_ZONE_INFORMATION tzi = TimeZone_GetInfo(hTz); int offset = tzi->Bias + tzi->StandardBias; char str[80]; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 4f7d8b0cc0..14e239b8f6 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -2,7 +2,6 @@ EXPORTS CallContactService @1 CallProtoService @2 -RecalculateTime @3 Skin_LoadProtoIcon @4 Skin_LoadIcon @5 Button_FreeIcon_IcoLib @6 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index c5fd8c2d4e..26677f922c 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -2,7 +2,6 @@ EXPORTS CallContactService @1 CallProtoService @2 -RecalculateTime @3 Skin_LoadProtoIcon @4 Skin_LoadIcon @5 Button_FreeIcon_IcoLib @6 diff --git a/src/mir_app/src/timeutils.cpp b/src/mir_app/src/timeutils.cpp deleted file mode 100644 index 57afeff219..0000000000 --- a/src/mir_app/src/timeutils.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -implements services to handle location - based timezones, instead of -simple UTC offsets. -*/ - -#include "stdafx.h" - -// KB167296 -void UnixTimeToFileTime(mir_time ts, LPFILETIME pft) -{ - unsigned __int64 ll = UInt32x32To64(ts, 10000000) + 116444736000000000i64; - pft->dwLowDateTime = (DWORD)ll; - pft->dwHighDateTime = ll >> 32; -} - -mir_time FileTimeToUnixTime(LPFILETIME pft) -{ - unsigned __int64 ll = (unsigned __int64)pft->dwHighDateTime << 32 | pft->dwLowDateTime; - ll -= 116444736000000000i64; - return (mir_time)(ll / 10000000); -} - -void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest) -{ - if (szDest == NULL || cbDest == 0) return; - - CMString tszTemp; - - for (const TCHAR* pFormat = szFormat; *pFormat; ++pFormat) { - DWORD fmt = 0; - bool date = false, iso = false; - switch (*pFormat) { - case 't': - fmt = TIME_NOSECONDS; - date = false; - break; - - case 's': - fmt = 0; - date = false; - break; - - case 'm': - fmt = TIME_NOMINUTESORSECONDS; - date = false; - break; - - case 'd': - fmt = DATE_SHORTDATE; - date = true; - break; - - case 'D': - fmt = DATE_LONGDATE; - date = true; - break; - - case 'I': - iso = true; - break; - - default: - tszTemp.AppendChar(*pFormat); - continue; - } - - TCHAR dateTimeStr[64]; - if (iso) - tszTemp.AppendFormat(_T("%d-%02d-%02dT%02d:%02d:%02dZ"), st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond); - else if (date) { - GetDateFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr)); - tszTemp.Append(dateTimeStr); - } - else { - GetTimeFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr)); - tszTemp.Append(dateTimeStr); - } - } - - _tcsncpy_s(szDest, cbDest, tszTemp, _TRUNCATE); -} diff --git a/src/mir_app/src/timezones.cpp b/src/mir_app/src/timezones.cpp deleted file mode 100644 index d95fef6169..0000000000 --- a/src/mir_app/src/timezones.cpp +++ /dev/null @@ -1,557 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -implements services to handle location - based timezones, instead of -simple UTC offsets. -*/ - -#include "stdafx.h" - -TIME_API tmi; - -typedef DWORD (WINAPI *pfnGetDynamicTimeZoneInformation_t)(DYNAMIC_TIME_ZONE_INFORMATION *pdtzi); -static pfnGetDynamicTimeZoneInformation_t pfnGetDynamicTimeZoneInformation; - -struct REG_TZI_FORMAT -{ - LONG Bias; - LONG StandardBias; - LONG DaylightBias; - SYSTEMTIME StandardDate; - SYSTEMTIME DaylightDate; -}; - -#define MIM_TZ_DISPLAYLEN 128 - -struct MIM_TIMEZONE -{ - unsigned hash; - int offset; - - TCHAR tszName[MIM_TZ_NAMELEN]; // windows name for the time zone - wchar_t szDisplay[MIM_TZ_DISPLAYLEN]; // more descriptive display name (that's what usually appears in dialogs) - // every hour should be sufficient. - TIME_ZONE_INFORMATION tzi; - - static int compareBias(const MIM_TIMEZONE* p1, const MIM_TIMEZONE* p2) - { return p2->tzi.Bias - p1->tzi.Bias; } -}; - -struct TZ_INT_INFO -{ - DWORD timestamp; // last time updated - MIM_TIMEZONE myTZ; // set to my own timezone -}; - -static TZ_INT_INFO myInfo; - -static OBJLIST g_timezones(55, NumericKeySortT); -static LIST g_timezonesBias(55, MIM_TIMEZONE::compareBias); - -void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest); -void UnixTimeToFileTime(mir_time ts, LPFILETIME pft); -mir_time FileTimeToUnixTime(LPFILETIME pft); - -#define fnSystemTimeToTzSpecificLocalTime SystemTimeToTzSpecificLocalTime - -static int timeapiGetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st) -{ - if (st == NULL) return 1; - - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == UTC_TIME_HANDLE) - GetSystemTime(st); - else if (tz && tz != &myInfo.myTZ) { - SYSTEMTIME sto; - GetSystemTime(&sto); - return !fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &sto, st); - } - else - GetLocalTime(st); - - return 0; -} - -static LPCTSTR timeapiGetTzName(HANDLE hTZ) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL) - return myInfo.myTZ.tszName; - else if (tz == UTC_TIME_HANDLE) - return _T("UTC"); - - return tz->tszName; -} - -static LPCTSTR timeapiGetTzDescription(LPCTSTR TZname) -{ - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - MIM_TIMEZONE *tz = g_timezonesBias[i]; - - if (!mir_tstrcmp(tz->tszName, TZname)) - return tz->szDisplay; - } - return _T(""); -} - -static void CalcTsOffset(MIM_TIMEZONE *tz) -{ - SYSTEMTIME st, stl; - GetSystemTime(&st); - - FILETIME ft; - SystemTimeToFileTime(&st, &ft); - mir_time ts1 = FileTimeToUnixTime(&ft); - - if (!fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &st, &stl)) - return; - - SystemTimeToFileTime(&stl, &ft); - mir_time ts2 = FileTimeToUnixTime(&ft); - - tz->offset = ts2 - ts1; -} - -static bool IsSameTime(MIM_TIMEZONE *tz) -{ - SYSTEMTIME st, stl; - - if (tz == &myInfo.myTZ) - return true; - - timeapiGetTimeZoneTime(tz, &stl); - timeapiGetTimeZoneTime(NULL, &st); - - return st.wHour == stl.wHour && st.wMinute == stl.wMinute; -} - -static HANDLE timeapiGetInfoByName(LPCTSTR tszName, DWORD dwFlags) -{ - if (tszName == NULL) - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; - - if (mir_tstrcmp(myInfo.myTZ.tszName, tszName) == 0) - return (dwFlags & TZF_DIFONLY) ? NULL : &myInfo.myTZ; - - MIM_TIMEZONE tzsearch; - tzsearch.hash = mir_hashstrT(tszName); - - MIM_TIMEZONE *tz = g_timezones.find(&tzsearch); - if (tz == NULL) - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; - - if (dwFlags & TZF_DIFONLY) - return IsSameTime(tz) ? NULL : tz; - - return tz; -} - -static HANDLE timeapiGetInfoByContact(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags) -{ - if (hContact == NULL && szModule == NULL) - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; - - if (szModule == NULL) szModule = "UserInfo"; - - DBVARIANT dbv; - if (!db_get_ts(hContact, szModule, "TzName", &dbv)) { - HANDLE res = timeapiGetInfoByName(dbv.ptszVal, dwFlags); - db_free(&dbv); - if (res) return res; - } - - signed char timezone = (signed char)db_get_b(hContact, szModule, "Timezone", -1); - if (timezone == -1) { - char *szProto = GetContactProto(hContact); - if (!db_get_ts(hContact, szProto, "TzName", &dbv)) { - HANDLE res = timeapiGetInfoByName(dbv.ptszVal, dwFlags); - db_free(&dbv); - if (res) return res; - } - timezone = (signed char)db_get_b(hContact, szProto, "Timezone", -1); - } - - if (timezone != -1) { - MIM_TIMEZONE tzsearch; - tzsearch.tzi.Bias = timezone * 30; - if (myInfo.myTZ.tzi.Bias == tzsearch.tzi.Bias) { - if (dwFlags & TZF_DIFONLY) return NULL; - return &myInfo.myTZ; - } - - int i = g_timezonesBias.getIndex(&tzsearch); - while (i >= 0 && g_timezonesBias[i]->tzi.Bias == tzsearch.tzi.Bias) --i; - - int delta = LONG_MAX; - for (int j = ++i; j < g_timezonesBias.getCount() && g_timezonesBias[j]->tzi.Bias == tzsearch.tzi.Bias; ++j) { - int delta1 = abs(g_timezonesBias[j]->tzi.DaylightDate.wMonth - myInfo.myTZ.tzi.DaylightDate.wMonth); - if (delta1 <= delta) { - delta = delta1; - i = j; - } - } - - if (i >= 0) { - MIM_TIMEZONE *tz = g_timezonesBias[i]; - return ((dwFlags & TZF_DIFONLY) && IsSameTime(tz)) ? NULL : tz; - } - } - return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; -} - -static void timeapiSetInfoByContact(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ) -{ - if (szModule == NULL) szModule = "UserInfo"; - - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz) { - db_set_ts(hContact, szModule, "TzName", tz->tszName); - db_set_b(hContact, szModule, "Timezone", (char)((tz->tzi.Bias + tz->tzi.StandardBias) / 30)); - } - else { - db_unset(hContact, szModule, "TzName"); - db_unset(hContact, szModule, "Timezone"); - } -} - -static int timeapiPrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) - return 1; - - SYSTEMTIME st; - if (timeapiGetTimeZoneTime(tz, &st)) - return 1; - - FormatTime(&st, szFormat, szDest, cbDest); - return 0; -} - -static int timeapiPrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, int cbDest, DWORD dwFlags) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) - return 1; - - if (tz == NULL) - tz = &myInfo.myTZ; - - FILETIME ft; - if (tz == UTC_TIME_HANDLE) - UnixTimeToFileTime(ts, &ft); - else { - if (tz->offset == INT_MIN) - CalcTsOffset(tz); - - UnixTimeToFileTime(ts + tz->offset, &ft); - } - - SYSTEMTIME st; - FileTimeToSystemTime(&ft, &st); - - FormatTime(&st, szFormat, szDest, cbDest); - return 0; -} - -static LPTIME_ZONE_INFORMATION timeapiGetTzi(HANDLE hTZ) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - return tz ? &tz->tzi : &myInfo.myTZ.tzi; -} - -static mir_time timeapiTimeStampToTimeZoneTimeStamp(HANDLE hTZ, mir_time ts) -{ - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; - if (tz == NULL) - tz = &myInfo.myTZ; - - if (tz == UTC_TIME_HANDLE) - return ts; - - if (tz->offset == INT_MIN) - CalcTsOffset(tz); - - return ts + tz->offset; -} - -struct ListMessages -{ - UINT addStr, getSel, setSel, getData, setData; -}; - -static const ListMessages lbMessages = { LB_ADDSTRING, LB_GETCURSEL, LB_SETCURSEL, LB_GETITEMDATA, LB_SETITEMDATA }; -static const ListMessages cbMessages = { CB_ADDSTRING, CB_GETCURSEL, CB_SETCURSEL, CB_GETITEMDATA, CB_SETITEMDATA }; - -static const ListMessages* GetListMessages(HWND hWnd, DWORD dwFlags) -{ - if (hWnd == NULL) - return NULL; - - if (!(dwFlags & (TZF_PLF_CB | TZF_PLF_LB))) { - TCHAR tszClassName[128]; - GetClassName(hWnd, tszClassName, SIZEOF(tszClassName)); - if (!mir_tstrcmpi(tszClassName, _T("COMBOBOX"))) - dwFlags |= TZF_PLF_CB; - else if (!mir_tstrcmpi(tszClassName, _T("LISTBOX"))) - dwFlags |= TZF_PLF_LB; - } - if (dwFlags & TZF_PLF_CB) - return &cbMessages; - else if (dwFlags & TZF_PLF_LB) - return &lbMessages; - else - return NULL; -} - -/////////////////////////////////////////////////////////////////////////////// - -static int timeapiSelectListItem(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) -{ - const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); - if (lstMsg == NULL) - return -1; - - if (szModule == NULL) szModule = "UserInfo"; - - int iSelection = 0; - ptrT tszName(db_get_tsa(hContact, szModule, "TzName")); - if (tszName != NULL) { - unsigned hash = mir_hashstrT(tszName); - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - if (hash == g_timezonesBias[i]->hash) { - iSelection = i + 1; - break; - } - } - } - else { - signed char cBias = db_get_b(hContact, szModule, "Timezone", -100); - if (cBias != -100) { - int iBias = cBias * 30; - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - if (iBias == g_timezonesBias[i]->tzi.Bias) { - iSelection = i + 1; - break; - } - } - } - } - - SendMessage(hWnd, lstMsg->setSel, iSelection, 0); - return iSelection; -} - -static int timeapiPrepareList(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) -{ - const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); - if (lstMsg == NULL) - return 0; - - SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)TranslateT("")); - - for (int i = 0; i < g_timezonesBias.getCount(); i++) { - MIM_TIMEZONE *tz = g_timezonesBias[i]; - - SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)tz->szDisplay); - SendMessage(hWnd, lstMsg->setData, i + 1, (LPARAM)tz); - } - - return timeapiSelectListItem(hContact, szModule, hWnd, dwFlags); -} - -static void timeapiStoreListResult(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) -{ - if (szModule == NULL) szModule = "UserInfo"; - - const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); - if (lstMsg) { - LRESULT offset = SendMessage(hWnd, lstMsg->getSel, 0, 0); - if (offset > 0) { - MIM_TIMEZONE *tz = (MIM_TIMEZONE*)SendMessage(hWnd, lstMsg->getData, offset, 0); - if ((INT_PTR)tz != CB_ERR && tz != NULL) - timeapiSetInfoByContact(hContact, szModule, tz); - } - else timeapiSetInfoByContact(hContact, szModule, NULL); - } -} - -/////////////////////////////////////////////////////////////////////////////// - -static INT_PTR GetTimeApi(WPARAM, LPARAM lParam) -{ - TIME_API* tmi = (TIME_API*)lParam; - if (tmi == NULL) - return FALSE; - - if (tmi->cbSize != sizeof(TIME_API)) - return FALSE; - - tmi->createByName = timeapiGetInfoByName; - tmi->createByContact = timeapiGetInfoByContact; - tmi->storeByContact = timeapiSetInfoByContact; - - tmi->printDateTime = timeapiPrintDateTime; - tmi->printTimeStamp = timeapiPrintTimeStamp; - - tmi->prepareList = timeapiPrepareList; - tmi->selectListItem = timeapiSelectListItem; - tmi->storeListResults = timeapiStoreListResult; - - tmi->getTimeZoneTime = timeapiGetTimeZoneTime; - tmi->timeStampToTimeZoneTimeStamp = timeapiTimeStampToTimeZoneTimeStamp; - tmi->getTzi = timeapiGetTzi; - tmi->getTzName = timeapiGetTzName; - tmi->getTzDescription = timeapiGetTzDescription; - - return TRUE; -} - -static INT_PTR TimestampToLocal(WPARAM wParam, LPARAM) -{ - return timeapiTimeStampToTimeZoneTimeStamp(NULL, (mir_time)wParam); -} - -static INT_PTR TimestampToStringT(WPARAM wParam, LPARAM lParam) -{ - DBTIMETOSTRINGT *tts = (DBTIMETOSTRINGT*)lParam; - if (tts != NULL) - timeapiPrintTimeStamp(NULL, (mir_time)wParam, tts->szFormat, tts->szDest, tts->cbDest, 0); - return 0; -} - -static INT_PTR TimestampToStringA(WPARAM wParam, LPARAM lParam) -{ - DBTIMETOSTRING *tts = (DBTIMETOSTRING*)lParam; - if (tts != NULL) { - TCHAR *szDest = (TCHAR*)alloca(tts->cbDest*sizeof(TCHAR)); - timeapiPrintTimeStamp(NULL, (mir_time)wParam, _A2T(tts->szFormat), szDest, tts->cbDest, 0); - WideCharToMultiByte(CP_ACP, 0, szDest, -1, tts->szDest, tts->cbDest, NULL, NULL); - } - return 0; -} - -void GetLocalizedString(HKEY hSubKey, const TCHAR *szName, wchar_t *szBuf, DWORD cbLen) -{ - DWORD dwLength = cbLen * sizeof(wchar_t); - RegQueryValueEx(hSubKey, szName, NULL, NULL, (unsigned char *)szBuf, &dwLength); - szBuf[min(dwLength / sizeof(TCHAR), cbLen - 1)] = 0; -} - -extern "C" void RecalculateTime(void) -{ - GetTimeZoneInformation(&myInfo.myTZ.tzi); - myInfo.timestamp = time(NULL); - myInfo.myTZ.offset = INT_MIN; - - bool found = false; - DYNAMIC_TIME_ZONE_INFORMATION dtzi; - - if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID) { - TCHAR *myTzKey = mir_u2t(dtzi.TimeZoneKeyName); - _tcsncpy_s(myInfo.myTZ.tszName, myTzKey, _TRUNCATE); - mir_free(myTzKey); - found = true; - } - - for (int i = 0; i < g_timezones.getCount(); i++) { - MIM_TIMEZONE &tz = g_timezones[i]; - if (tz.offset != INT_MIN) - tz.offset = INT_MIN; - - if (!found) { - if (!mir_wstrcmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) || !mir_wstrcmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName)) { - _tcsncpy_s(myInfo.myTZ.tszName, tz.tszName, _TRUNCATE); - found = true; - } - } - } -} - -void InitTimeZones(void) -{ - REG_TZI_FORMAT tzi; - HKEY hKey; - - const TCHAR *tszKey = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); - - /* - * use GetDynamicTimeZoneInformation() on Vista+ - this will return a structure with - * the registry key name, so finding our own time zone later will be MUCH easier for - * localized systems or systems with a MUI pack installed - */ - if (IsWinVerVistaPlus()) - pfnGetDynamicTimeZoneInformation = (pfnGetDynamicTimeZoneInformation_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetDynamicTimeZoneInformation"); - - if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey)) { - DWORD dwIndex = 0; - HKEY hSubKey; - TCHAR tszName[MIM_TZ_NAMELEN]; - - DWORD dwSize = SIZEOF(tszName); - while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL)) { - if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) { - dwSize = sizeof(tszName); - - DWORD dwLength = sizeof(tzi); - if (ERROR_SUCCESS != RegQueryValueEx(hSubKey, _T("TZI"), NULL, NULL, (unsigned char *)&tzi, &dwLength)) - continue; - - MIM_TIMEZONE *tz = new MIM_TIMEZONE; - - tz->tzi.Bias = tzi.Bias; - tz->tzi.StandardDate = tzi.StandardDate; - tz->tzi.StandardBias = tzi.StandardBias; - tz->tzi.DaylightDate = tzi.DaylightDate; - tz->tzi.DaylightBias = tzi.DaylightBias; - - mir_tstrcpy(tz->tszName, tszName); - tz->hash = mir_hashstrT(tszName); - tz->offset = INT_MIN; - - GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay)); - GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, SIZEOF(tz->tzi.StandardName)); - GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, SIZEOF(tz->tzi.DaylightName)); - - g_timezones.insert(tz); - g_timezonesBias.insert(tz); - - RegCloseKey(hSubKey); - } - dwSize = SIZEOF(tszName); - } - RegCloseKey(hKey); - } - - RecalculateTime(); - - CreateServiceFunction(MS_SYSTEM_GET_TMI, GetTimeApi); - - CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOLOCAL, TimestampToLocal); - CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRINGT, TimestampToStringT); - - CreateServiceFunction(MS_DB_TIME_TIMESTAMPTOSTRING, TimestampToStringA); - - tmi.cbSize = sizeof(tmi); - GetTimeApi(0, (LPARAM)&tmi); -} diff --git a/src/mir_app/src/utils.cpp b/src/mir_app/src/utils.cpp index 2b96d5f4cf..cba82ce12d 100644 --- a/src/mir_app/src/utils.cpp +++ b/src/mir_app/src/utils.cpp @@ -34,8 +34,6 @@ int InitHyperlink(void); int InitColourPicker(void); void InitXmlApi(void); -void InitTimeZones(void); - int InitCrypt(void); void UninitCrypt(void); @@ -384,7 +382,6 @@ int LoadUtilsModule(void) InitPathUtils(); InitColourPicker(); InitXmlApi(); - InitTimeZones(); InitCrypt(); return 0; } diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index f693d41233..70ee0c1c1d 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -953,3 +953,19 @@ Utils_AssertInsideScreen @1110 Utils_RestoreWindowPosition @1111 Utils_SaveWindowPosition @1112 mir_getLP @1113 +TimeZone_CreateByContact @1114 +TimeZone_CreateByName @1115 +TimeZone_GetDescription @1116 +TimeZone_GetInfo @1117 +TimeZone_GetName @1118 +TimeZone_GetTimeZoneTime @1119 +TimeZone_PrepareList @1120 +TimeZone_PrintDateTime @1121 +TimeZone_PrintTimeStamp @1122 +TimeZone_SelectListItem @1123 +TimeZone_StoreByContact @1124 +TimeZone_StoreListResult @1125 +TimeZone_ToLocal @1126 +TimeZone_ToString @1127 +TimeZone_ToStringW @1128 +TimeZone_UtcToLocal @1129 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index eadbef2572..cc345a6ca8 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -953,3 +953,19 @@ Utils_AssertInsideScreen @1110 Utils_RestoreWindowPosition @1111 Utils_SaveWindowPosition @1112 mir_getLP @1113 +TimeZone_CreateByContact @1114 +TimeZone_CreateByName @1115 +TimeZone_GetDescription @1116 +TimeZone_GetInfo @1117 +TimeZone_GetName @1118 +TimeZone_GetTimeZoneTime @1119 +TimeZone_PrepareList @1120 +TimeZone_PrintDateTime @1121 +TimeZone_PrintTimeStamp @1122 +TimeZone_SelectListItem @1123 +TimeZone_StoreByContact @1124 +TimeZone_StoreListResult @1125 +TimeZone_ToLocal @1126 +TimeZone_ToString @1127 +TimeZone_ToStringW @1128 +TimeZone_UtcToLocal @1129 diff --git a/src/mir_core/src/miranda.cpp b/src/mir_core/src/miranda.cpp index 53091dc2c9..fa99d1d8db 100644 --- a/src/mir_core/src/miranda.cpp +++ b/src/mir_core/src/miranda.cpp @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. HWND hAPCWindow = NULL; int InitPathUtils(void); -void (*RecalculateTime)(void); +void RecalculateTime(void); void CheckLogs(); void InitLogs(); @@ -36,6 +36,7 @@ void UninitLogs(); void InitWinver(); void InitMetaContacts(); +void InitTimeZones(); int hLangpack = 0; HINSTANCE hInst = 0; @@ -57,7 +58,7 @@ static LRESULT CALLBACK APCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP if (msg == WM_TIMER) CheckLogs(); - if (msg == WM_TIMECHANGE && RecalculateTime) + if (msg == WM_TIMECHANGE) RecalculateTime(); return DefWindowProc(hwnd, msg, wParam, lParam); @@ -73,7 +74,6 @@ static void LoadCoreModule(void) hAPCWindow = CreateWindowEx(0, _T("ComboLBox"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetClassLongPtr(hAPCWindow, GCL_STYLE, GetClassLongPtr(hAPCWindow, GCL_STYLE) | CS_DROPSHADOW); DestroyWindow(hAPCWindow); - hAPCWindow = NULL; hAPCWindow = CreateWindowEx(0, _T("STATIC"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetWindowLongPtr(hAPCWindow, GWLP_WNDPROC, (LONG_PTR)APCWndProc); @@ -81,16 +81,10 @@ static void LoadCoreModule(void) hStackMutex = CreateMutex(NULL, FALSE, NULL); hThreadQueueEmpty = CreateEvent(NULL, TRUE, TRUE, NULL); - #ifdef _WIN64 - HMODULE mirInst = GetModuleHandleA("miranda64.exe"); - #else - HMODULE mirInst = GetModuleHandleA("miranda32.exe"); - #endif - RecalculateTime = (void (*)()) GetProcAddress(mirInst, "RecalculateTime"); - InitWinver(); InitPathUtils(); InitLogs(); + InitTimeZones(); InitialiseModularEngine(); InitMetaContacts(); } diff --git a/src/mir_core/src/stdafx.h b/src/mir_core/src/stdafx.h index 359230ab17..eb5f1ac352 100644 --- a/src/mir_core/src/stdafx.h +++ b/src/mir_core/src/stdafx.h @@ -57,6 +57,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include +#include #include "miranda.h" diff --git a/src/mir_core/src/timezones.cpp b/src/mir_core/src/timezones.cpp new file mode 100644 index 0000000000..b9510f2a71 --- /dev/null +++ b/src/mir_core/src/timezones.cpp @@ -0,0 +1,587 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +implements services to handle location - based timezones, instead of +simple UTC offsets. +*/ + +#include "stdafx.h" + +typedef DWORD (WINAPI *pfnGetDynamicTimeZoneInformation_t)(DYNAMIC_TIME_ZONE_INFORMATION *pdtzi); +static pfnGetDynamicTimeZoneInformation_t pfnGetDynamicTimeZoneInformation; + +struct REG_TZI_FORMAT +{ + LONG Bias; + LONG StandardBias; + LONG DaylightBias; + SYSTEMTIME StandardDate; + SYSTEMTIME DaylightDate; +}; + +#define MIM_TZ_DISPLAYLEN 128 + +struct MIM_TIMEZONE +{ + unsigned hash; + int offset; + + TCHAR tszName[MIM_TZ_NAMELEN]; // windows name for the time zone + wchar_t szDisplay[MIM_TZ_DISPLAYLEN]; // more descriptive display name (that's what usually appears in dialogs) + // every hour should be sufficient. + TIME_ZONE_INFORMATION tzi; + + static int compareBias(const MIM_TIMEZONE* p1, const MIM_TIMEZONE* p2) + { return p2->tzi.Bias - p1->tzi.Bias; + } +}; + +struct TZ_INT_INFO +{ + DWORD timestamp; // last time updated + MIM_TIMEZONE myTZ; // set to my own timezone +}; + +static TZ_INT_INFO myInfo; + +static OBJLIST g_timezones(55, NumericKeySortT); +static LIST g_timezonesBias(55, MIM_TIMEZONE::compareBias); + +// KB167296 +void UnixTimeToFileTime(mir_time ts, LPFILETIME pft) +{ + unsigned __int64 ll = UInt32x32To64(ts, 10000000) + 116444736000000000i64; + pft->dwLowDateTime = (DWORD)ll; + pft->dwHighDateTime = ll >> 32; +} + +mir_time FileTimeToUnixTime(LPFILETIME pft) +{ + unsigned __int64 ll = (unsigned __int64)pft->dwHighDateTime << 32 | pft->dwLowDateTime; + ll -= 116444736000000000i64; + return (mir_time)(ll / 10000000); +} + +void FormatTime(const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, size_t cbDest) +{ + if (szDest == NULL || cbDest == 0) return; + + CMString tszTemp; + + for (const TCHAR* pFormat = szFormat; *pFormat; ++pFormat) { + DWORD fmt = 0; + bool date = false, iso = false; + switch (*pFormat) { + case 't': + fmt = TIME_NOSECONDS; + date = false; + break; + + case 's': + fmt = 0; + date = false; + break; + + case 'm': + fmt = TIME_NOMINUTESORSECONDS; + date = false; + break; + + case 'd': + fmt = DATE_SHORTDATE; + date = true; + break; + + case 'D': + fmt = DATE_LONGDATE; + date = true; + break; + + case 'I': + iso = true; + break; + + default: + tszTemp.AppendChar(*pFormat); + continue; + } + + TCHAR dateTimeStr[64]; + if (iso) + tszTemp.AppendFormat(_T("%d-%02d-%02dT%02d:%02d:%02dZ"), st->wYear, st->wMonth, st->wDay, st->wHour, st->wMinute, st->wSecond); + else if (date) { + GetDateFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr)); + tszTemp.Append(dateTimeStr); + } + else { + GetTimeFormat(LOCALE_USER_DEFAULT, fmt, st, NULL, dateTimeStr, SIZEOF(dateTimeStr)); + tszTemp.Append(dateTimeStr); + } + } + + _tcsncpy_s(szDest, cbDest, tszTemp, _TRUNCATE); +} + +#define fnSystemTimeToTzSpecificLocalTime SystemTimeToTzSpecificLocalTime + +MIR_CORE_DLL(int) TimeZone_GetTimeZoneTime(HANDLE hTZ, SYSTEMTIME *st) +{ + if (st == NULL) return 1; + + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + if (tz == UTC_TIME_HANDLE) + GetSystemTime(st); + else if (tz && tz != &myInfo.myTZ) { + SYSTEMTIME sto; + GetSystemTime(&sto); + return !fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &sto, st); + } + else + GetLocalTime(st); + + return 0; +} + +MIR_CORE_DLL(LPCTSTR) TimeZone_GetName(HANDLE hTZ) +{ + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + if (tz == NULL) + return myInfo.myTZ.tszName; + else if (tz == UTC_TIME_HANDLE) + return _T("UTC"); + + return tz->tszName; +} + +MIR_CORE_DLL(LPCTSTR) TimeZone_GetDescription(LPCTSTR TZname) +{ + for (int i = 0; i < g_timezonesBias.getCount(); i++) { + MIM_TIMEZONE *tz = g_timezonesBias[i]; + + if (!mir_tstrcmp(tz->tszName, TZname)) + return tz->szDisplay; + } + return _T(""); +} + +static void CalcTsOffset(MIM_TIMEZONE *tz) +{ + SYSTEMTIME st, stl; + GetSystemTime(&st); + + FILETIME ft; + SystemTimeToFileTime(&st, &ft); + mir_time ts1 = FileTimeToUnixTime(&ft); + + if (!fnSystemTimeToTzSpecificLocalTime(&tz->tzi, &st, &stl)) + return; + + SystemTimeToFileTime(&stl, &ft); + mir_time ts2 = FileTimeToUnixTime(&ft); + + tz->offset = ts2 - ts1; +} + +static bool IsSameTime(MIM_TIMEZONE *tz) +{ + SYSTEMTIME st, stl; + + if (tz == &myInfo.myTZ) + return true; + + TimeZone_GetTimeZoneTime(tz, &stl); + TimeZone_GetTimeZoneTime(NULL, &st); + + return st.wHour == stl.wHour && st.wMinute == stl.wMinute; +} + +MIR_CORE_DLL(HANDLE) TimeZone_CreateByName(LPCTSTR tszName, DWORD dwFlags) +{ + if (tszName == NULL) + return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; + + if (mir_tstrcmp(myInfo.myTZ.tszName, tszName) == 0) + return (dwFlags & TZF_DIFONLY) ? NULL : &myInfo.myTZ; + + MIM_TIMEZONE tzsearch; + tzsearch.hash = mir_hashstrT(tszName); + + MIM_TIMEZONE *tz = g_timezones.find(&tzsearch); + if (tz == NULL) + return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; + + if (dwFlags & TZF_DIFONLY) + return IsSameTime(tz) ? NULL : tz; + + return tz; +} + +MIR_CORE_DLL(HANDLE) TimeZone_CreateByContact(MCONTACT hContact, LPCSTR szModule, DWORD dwFlags) +{ + if (hContact == NULL && szModule == NULL) + return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; + + if (szModule == NULL) szModule = "UserInfo"; + + DBVARIANT dbv; + if (!db_get_ts(hContact, szModule, "TzName", &dbv)) { + HANDLE res = TimeZone_CreateByName(dbv.ptszVal, dwFlags); + db_free(&dbv); + if (res) return res; + } + + signed char timezone = (signed char)db_get_b(hContact, szModule, "Timezone", -1); + if (timezone == -1) { + char *szProto = GetContactProto(hContact); + if (!db_get_ts(hContact, szProto, "TzName", &dbv)) { + HANDLE res = TimeZone_CreateByName(dbv.ptszVal, dwFlags); + db_free(&dbv); + if (res) return res; + } + timezone = (signed char)db_get_b(hContact, szProto, "Timezone", -1); + } + + if (timezone != -1) { + MIM_TIMEZONE tzsearch; + tzsearch.tzi.Bias = timezone * 30; + if (myInfo.myTZ.tzi.Bias == tzsearch.tzi.Bias) { + if (dwFlags & TZF_DIFONLY) return NULL; + return &myInfo.myTZ; + } + + int i = g_timezonesBias.getIndex(&tzsearch); + while (i >= 0 && g_timezonesBias[i]->tzi.Bias == tzsearch.tzi.Bias) --i; + + int delta = LONG_MAX; + for (int j = ++i; j < g_timezonesBias.getCount() && g_timezonesBias[j]->tzi.Bias == tzsearch.tzi.Bias; ++j) { + int delta1 = abs(g_timezonesBias[j]->tzi.DaylightDate.wMonth - myInfo.myTZ.tzi.DaylightDate.wMonth); + if (delta1 <= delta) { + delta = delta1; + i = j; + } + } + + if (i >= 0) { + MIM_TIMEZONE *tz = g_timezonesBias[i]; + return ((dwFlags & TZF_DIFONLY) && IsSameTime(tz)) ? NULL : tz; + } + } + return (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY)) ? NULL : &myInfo.myTZ; +} + +MIR_CORE_DLL(void) TimeZone_StoreByContact(MCONTACT hContact, LPCSTR szModule, HANDLE hTZ) +{ + if (szModule == NULL) szModule = "UserInfo"; + + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + if (tz) { + db_set_ts(hContact, szModule, "TzName", tz->tszName); + db_set_b(hContact, szModule, "Timezone", (char)((tz->tzi.Bias + tz->tzi.StandardBias) / 30)); + } + else { + db_unset(hContact, szModule, "TzName"); + db_unset(hContact, szModule, "Timezone"); + } +} + +MIR_CORE_DLL(int) TimeZone_PrintDateTime(HANDLE hTZ, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags) +{ + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) + return 1; + + SYSTEMTIME st; + if (TimeZone_GetTimeZoneTime(tz, &st)) + return 1; + + FormatTime(&st, szFormat, szDest, cbDest); + return 0; +} + +MIR_CORE_DLL(int) TimeZone_PrintTimeStamp(HANDLE hTZ, mir_time ts, LPCTSTR szFormat, LPTSTR szDest, size_t cbDest, DWORD dwFlags) +{ + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + if (tz == NULL && (dwFlags & (TZF_DIFONLY | TZF_KNOWNONLY))) + return 1; + + if (tz == NULL) + tz = &myInfo.myTZ; + + FILETIME ft; + if (tz == UTC_TIME_HANDLE) + UnixTimeToFileTime(ts, &ft); + else { + if (tz->offset == INT_MIN) + CalcTsOffset(tz); + + UnixTimeToFileTime(ts + tz->offset, &ft); + } + + SYSTEMTIME st; + FileTimeToSystemTime(&ft, &st); + + FormatTime(&st, szFormat, szDest, cbDest); + return 0; +} + +MIR_CORE_DLL(LPTIME_ZONE_INFORMATION) TimeZone_GetInfo(HANDLE hTZ) +{ + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + return tz ? &tz->tzi : &myInfo.myTZ.tzi; +} + +MIR_CORE_DLL(mir_time) TimeZone_UtcToLocal(HANDLE hTZ, mir_time ts) +{ + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)hTZ; + if (tz == NULL) + tz = &myInfo.myTZ; + + if (tz == UTC_TIME_HANDLE) + return ts; + + if (tz->offset == INT_MIN) + CalcTsOffset(tz); + + return ts + tz->offset; +} + +/////////////////////////////////////////////////////////////////////////////// + +struct ListMessages +{ + UINT addStr, getSel, setSel, getData, setData; +}; + +static const ListMessages lbMessages = { LB_ADDSTRING, LB_GETCURSEL, LB_SETCURSEL, LB_GETITEMDATA, LB_SETITEMDATA }; +static const ListMessages cbMessages = { CB_ADDSTRING, CB_GETCURSEL, CB_SETCURSEL, CB_GETITEMDATA, CB_SETITEMDATA }; + +static const ListMessages* GetListMessages(HWND hWnd, DWORD dwFlags) +{ + if (hWnd == NULL) + return NULL; + + if (!(dwFlags & (TZF_PLF_CB | TZF_PLF_LB))) { + TCHAR tszClassName[128]; + GetClassName(hWnd, tszClassName, SIZEOF(tszClassName)); + if (!mir_tstrcmpi(tszClassName, _T("COMBOBOX"))) + dwFlags |= TZF_PLF_CB; + else if (!mir_tstrcmpi(tszClassName, _T("LISTBOX"))) + dwFlags |= TZF_PLF_LB; + } + if (dwFlags & TZF_PLF_CB) + return &cbMessages; + else if (dwFlags & TZF_PLF_LB) + return &lbMessages; + else + return NULL; +} + +/////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(int) TimeZone_SelectListItem(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) +{ + const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); + if (lstMsg == NULL) + return -1; + + if (szModule == NULL) szModule = "UserInfo"; + + int iSelection = 0; + ptrT tszName(db_get_tsa(hContact, szModule, "TzName")); + if (tszName != NULL) { + unsigned hash = mir_hashstrT(tszName); + for (int i = 0; i < g_timezonesBias.getCount(); i++) { + if (hash == g_timezonesBias[i]->hash) { + iSelection = i + 1; + break; + } + } + } + else { + signed char cBias = db_get_b(hContact, szModule, "Timezone", -100); + if (cBias != -100) { + int iBias = cBias * 30; + for (int i = 0; i < g_timezonesBias.getCount(); i++) { + if (iBias == g_timezonesBias[i]->tzi.Bias) { + iSelection = i + 1; + break; + } + } + } + } + + SendMessage(hWnd, lstMsg->setSel, iSelection, 0); + return iSelection; +} + +MIR_CORE_DLL(int) TimeZone_PrepareList(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) +{ + const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); + if (lstMsg == NULL) + return 0; + + SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)TranslateT("")); + + for (int i = 0; i < g_timezonesBias.getCount(); i++) { + MIM_TIMEZONE *tz = g_timezonesBias[i]; + + SendMessage(hWnd, lstMsg->addStr, 0, (LPARAM)tz->szDisplay); + SendMessage(hWnd, lstMsg->setData, i + 1, (LPARAM)tz); + } + + return TimeZone_SelectListItem(hContact, szModule, hWnd, dwFlags); +} + +MIR_CORE_DLL(void) TimeZone_StoreListResult(MCONTACT hContact, LPCSTR szModule, HWND hWnd, DWORD dwFlags) +{ + if (szModule == NULL) szModule = "UserInfo"; + + const ListMessages *lstMsg = GetListMessages(hWnd, dwFlags); + if (lstMsg) { + LRESULT offset = SendMessage(hWnd, lstMsg->getSel, 0, 0); + if (offset > 0) { + MIM_TIMEZONE *tz = (MIM_TIMEZONE*)SendMessage(hWnd, lstMsg->getData, offset, 0); + if ((INT_PTR)tz != CB_ERR && tz != NULL) + TimeZone_StoreByContact(hContact, szModule, tz); + } + else TimeZone_StoreByContact(hContact, szModule, NULL); + } +} + +/////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(DWORD) TimeZone_ToLocal(DWORD timeVal) +{ + return TimeZone_UtcToLocal(NULL, (mir_time)timeVal); +} + +MIR_CORE_DLL(char*) TimeZone_ToString(mir_time timeVal, const char *szFormat, char *szDest, size_t cchDest) +{ + TCHAR *szTemp = (TCHAR*)alloca(cchDest*sizeof(TCHAR)); + TimeZone_PrintTimeStamp(NULL, timeVal, _A2T(szFormat), szTemp, cchDest, 0); + WideCharToMultiByte(CP_ACP, 0, szTemp, -1, szDest, (int)cchDest, NULL, NULL); + return szDest; +} + +MIR_CORE_DLL(wchar_t*) TimeZone_ToStringW(mir_time timeVal, const wchar_t *wszFormat, wchar_t *wszDest, size_t cchDest) +{ + TimeZone_PrintTimeStamp(NULL, timeVal, wszFormat, wszDest, cchDest, 0); + return wszDest; +} + +/////////////////////////////////////////////////////////////////////////////// + +void GetLocalizedString(HKEY hSubKey, const TCHAR *szName, wchar_t *szBuf, DWORD cbLen) +{ + DWORD dwLength = cbLen * sizeof(wchar_t); + RegQueryValueEx(hSubKey, szName, NULL, NULL, (unsigned char *)szBuf, &dwLength); + szBuf[min(dwLength / sizeof(TCHAR), cbLen - 1)] = 0; +} + +void RecalculateTime(void) +{ + GetTimeZoneInformation(&myInfo.myTZ.tzi); + myInfo.timestamp = time(NULL); + myInfo.myTZ.offset = INT_MIN; + + bool found = false; + DYNAMIC_TIME_ZONE_INFORMATION dtzi; + + if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID) { + TCHAR *myTzKey = mir_u2t(dtzi.TimeZoneKeyName); + _tcsncpy_s(myInfo.myTZ.tszName, myTzKey, _TRUNCATE); + mir_free(myTzKey); + found = true; + } + + for (int i = 0; i < g_timezones.getCount(); i++) { + MIM_TIMEZONE &tz = g_timezones[i]; + if (tz.offset != INT_MIN) + tz.offset = INT_MIN; + + if (!found) { + if (!mir_wstrcmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) || !mir_wstrcmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName)) { + _tcsncpy_s(myInfo.myTZ.tszName, tz.tszName, _TRUNCATE); + found = true; + } + } + } +} + +void InitTimeZones(void) +{ + REG_TZI_FORMAT tzi; + HKEY hKey; + + const TCHAR *tszKey = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); + + /* + * use GetDynamicTimeZoneInformation() on Vista+ - this will return a structure with + * the registry key name, so finding our own time zone later will be MUCH easier for + * localized systems or systems with a MUI pack installed + */ + if (IsWinVerVistaPlus()) + pfnGetDynamicTimeZoneInformation = (pfnGetDynamicTimeZoneInformation_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetDynamicTimeZoneInformation"); + + if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey)) { + DWORD dwIndex = 0; + HKEY hSubKey; + TCHAR tszName[MIM_TZ_NAMELEN]; + + DWORD dwSize = SIZEOF(tszName); + while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL)) { + if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) { + dwSize = sizeof(tszName); + + DWORD dwLength = sizeof(tzi); + if (ERROR_SUCCESS != RegQueryValueEx(hSubKey, _T("TZI"), NULL, NULL, (unsigned char *)&tzi, &dwLength)) + continue; + + MIM_TIMEZONE *tz = new MIM_TIMEZONE; + + tz->tzi.Bias = tzi.Bias; + tz->tzi.StandardDate = tzi.StandardDate; + tz->tzi.StandardBias = tzi.StandardBias; + tz->tzi.DaylightDate = tzi.DaylightDate; + tz->tzi.DaylightBias = tzi.DaylightBias; + + mir_tstrcpy(tz->tszName, tszName); + tz->hash = mir_hashstrT(tszName); + tz->offset = INT_MIN; + + GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay)); + GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, SIZEOF(tz->tzi.StandardName)); + GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, SIZEOF(tz->tzi.DaylightName)); + + g_timezones.insert(tz); + g_timezonesBias.insert(tz); + + RegCloseKey(hSubKey); + } + dwSize = SIZEOF(tszName); + } + RegCloseKey(hKey); + } + + RecalculateTime(); +} -- cgit v1.2.3