From d9a6b5d8a72c282f5a04ae2ea960535a0ad1ac0f Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Fri, 21 May 2021 23:19:41 +0900 Subject: [PATCH] - Allow environment variables to be included in the path of the external editor - Set the initial value of the path of the external editor to% windir%\NOTEPAD.EXE --- Src/Environment.cpp | 13 +++++++++++++ Src/Environment.h | 2 ++ Src/Merge.cpp | 2 +- Src/OptionsInit.cpp | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Src/Environment.cpp b/Src/Environment.cpp index fcbfeabbc..327f6d7c4 100644 --- a/Src/Environment.cpp +++ b/Src/Environment.cpp @@ -182,6 +182,19 @@ static bool launchProgram(const String& sCmd, WORD wShowWindow) return true; } +String ExpandEnvironmentVariables(const String& text) +{ + TCHAR buf[512]; + buf[0] = 0; + const unsigned size = sizeof(buf) / sizeof(buf[0]); + const unsigned expandedSize = ::ExpandEnvironmentStrings(text.c_str(), buf, size); + if (expandedSize <= size) + return buf; + std::vector newbuf(expandedSize); + ::ExpandEnvironmentStrings(text.c_str(), newbuf.data(), expandedSize); + return newbuf.data(); +} + /** * @brief Load registry keys from .reg file if existing .reg file */ diff --git a/Src/Environment.h b/Src/Environment.h index c8d4371ad..527f08c34 100644 --- a/Src/Environment.h +++ b/Src/Environment.h @@ -24,6 +24,8 @@ String GetSystemTempPath(); String GetPerInstanceString(const String& name); +String ExpandEnvironmentVariables(const String& text); + bool LoadRegistryFromFile(const String& sRegFilePath); bool SaveRegistryToFile(const String& sRegFilePath, const String& sRegDir); diff --git a/Src/Merge.cpp b/Src/Merge.cpp index e05fa33f2..5aa61d690 100644 --- a/Src/Merge.cpp +++ b/Src/Merge.cpp @@ -803,7 +803,7 @@ void CMergeApp::OnHelp() */ void CMergeApp::OpenFileToExternalEditor(const String& file, int nLineNumber/* = 1*/) { - String sCmd = GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD); + String sCmd = env::ExpandEnvironmentVariables(GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD)); String sFile(file); strutils::replace(sCmd, _T("$linenum"), strutils::to_str(nLineNumber)); diff --git a/Src/OptionsInit.cpp b/Src/OptionsInit.cpp index d908f923a..5c28f660e 100644 --- a/Src/OptionsInit.cpp +++ b/Src/OptionsInit.cpp @@ -114,7 +114,7 @@ void Init(COptionsMgr *pOptions) pOptions->InitOption(OPT_TAB_SIZE, (int)4); pOptions->InitOption(OPT_TAB_TYPE, (int)0); // 0 means tabs inserted - pOptions->InitOption(OPT_EXT_EDITOR_CMD, paths::ConcatPath(env::GetWindowsDirectory(), _T("NOTEPAD.EXE"))); + pOptions->InitOption(OPT_EXT_EDITOR_CMD, _T("%windir%\\NOTEPAD.EXE")); pOptions->InitOption(OPT_USE_RECYCLE_BIN, true); pOptions->InitOption(OPT_SINGLE_INSTANCE, 0); pOptions->InitOption(OPT_MERGE_MODE, false); -- 2.11.0