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; }
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 = _countof(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, _countof(tz->szDisplay)); GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, _countof(tz->tzi.StandardName)); GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, _countof(tz->tzi.DaylightName)); g_timezones.insert(tz); g_timezonesBias.insert(tz); RegCloseKey(hSubKey); } dwSize = _countof(tszName); } RegCloseKey(hKey); } RecalculateTime(); }
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; }
PageHash GetPluginPageHash(const OptionsPageData *page) { return mir_hashstrT(page->ptszGroup) + mir_hashstrT(page->ptszTitle) + mir_hashstrT(page->ptszTab); }