summaryrefslogtreecommitdiffstats
path: root/shell/source/win32/shlxthandler/util
diff options
context:
space:
mode:
Diffstat (limited to 'shell/source/win32/shlxthandler/util')
-rw-r--r--shell/source/win32/shlxthandler/util/fileextensions.cxx106
-rw-r--r--shell/source/win32/shlxthandler/util/iso8601_converter.cxx155
-rw-r--r--shell/source/win32/shlxthandler/util/registry.cxx173
-rw-r--r--shell/source/win32/shlxthandler/util/utilities.cxx565
4 files changed, 999 insertions, 0 deletions
diff --git a/shell/source/win32/shlxthandler/util/fileextensions.cxx b/shell/source/win32/shlxthandler/util/fileextensions.cxx
new file mode 100644
index 000000000..57c8068ef
--- /dev/null
+++ b/shell/source/win32/shlxthandler/util/fileextensions.cxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <algorithm>
+#include <fileextensions.hxx>
+#include <rtl/character.hxx>
+#include <sal/macros.h>
+
+
+const std::wstring WRITER_FILE_EXTENSIONS = L"sxwstwsxgodtottodm";
+const std::wstring CALC_FILE_EXTENSIONS = L"sxcstcodsots";
+const std::wstring DRAW_FILE_EXTENSIONS = L"sxdstdodgotg";
+const std::wstring IMPRESS_FILE_EXTENSIONS = L"sxistiodpotp";
+const std::wstring MATH_FILE_EXTENSIONS = L"sxmodf";
+const std::wstring WEB_FILE_EXTENSIONS = L"oth";
+const std::wstring DATABASE_FILE_EXTENSIONS = L"odb";
+
+const FileExtensionEntry OOFileExtensionTable[] = {
+ { ".sxw", L".sxw", L"soffice.StarWriterDocument.6" },
+ { ".sxc", L".sxc", L"soffice.StarCalcDocument.6" },
+ { ".sxi", L".sxi", L"soffice.StarImpressDocument.6" },
+ { ".sxd", L".sxd", L"soffice.StarDrawDocument.6" },
+ { ".sxm", L".sxm", L"soffice.StarMathDocument.6" },
+ { ".stw", L".stw", L"soffice.StarWriterTemplate.6" },
+ { ".sxg", L".sxg", L"soffice.StarWriterGlobalDocument.6" },
+ { ".std", L".std", L"soffice.StarDrawTemplate.6" },
+ { ".sti", L".sti", L"soffice.StarImpressTemplate.6" },
+ { ".stc", L".stc", L"soffice.StarCalcTemplate.6" },
+ { ".odt", L".odt", L"LibreOffice.WriterDocument.1" },
+ { ".ott", L".ott", L"LibreOffice.WriterTemplate.1" },
+ { ".odm", L".odm", L"LibreOffice.WriterGlobalDocument.1" },
+ { ".oth", L".oth", L"LibreOffice.WriterWebTemplate.1" },
+ { ".ods", L".ods", L"LibreOffice.CalcDocument.1" },
+ { ".ots", L".ots", L"LibreOffice.CalcTemplate.1" },
+ { ".odg", L".odg", L"LibreOffice.DrawDocument.1" },
+ { ".otg", L".otg", L"LibreOffice.DrawTemplate.1" },
+ { ".odp", L".odp", L"LibreOffice.ImpressDocument.1" },
+ { ".otp", L".otp", L"LibreOffice.ImpressTemplate.1" },
+ { ".odf", L".odf", L"LibreOffice.MathDocument.1" },
+ { ".odb", L".odb", L"LibreOffice.DatabaseDocument.1" }
+ };
+
+
+const size_t OOFileExtensionTableSize = SAL_N_ELEMENTS(OOFileExtensionTable);
+
+
+/** Return the extension of a file
+ name without the '.'
+*/
+Filepath_t get_file_name_extension(const Filepath_t& file_name)
+{
+ std::wstring::size_type idx = file_name.find_last_of(L".");
+
+ if (std::wstring::npos != idx++)
+ return std::wstring(file_name.begin() + idx, file_name.end());
+
+ return std::wstring();
+}
+
+
+/** Return the type of a file
+*/
+
+File_Type_t get_file_type(const Filepath_t& file_name)
+{
+ std::wstring fext = get_file_name_extension(file_name);
+ std::transform(
+ fext.begin(), fext.end(), fext.begin(),
+ [](wchar_t c) {
+ return rtl::toAsciiLowerCase(c); });
+
+ if (std::wstring::npos != WRITER_FILE_EXTENSIONS.find(fext))
+ return WRITER;
+ else if (std::wstring::npos != CALC_FILE_EXTENSIONS.find(fext))
+ return CALC;
+ else if (std::wstring::npos != DRAW_FILE_EXTENSIONS.find(fext))
+ return DRAW;
+ else if (std::wstring::npos != IMPRESS_FILE_EXTENSIONS.find(fext))
+ return IMPRESS;
+ else if (std::wstring::npos != MATH_FILE_EXTENSIONS.find(fext))
+ return MATH;
+ else if (std::wstring::npos != WEB_FILE_EXTENSIONS.find(fext))
+ return WEB;
+ else if (std::wstring::npos != DATABASE_FILE_EXTENSIONS.find(fext))
+ return DATABASE;
+ else
+ return UNKNOWN;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/win32/shlxthandler/util/iso8601_converter.cxx b/shell/source/win32/shlxthandler/util/iso8601_converter.cxx
new file mode 100644
index 000000000..c0415deb9
--- /dev/null
+++ b/shell/source/win32/shlxthandler/util/iso8601_converter.cxx
@@ -0,0 +1,155 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <stdlib.h>
+
+#include <iso8601_converter.hxx>
+#include <utilities.hxx>
+
+#include <sstream>
+#include <iomanip>
+
+#include <rtl/character.hxx>
+
+/* Converts ISO 8601 compliant date/time
+ representation to the representation
+ conforming to the current locale
+*/
+std::wstring iso8601_date_to_local_date(const std::wstring& isoDate )
+{
+ ::std::wstring ws8601DateTime(isoDate);
+
+ // Get rid of the optional milliseconds part if it exists.
+ // Function accepts date/time as a combined date/time string in extended ISO8601 format,
+ // which is yyyy-mm-ddThh:mm:ss[.mmm]. Last part is the optional "fraction of second" part,
+ // that's why we cut off at 19.
+ if (ws8601DateTime.length() > 19)
+ {
+ ws8601DateTime.erase(19, ::std::basic_string<char>::npos);
+ }
+
+ if ( ws8601DateTime.length() == 19 )
+ {
+ std::string asDateTime = WStringToString( ws8601DateTime );
+ SYSTEMTIME DateTime;
+ DateTime.wYear = static_cast<unsigned short>(strtol( asDateTime.substr( 0, 4 ).c_str(), nullptr, 10 ));
+ DateTime.wMonth = static_cast<unsigned short>(strtol( asDateTime.substr( 5, 2 ).c_str(), nullptr, 10 ));
+ DateTime.wDayOfWeek = 0;
+ DateTime.wDay = static_cast<unsigned short>(strtol( asDateTime.substr( 8, 2 ).c_str(), nullptr, 10 ));
+ DateTime.wHour = static_cast<unsigned short>(strtol( asDateTime.substr( 11,2 ).c_str(), nullptr, 10 ));
+ DateTime.wMinute = static_cast<unsigned short>(strtol( asDateTime.substr( 14,2 ).c_str(), nullptr, 10 ));
+ DateTime.wSecond = static_cast<unsigned short>(strtol( asDateTime.substr( 17,2 ).c_str(), nullptr, 10 ));
+ DateTime.wMilliseconds = 0;
+
+ //get Date info from structure
+ WCHAR DateBuffer[ MAX_PATH ];
+ int DateSize = GetDateFormatW(
+ LOCALE_SYSTEM_DEFAULT,
+ 0,
+ &DateTime,
+ nullptr,
+ DateBuffer,
+ MAX_PATH );
+
+ if ( DateSize )
+ ws8601DateTime.assign(DateBuffer);
+ else
+ ws8601DateTime = StringToWString( asDateTime );
+
+ //get Time info from structure
+ WCHAR TimeBuffer[ MAX_PATH ];
+
+ int TimeSize = GetTimeFormatW(
+ LOCALE_SYSTEM_DEFAULT,
+ 0,
+ &DateTime,
+ nullptr,
+ TimeBuffer,
+ MAX_PATH );
+
+ if ( TimeSize )
+ {
+ ws8601DateTime.append(L" ");
+ ws8601DateTime.append(TimeBuffer);
+ }
+ else
+ ws8601DateTime = StringToWString( asDateTime );
+ }
+
+ return ws8601DateTime;
+}
+
+
+/* Converts ISO 8601 conform duration
+ representation to the representation
+ conforming to the current locale
+
+ Expect format PTnHnMnS according to
+ ISO 8601 where n is arbitrary number
+ of digits
+*/
+
+std::wstring iso8601_duration_to_local_duration(const std::wstring& iso8601duration)
+{
+ std::wstring days;
+ std::wstring hours;
+ std::wstring minutes;
+ std::wstring seconds;
+
+ std::wstring num;
+
+ for (const auto& w_ch : iso8601duration)
+ {
+ if (rtl::isAsciiDigit(w_ch)) // wchar_t is unsigned under MSVC
+ {
+ num += w_ch;
+ }
+ else
+ {
+ if (w_ch == L'D' || w_ch == L'd')
+ days = num;
+ else if (w_ch == L'H' || w_ch == L'h')
+ hours = num;
+ else if (w_ch == L'M' || w_ch == L'm')
+ minutes = num;
+ else if (w_ch == L'S' || w_ch == L's')
+ seconds = num;
+
+ num.clear();
+ }
+ }
+
+ if (days.length() > 0)
+ {
+ int h = (_wtoi(days.c_str()) * 24) + _wtoi(hours.c_str());
+ wchar_t buff[10];
+ _itow(h, buff, 10);
+ hours = buff;
+ }
+
+ std::wostringstream oss;
+ oss << std::setw(2) << std::setfill(wchar_t('0')) << hours << L":" <<
+ std::setw(2) << std::setfill(wchar_t('0')) << minutes << L":" <<
+ std::setw(2) << std::setfill(wchar_t('0')) << seconds;
+ return oss.str();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/win32/shlxthandler/util/registry.cxx b/shell/source/win32/shlxthandler/util/registry.cxx
new file mode 100644
index 000000000..cc42c092e
--- /dev/null
+++ b/shell/source/win32/shlxthandler/util/registry.cxx
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#if !defined WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+#endif
+#include <windows.h>
+
+#include <malloc.h>
+#include <registry.hxx>
+
+#include <objbase.h>
+
+bool SetRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const Filepath_char_t* ValueName, const Filepath_char_t* Value)
+{
+ HKEY hSubKey;
+
+ // open or create the desired key
+ wchar_t dummy[] = L"";
+ int rc = RegCreateKeyExW(
+ RootKey, KeyName, 0, dummy, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &hSubKey, nullptr);
+
+ if (ERROR_SUCCESS == rc)
+ {
+ rc = RegSetValueExW(
+ hSubKey, ValueName, 0, REG_SZ, reinterpret_cast<const BYTE*>(Value),
+ static_cast<DWORD>((wcslen(Value) + 1) * sizeof(*Value)));
+
+ RegCloseKey(hSubKey);
+ }
+
+ return (ERROR_SUCCESS == rc);
+}
+
+
+bool DeleteRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName)
+{
+ HKEY hKey;
+
+ int rc = RegOpenKeyExW(
+ RootKey,
+ KeyName,
+ 0,
+ KEY_READ | DELETE,
+ &hKey);
+
+ if ( rc == ERROR_FILE_NOT_FOUND )
+ return true;
+
+ if (ERROR_SUCCESS == rc)
+ {
+ wchar_t* SubKey;
+ DWORD nMaxSubKeyLen;
+
+ rc = RegQueryInfoKeyW(
+ hKey, nullptr, nullptr, nullptr, nullptr,
+ &nMaxSubKeyLen,
+ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
+
+ nMaxSubKeyLen++; // space for trailing '\0'
+
+ SubKey = static_cast<wchar_t*>(
+ _alloca(nMaxSubKeyLen*sizeof(wchar_t)));
+
+ while (ERROR_SUCCESS == rc)
+ {
+ DWORD nLen = nMaxSubKeyLen;
+
+ rc = RegEnumKeyExW(
+ hKey,
+ 0, // always index zero
+ SubKey,
+ &nLen,
+ nullptr, nullptr, nullptr, nullptr);
+
+ if (ERROR_NO_MORE_ITEMS == rc)
+ {
+ rc = RegDeleteKeyW(RootKey, KeyName);
+ break;
+ }
+ else if (rc == ERROR_SUCCESS)
+ {
+ DeleteRegistryKey(hKey, SubKey);
+ }
+
+ } // while
+
+ RegCloseKey(hKey);
+
+ } // if
+
+ return (ERROR_SUCCESS == rc);
+}
+
+/** May be used to determine if the specified registry key has subkeys
+ The function returns true on success else if an error occurs false
+*/
+bool HasSubkeysRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, /* out */ bool& bResult)
+{
+ HKEY hKey;
+
+ LONG rc = RegOpenKeyExW(RootKey, KeyName, 0, KEY_READ, &hKey);
+
+ if (ERROR_SUCCESS == rc)
+ {
+ DWORD nSubKeys = 0;
+
+ rc = RegQueryInfoKeyW(hKey, nullptr, nullptr, nullptr, &nSubKeys, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
+
+ RegCloseKey(hKey);
+ bResult = (nSubKeys > 0);
+ }
+
+ return (ERROR_SUCCESS == rc);
+}
+
+// Convert a CLSID to a char string.
+Filepath_t ClsidToString(const CLSID& clsid)
+{
+ // Get CLSID
+ LPOLESTR wszCLSID = nullptr;
+ StringFromCLSID(clsid, &wszCLSID);
+
+ std::wstring sResult = wszCLSID;
+
+ // Free memory.
+ CoTaskMemFree(wszCLSID) ;
+
+ return sResult;
+}
+
+
+bool QueryRegistryKey(HKEY RootKey, const Filepath_char_t* KeyName, const Filepath_char_t* ValueName, Filepath_char_t *pszData, DWORD dwBufLen)
+{
+ HKEY hKey;
+
+ int rc = RegOpenKeyExW(
+ RootKey,
+ KeyName,
+ 0,
+ KEY_READ,
+ &hKey);
+
+ if (ERROR_SUCCESS == rc)
+ {
+ DWORD dwBytes = dwBufLen * sizeof(*pszData);
+ rc = RegQueryValueExW(
+ hKey, ValueName, nullptr, nullptr, reinterpret_cast<LPBYTE>(pszData),&dwBytes);
+
+ RegCloseKey(hKey);
+ }
+
+ return (ERROR_SUCCESS == rc);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/win32/shlxthandler/util/utilities.cxx b/shell/source/win32/shlxthandler/util/utilities.cxx
new file mode 100644
index 000000000..27bf12c21
--- /dev/null
+++ b/shell/source/win32/shlxthandler/util/utilities.cxx
@@ -0,0 +1,565 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <memory>
+
+#include <config.hxx>
+#include <global.hxx>
+#include <utilities.hxx>
+
+// constants
+
+
+const size_t MAX_RES_STRING = 1024;
+const wchar_t SPACE_CHAR = L' ';
+
+static std::wstring StringToWString(const std::string& String, int codepage)
+{
+ int len = MultiByteToWideChar(
+ codepage, 0, String.c_str(), -1, nullptr, 0);
+
+ wchar_t* buff = static_cast<wchar_t*>(
+ _alloca(len * sizeof(wchar_t)));
+
+ MultiByteToWideChar(
+ codepage, 0, String.c_str(), -1, buff, len);
+
+ return std::wstring(buff);
+}
+
+static std::string WStringToString(const std::wstring& String, int codepage)
+{
+ int len = WideCharToMultiByte(
+ codepage, 0, String.c_str(), -1, nullptr, 0, nullptr, nullptr);
+
+ char* buff = static_cast<char*>(
+ _alloca(len * sizeof(char)));
+
+ WideCharToMultiByte(
+ codepage, 0, String.c_str(), -1, buff, len, nullptr, nullptr);
+
+ return std::string(buff);
+}
+
+
+std::wstring StringToWString(const std::string& String)
+{
+ return StringToWString(String, CP_ACP);
+}
+
+
+std::string WStringToString(const std::wstring& String)
+{
+ return WStringToString(String, CP_ACP);
+}
+
+
+std::wstring UTF8ToWString(const std::string& String)
+{
+ return StringToWString(String, CP_UTF8);
+}
+
+
+std::wstring GetResString(int ResId)
+{
+ wchar_t szResStr[MAX_RES_STRING];
+
+ int rc = LoadStringW( GetCurrentModuleHandle(), ResId, szResStr, sizeof(szResStr) );
+
+ OutputDebugStringFormatW( L"GetResString: read %d chars\n", rc );
+ // OSL_ENSURE(rc, "String resource not found");
+
+ return std::wstring(szResStr);
+}
+
+
+/** helper function to judge if the string is only has spaces.
+ @returns
+ <TRUE>if the provided string contains only but at least one space
+ character else <FALSE/>.
+*/
+
+bool HasOnlySpaces(const std::wstring& String)
+{
+ if ( String.length() == 0 )
+ return false;
+
+ const wchar_t* p = String.c_str();
+
+ while (*p)
+ {
+ if (*p++ != SPACE_CHAR)
+ return false;
+ }
+
+ return true;
+}
+
+
+/** helper function to convert windows paths to short form.
+ @returns
+ shortened path.
+*/
+
+std::wstring getShortPathName( const std::wstring& aLongName )
+{
+ std::wstring shortName = aLongName;
+ DWORD length = GetShortPathNameW( aLongName.c_str(), nullptr, 0 );
+
+ if ( length != 0 )
+ {
+ auto buffer = std::make_unique<WCHAR[]>( length+1 );
+ length = GetShortPathNameW( aLongName.c_str(), buffer.get(), length );
+ if ( length != 0 )
+ shortName = std::wstring( buffer.get() );
+ }
+ return shortName;
+}
+
+
+/** convert LocaleSet pair into Microsoft List of Locale ID (LCID)
+ according to ISO-639 and ISO-3166.
+ http://etext.lib.virginia.edu/tei/iso639.html
+ http://nl.ijs.si/gnusl/cee/std/ISO_3166.html
+ @param
+ Locale, LocaleSet
+ @returns
+ Windows Locale Identifier corresponding to input LocaleSet.
+ @Usage Sample
+ LocaleSet_t myDefaultLocale( ::std::wstring( L"zh" ),::std::wstring(L"HK") );
+ DWORD myLCID = LocaleSetToLCID( myDefaultLocale );
+ wchar_t buffer[20];
+ _ultow( myLCID, buffer, 16 );
+ MessageBox( NULL, buffer,L"the LCID is:",MB_OK );
+*/
+
+LCID LocaleSetToLCID( const LocaleSet_t & Locale )
+{
+ if ( EMPTY_LOCALE == Locale )
+ return GetSystemDefaultLCID();
+
+ USHORT usPrimaryLang= LANG_NEUTRAL;
+ USHORT usSubLang=SUBLANG_DEFAULT;
+
+ ::std::wstring wsLanguage(Locale.first);
+ ::std::wstring wsCountry(Locale.second);
+
+ if ( wsLanguage == L"ar" )
+ {
+ usPrimaryLang = LANG_ARABIC; // Arabic 01
+
+ if ( wsCountry == L"SA" )
+ usSubLang = SUBLANG_ARABIC_SAUDI_ARABIA; // Arabic (Saudi Arabia)
+ else if ( wsCountry == L"IQ" )
+ usSubLang = SUBLANG_ARABIC_IRAQ; // Arabic (Iraq)
+ else if ( wsCountry == L"EG" )
+ usSubLang = SUBLANG_ARABIC_EGYPT; // Arabic (Egypt)
+ else if ( wsCountry == L"LY" )
+ usSubLang = SUBLANG_ARABIC_LIBYA; // Arabic (Libya)
+ else if ( wsCountry == L"DZ" )
+ usSubLang = SUBLANG_ARABIC_ALGERIA; // Arabic (Algeria)
+ else if ( wsCountry == L"MA" )
+ usSubLang = SUBLANG_ARABIC_MOROCCO; // Arabic (Morocco)
+ else if ( wsCountry == L"TN" )
+ usSubLang = SUBLANG_ARABIC_TUNISIA; // Arabic (Tunisia)
+ else if ( wsCountry == L"OM" )
+ usSubLang = SUBLANG_ARABIC_OMAN; // Arabic (Oman)
+ else if ( wsCountry == L"YE" )
+ usSubLang = SUBLANG_ARABIC_YEMEN; // Arabic (Yemen)
+ else if ( wsCountry == L"SY" )
+ usSubLang = SUBLANG_ARABIC_SYRIA; // Arabic (Syria)
+ else if ( wsCountry == L"JO" )
+ usSubLang = SUBLANG_ARABIC_JORDAN; // Arabic (Jordan)
+ else if ( wsCountry == L"LB" )
+ usSubLang = SUBLANG_ARABIC_LEBANON; // Arabic (Lebanon)
+ else if ( wsCountry == L"KW" )
+ usSubLang = SUBLANG_ARABIC_KUWAIT; // Arabic (Kuwait)
+ else if ( wsCountry == L"AE" )
+ usSubLang = SUBLANG_ARABIC_UAE; // Arabic (U.A.E.)
+ else if ( wsCountry == L"BH" )
+ usSubLang = SUBLANG_ARABIC_BAHRAIN; // Arabic (Bahrain)
+ else if ( wsCountry == L"QA" )
+ usSubLang = SUBLANG_ARABIC_QATAR; // Arabic (Qatar)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"bg" )
+ usPrimaryLang = LANG_BULGARIAN; //Bulgarian 02
+ else if ( wsLanguage == L"ca" )
+ usPrimaryLang = LANG_CATALAN; //Catalan 03
+ else if ( wsLanguage == L"zh" )
+ {
+ usPrimaryLang = LANG_CHINESE; //Chinese
+ if ( wsCountry == L"TW" )
+ usSubLang = SUBLANG_CHINESE_TRADITIONAL; // Chinese (Traditional)
+ else if ( wsCountry == L"CN" )
+ usSubLang = SUBLANG_CHINESE_SIMPLIFIED; // Chinese (Simplified)
+ else if ( wsCountry == L"HK" )
+ usSubLang = SUBLANG_CHINESE_HONGKONG; // Chinese (Hong Kong SAR, PRC)
+ else if ( wsCountry == L"SG" )
+ usSubLang = SUBLANG_CHINESE_SINGAPORE; // Chinese (Singapore)
+ else if ( wsCountry == L"MO" )
+ usSubLang = SUBLANG_CHINESE_MACAU; // Chinese (Macau SAR)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"cs" )
+ usPrimaryLang = LANG_CZECH; //Czech
+ else if ( wsLanguage == L"da" )
+ usPrimaryLang = LANG_DANISH; //Danish
+ else if ( wsLanguage == L"de" )
+ {
+ usPrimaryLang = LANG_GERMAN; //German
+ if ( wsCountry == L"DE" )
+ usSubLang = SUBLANG_GERMAN; // German
+ else if ( wsCountry == L"CH" )
+ usSubLang = SUBLANG_GERMAN_SWISS; // German (Swiss)
+ else if ( wsCountry == L"AT" )
+ usSubLang = SUBLANG_GERMAN_AUSTRIAN; // German (Austrian)
+ else if ( wsCountry == L"LU" )
+ usSubLang = SUBLANG_GERMAN_LUXEMBOURG; // German (Luxembourg)
+ else if ( wsCountry == L"LI" )
+ usSubLang = SUBLANG_GERMAN_LIECHTENSTEIN; // German (Liechtenstein)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"el" )
+ usPrimaryLang = LANG_GREEK; //Greek
+ else if ( wsLanguage == L"en" )
+ {
+ usPrimaryLang = LANG_ENGLISH; //English
+ if ( wsCountry == L"US" )
+ usSubLang = SUBLANG_ENGLISH_US; // English (US)
+ else if ( wsCountry == L"GB" )
+ usSubLang = SUBLANG_ENGLISH_UK; // English (UK)
+ else if ( wsCountry == L"AU" )
+ usSubLang = SUBLANG_ENGLISH_AUS; // English (Australian)
+ else if ( wsCountry == L"CA" )
+ usSubLang = SUBLANG_ENGLISH_CAN; // English (Canadian)
+ else if ( wsCountry == L"NZ" )
+ usSubLang = SUBLANG_ENGLISH_NZ; // English (New Zealand)
+ else if ( wsCountry == L"IE" )
+ usSubLang = SUBLANG_ENGLISH_EIRE; // English (Ireland)
+ else if ( wsCountry == L"ZA" )
+ usSubLang = SUBLANG_ENGLISH_SOUTH_AFRICA; // English (South Africa)
+ else if ( wsCountry == L"JM" )
+ usSubLang = SUBLANG_ENGLISH_JAMAICA; // English (Jamaica)
+ else if ( wsCountry == L"GD" )
+ usSubLang = SUBLANG_ENGLISH_CARIBBEAN; // English (Caribbean) Grenada
+ else if ( wsCountry == L"BZ" )
+ usSubLang = SUBLANG_ENGLISH_BELIZE; // English (Belize)
+ else if ( wsCountry == L"TT" )
+ usSubLang = SUBLANG_ENGLISH_TRINIDAD; // English (Trinidad)
+ else if ( wsCountry == L"ZW" )
+ usSubLang = SUBLANG_ENGLISH_ZIMBABWE; // English (Zimbabwe)
+ else if ( wsCountry == L"PH" )
+ usSubLang = SUBLANG_ENGLISH_PHILIPPINES; // English (Philippines)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"es" )
+ {
+ usPrimaryLang = LANG_SPANISH; //Spanish
+ if ( wsCountry == L"MX" )
+ usSubLang = SUBLANG_SPANISH_MEXICAN; // Spanish (Mexican)
+ else if ( wsCountry == L"ES" )
+ usSubLang = SUBLANG_SPANISH_MODERN; // Spanish (Spain)
+ else if ( wsCountry == L"GT" )
+ usSubLang = SUBLANG_SPANISH_GUATEMALA; // Spanish (Guatemala)
+ else if ( wsCountry == L"CR" )
+ usSubLang = SUBLANG_SPANISH_COSTA_RICA; // Spanish (Costa Rica)
+ else if ( wsCountry == L"PA" )
+ usSubLang = SUBLANG_SPANISH_PANAMA; // Spanish (Panama)
+ else if ( wsCountry == L"DO" )
+ usSubLang = SUBLANG_SPANISH_DOMINICAN_REPUBLIC; // Spanish (Dominican Republic)
+ else if ( wsCountry == L"VE" )
+ usSubLang = SUBLANG_SPANISH_VENEZUELA; // Spanish (Venezuela)
+ else if ( wsCountry == L"CO" )
+ usSubLang = SUBLANG_SPANISH_COLOMBIA; // Spanish (Colombia)
+ else if ( wsCountry == L"PE" )
+ usSubLang = SUBLANG_SPANISH_PERU; // Spanish (Peru)
+ else if ( wsCountry == L"AR" )
+ usSubLang = SUBLANG_SPANISH_ARGENTINA; // Spanish (Argentina)
+ else if ( wsCountry == L"EC" )
+ usSubLang = SUBLANG_SPANISH_ECUADOR; // Spanish (Ecuador)
+ else if ( wsCountry == L"CL" )
+ usSubLang = SUBLANG_SPANISH_CHILE; // Spanish (Chile)
+ else if ( wsCountry == L"UY" )
+ usSubLang = SUBLANG_SPANISH_URUGUAY; // Spanish (Uruguay)
+ else if ( wsCountry == L"PY" )
+ usSubLang = SUBLANG_SPANISH_PARAGUAY; // Spanish (Paraguay)
+ else if ( wsCountry == L"BO" )
+ usSubLang = SUBLANG_SPANISH_BOLIVIA; // Spanish (Bolivia)
+ else if ( wsCountry == L"SV" )
+ usSubLang = SUBLANG_SPANISH_EL_SALVADOR; // Spanish (El Salvador)
+ else if ( wsCountry == L"HN" )
+ usSubLang = SUBLANG_SPANISH_HONDURAS; // Spanish (Honduras)
+ else if ( wsCountry == L"NI" )
+ usSubLang = SUBLANG_SPANISH_NICARAGUA; // Spanish (Nicaragua)
+ else if ( wsCountry == L"PR" )
+ usSubLang = SUBLANG_SPANISH_PUERTO_RICO; // Spanish (Puerto Rico)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"fi" )
+ usPrimaryLang = LANG_FINNISH; //Finnish
+ else if ( wsLanguage == L"fr" )
+ {
+ usPrimaryLang = LANG_FRENCH; //French
+ if ( wsCountry == L"FR" )
+ usSubLang = SUBLANG_FRENCH; // French
+ else if ( wsCountry == L"BE" )
+ usSubLang = SUBLANG_FRENCH_BELGIAN; // French (Belgian)
+ else if ( wsCountry == L"CA" )
+ usSubLang = SUBLANG_FRENCH_CANADIAN; // French (Canadian)
+ else if ( wsCountry == L"CH" )
+ usSubLang = SUBLANG_FRENCH_SWISS; // French (Swiss)
+ else if ( wsCountry == L"LU" )
+ usSubLang = SUBLANG_FRENCH_LUXEMBOURG; // French (Luxembourg)
+ else if ( wsCountry == L"MC" )
+ usSubLang = SUBLANG_FRENCH_MONACO; // French (Monaco)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"iw" )
+ usPrimaryLang = LANG_HEBREW; //Hebrew
+ else if ( wsLanguage == L"hu" )
+ usPrimaryLang = LANG_HUNGARIAN; //Hungarian
+ else if ( wsLanguage == L"is" )
+ usPrimaryLang = LANG_ICELANDIC; //Icelandic
+ else if ( wsLanguage == L"it" )
+ {
+ usPrimaryLang = LANG_ITALIAN; //Italian
+ if ( wsCountry == L"IT" )
+ usSubLang = SUBLANG_ITALIAN; // Italian
+ else if ( wsCountry == L"CH" )
+ usSubLang = SUBLANG_ITALIAN_SWISS; // Italian (Swiss)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"ja" )
+ usPrimaryLang = LANG_JAPANESE; //Japanese
+ else if ( wsLanguage == L"ko" )
+ {
+ usPrimaryLang = LANG_KOREAN; //Korean
+ if ( wsCountry == L"KR" )
+ usSubLang = SUBLANG_KOREAN; // Korean
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"nl" )
+ {
+ usPrimaryLang = LANG_DUTCH; //Dutch
+ if ( wsCountry == L"NL" )
+ usSubLang = SUBLANG_DUTCH; // Dutch
+ else if ( wsCountry == L"BE" )
+ usSubLang = SUBLANG_DUTCH_BELGIAN; // Dutch (Belgian)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"no" )
+ {
+ usPrimaryLang = LANG_NORWEGIAN; //Norwegian
+ if ( wsCountry == L"NO" )
+ usSubLang = SUBLANG_NORWEGIAN_BOKMAL; // Norwegian (Bokmal)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"pl" )
+ usPrimaryLang = LANG_POLISH; //Polish
+ else if ( wsLanguage == L"pt" )
+ {
+ usPrimaryLang = LANG_PORTUGUESE; //Portuguese
+ if ( wsCountry == L"BR" )
+ usSubLang = SUBLANG_PORTUGUESE_BRAZILIAN; // Portuguese (Brazil)
+ else if ( wsCountry == L"PT" )
+ usSubLang = SUBLANG_PORTUGUESE; // Portuguese (Portugal)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"ro" )
+ usPrimaryLang = LANG_ROMANIAN; //Romanian
+ else if ( wsLanguage == L"ru" )
+ usPrimaryLang = LANG_RUSSIAN; //Russian
+ else if ( wsLanguage == L"hr" )
+ usPrimaryLang = LANG_CROATIAN; //Croatian
+ else if ( wsLanguage == L"sr" )
+ {
+ usPrimaryLang = LANG_SERBIAN; //Serbian
+ if ( wsCountry == L"VA" )
+ usSubLang = SUBLANG_SERBIAN_LATIN; // Serbian (Latin)
+ else if ( wsCountry == L"HR" )
+ usSubLang = SUBLANG_SERBIAN_CYRILLIC; // Serbian (Cyrillic)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"sk" )
+ usPrimaryLang = LANG_SLOVAK; //Slovak
+ else if ( wsLanguage == L"sq" )
+ usPrimaryLang = LANG_ALBANIAN; //Albanian
+ else if ( wsLanguage == L"sv" )
+ {
+ usPrimaryLang = LANG_SWEDISH; //Swedish
+ if ( wsCountry == L"SE" )
+ usSubLang = SUBLANG_SWEDISH; // Swedish
+ else if ( wsCountry == L"FI" )
+ usSubLang = SUBLANG_SWEDISH_FINLAND; // Swedish (Finland)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"th" )
+ usPrimaryLang = LANG_THAI; //Thai
+ else if ( wsLanguage == L"tr" )
+ usPrimaryLang = LANG_TURKISH; //Turkish
+ else if ( wsLanguage == L"ur" )
+ {
+ usPrimaryLang = LANG_URDU; //Urdu
+ if ( wsCountry == L"PK" )
+ usSubLang = SUBLANG_URDU_PAKISTAN; // Urdu (Pakistan)
+ else if ( wsCountry == L"IN" )
+ usSubLang = SUBLANG_URDU_INDIA; // Urdu (India)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"in" )
+ usPrimaryLang = LANG_INDONESIAN; //Indonesian
+ else if ( wsLanguage == L"uk" )
+ usPrimaryLang = LANG_UKRAINIAN; //Ukrainian
+ else if ( wsLanguage == L"be" )
+ usPrimaryLang = LANG_BELARUSIAN; //Belarusian
+ else if ( wsLanguage == L"sl" )
+ usPrimaryLang = LANG_SLOVENIAN; //Slovenian
+ else if ( wsLanguage == L"et" )
+ usPrimaryLang = LANG_ESTONIAN; //Estonian
+ else if ( wsLanguage == L"lv" )
+ usPrimaryLang = LANG_LATVIAN; //Latvian
+ else if ( wsLanguage == L"lt" )
+ {
+ usPrimaryLang = LANG_LITHUANIAN; //Lithuanian
+ if ( wsCountry == L"LT" )
+ usSubLang = SUBLANG_LITHUANIAN; // Lithuanian
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"fa" )
+ usPrimaryLang = LANG_FARSI; //Farsi
+ else if ( wsLanguage == L"vi" )
+ usPrimaryLang = LANG_VIETNAMESE; //Vietnamese
+ else if ( wsLanguage == L"hy" )
+ usPrimaryLang = LANG_ARMENIAN; //Armenian
+ else if ( wsLanguage == L"az" )
+ usPrimaryLang = LANG_AZERI; //Azeri
+ else if ( wsLanguage == L"eu" )
+ usPrimaryLang = LANG_BASQUE; //Basque
+ else if ( wsLanguage == L"mk" )
+ usPrimaryLang = LANG_MACEDONIAN; //FYRO Macedonian
+ else if ( wsLanguage == L"af" )
+ usPrimaryLang = LANG_AFRIKAANS; //Afrikaans
+ else if ( wsLanguage == L"ka" )
+ usPrimaryLang = LANG_GEORGIAN; //Georgian
+ else if ( wsLanguage == L"fo" )
+ usPrimaryLang = LANG_FAEROESE; //Faeroese
+ else if ( wsLanguage == L"hi" )
+ usPrimaryLang = LANG_HINDI; //Hindi
+ else if ( wsLanguage == L"ms" )
+ {
+ usPrimaryLang = LANG_MALAY; //Malay
+ if ( wsCountry == L"MY" )
+ usSubLang = SUBLANG_MALAY_MALAYSIA; // Malay (Malaysia)
+ else if ( wsCountry == L"BN" )
+ usSubLang = SUBLANG_MALAY_BRUNEI_DARUSSALAM; // Malay (Brunei Darassalam)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"kk" )
+ usPrimaryLang = LANG_KAZAK; //Kazakh
+ else if ( wsLanguage == L"ky" )
+ usPrimaryLang = LANG_KYRGYZ; //Kyrgyz
+ else if ( wsLanguage == L"sw" )
+ usPrimaryLang = LANG_SWAHILI; //Swahili
+ else if ( wsLanguage == L"uz" )
+ {
+ usPrimaryLang = LANG_UZBEK; //Uzbek
+ if ( wsCountry == L"UZ" )
+ usSubLang = SUBLANG_UZBEK_LATIN; // Uzbek (Latin)
+ else if ( wsCountry == L"DE" )
+ usSubLang = SUBLANG_UZBEK_CYRILLIC; // Uzbek (Cyrillic)
+ else
+ usSubLang = SUBLANG_DEFAULT; //default sub language
+ }
+ else if ( wsLanguage == L"tt" )
+ usPrimaryLang = LANG_TATAR; //Tatar
+ else if ( wsLanguage == L"bn" )
+ usPrimaryLang = LANG_BENGALI; //Not supported.
+ else if ( wsLanguage == L"pa" )
+ usPrimaryLang = LANG_PUNJABI; //Punjabi
+ else if ( wsLanguage == L"gu" )
+ usPrimaryLang = LANG_GUJARATI; //Gujarati
+ else if ( wsLanguage == L"or" )
+ usPrimaryLang = LANG_ORIYA; //Not supported.
+ else if ( wsLanguage == L"ta" )
+ usPrimaryLang = LANG_TAMIL; //Tamil
+ else if ( wsLanguage == L"te" )
+ usPrimaryLang = LANG_TELUGU; //Telugu
+ else if ( wsLanguage == L"kn" )
+ usPrimaryLang = LANG_KANNADA; //Kannada
+ else if ( wsLanguage == L"ml" )
+ usPrimaryLang = LANG_MALAYALAM; //Not supported.
+ else if ( wsLanguage == L"as" )
+ usPrimaryLang = LANG_ASSAMESE; //Not supported.
+ else if ( wsLanguage == L"mr" )
+ usPrimaryLang = LANG_MARATHI; //Marathi
+ else if ( wsLanguage == L"sa" )
+ usPrimaryLang = LANG_SANSKRIT; //Sanskrit
+ else if ( wsLanguage == L"mn" )
+ usPrimaryLang = LANG_MONGOLIAN; //Mongolian
+ else if ( wsLanguage == L"gl" )
+ usPrimaryLang = LANG_GALICIAN; //Galician
+ else if ( wsLanguage == L"sd" )
+ usPrimaryLang = LANG_SINDHI; //Not supported.
+ else if ( wsLanguage == L"ks" )
+ usPrimaryLang = LANG_KASHMIRI; //Not supported.
+ else if ( wsLanguage == L"ne" )
+ usPrimaryLang = LANG_NEPALI; //Not supported.
+ else
+ return GetSystemDefaultLCID(); //System Default Locale
+
+ return MAKELCID( MAKELANGID( usPrimaryLang, usSubLang ), SORT_DEFAULT );
+}
+
+// The function is defined in the static library, and thus its address is local to current module
+HMODULE GetCurrentModuleHandle()
+{
+ HMODULE h{};
+
+ if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
+ | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<LPCWSTR>(&GetCurrentModuleHandle), &h)
+ == 0)
+ {
+ const DWORD dwError = GetLastError();
+ OutputDebugStringFormatW(
+ L"GetCurrentModuleHandle: GetModuleHandleExW failed, error is 0x%X", dwError);
+ }
+ return h;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */