summaryrefslogtreecommitdiff
path: root/plugins/Quotes/src/Locale.cpp
blob: 4e72558cffdccff56d8ceb8b95ba94a2ed34ea7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "StdAfx.h"

const std::locale GetSystemLocale()
{
	return std::locale("");
}

tstring get_int_registry_value(LPCTSTR pszValueName)
{
	tstring sResult;
	HKEY hKey = NULL;
	LONG lResult = ::RegOpenKeyEx(HKEY_CURRENT_USER,
		_T("Control Panel\\International"), 0, KEY_QUERY_VALUE, &hKey);
	if ((ERROR_SUCCESS == lResult) && (NULL != 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<TCHAR> 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 (NULL != hKey) {
		lResult = ::RegCloseKey(hKey);
		assert(ERROR_SUCCESS == lResult);
	}

	return sResult;
}

LPCTSTR date_win_2_boost(const tstring& sFrmt)
{
	if (sFrmt == _T("dd/MM/yy"))
		return _T("%d/%m/%y");
	if (sFrmt == _T("yyyy-MM-dd"))
		return _T("%y-%m-%d");
	return _T("%d.%m.%y");
}

LPCTSTR time_win_2_boost(const tstring& sFrmt)
{
	if (sFrmt == _T("H:mm") || sFrmt == _T("HH:mm"))
		return _T("%H:%M");

	return _T("%H:%M:%S");
}

LPCTSTR Quotes_GetDateFormat(bool bShort)
{
	return date_win_2_boost(get_int_registry_value(bShort ? _T("sShortDate") : _T("sLongDate")));
}

LPCTSTR Quotes_GetTimeFormat(bool bShort)
{
	return time_win_2_boost(get_int_registry_value(bShort ? _T("sShortTime") : _T("sTimeFormat")));
}