From f6e313f48a92fc2c5b9db3689475ce60677d906a Mon Sep 17 00:00:00 2001 From: RaiKoHoff Date: Mon, 24 Aug 2020 14:14:32 +0200 Subject: [PATCH] + chg: grepWinNP3: Export search result list (NP3 enhancements) --- grepWinNP3/src/SearchDlg.cpp | 65 ++++++++++++++++++++++++++--------- grepWinNP3/src/last/version.h | 12 +++---- src/Dialogs.c | 28 ++++++++++----- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/grepWinNP3/src/SearchDlg.cpp b/grepWinNP3/src/SearchDlg.cpp index 1f236c259..662861aa0 100644 --- a/grepWinNP3/src/SearchDlg.cpp +++ b/grepWinNP3/src/SearchDlg.cpp @@ -1459,6 +1459,15 @@ LRESULT CSearchDlg::DoCommand(int id, int msg) if (FailedShowMessage(hr)) break; + COMDLG_FILTERSPEC const aFileTypes[] = { {L"Text files", L"*.txt; *.lst"}, {L"All types", L"*.*"} }; + hr = pfd->SetFileTypes(_countof(aFileTypes), aFileTypes); + if (FailedShowMessage(hr)) + break; + + hr = pfd->SetFileName(L"gw_search_results.txt"); + if (FailedShowMessage(hr)) + break; + IFileDialogCustomizePtr pfdCustomize; hr = pfd.QueryInterface(IID_PPV_ARGS(&pfdCustomize)); if (SUCCEEDED(hr)) @@ -1538,14 +1547,17 @@ LRESULT CSearchDlg::DoCommand(int id, int msg) bool needSeparator = false; if (includePaths) { - file << CUnicodeUtils::StdGetUTF8(item.filepath); + std::string fpath = CUnicodeUtils::StdGetUTF8(item.filepath); + std::transform(fpath.begin(), fpath.end(), fpath.begin(), [](char c) { return (c == '\\' ? '/' : c); }); + file << std::string("file://"); + file << fpath; needSeparator = true; } if (includeMatchLineNumbers) { if (needSeparator) file << separator; - file << CStringUtils::Format("%lld", item.matchlinesnumbers[i]); + file << CStringUtils::Format("(%lld)", item.matchlinesnumbers[i]); needSeparator = true; } if (includeMatchLineTexts) @@ -1571,19 +1583,41 @@ LRESULT CSearchDlg::DoCommand(int id, int msg) } else { - auto exportpaths = CRegStdDWORD(L"Software\\grepWin\\export_paths"); - auto exportlinenumbers = CRegStdDWORD(L"Software\\grepWin\\export_linenumbers"); - auto exportlinecontent = CRegStdDWORD(L"Software\\grepWin\\export_linecontent"); + auto exportpaths = CRegStdDWORD(L"Software\\grepWinNP3\\export_paths"); + auto exportlinenumbers = CRegStdDWORD(L"Software\\grepWinNP3\\export_linenumbers"); + auto exportlinecontent = CRegStdDWORD(L"Software\\grepWinNP3\\export_linecontent"); exportpaths = includePaths ? 1 : 0; exportlinenumbers = includeMatchLineNumbers ? 1 : 0; exportlinecontent = includeMatchLineTexts ? 1 : 0; } - SHELLEXECUTEINFO sei = {0}; - sei.cbSize = sizeof(SHELLEXECUTEINFO); - sei.lpVerb = TEXT("open"); - sei.lpFile = path.c_str(); - sei.nShow = SW_SHOWNORMAL; - ShellExecuteEx(&sei); + + // open file + std::wstring cmd = bPortable ? g_iniFile.GetValue(L"global", L"editorcmd", L"") : + (std::wstring)CRegStdString(L"Software\\grepWinNP3\\editorcmd", L""); + if (!cmd.empty()) + { + SearchReplace(cmd, L"%mode%", L"mb"); + SearchReplace(cmd, L"%pattern%", L""); + SearchReplace(cmd, L"%line%", L"0"); + SearchReplace(cmd, L"%path%", path.c_str()); + STARTUPINFO startupInfo; + PROCESS_INFORMATION processInfo; + SecureZeroMemory(&startupInfo, sizeof(startupInfo)); + startupInfo.cb = sizeof(STARTUPINFO); + SecureZeroMemory(&processInfo, sizeof(processInfo)); + CreateProcess(NULL, const_cast(cmd.c_str()), NULL, NULL, FALSE, 0, 0, NULL, &startupInfo, &processInfo); + CloseHandle(processInfo.hThread); + CloseHandle(processInfo.hProcess); + } + else + { + SHELLEXECUTEINFO sei = {0}; + sei.cbSize = sizeof(SHELLEXECUTEINFO); + sei.lpVerb = TEXT("open"); + sei.lpFile = path.c_str(); + sei.nShow = SW_SHOWNORMAL; + ShellExecuteEx(&sei); + } } } } @@ -2328,10 +2362,8 @@ void CSearchDlg::OpenFileAtListIndex(int listIndex) if (dotPos != std::wstring::npos) ext = inf.filepath.substr(dotPos); - CRegStdString regEditorCmd(L"Software\\grepWinNP3\\editorcmd"); - std::wstring cmd = regEditorCmd; - if (bPortable) - cmd = g_iniFile.GetValue(L"global", L"editorcmd", L""); + std::wstring cmd = bPortable ? g_iniFile.GetValue(L"global", L"editorcmd", L"") : + (std::wstring)CRegStdString(L"Software\\grepWinNP3\\editorcmd", L""); if (!cmd.empty()) { bool filelist = (IsDlgButtonChecked(*this, IDC_RESULTFILES) == BST_CHECKED); @@ -3333,7 +3365,8 @@ int CSearchDlg::SearchFile(std::shared_ptr sinfoPtr, const std::wst else { ProfileTimer profile((L"file load and parse: " + sinfoPtr->filepath).c_str()); - auto nNullCount = bPortable ? _wtoi(g_iniFile.GetValue(L"settings", L"nullbytes", L"0")) : int(DWORD(CRegStdDWORD(L"Software\\grepWin\\nullbytes", 0))); + auto nNullCount = bPortable ? int(g_iniFile.GetLongValue(L"settings", L"nullbytes", 0)) : + int(DWORD(CRegStdDWORD(L"Software\\grepWinNP3\\nullbytes", 0))); if (nNullCount > 0) { constexpr __int64 oneMB = 1024 * 1024; diff --git a/grepWinNP3/src/last/version.h b/grepWinNP3/src/last/version.h index 70a2004a1..80dc87e80 100644 --- a/grepWinNP3/src/last/version.h +++ b/grepWinNP3/src/last/version.h @@ -6,13 +6,13 @@ //#pragma message(__LOC__"Run the NAnt script to get proper version info") -#define FILEVER 2, 1, 3, 26 -#define PRODUCTVER 2, 1, 3, 26 -#define STRFILEVER "2.1.3.26\0" -#define STRPRODUCTVER "2.1.3.26\0" +#define FILEVER 2, 1, 3, 27 +#define PRODUCTVER 2, 1, 3, 27 +#define STRFILEVER "2.1.3.27\0" +#define STRPRODUCTVER "2.1.3.27\0" #define GREPWIN_VERMAJOR 2 #define GREPWIN_VERMINOR 1 #define GREPWIN_VERMICRO 3 -#define GREPWIN_VERBUILD 26 -#define GREPWIN_VERDATE "2020-08-17" +#define GREPWIN_VERBUILD 27 +#define GREPWIN_VERDATE "2020-08-24" diff --git a/src/Dialogs.c b/src/Dialogs.c index 96079b8e9..0eb6ba908 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -3755,12 +3755,12 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern) } if (lngIdx >= 0) { - IniSectionGetString(L"global", L"languagefile", grepWinLangResName[lngIdx].filename, tchTemp, COUNTOF(tchTemp)); - IniSectionSetString(L"global", L"languagefile", tchTemp); + IniSectionGetString(globalSection, L"languagefile", grepWinLangResName[lngIdx].filename, tchTemp, COUNTOF(tchTemp)); + IniSectionSetString(globalSection, L"languagefile", tchTemp); } else { - IniSectionGetString(L"global", L"languagefile", L"", tchTemp, COUNTOF(tchTemp)); + IniSectionGetString(globalSection, L"languagefile", L"", tchTemp, COUNTOF(tchTemp)); if (StrIsEmpty(tchTemp)) { - IniSectionDelete(L"global", L"languagefile", false); + IniSectionDelete(globalSection, L"languagefile", false); } } @@ -3768,10 +3768,22 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern) IniSectionSetString(globalSection, L"editorcmd", tchTemp); // [settings] - bool const bEscClose = IniSectionGetBool(L"settings", L"escclose", (Settings.EscFunction == 2)); - IniSectionSetBool(L"settings", L"escclose", bEscClose); - bool const bBackupInFolder = IniSectionGetBool(L"settings", L"backupinfolder", true); - IniSectionSetBool(L"settings", L"backupinfolder", bBackupInFolder); + const WCHAR *const settingsSection = L"settings"; + + bool const bEscClose = IniSectionGetBool(settingsSection, L"escclose", (Settings.EscFunction == 2)); + IniSectionSetBool(settingsSection, L"escclose", bEscClose); + bool const bBackupInFolder = IniSectionGetBool(settingsSection, L"backupinfolder", true); + IniSectionSetBool(settingsSection, L"backupinfolder", bBackupInFolder); + + // [export] + const WCHAR *const exportSection = L"export"; + bool const bExpPaths = IniSectionGetBool(exportSection, L"paths", true); + IniSectionSetBool(exportSection, L"paths", bExpPaths); + bool const bExpLnNums = IniSectionGetBool(exportSection, L"linenumbers", true); + IniSectionSetBool(exportSection, L"linenumbers", bExpLnNums); + bool const bExpContent = IniSectionGetBool(exportSection, L"linecontent", true); + IniSectionSetBool(exportSection, L"linecontent", bExpContent); + // search directory WCHAR tchSearchDir[MAX_PATH] = { L'\0' };