summaryrefslogtreecommitdiff
path: root/protocols/CurrencyRates/src/Locale.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:44 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:55 +0300
commit931a7dc1ac0dbc7e6c1083583ced915e572f5b47 (patch)
tree9fe9a6448d44030e26aa7107ce16044ed413e0d0 /protocols/CurrencyRates/src/Locale.cpp
parentdd7d9954042254e66e3bbbec7195c6be8b1a0663 (diff)
all protocols (even virtual ones) moved to the Protocols folder
Diffstat (limited to 'protocols/CurrencyRates/src/Locale.cpp')
-rw-r--r--protocols/CurrencyRates/src/Locale.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/protocols/CurrencyRates/src/Locale.cpp b/protocols/CurrencyRates/src/Locale.cpp
new file mode 100644
index 0000000000..501015eb21
--- /dev/null
+++ b/protocols/CurrencyRates/src/Locale.cpp
@@ -0,0 +1,59 @@
+#include "StdAfx.h"
+
+const std::locale GetSystemLocale()
+{
+ return std::locale("");
+}
+
+tstring get_int_registry_value(LPCTSTR pszValueName)
+{
+ tstring sResult;
+ HKEY hKey = nullptr;
+ LONG lResult = ::RegOpenKeyEx(HKEY_CURRENT_USER,
+ L"Control Panel\\International", 0, KEY_QUERY_VALUE, &hKey);
+ if ((ERROR_SUCCESS == lResult) && (nullptr != hKey)) {
+ DWORD dwType = 0;
+ DWORD dwSize = 0;
+ lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, &dwType, nullptr, &dwSize);
+ if ((ERROR_SUCCESS == lResult) && ((REG_SZ == dwType) || (REG_EXPAND_SZ == dwType))) {
+ std::vector<wchar_t> aBuffer(dwSize);
+ lResult = ::RegQueryValueEx(hKey, pszValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(&*aBuffer.begin()), &dwSize);
+ if (ERROR_SUCCESS == lResult)
+ std::copy(aBuffer.begin(), aBuffer.end(), std::back_inserter(sResult));
+ }
+ }
+
+ if (nullptr != hKey) {
+ lResult = ::RegCloseKey(hKey);
+ assert(ERROR_SUCCESS == lResult);
+ }
+
+ return sResult;
+}
+
+LPCTSTR date_win_2_boost(const tstring& sFrmt)
+{
+ if (sFrmt == L"dd/MM/yy")
+ return L"%d/%m/%y";
+ if (sFrmt == L"yyyy-MM-dd")
+ return L"%y-%m-%d";
+ return L"%d.%m.%y";
+}
+
+LPCTSTR time_win_2_boost(const tstring& sFrmt)
+{
+ if (sFrmt == L"H:mm" || sFrmt == L"HH:mm")
+ return L"%H:%M";
+
+ return L"%H:%M:%S";
+}
+
+LPCTSTR CurrencyRates_GetDateFormat(bool bShort)
+{
+ return date_win_2_boost(get_int_registry_value(bShort ? L"sShortDate" : L"sLongDate"));
+}
+
+LPCTSTR CurrencyRates_GetTimeFormat(bool bShort)
+{
+ return time_win_2_boost(get_int_registry_value(bShort ? L"sShortTime" : L"sTimeFormat"));
+}