From d59b2d9dee482a448f32d2e225114ba66e88ebc4 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 25 Sep 2020 23:46:52 +0200 Subject: [PATCH] + fix: grepWinNP3: wide char path names for language files + fix: clone full .ini-file path for forked new instance --- grepWinNP3/sktoolslib_mod/Language.cpp | 13 +++++++++---- grepWinNP3/src/SearchDlg.cpp | 11 +++-------- grepWinNP3/src/Settings.cpp | 9 +++++++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/grepWinNP3/sktoolslib_mod/Language.cpp b/grepWinNP3/sktoolslib_mod/Language.cpp index cc7320b64..3a79f0c96 100644 --- a/grepWinNP3/sktoolslib_mod/Language.cpp +++ b/grepWinNP3/sktoolslib_mod/Language.cpp @@ -1,4 +1,4 @@ -// sktoolslib - common files for SK tools +// sktoolslib - common files for SK tools // Copyright (C) 2013, 2017-2018, 2020 - Stefan Kueng @@ -40,9 +40,9 @@ bool CLanguage::LoadFile(const std::wstring& path) if (_wcsicmp(lastLangPath.c_str(), path.c_str())) { std::map langmap2; - for (auto it = langmap.cbegin(); it != langmap.cend(); ++it) + for (const auto& item : langmap) { - langmap2[it->second] = it->first; + langmap2[item.second] = item.first; } langmap = langmap2; } @@ -52,11 +52,16 @@ bool CLanguage::LoadFile(const std::wstring& path) lastLangPath = path; +#ifdef _WIN32 + // The wchar_t version is a compiler extension, it works on Microsoft C++ compiler + const wchar_t* const filepath = path.c_str(); +#else // since stream classes still expect the filepath in char and not wchar_t // we need to convert the filepath to multibyte first char filepath[MAX_PATH + 1]; SecureZeroMemory(filepath, sizeof(filepath)); WideCharToMultiByte(CP_ACP, 0, path.c_str(), -1, filepath, _countof(filepath) - 1, nullptr, nullptr); +#endif std::wifstream File; File.imbue(std::locale(std::locale(), new utf8_conversion())); @@ -72,7 +77,7 @@ bool CLanguage::LoadFile(const std::wstring& path) { return false; } - auto line = std::make_unique(2 * MAX_STRING_LENGTH); + auto line = std::make_unique(2 * MAX_STRING_LENGTH); std::vector entry; do { diff --git a/grepWinNP3/src/SearchDlg.cpp b/grepWinNP3/src/SearchDlg.cpp index 49f50f6b9..91b319dce 100644 --- a/grepWinNP3/src/SearchDlg.cpp +++ b/grepWinNP3/src/SearchDlg.cpp @@ -4136,19 +4136,14 @@ bool CSearchDlg::IsVersionNewer(const std::wstring& sVer) bool CSearchDlg::CloneWindow() { - if (!SaveSettings()) - return false; - if (bPortable) - { - g_iniFile.SaveFile(g_iniPath.c_str()); - } + if (!SaveSettings()) { return false; } + if (bPortable) { g_iniFile.SaveFile(g_iniPath.c_str()); } auto const dir = CPathUtils::GetModuleDir(); auto const file = CPathUtils::GetFileName(CPathUtils::GetModulePath()); - auto const inifn = CPathUtils::GetFileName(g_iniPath); std::wstring arguments; - arguments += CStringUtils::Format(L" /inipath:\"%s\"", inifn.c_str()); + arguments += CStringUtils::Format(L" /inipath:\"%s\"", g_iniPath.c_str()); arguments += CStringUtils::Format(L" /searchpath:\"%s\"", m_searchpath.c_str()); arguments += CStringUtils::Format(L" /searchfor:\"%s\"", m_searchString.c_str()); arguments += CStringUtils::Format(L" /replacewith:\"%s\"", m_replaceString.c_str()); diff --git a/grepWinNP3/src/Settings.cpp b/grepWinNP3/src/Settings.cpp index bbec02ac3..e712e9453 100644 --- a/grepWinNP3/src/Settings.cpp +++ b/grepWinNP3/src/Settings.cpp @@ -142,8 +142,8 @@ LRESULT CSettingsDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa std::wstring path = moduledir; bool bRecurse = false; bool bIsDirectory = false; - CRegStdString regLang(L"Software\\grepWinNP3\\languagefile"); - std::wstring setLang = regLang; + + std::wstring setLang; if (bPortable) { @@ -174,6 +174,11 @@ LRESULT CSettingsDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa setLang = absLngPath; path = moduledir; } + else + { + CRegStdString regLang(L"Software\\grepWinNP3\\languagefile"); + setLang = regLang; + } // ordered map of language files std::wstring sPath;