mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-28 21:02:59 +08:00
Merge pull request #2345 from RaiKoHoff/grepWin_Integration
Revised grepWinNP3.ini file creation
This commit is contained in:
commit
c7012d8401
@ -232,7 +232,7 @@ extern "C" bool OpenSettingsFile(bool* keepCached)
|
||||
{
|
||||
if (StrIsNotEmpty(Globals.IniFile))
|
||||
{
|
||||
CreateIniFile();
|
||||
CreateIniFile(Globals.IniFile, NULL);
|
||||
|
||||
if (!IsIniFileCached()) {
|
||||
LoadIniFileCache(Globals.IniFile);
|
||||
@ -858,33 +858,36 @@ extern "C" bool FindIniFile()
|
||||
//=============================================================================
|
||||
|
||||
|
||||
extern "C" bool TestIniFile() {
|
||||
extern "C" bool TestIniFile()
|
||||
{
|
||||
LPWSTR const pszIniFilePath = Globals.IniFile;
|
||||
size_t const pathBufCount = COUNTOF(Globals.IniFile);
|
||||
|
||||
if (StringCchCompareXI(Globals.IniFile, L"*?") == 0) {
|
||||
if (StringCchCompareXI(pszIniFilePath, L"*?") == 0) {
|
||||
StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), L"");
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), L"");
|
||||
StringCchCopy(pszIniFilePath, pathBufCount, L"");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PathIsDirectory(Globals.IniFile) || *CharPrev(Globals.IniFile, StrEnd(Globals.IniFile, COUNTOF(Globals.IniFile))) == L'\\') {
|
||||
if (PathIsDirectory(pszIniFilePath) || *CharPrev(pszIniFilePath, StrEnd(pszIniFilePath, pathBufCount)) == L'\\') {
|
||||
WCHAR wchModule[MAX_PATH] = { L'\0' };
|
||||
GetModuleFileName(NULL, wchModule, COUNTOF(wchModule));
|
||||
PathCchAppend(Globals.IniFile, COUNTOF(Globals.IniFile), PathFindFileName(wchModule));
|
||||
PathCchRenameExtension(Globals.IniFile, COUNTOF(Globals.IniFile), L".ini");
|
||||
if (!PathIsExistingFile(Globals.IniFile)) {
|
||||
StringCchCopy(PathFindFileName(Globals.IniFile), COUNTOF(Globals.IniFile), _W(SAPPNAME) L".ini");
|
||||
if (!PathIsExistingFile(Globals.IniFile)) {
|
||||
StringCchCopy(PathFindFileName(Globals.IniFile), COUNTOF(Globals.IniFile), PathFindFileName(wchModule));
|
||||
PathCchRenameExtension(Globals.IniFile, COUNTOF(Globals.IniFile), L".ini");
|
||||
PathCchAppend(pszIniFilePath, pathBufCount, PathFindFileName(wchModule));
|
||||
PathCchRenameExtension(pszIniFilePath, pathBufCount, L".ini");
|
||||
if (!PathIsExistingFile(pszIniFilePath)) {
|
||||
StringCchCopy(PathFindFileName(pszIniFilePath), pathBufCount, _W(SAPPNAME) L".ini");
|
||||
if (!PathIsExistingFile(pszIniFilePath)) {
|
||||
StringCchCopy(PathFindFileName(pszIniFilePath), pathBufCount, PathFindFileName(wchModule));
|
||||
PathCchRenameExtension(pszIniFilePath, pathBufCount, L".ini");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NormalizePathEx(Globals.IniFile, COUNTOF(Globals.IniFile), true, false);
|
||||
NormalizePathEx(pszIniFilePath, pathBufCount, true, false);
|
||||
|
||||
if (!PathFileExists(Globals.IniFile) || PathIsDirectory(Globals.IniFile)) {
|
||||
StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), Globals.IniFile);
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), L"");
|
||||
if (!PathFileExists(pszIniFilePath) || PathIsDirectory(pszIniFilePath)) {
|
||||
StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), pszIniFilePath);
|
||||
StringCchCopy(pszIniFilePath, pathBufCount, L"");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -893,24 +896,24 @@ extern "C" bool TestIniFile() {
|
||||
//=============================================================================
|
||||
|
||||
|
||||
extern "C" bool CreateIniFile()
|
||||
extern "C" bool CreateIniFile(LPCWSTR pszIniFilePath, DWORD* pdwFileSize_out)
|
||||
{
|
||||
bool result = false;
|
||||
if (StrIsNotEmpty(Globals.IniFile))
|
||||
if (StrIsNotEmpty(pszIniFilePath))
|
||||
{
|
||||
WCHAR* pwchTail = StrRChrW(Globals.IniFile, NULL, L'\\');
|
||||
WCHAR* pwchTail = StrRChrW(pszIniFilePath, NULL, L'\\');
|
||||
|
||||
if (pwchTail) {
|
||||
*pwchTail = 0;
|
||||
SHCreateDirectoryEx(NULL, Globals.IniFile, NULL);
|
||||
*pwchTail = L'\0';
|
||||
SHCreateDirectoryEx(NULL, pszIniFilePath, NULL);
|
||||
*pwchTail = L'\\';
|
||||
}
|
||||
|
||||
DWORD dwFileSize = 0UL;
|
||||
|
||||
if (!PathIsExistingFile(Globals.IniFile))
|
||||
if (!PathIsExistingFile(pszIniFilePath))
|
||||
{
|
||||
HANDLE hFile = CreateFile(Globals.IniFile,
|
||||
HANDLE hFile = CreateFile(pszIniFilePath,
|
||||
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
|
||||
@ -920,12 +923,15 @@ extern "C" bool CreateIniFile()
|
||||
else {
|
||||
wchar_t msg[MAX_PATH + 128] = { 0 };
|
||||
StringCchPrintf(msg, ARRAYSIZE(msg),
|
||||
L"CreateIniFile(%s): FAILD TO CREATE INITIAL INI FILE!", Globals.IniFile);
|
||||
L"CreateIniFile(%s): FAILD TO CREATE INITIAL INI FILE!", pszIniFilePath);
|
||||
MsgBoxLastError(msg, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
HANDLE hFile = CreateFile(Globals.IniFile,
|
||||
else
|
||||
{
|
||||
SetFileAttributes(pszIniFilePath, FILE_ATTRIBUTE_NORMAL);
|
||||
|
||||
HANDLE hFile = CreateFile(pszIniFilePath,
|
||||
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
|
||||
@ -937,21 +943,20 @@ extern "C" bool CreateIniFile()
|
||||
else {
|
||||
wchar_t msg[MAX_PATH + 128] = { 0 };
|
||||
StringCchPrintf(msg, ARRAYSIZE(msg),
|
||||
L"CreateIniFile(%s): FAILED TO GET FILESIZE!", Globals.IniFile);
|
||||
L"CreateIniFile(%s): FAILED TO GET FILESIZE!", pszIniFilePath);
|
||||
MsgBoxLastError(msg, 0);
|
||||
dwFileSize = INVALID_FILE_SIZE;
|
||||
}
|
||||
}
|
||||
if (pdwFileSize_out) { *pdwFileSize_out = dwFileSize; }
|
||||
|
||||
if (dwFileSize == 0UL) {
|
||||
result = IniFileSetString(Globals.IniFile, _W(SAPPNAME), NULL, NULL);
|
||||
Globals.bIniFileFromScratch = true;
|
||||
// Set at least Application Name Section
|
||||
result = IniFileSetString(pszIniFilePath, _W(SAPPNAME), NULL, NULL);
|
||||
}
|
||||
else {
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ extern "C" {
|
||||
|
||||
bool FindIniFile();
|
||||
bool TestIniFile();
|
||||
bool CreateIniFile();
|
||||
bool CreateIniFile(LPCWSTR pszIniFilePath, DWORD* pdwFileSize_out);
|
||||
void LoadSettings();
|
||||
bool SaveWindowPositionSettings(bool bClearSettings);
|
||||
bool SaveAllSettings(bool bForceSaveSettings);
|
||||
|
||||
@ -3521,7 +3521,7 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
|
||||
GetModuleFileName(NULL, tchNotepad3Path, COUNTOF(tchNotepad3Path));
|
||||
PathCanonicalizeEx(tchNotepad3Path, COUNTOF(tchNotepad3Path));
|
||||
|
||||
// grepWin executable
|
||||
// find grepWin executable (side-by-side .ini file)
|
||||
if (StrIsNotEmpty(Settings2.GrepWinPath)) {
|
||||
ExtractFirstArgument(Settings2.GrepWinPath, tchExeFile, tchOptions, COUNTOF(tchExeFile));
|
||||
ExpandEnvironmentStringsEx(tchExeFile, COUNTOF(tchExeFile));
|
||||
@ -3554,37 +3554,28 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
|
||||
// grepWin INI-File
|
||||
const WCHAR* const gwIniFileName = L"grepWinNP3.ini";
|
||||
StringCchCopy(tchIniFilePath, COUNTOF(tchIniFilePath), StrIsNotEmpty(Globals.IniFile) ? Globals.IniFile : Globals.IniFileDefault);
|
||||
|
||||
PathRemoveFileSpec(tchIniFilePath);
|
||||
PathAppend(tchIniFilePath, gwIniFileName);
|
||||
if (PathIsRelative(tchIniFilePath)) {
|
||||
StringCchCopy(tchIniFilePath, COUNTOF(tchIniFilePath), tchGrepWinDir);
|
||||
PathAppend(tchIniFilePath, gwIniFileName);
|
||||
}
|
||||
if (!PathIsExistingFile(tchIniFilePath)) {
|
||||
HANDLE hFile = CreateFile(tchIniFilePath,
|
||||
GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
||||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile != INVALID_HANDLE_VALUE) {
|
||||
WriteFile(hFile, "\xEF\xBB\xBF", 3, NULL, NULL);
|
||||
CloseHandle(hFile); // done
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get grepWin language
|
||||
int lngIdx = -1;
|
||||
for (int i = 0; i < grepWinLang_CountOf(); ++i) {
|
||||
if (grepWinLangResName[i].lngid == Globals.iPrefLANGID) {
|
||||
lngIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (LoadIniFileCache(tchIniFilePath))
|
||||
if (CreateIniFile(tchIniFilePath, NULL) && LoadIniFileCache(tchIniFilePath))
|
||||
{
|
||||
// preserve [global] user settings from last call
|
||||
const WCHAR* const globalSection = L"global";
|
||||
|
||||
// get grepWin language
|
||||
int lngIdx = -1;
|
||||
for (int i = 0; i < grepWinLang_CountOf(); ++i) {
|
||||
if (grepWinLangResName[i].lngid == Globals.iPrefLANGID) {
|
||||
lngIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
WCHAR value[HUGE_BUFFER];
|
||||
for (int i = 0; i < COUNTOF(grepWinIniSettings); ++i) {
|
||||
IniSectionGetString(globalSection, grepWinIniSettings[i].key, grepWinIniSettings[i].val, value, COUNTOF(value));
|
||||
@ -3630,13 +3621,18 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
|
||||
}
|
||||
|
||||
// grepWin arguments
|
||||
const WCHAR* const tchParamFmt = L"/portable /content %s /inipath:\"%s\"";
|
||||
WCHAR tchParams[MAX_PATH + 80] = { L'\0' };
|
||||
// relative grepWinNP3.ini path (for shorter cmdline)
|
||||
if (PathRelativePathTo(tchTemp, tchGrepWinDir, FILE_ATTRIBUTE_DIRECTORY, tchIniFilePath, FILE_ATTRIBUTE_NORMAL)) {
|
||||
StringCchCopy(tchIniFilePath, COUNTOF(tchIniFilePath), tchTemp);
|
||||
WCHAR tchParams[2*MAX_PATH] = { L'\0' };
|
||||
|
||||
if (PathIsExistingFile(tchIniFilePath)) {
|
||||
// relative grepWinNP3.ini path (for shorter cmdline)
|
||||
if (PathRelativePathTo(tchTemp, tchGrepWinDir, FILE_ATTRIBUTE_DIRECTORY, tchIniFilePath, FILE_ATTRIBUTE_NORMAL)) {
|
||||
StringCchCopy(tchIniFilePath, COUNTOF(tchIniFilePath), tchTemp);
|
||||
}
|
||||
StringCchPrintf(tchParams, COUNTOF(tchParams), L"/portable /content %s /inipath:\"%s\"", tchOptions, tchIniFilePath);
|
||||
}
|
||||
else {
|
||||
StringCchPrintf(tchParams, COUNTOF(tchParams), L"/portable /content %s", tchOptions);
|
||||
}
|
||||
StringCchPrintf(tchParams, COUNTOF(tchParams), tchParamFmt, tchOptions, tchIniFilePath);
|
||||
//if (StrIsNotEmpty(searchPattern)) {
|
||||
// SetClipboardTextW(hwnd, searchPattern, StringCchLen(searchPattern, 0));
|
||||
//}
|
||||
|
||||
@ -832,7 +832,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
|
||||
ParseCommandLine();
|
||||
FindIniFile();
|
||||
TestIniFile();
|
||||
CreateIniFile();
|
||||
DWORD dwFileSize = 0UL;
|
||||
CreateIniFile(Globals.IniFile, &dwFileSize);
|
||||
Globals.bIniFileFromScratch = (dwFileSize == 0UL);
|
||||
LoadSettings();
|
||||
|
||||
// set AppUserModelID
|
||||
@ -5564,7 +5566,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
if (StrIsNotEmpty(Globals.IniFileDefault)) {
|
||||
StringCchCopy(Globals.IniFile, COUNTOF(Globals.IniFile), Globals.IniFileDefault);
|
||||
if (CreateIniFile(Globals.IniFile)) {
|
||||
if (CreateIniFile(Globals.IniFile, NULL)) {
|
||||
StringCchCopy(Globals.IniFileDefault, COUNTOF(Globals.IniFileDefault), L"");
|
||||
}
|
||||
else {
|
||||
|
||||
@ -316,7 +316,7 @@ void Style_DynamicThemesMenuCmd(int cmd)
|
||||
}
|
||||
else if (Globals.idxSelectedTheme == 1) {
|
||||
if (!Flags.bSettingsFileSoftLocked) {
|
||||
CreateIniFile();
|
||||
CreateIniFile(Globals.IniFile, NULL);
|
||||
if (StrIsNotEmpty(Globals.IniFile)) {
|
||||
Style_ExportToFile(Globals.IniFile, Globals.bIniFileFromScratch);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user