diff --git a/grepWinNP3/src/SearchDlg.cpp b/grepWinNP3/src/SearchDlg.cpp index b71219839..5bb00c8fa 100644 --- a/grepWinNP3/src/SearchDlg.cpp +++ b/grepWinNP3/src/SearchDlg.cpp @@ -113,7 +113,7 @@ CSearchDlg::CSearchDlg(HWND hParent) , m_bUseRegex(false) , m_bUseRegexForPaths(false) , m_bAllSize(false) - , m_lSize(0) + , m_lSize(2000 << 10) , m_sizeCmp(0) , m_bIncludeSystem(false) , m_bIncludeSystemC(false) @@ -136,7 +136,7 @@ CSearchDlg::CSearchDlg(HWND hParent) , m_bCaseSensitiveC(false) , m_bDotMatchesNewline(false) , m_bDotMatchesNewlineC(false) - //, m_bNotSearch(false) + , m_bNotSearch(false) , m_bCaptureSearch(false) , m_bSizeC(false) , m_endDialog(false) @@ -361,16 +361,14 @@ LRESULT CSearchDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara } wchar_t buf[MAX_PATH] = {0}; - if (m_bSizeC && (m_lSize != static_cast(0))) + if (m_bSizeC && (m_lSize != MaxFileSize())) { - swprintf_s(buf, _countof(buf), L"%I64u", m_lSize); + swprintf_s(buf, _countof(buf), L"%I64u", m_lSize >> 10); SetDlgItemText(hwndDlg, IDC_SIZEEDIT, buf); } else { - uint64_t s = _wtoll(std::wstring(m_regSize).c_str()); - if (bPortable) - s = g_iniFile.GetLongValue(L"global", L"size", 2000); + uint64_t const s = bPortable ? g_iniFile.GetLongValue(L"global", L"Size", 2000) : _wtoll(std::wstring(m_regSize).c_str()); swprintf_s(buf, _countof(buf), L"%I64u", s); SetDlgItemText(hwndDlg, IDC_SIZEEDIT, buf); } @@ -2292,7 +2290,7 @@ void CSearchDlg::DoListNotify(LPNMITEMACTIVATE lpNMItemActivate) std::wstring matchString = inf.filePath + L"\n"; std::wstring sFormat = TranslatedString(hResource, IDS_CONTEXTLINE); - for (size_t i = 0; i < min(inf.matchLines.size(), 5); ++i) + for (size_t i = 0; i < std::min(inf.matchLines.size(), 5); ++i) { std::wstring matchText = inf.matchLines[i]; CStringUtils::trim(matchText); @@ -2830,7 +2828,6 @@ bool CSearchDlg::SaveSettings() m_bAllSize = (IsDlgButtonChecked(*this, IDC_ALLSIZERADIO) == BST_CHECKED); - m_lSize = 0; m_sizeCmp = 0; if (!m_bAllSize) { @@ -2896,9 +2893,9 @@ bool CSearchDlg::SaveSettings() m_regAllSize = static_cast(m_bAllSize); if (bPortable) - g_iniFile.SetValue(L"global", L"Size", CStringUtils::Format(L"%I64u", m_lSize / 1024).c_str()); + g_iniFile.SetValue(L"global", L"Size", CStringUtils::Format(L"%I64u", m_lSize >> 10).c_str()); else - m_regSize = CStringUtils::Format(L"%I64u", m_lSize / 1024).c_str(); + m_regSize = CStringUtils::Format(L"%I64u", m_lSize >> 10).c_str(); if (bPortable) g_iniFile.SetValue(L"global", L"SizeCombo", CStringUtils::Format(L"%d", m_sizeCmp).c_str()); @@ -3077,7 +3074,7 @@ DWORD CSearchDlg::SearchThread() auto pathBuf = std::make_unique(MAX_PATH_NEW); DWORD const nMaxNumOfWorker = std::thread::hardware_concurrency() << 2; - DWORD const nOfWorker = max(min(bPortable ? g_iniFile.GetLongValue(L"global", L"MaxNumOfWorker", nMaxNumOfWorker >> 1) : + DWORD const nOfWorker = std::max(std::min(bPortable ? g_iniFile.GetLongValue(L"global", L"MaxNumOfWorker", nMaxNumOfWorker >> 1) : static_cast(CRegStdDWORD(L"Software\\grepWinNP3\\MaxNumOfWorker", nMaxNumOfWorker >> 1)), nMaxNumOfWorker), 1); s_SearchThreadMap.clear(); @@ -4204,7 +4201,7 @@ void CSearchDlg::AutoSizeAllColumns() Header_GetItem(headerCtrl, col, &hdi); int cx = ListView_GetStringWidth(hListControl, hdi.pszText) + 20; // 20 pixels for col separator and margin - int inc = max(1, nItemCount / 1000); + int inc = std::max(1, nItemCount / 1000); for (int index = 0; index < nItemCount; index = index + inc) { // get the width of the string and add 14 pixels for the column separator and margins diff --git a/grepWinNP3/src/SearchDlg.h b/grepWinNP3/src/SearchDlg.h index 3b4c1a877..a9c8d3d6b 100644 --- a/grepWinNP3/src/SearchDlg.h +++ b/grepWinNP3/src/SearchDlg.h @@ -30,10 +30,18 @@ #include #include #include +#include #ifdef NP3_ALLOW_UPDATE #include #endif +#ifdef max +# undef max +#endif +#ifdef min +# undef min +#endif + #include using namespace Microsoft::WRL; @@ -49,6 +57,12 @@ using namespace Microsoft::WRL; #define ALPHA_OPAQUE (255) + +static constexpr uint64_t MaxFileSize() +{ + return std::numeric_limits::max(); +} + enum class ExecuteAction { None, @@ -111,7 +125,7 @@ public: inline void SetWholeWords(bool bSet) { m_bWholeWordsC = true; m_bWholeWords = bSet; } inline void SetUTF8(bool bSet) { m_bUTF8C = true; m_bUTF8 = bSet; m_bForceBinary = false; } inline void SetBinary(bool bSet) { m_bUTF8C = true; m_bForceBinary = bSet; m_bUTF8 = false; } - inline void SetSize(uint64_t size, int cmp) { m_bSizeC = true; m_lSize = size; m_sizeCmp = cmp; m_bAllSize = (size == (uint64_t)0); } + inline void SetSize(uint64_t size, int cmp) { m_bSizeC = true; m_lSize = size; m_sizeCmp = cmp; m_bAllSize = (size == MaxFileSize()); } inline void SetIncludeSystem(bool bSet) { m_bIncludeSystemC = true; m_bIncludeSystem = bSet; } inline void SetIncludeHidden(bool bSet) { m_bIncludeHiddenC = true; m_bIncludeHidden = bSet; } inline void SetIncludeSubfolders(bool bSet) { m_bIncludeSubfoldersC = true; m_bIncludeSubfolders = bSet; } diff --git a/src/Dialogs.c b/src/Dialogs.c index a4533903e..63b2ead0b 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -4630,7 +4630,7 @@ grepWin_t; static grepWin_t grepWinIniSettings[13] = { { L"onlyone", L"1" }, { L"AllSize", L"1" }, - { L"Size", L"2000" }, + { L"Size", L"2000" }, { L"CaseSensitive", L"0" }, { L"CreateBackup", L"1" }, { L"DateLimit", L"0" },