1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
10 * @brief Defines the class behaviors for the application.
16 #include "Constants.h"
17 #include "UnicodeString.h"
19 #include "Environment.h"
20 #include "OptionsMgr.h"
21 #include "OptionsInit.h"
22 #include "RegOptionsMgr.h"
23 #include "IniOptionsMgr.h"
27 #include "HexMergeDoc.h"
28 #include "HexMergeFrm.h"
29 #include "HexMergeView.h"
32 #include "MergeEditFrm.h"
37 #include "PropBackups.h"
38 #include "FileOrFolderSelect.h"
39 #include "FileFilterHelper.h"
40 #include "LineFiltersList.h"
41 #include "SubstitutionFiltersList.h"
42 #include "SyntaxColors.h"
43 #include "CCrystalTextMarkers.h"
44 #include "OptionsSyntaxColors.h"
46 #include "ProjectFile.h"
47 #include "MergeEditSplitterView.h"
48 #include "LanguageSelect.h"
49 #include "OptionsDef.h"
50 #include "MergeCmdLineInfo.h"
51 #include "ConflictFileParser.h"
53 #include "stringdiffs.h"
57 #include "CompareStats.h"
59 #include "charsets.h" // For shutdown cleanup
65 /** @brief Location for command line help to open. */
66 static const TCHAR CommandLineHelpLocation[] = _T("::/htmlhelp/Command_line.html");
68 /** @brief Backup file extension. */
69 static const TCHAR BACKUP_FILE_EXT[] = _T("bak");
71 /////////////////////////////////////////////////////////////////////////////
74 BEGIN_MESSAGE_MAP(CMergeApp, CWinApp)
75 //{{AFX_MSG_MAP(CMergeApp)
76 ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
77 ON_COMMAND(ID_HELP, OnHelp)
78 ON_COMMAND_EX_RANGE(ID_FILE_PROJECT_MRU_FIRST, ID_FILE_PROJECT_MRU_LAST, OnOpenRecentFile)
79 ON_UPDATE_COMMAND_UI(ID_FILE_PROJECT_MRU_FIRST, CWinApp::OnUpdateRecentFileMenu)
80 ON_COMMAND(ID_FILE_MERGINGMODE, OnMergingMode)
81 ON_UPDATE_COMMAND_UI(ID_FILE_MERGINGMODE, OnUpdateMergingMode)
82 ON_UPDATE_COMMAND_UI(ID_STATUS_MERGINGMODE, OnUpdateMergingStatus)
84 // Standard file based document commands
85 //ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
86 //ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
87 // Standard print setup command
88 ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
91 /////////////////////////////////////////////////////////////////////////////
92 // CMergeApp construction
94 CMergeApp::CMergeApp() :
95 m_bNeedIdleTimer(false)
96 , m_pOpenTemplate(nullptr)
97 , m_pDiffTemplate(nullptr)
98 , m_pHexMergeTemplate(nullptr)
99 , m_pDirTemplate(nullptr)
100 , m_mainThreadScripts(nullptr)
101 , m_nLastCompareResult(0)
102 , m_bNonInteractive(false)
103 , m_pOptions(CreateOptionManager())
104 , m_pGlobalFileFilter(new FileFilterHelper())
105 , m_nActiveOperations(0)
106 , m_pLangDlg(new CLanguageSelect())
107 , m_bEscShutdown(false)
108 , m_bExitIfNoDiff(MergeCmdLineInfo::ExitNoDiff::Disabled)
109 , m_pLineFilters(new LineFiltersList())
110 , m_pSubstitutionFiltersList(new SubstitutionFiltersList())
111 , m_pSyntaxColors(new SyntaxColors())
112 , m_pMarkers(new CCrystalTextMarkers())
113 , m_bMergingMode(false)
115 // add construction code here,
116 // Place all significant initialization in InitInstance
120 * @brief Chose which options manager should be initialized.
121 * @return IniOptionsMgr if initial config file exists,
122 * CRegOptionsMgr otherwise.
124 COptionsMgr *CreateOptionManager()
126 String iniFilePath = paths::ConcatPath(env::GetProgPath(), _T("winmerge.ini"));
127 if (paths::DoesPathExist(iniFilePath) == paths::IS_EXISTING_FILE)
129 return new CIniOptionsMgr(iniFilePath);
133 return new CRegOptionsMgr();
137 CMergeApp::~CMergeApp()
141 /////////////////////////////////////////////////////////////////////////////
142 // The one and only CMergeApp object
146 /////////////////////////////////////////////////////////////////////////////
147 // CMergeApp initialization
150 * @brief Initialize WinMerge application instance.
151 * @return TRUE if application initialization succeeds (and we'll run it),
152 * FALSE if something failed and we exit the instance.
153 * @todo We could handle these failure situations more gratefully, i.e. show
154 * at least some error message to the user..
156 BOOL CMergeApp::InitInstance()
158 // Prevents DLL hijacking
159 HMODULE hLibrary = GetModuleHandle(_T("kernel32.dll"));
160 BOOL (WINAPI *pfnSetSearchPathMode)(DWORD) = (BOOL (WINAPI *)(DWORD))GetProcAddress(hLibrary, "SetSearchPathMode");
161 if (pfnSetSearchPathMode != nullptr)
162 pfnSetSearchPathMode(0x00000001L /*BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE*/ | 0x00008000L /*BASE_SEARCH_PATH_PERMANENT*/);
163 BOOL (WINAPI *pfnSetDllDirectoryA)(LPCSTR) = (BOOL (WINAPI *)(LPCSTR))GetProcAddress(hLibrary, "SetDllDirectoryA");
164 if (pfnSetDllDirectoryA != nullptr)
165 pfnSetDllDirectoryA("");
167 JumpList::SetCurrentProcessExplicitAppUserModelID(L"Thingamahoochie.WinMerge");
169 InitCommonControls(); // initialize common control library
170 CWinApp::InitInstance(); // call parent class method
172 m_imageForInitializingGdiplus.Load((IStream*)nullptr); // initialize GDI+
174 // Runtime switch so programmer may set this in interactive debugger
178 // get current setting
179 int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
180 // Keep freed memory blocks in the heap's linked list and mark them as freed
181 tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
182 // Call _CrtCheckMemory at every allocation and deallocation request.
183 // WARNING: This slows down WinMerge *A LOT*
184 tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
185 // Set the new state for the flag
186 _CrtSetDbgFlag( tmpFlag );
189 // CCrystalEdit Drag and Drop functionality needs AfxOleInit.
192 TRACE(_T("AfxOleInitFailed. OLE functionality disabled"));
195 // Standard initialization
196 // If you are not using these features and wish to reduce the size
197 // of your final executable, you should remove from the following
198 // the specific initialization routines you do not need.
200 // Revoke the standard OLE Message Filter to avoid drawing frame while loading files.
201 COleMessageFilter* pOldFilter = AfxOleGetMessageFilter();
202 pOldFilter->Revoke();
204 // Load registry keys from WinMerge.reg if existing WinMerge.reg
205 env::LoadRegistryFromFile(paths::ConcatPath(env::GetProgPath(), _T("WinMerge.reg")));
207 // Parse command-line arguments.
209 MergeCmdLineInfo cmdInfo(_T(""));
211 MergeCmdLineInfo cmdInfo(GetCommandLine());
213 if (cmdInfo.m_bNoPrefs)
214 m_pOptions->SetSerializing(false); // Turn off serializing to registry.
216 Options::CopyHKLMValues();
217 Options::Init(m_pOptions.get()); // Implementation in OptionsInit.cpp
218 ApplyCommandLineConfigOptions(cmdInfo);
219 if (cmdInfo.m_sErrorMessages.size() > 0)
221 if (AttachConsole(ATTACH_PARENT_PROCESS))
224 for (auto& msg : cmdInfo.m_sErrorMessages)
226 String line = _T("WinMerge: ") + msg + _T("\n");
227 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), line.c_str(), static_cast<DWORD>(line.length()), &dwWritten, nullptr);
233 // Initialize temp folder
236 // If paths were given to commandline we consider this being an invoke from
237 // commandline (from other application, shellextension etc).
238 bool bCommandLineInvoke = cmdInfo.m_Files.GetSize() > 0;
240 // WinMerge registry settings are stored under HKEY_CURRENT_USER/Software/Thingamahoochie
241 // This is the name of the company of the original author (Dean Grimm)
242 SetRegistryKey(_T("Thingamahoochie"));
244 int nSingleInstance = cmdInfo.m_nSingleInstance.has_value() ?
245 *cmdInfo.m_nSingleInstance : GetOptionsMgr()->GetInt(OPT_SINGLE_INSTANCE);
247 // Create exclusion mutex name
248 TCHAR szDesktopName[MAX_PATH] = _T("Win9xDesktop");
249 DWORD dwLengthNeeded;
250 GetUserObjectInformation(GetThreadDesktop(GetCurrentThreadId()), UOI_NAME,
251 szDesktopName, sizeof(szDesktopName), &dwLengthNeeded);
252 TCHAR szMutexName[MAX_PATH + 40];
253 // Combine window class name and desktop name to form a unique mutex name.
254 // As the window class name is decorated to distinguish between ANSI and
255 // UNICODE build, so will be the mutex name.
256 wsprintf(szMutexName, _T("%s-%s"), CMainFrame::szClassName, szDesktopName);
257 HANDLE hMutex = CreateMutex(nullptr, FALSE, szMutexName);
258 if (hMutex != nullptr)
259 WaitForSingleObject(hMutex, INFINITE);
260 if (nSingleInstance != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
262 // Activate previous instance and send commandline to it
263 HWND hWnd = FindWindow(CMainFrame::szClassName, nullptr);
267 ShowWindow(hWnd, SW_RESTORE);
268 SetForegroundWindow(GetLastActivePopup(hWnd));
269 LPTSTR cmdLine = GetCommandLine();
270 COPYDATASTRUCT data = { 0, (lstrlen(cmdLine) + 1) * sizeof(TCHAR), cmdLine};
271 if (::SendMessage(hWnd, WM_COPYDATA, NULL, (LPARAM)&data))
273 ReleaseMutex(hMutex);
275 if (nSingleInstance > 1)
277 DWORD dwProcessId = 0;
278 GetWindowThreadProcessId(hWnd, &dwProcessId);
279 HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, dwProcessId);
281 WaitForSingleObject(hProcess, INFINITE);
288 LoadStdProfileSettings(GetOptionsMgr()->GetInt(OPT_MRU_MAX)); // Load standard INI file options (including MRU)
290 InitializeFileFilters();
292 // Read last used filter from registry
293 // If filter fails to set, reset to default
294 const String filterString = m_pOptions->GetString(OPT_FILEFILTER_CURRENT);
295 bool bFilterSet = m_pGlobalFileFilter->SetFilter(filterString);
298 String filter = m_pGlobalFileFilter->GetFilterNameOrMask();
299 m_pOptions->SaveOption(OPT_FILEFILTER_CURRENT, filter);
303 UpdateCodepageModule();
305 FileTransform::g_UnpackerMode = static_cast<PLUGIN_MODE>(GetOptionsMgr()->GetInt(OPT_PLUGINS_UNPACKER_MODE));
306 FileTransform::g_PredifferMode = static_cast<PLUGIN_MODE>(GetOptionsMgr()->GetInt(OPT_PLUGINS_PREDIFFER_MODE));
308 NONCLIENTMETRICS ncm = { sizeof NONCLIENTMETRICS };
309 if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof NONCLIENTMETRICS, &ncm, 0))
311 const int lfHeight = -MulDiv(9, CClientDC(CWnd::GetDesktopWindow()).GetDeviceCaps(LOGPIXELSY), 72);
312 if (abs(ncm.lfMenuFont.lfHeight) > abs(lfHeight))
313 ncm.lfMenuFont.lfHeight = lfHeight;
314 if (wcscmp(ncm.lfMenuFont.lfFaceName, L"Meiryo") == 0 || wcscmp(ncm.lfMenuFont.lfFaceName, L"\U000030e1\U000030a4\U000030ea\U000030aa"/* "Meiryo" in Japanese */) == 0)
315 wcscpy_s(ncm.lfMenuFont.lfFaceName, L"Meiryo UI");
316 m_fontGUI.CreateFontIndirect(&ncm.lfMenuFont);
319 if (m_pSyntaxColors != nullptr)
320 Options::SyntaxColors::Init(GetOptionsMgr(), m_pSyntaxColors.get());
322 if (m_pMarkers != nullptr)
323 m_pMarkers->LoadFromRegistry();
325 CCrystalTextView::SetRenderingModeDefault(static_cast<CCrystalTextView::RENDERING_MODE>(GetOptionsMgr()->GetInt(OPT_RENDERING_MODE)));
327 if (m_pLineFilters != nullptr)
328 m_pLineFilters->Initialize(GetOptionsMgr());
330 // If there are no filters loaded, and there is filter string in previous
331 // option string, import old filters to new place.
332 if (m_pLineFilters->GetCount() == 0)
334 String oldFilter = theApp.GetProfileString(_T("Settings"), _T("RegExps"));
335 if (!oldFilter.empty())
336 m_pLineFilters->Import(oldFilter);
339 if (m_pSubstitutionFiltersList != nullptr)
340 m_pSubstitutionFiltersList->Initialize(GetOptionsMgr());
342 // Check if filter folder is set, and create it if not
343 String pathMyFolders = GetOptionsMgr()->GetString(OPT_FILTER_USERPATH);
344 if (pathMyFolders.empty())
346 // No filter path, set it to default and make sure it exists.
347 pathMyFolders = GetOptionsMgr()->GetDefault<String>(OPT_FILTER_USERPATH);
348 GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, pathMyFolders);
349 theApp.m_pGlobalFileFilter->SetUserFilterPath(pathMyFolders);
351 if (!paths::CreateIfNeeded(pathMyFolders))
353 // Failed to create a folder, check it didn't already
355 DWORD errCode = GetLastError();
356 if (errCode != ERROR_ALREADY_EXISTS)
358 // Failed to create a folder for filters, fallback to
359 // "My Documents"-folder. It is not worth the trouble to
360 // bother user about this or user more clever solutions.
361 GetOptionsMgr()->SaveOption(OPT_FILTER_USERPATH, env::GetMyDocuments());
365 strdiff::Init(); // String diff init
366 strdiff::SetBreakChars(GetOptionsMgr()->GetString(OPT_BREAK_SEPARATORS).c_str());
368 m_bMergingMode = GetOptionsMgr()->GetBool(OPT_MERGE_MODE);
370 // Initialize i18n (multiple language) support
372 m_pLangDlg->InitializeLanguage((WORD)GetOptionsMgr()->GetInt(OPT_SELECTED_LANGUAGE));
374 m_mainThreadScripts = new CAssureScriptsForThread;
376 // Register the application's document templates. Document templates
377 // serve as the connection between documents, frame windows and views.
380 m_pOpenTemplate = new CMultiDocTemplate(
382 RUNTIME_CLASS(COpenDoc),
383 RUNTIME_CLASS(COpenFrame), // custom MDI child frame
384 RUNTIME_CLASS(COpenView));
385 AddDocTemplate(m_pOpenTemplate);
388 m_pDiffTemplate = new CMultiDocTemplate(
390 RUNTIME_CLASS(CMergeDoc),
391 RUNTIME_CLASS(CMergeEditFrame), // custom MDI child frame
392 RUNTIME_CLASS(CMergeEditSplitterView));
393 AddDocTemplate(m_pDiffTemplate);
396 m_pHexMergeTemplate = new CMultiDocTemplate(
398 RUNTIME_CLASS(CHexMergeDoc),
399 RUNTIME_CLASS(CHexMergeFrame), // custom MDI child frame
400 RUNTIME_CLASS(CHexMergeView));
401 AddDocTemplate(m_pHexMergeTemplate);
404 m_pDirTemplate = new CMultiDocTemplate(
406 RUNTIME_CLASS(CDirDoc),
407 RUNTIME_CLASS(CDirFrame), // custom MDI child frame
408 RUNTIME_CLASS(CDirView));
409 AddDocTemplate(m_pDirTemplate);
411 // create main MDI Frame window
412 CMainFrame* pMainFrame = new CMainFrame;
413 if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
415 if (hMutex != nullptr)
417 ReleaseMutex(hMutex);
422 m_pMainWnd = pMainFrame;
424 // Init menus -- hMenuDefault is for MainFrame
425 pMainFrame->m_hMenuDefault = pMainFrame->NewDefaultMenu();
428 // Note : for Windows98 compatibility, use FromHandle and not Attach/Detach
429 CMenu * pNewMenu = CMenu::FromHandle(pMainFrame->m_hMenuDefault);
430 pMainFrame->MDISetMenu(pNewMenu, nullptr);
432 // The main window has been initialized, so activate it.
433 pMainFrame->ActivateFrame(cmdInfo.m_nCmdShow);
435 // Since this function actually opens paths for compare it must be
436 // called after initializing CMainFrame!
437 bool bContinue = true;
438 if (!ParseArgsAndDoOpen(cmdInfo, pMainFrame) && bCommandLineInvoke)
441 if (hMutex != nullptr)
442 ReleaseMutex(hMutex);
444 // If user wants to cancel the compare, close WinMerge
447 pMainFrame->PostMessage(WM_CLOSE, 0, 0);
451 WinMergeTest::TestAll();
457 static void OpenContributersFile(int&)
459 CMergeApp::OpenFileToExternalEditor(paths::ConcatPath(env::GetProgPath(), ContributorsPath));
462 static void OpenUrl(int&)
464 shell::Open(WinMergeURL);
467 // App command to run the dialog
468 void CMergeApp::OnAppAbout()
471 aboutDlg.m_onclick_contributers += Poco::delegate(OpenContributersFile);
472 aboutDlg.m_onclick_url += Poco::delegate(OpenUrl);
474 aboutDlg.m_onclick_contributers.clear();
475 aboutDlg.m_onclick_url.clear();
478 /////////////////////////////////////////////////////////////////////////////
479 // CMergeApp commands
482 * @brief Called when application is about to exit.
483 * This functions is called when application is exiting, so this is
484 * good place to do cleanups.
485 * @return Application's exit value (returned from WinMain()).
487 int CMergeApp::ExitInstance()
491 // Save registry keys if existing WinMerge.reg
492 env::SaveRegistryToFile(paths::ConcatPath(env::GetProgPath(), _T("WinMerge.reg")), RegDir);
495 const String temp = env::GetTemporaryPath();
496 ClearTempfolder(temp);
498 // Cleanup left over tempfiles from previous instances.
499 // Normally this should not need to do anything - but if for some reason
500 // WinMerge did not delete temp files this makes sure they are removed.
503 delete m_mainThreadScripts;
504 CWinApp::ExitInstance();
508 int CMergeApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
510 // This is a convenient point for breakpointing !!!
512 // Create a handle to store the parent window of the message box.
513 CWnd* pParentWnd = CWnd::GetActiveWindow();
515 // Check whether an active window was retrieved successfully.
516 if (pParentWnd == nullptr)
518 // Try to retrieve a handle to the last active popup.
519 CWnd * mainwnd = GetMainWnd();
520 if (mainwnd != nullptr)
521 pParentWnd = mainwnd->GetLastActivePopup();
524 // Use our own message box implementation, which adds the
525 // do not show again checkbox, and implements it on subsequent calls
526 // (if caller set the style)
528 if (m_bNonInteractive)
530 if (AttachConsole(ATTACH_PARENT_PROCESS))
533 String line = _T("WinMerge: ") + String(lpszPrompt) + _T("\n");
534 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), line.c_str(), static_cast<DWORD>(line.length()), &dwWritten, nullptr);
540 // Create the message box dialog.
541 CMessageBoxDialog dlgMessage(pParentWnd, lpszPrompt, _T(""), nType | MB_RIGHT_ALIGN,
544 if (m_pMainWnd->IsIconic())
545 m_pMainWnd->ShowWindow(SW_RESTORE);
547 // Display the message box dialog and return the result.
548 return static_cast<int>(dlgMessage.DoModal());
551 bool CMergeApp::IsReallyIdle() const
554 POSITION pos = m_pDirTemplate->GetFirstDocPosition();
555 while (pos != nullptr)
557 CDirDoc *pDirDoc = static_cast<CDirDoc *>(m_pDirTemplate->GetNextDoc(pos));
558 if (const CompareStats *pCompareStats = pDirDoc->GetCompareStats())
560 if (!pCompareStats->IsCompareDone() || pDirDoc->GetGeneratingReport())
567 BOOL CMergeApp::OnIdle(LONG lCount)
569 if (CWinApp::OnIdle(lCount))
572 // If anyone has requested notification when next idle occurs, send it
573 if (m_bNeedIdleTimer)
575 m_bNeedIdleTimer = false;
576 m_pMainWnd->SendMessageToDescendants(WM_TIMER, IDLE_TIMER, lCount, TRUE, FALSE);
579 if (m_bNonInteractive && IsReallyIdle())
580 m_pMainWnd->PostMessage(WM_CLOSE, 0, 0);
582 if (typeid(*GetOptionsMgr()) == typeid(CRegOptionsMgr))
584 static_cast<CRegOptionsMgr*>(GetOptionsMgr())->CloseKeys();
591 * @brief Load any known file filters.
593 * This function loads filter files from paths we know contain them.
594 * @note User's filter location may not be set yet.
596 void CMergeApp::InitializeFileFilters()
598 String filterPath = GetOptionsMgr()->GetString(OPT_FILTER_USERPATH);
600 if (!filterPath.empty())
602 m_pGlobalFileFilter->SetUserFilterPath(filterPath);
604 m_pGlobalFileFilter->LoadAllFileFilters();
607 void CMergeApp::ApplyCommandLineConfigOptions(MergeCmdLineInfo& cmdInfo)
609 if (cmdInfo.m_bNoPrefs)
610 m_pOptions->SetSerializing(false); // Turn off serializing to registry.
612 for (const auto& it : cmdInfo.m_Options)
614 if (m_pOptions->Set(it.first, it.second) == COption::OPT_NOTFOUND)
616 String longname = m_pOptions->ExpandShortName(it.first);
617 if (!longname.empty())
619 m_pOptions->Set(longname, it.second);
623 cmdInfo.m_sErrorMessages.push_back(strutils::format_string1(_T("Invalid key '%1' specified in /config option"), it.first));
629 /** @brief Read command line arguments and open files for comparison.
631 * The name of the function is a legacy code from the time that this function
632 * actually parsed the command line. Today the parsing is done using the
633 * MergeCmdLineInfo class.
634 * @param [in] cmdInfo Commandline parameters info.
635 * @param [in] pMainFrame Pointer to application main frame.
636 * @return `true` if we opened the compare, `false` if the compare was canceled.
638 bool CMergeApp::ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainFrame)
640 bool bCompared = false;
642 std::unique_ptr<PackingInfo> infoUnpacker;
644 m_bNonInteractive = cmdInfo.m_bNonInteractive;
646 if (!cmdInfo.m_sUnpacker.empty())
648 infoUnpacker.reset(new PackingInfo(PLUGIN_MODE::PLUGIN_MANUAL));
649 infoUnpacker->m_PluginName = cmdInfo.m_sUnpacker;
652 // Set the global file filter.
653 if (!cmdInfo.m_sFileFilter.empty())
655 m_pGlobalFileFilter->SetFilter(cmdInfo.m_sFileFilter);
659 if (cmdInfo.m_nCodepage)
661 UpdateDefaultCodepage(2,cmdInfo.m_nCodepage);
664 // Set compare method
665 if (cmdInfo.m_nCompMethod.has_value())
666 GetOptionsMgr()->Set(OPT_CMP_METHOD, *cmdInfo.m_nCompMethod);
668 // Unless the user has requested to see WinMerge's usage open files for
670 if (cmdInfo.m_bShowUsage)
672 ShowHelp(CommandLineHelpLocation);
676 // Set the required information we need from the command line:
678 m_bExitIfNoDiff = cmdInfo.m_bExitIfNoDiff;
679 m_bEscShutdown = cmdInfo.m_bEscShutdown;
681 m_strSaveAsPath = cmdInfo.m_sOutputpath;
683 strDesc[0] = cmdInfo.m_sLeftDesc;
684 if (cmdInfo.m_Files.GetSize() < 3)
686 strDesc[1] = cmdInfo.m_sRightDesc;
690 strDesc[1] = cmdInfo.m_sMiddleDesc;
691 strDesc[2] = cmdInfo.m_sRightDesc;
694 if (cmdInfo.m_Files.GetSize() > 2)
696 cmdInfo.m_dwLeftFlags |= FFILEOPEN_CMDLINE;
697 cmdInfo.m_dwMiddleFlags |= FFILEOPEN_CMDLINE;
698 cmdInfo.m_dwRightFlags |= FFILEOPEN_CMDLINE;
699 DWORD dwFlags[3] = {cmdInfo.m_dwLeftFlags, cmdInfo.m_dwMiddleFlags, cmdInfo.m_dwRightFlags};
700 bCompared = pMainFrame->DoFileOpen(&cmdInfo.m_Files,
701 dwFlags, strDesc, cmdInfo.m_sReportFile, cmdInfo.m_bRecurse, nullptr,
702 cmdInfo.m_sPreDiffer, infoUnpacker.get());
704 else if (cmdInfo.m_Files.GetSize() > 1)
706 DWORD dwFlags[3] = {cmdInfo.m_dwLeftFlags, cmdInfo.m_dwRightFlags, FFILEOPEN_NONE};
707 bCompared = pMainFrame->DoFileOpen(&cmdInfo.m_Files,
708 dwFlags, strDesc, cmdInfo.m_sReportFile, cmdInfo.m_bRecurse, nullptr,
709 cmdInfo.m_sPreDiffer, infoUnpacker.get());
711 else if (cmdInfo.m_Files.GetSize() == 1)
713 String sFilepath = cmdInfo.m_Files[0];
714 if (cmdInfo.m_bSelfCompare)
716 strDesc[0] = cmdInfo.m_sLeftDesc;
717 strDesc[1] = cmdInfo.m_sRightDesc;
718 bCompared = pMainFrame->DoSelfCompare(IDOK, sFilepath, strDesc);
720 else if (IsProjectFile(sFilepath))
722 bCompared = LoadAndOpenProjectFile(sFilepath);
724 else if (IsConflictFile(sFilepath))
726 //For a conflict file, load the descriptions in their respective positions: (they will be reordered as needed)
727 strDesc[0] = cmdInfo.m_sLeftDesc;
728 strDesc[1] = cmdInfo.m_sMiddleDesc;
729 strDesc[2] = cmdInfo.m_sRightDesc;
730 bCompared = pMainFrame->DoOpenConflict(sFilepath, strDesc);
734 DWORD dwFlags[3] = {cmdInfo.m_dwLeftFlags, cmdInfo.m_dwRightFlags, FFILEOPEN_NONE};
735 bCompared = pMainFrame->DoFileOpen(&cmdInfo.m_Files,
736 dwFlags, strDesc, cmdInfo.m_sReportFile, cmdInfo.m_bRecurse, nullptr,
737 cmdInfo.m_sPreDiffer, infoUnpacker.get());
740 else if (cmdInfo.m_Files.GetSize() == 0) // if there are no input args, we can check the display file dialog flag
742 bool showFiles = m_pOptions->GetBool(OPT_SHOW_SELECT_FILES_AT_STARTUP);
744 pMainFrame->DoFileOpen();
750 void CMergeApp::UpdateDefaultCodepage(int cpDefaultMode, int cpCustomCodepage)
754 switch (cpDefaultMode)
757 ucr::setDefaultCodepage(GetACP());
761 wLangId = GetLangId();
762 if (GetLocaleInfo(wLangId, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof(buff)/sizeof(buff[0])))
763 ucr::setDefaultCodepage(_ttol(buff));
765 ucr::setDefaultCodepage(GetACP());
768 ucr::setDefaultCodepage(cpCustomCodepage);
771 // no other valid option
773 ucr::setDefaultCodepage(GetACP());
778 * @brief Send current option settings into codepage module
780 void CMergeApp::UpdateCodepageModule()
782 // Get current codepage settings from the options module
783 // and push them into the codepage module
784 UpdateDefaultCodepage(GetOptionsMgr()->GetInt(OPT_CP_DEFAULT_MODE), GetOptionsMgr()->GetInt(OPT_CP_DEFAULT_CUSTOM));
787 /** @brief Open help from mainframe when user presses F1*/
788 void CMergeApp::OnHelp()
794 * @brief Open given file to external editor specified in options.
795 * @param [in] file Full path to file to open.
797 * Opens file to defined (in Options/system), Notepad by default,
798 * external editor. Path is decorated with quotation marks if needed
799 * (contains spaces). Also '$file' in editor path is replaced by
801 * @param [in] file Full path to file to open.
802 * @param [in] nLineNumber Line number to go to.
804 void CMergeApp::OpenFileToExternalEditor(const String& file, int nLineNumber/* = 1*/)
806 String sCmd = env::ExpandEnvironmentVariables(GetOptionsMgr()->GetString(OPT_EXT_EDITOR_CMD));
808 strutils::replace(sCmd, _T("$linenum"), strutils::to_str(nLineNumber));
810 size_t nIndex = sCmd.find(_T("$file"));
811 if (nIndex != String::npos)
813 sFile.insert(0, _T("\""));
814 strutils::replace(sCmd, _T("$file"), sFile);
815 nIndex = sCmd.find(' ', nIndex + sFile.length());
816 if (nIndex != String::npos)
817 sCmd.insert(nIndex, _T("\""));
829 STARTUPINFO stInfo = { sizeof STARTUPINFO };
830 PROCESS_INFORMATION processInfo;
832 retVal = !!CreateProcess(nullptr, (LPTSTR)sCmd.c_str(),
833 nullptr, nullptr, FALSE, CREATE_DEFAULT_ERROR_MODE, nullptr, nullptr,
834 &stInfo, &processInfo);
838 // Error invoking external editor
839 String msg = strutils::format_string1(_("Failed to execute external editor: %1"), sCmd);
840 AfxMessageBox(msg.c_str(), MB_ICONSTOP);
844 CloseHandle(processInfo.hThread);
845 CloseHandle(processInfo.hProcess);
850 * @brief Show Help - this is for opening help from outside mainframe.
851 * @param [in] helpLocation Location inside help, if `nullptr` main help is opened.
853 void CMergeApp::ShowHelp(LPCTSTR helpLocation /*= nullptr*/)
856 LANGID LangId = GetLangId();
857 paths::SplitFilename(m_pLangDlg->GetFileName(LangId), nullptr, &name, &ext);
858 String sPath = paths::ConcatPath(env::GetProgPath(), strutils::format(DocsPath, name.c_str()));
859 if (paths::DoesPathExist(sPath) != paths::IS_EXISTING_FILE)
860 sPath = paths::ConcatPath(env::GetProgPath(), strutils::format(DocsPath, _T("")));
861 if (helpLocation == nullptr)
863 if (paths::DoesPathExist(sPath) == paths::IS_EXISTING_FILE)
864 ::HtmlHelp(nullptr, sPath.c_str(), HH_DISPLAY_TOC, NULL);
866 shell::Open(DocsURL);
870 if (paths::DoesPathExist(sPath) == paths::IS_EXISTING_FILE)
872 sPath += helpLocation;
873 ::HtmlHelp(nullptr, sPath.c_str(), HH_DISPLAY_TOPIC, NULL);
879 * @brief Creates backup before file is saved or copied over.
880 * This function handles formatting correct path and filename for
881 * backup file. Formatting is done based on several options available
882 * for users in Options/Backups dialog. After path is formatted, file
883 * is simply just copied. Not much error checking, just if copying
884 * succeeded or failed.
885 * @param [in] bFolder Are we creating backup in folder compare?
886 * @param [in] pszPath Full path to file to backup.
887 * @return `true` if backup succeeds, or isn't just done.
889 bool CMergeApp::CreateBackup(bool bFolder, const String& pszPath)
891 // If user doesn't want to backups in folder compare, return
892 // success so operations don't abort.
893 if (bFolder && !(GetOptionsMgr()->GetBool(OPT_BACKUP_FOLDERCMP)))
895 // Likewise if user doesn't want backups in file compare
896 else if (!bFolder && !(GetOptionsMgr()->GetBool(OPT_BACKUP_FILECMP)))
899 // create backup copy of file if destination file exists
900 if (paths::DoesPathExist(pszPath) == paths::IS_EXISTING_FILE)
907 paths::SplitFilename(paths::GetLongPath(pszPath), &path, &filename, &ext);
909 // Determine backup folder
910 if (GetOptionsMgr()->GetInt(OPT_BACKUP_LOCATION) ==
911 PropBackups::FOLDER_ORIGINAL)
913 // Put backups to same folder than original file
916 else if (GetOptionsMgr()->GetInt(OPT_BACKUP_LOCATION) ==
917 PropBackups::FOLDER_GLOBAL)
919 // Put backups to global folder defined in options
920 bakPath = GetOptionsMgr()->GetString(OPT_BACKUP_GLOBALFOLDER);
924 bakPath = paths::GetLongPath(bakPath);
928 _RPTF0(_CRT_ERROR, "Unknown backup location!");
931 bool success = false;
932 if (GetOptionsMgr()->GetBool(OPT_BACKUP_ADD_BAK))
934 // Don't add dot if there is no existing extension
937 ext += BACKUP_FILE_EXT;
940 // Append time to filename if wanted so
941 // NOTE just adds timestamp at the moment as I couldn't figure out
942 // nice way to add a real time (invalid chars etc).
943 if (GetOptionsMgr()->GetBool(OPT_BACKUP_ADD_TIME))
948 ::localtime_s(&tm, &curtime);
950 timestr.Format(_T("%04d%02d%02d%02d%02d%02d"), tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
955 // Append filename and extension (+ optional .bak) to path
956 if ((bakPath.length() + filename.length() + ext.length())
960 bakPath = paths::ConcatPath(bakPath, filename);
967 success = !!CopyFileW(TFile(pszPath).wpath().c_str(), TFile(bakPath).wpath().c_str(), FALSE);
972 String msg = strutils::format_string1(
973 _("Unable to backup original file:\n%1\n\nContinue anyway?"),
975 if (AfxMessageBox(msg.c_str(), MB_YESNO | MB_ICONWARNING | MB_DONT_ASK_AGAIN) != IDYES)
981 // we got here because we're either not backing up of there was nothing to backup
986 * @brief Checks if path (file/folder) is read-only and asks overwriting it.
988 * @param strSavePath [in,out] Path where to save (file or folder)
989 * @param bMultiFile [in] Single file or multiple files/folder
990 * @param bApplyToAll [in,out] Apply last user selection for all items?
991 * @return Users selection:
992 * - IDOK: Item was not readonly, no actions
993 * - IDYES/IDYESTOALL: Overwrite readonly item
994 * - IDNO: User selected new filename (single file) or user wants to skip
995 * - IDCANCEL: Cancel operation
996 * @sa CMainFrame::SyncFileToVCS()
997 * @sa CMergeDoc::DoSave()
999 int CMergeApp::HandleReadonlySave(String& strSavePath, bool bMultiFile,
1004 bool bFileRO = false;
1005 bool bFileExists = false;
1010 if (!strSavePath.empty())
1014 TFile file(strSavePath);
1015 bFileExists = file.exists();
1017 bFileRO = !file.canWrite();
1024 if (bFileExists && bFileRO)
1026 UINT userChoice = 0;
1028 // Don't ask again if its already asked
1033 // Prompt for user choice
1036 // Multiple files or folder
1037 str = strutils::format_string1(_("%1\nis marked read-only. Would you like to override the read-only item?"), strSavePath);
1038 userChoice = AfxMessageBox(str.c_str(), MB_YESNOCANCEL |
1039 MB_ICONWARNING | MB_DEFBUTTON3 | MB_DONT_ASK_AGAIN |
1040 MB_YES_TO_ALL, IDS_SAVEREADONLY_MULTI);
1045 str = strutils::format_string1(_("%1 is marked read-only. Would you like to override the read-only file? (No to save as new filename.)"), strSavePath);
1046 userChoice = AfxMessageBox(str.c_str(), MB_YESNOCANCEL |
1047 MB_ICONWARNING | MB_DEFBUTTON2 | MB_DONT_ASK_AGAIN,
1048 IDS_SAVEREADONLY_FMT);
1053 // Overwrite read-only file
1055 bApplyToAll = true; // Don't ask again (no break here)
1058 CFile::GetStatus(strSavePath.c_str(), status);
1059 status.m_mtime = 0; // Avoid unwanted changes
1060 status.m_attribute &= ~CFile::readOnly;
1061 CFile::SetStatus(strSavePath.c_str(), status);
1065 // Save to new filename (single) /skip this item (multiple)
1069 if (SelectFile(AfxGetMainWnd()->GetSafeHwnd(), s, false, strSavePath.c_str()))
1090 String CMergeApp::GetPackingErrorMessage(int pane, int paneCount, const String& path, const String& pluginName)
1092 return strutils::format_string2(
1094 _("Plugin '%2' cannot pack your changes to the left file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?")
1095 : (pane == paneCount - 1) ?
1096 _("Plugin '%2' cannot pack your changes to the right file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?")
1097 : _("Plugin '%2' cannot pack your changes to the middle file back into '%1'.\n\nThe original file will not be changed.\n\nDo you want to save the unpacked version to another file?"),
1102 * @brief Is specified file a project file?
1103 * @param [in] filepath Full path to file to check.
1104 * @return true if file is a projectfile.
1106 bool CMergeApp::IsProjectFile(const String& filepath) const
1109 paths::SplitFilename(filepath, nullptr, nullptr, &ext);
1110 if (strutils::compare_nocase(ext, ProjectFile::PROJECTFILE_EXT) == 0)
1116 bool CMergeApp::LoadProjectFile(const String& sProject, ProjectFile &project)
1118 if (sProject.empty())
1123 project.Read(sProject);
1125 catch (Poco::Exception& e)
1127 String sErr = _("Unknown error attempting to open project file.");
1128 sErr += ucr::toTString(e.displayText());
1129 String msg = strutils::format_string2(_("Cannot open file\n%1\n\n%2"), sProject, sErr);
1130 AfxMessageBox(msg.c_str(), MB_ICONSTOP);
1137 bool CMergeApp::SaveProjectFile(const String& sProject, const ProjectFile &project)
1141 project.Save(sProject);
1143 catch (Poco::Exception& e)
1145 String sErr = _("Unknown error attempting to save project file.");
1146 sErr += ucr::toTString(e.displayText());
1147 String msg = strutils::format_string2(_("Cannot open file\n%1\n\n%2"), sProject, sErr);
1148 AfxMessageBox(msg.c_str(), MB_ICONSTOP);
1156 * @brief Read project and perform comparison specified
1157 * @param [in] sProject Full path to project file.
1158 * @return `true` if loading project file and starting compare succeeded.
1160 bool CMergeApp::LoadAndOpenProjectFile(const String& sProject, const String& sReportFile)
1162 ProjectFile project;
1163 if (!LoadProjectFile(sProject, project))
1167 for (auto& projItem : project.Items())
1170 bool bRecursive = false;
1171 projItem.GetPaths(tFiles, bRecursive);
1172 for (int i = 0; i < tFiles.GetSize(); ++i)
1174 if (!paths::IsPathAbsolute(tFiles[i]))
1176 String sProjectDir = paths::GetParentPath(sProject);
1177 if (tFiles[i].substr(0, 1) == _T("\\"))
1179 if (sProjectDir.length() > 1 && sProjectDir[1] == ':')
1180 tFiles[i] = paths::ConcatPath(sProjectDir.substr(0, 2), tFiles[i]);
1183 tFiles[i] = paths::ConcatPath(sProjectDir, tFiles[i]);
1186 bool bLeftReadOnly = projItem.GetLeftReadOnly();
1187 bool bMiddleReadOnly = projItem.GetMiddleReadOnly();
1188 bool bRightReadOnly = projItem.GetRightReadOnly();
1189 if (projItem.HasFilter())
1191 String filter = projItem.GetFilter();
1192 filter = strutils::trim_ws(filter);
1193 m_pGlobalFileFilter->SetFilter(filter);
1195 if (projItem.HasSubfolders())
1196 bRecursive = projItem.GetSubfolders() > 0;
1198 DWORD dwFlags[3] = {
1199 static_cast<DWORD>(tFiles.GetPath(0).empty() ? FFILEOPEN_NONE : FFILEOPEN_PROJECT),
1200 static_cast<DWORD>(tFiles.GetPath(1).empty() ? FFILEOPEN_NONE : FFILEOPEN_PROJECT),
1201 static_cast<DWORD>(tFiles.GetPath(2).empty() ? FFILEOPEN_NONE : FFILEOPEN_PROJECT)
1204 dwFlags[0] |= FFILEOPEN_READONLY;
1205 if (tFiles.GetSize() == 2)
1208 dwFlags[1] |= FFILEOPEN_READONLY;
1212 if (bMiddleReadOnly)
1213 dwFlags[1] |= FFILEOPEN_READONLY;
1215 dwFlags[2] |= FFILEOPEN_READONLY;
1218 GetOptionsMgr()->SaveOption(OPT_CMP_INCLUDE_SUBDIRS, bRecursive);
1220 rtn &= GetMainFrame()->DoFileOpen(&tFiles, dwFlags, nullptr, sReportFile, bRecursive);
1223 AddToRecentProjectsMRU(sProject.c_str());
1228 * @brief Return windows language ID of current WinMerge GUI language
1230 WORD CMergeApp::GetLangId() const
1232 return m_pLangDlg->GetLangId();
1236 * @brief Lang aware version of CStatusBar::SetIndicators()
1238 void CMergeApp::SetIndicators(CStatusBar &sb, const UINT *rgid, int n) const
1240 m_pLangDlg->SetIndicators(sb, rgid, n);
1244 * @brief Translate menu to current WinMerge GUI language
1246 void CMergeApp::TranslateMenu(HMENU h) const
1248 m_pLangDlg->TranslateMenu(h);
1252 * @brief Translate dialog to current WinMerge GUI language
1254 void CMergeApp::TranslateDialog(HWND h) const
1256 CWnd *pWnd = CWnd::FromHandle(h);
1257 pWnd->SetFont(const_cast<CFont *>(&m_fontGUI));
1258 pWnd->SendMessageToDescendants(WM_SETFONT, (WPARAM)m_fontGUI.m_hObject, MAKELPARAM(FALSE, 0), TRUE);
1260 m_pLangDlg->TranslateDialog(h);
1264 * @brief Load string and translate to current WinMerge GUI language
1266 String CMergeApp::LoadString(UINT id) const
1268 return m_pLangDlg->LoadString(id);
1271 bool CMergeApp::TranslateString(const std::string& str, String& translated_str) const
1273 return m_pLangDlg->TranslateString(str, translated_str);
1277 * @brief Load dialog caption and translate to current WinMerge GUI language
1279 std::wstring CMergeApp::LoadDialogCaption(LPCTSTR lpDialogTemplateID) const
1281 return m_pLangDlg->LoadDialogCaption(lpDialogTemplateID);
1285 * @brief Adds specified file to the recent projects list.
1286 * @param [in] sPathName Path to project file
1288 void CMergeApp::AddToRecentProjectsMRU(LPCTSTR sPathName)
1290 // sPathName will be added to the top of the MRU list.
1291 // If sPathName already exists in the MRU list, it will be moved to the top
1292 if (m_pRecentFileList != nullptr) {
1293 m_pRecentFileList->Add(sPathName);
1294 m_pRecentFileList->WriteList();
1298 void CMergeApp::SetupTempPath()
1300 String instTemp = env::GetPerInstanceString(TempFolderPrefix);
1301 if (GetOptionsMgr()->GetBool(OPT_USE_SYSTEM_TEMP_PATH))
1302 env::SetTemporaryPath(paths::ConcatPath(env::GetSystemTempPath(), instTemp));
1304 env::SetTemporaryPath(paths::ConcatPath(GetOptionsMgr()->GetString(OPT_CUSTOM_TEMP_PATH), instTemp));
1308 * @brief Handles menu selection from recent projects list
1309 * @param [in] nID Menu ID of the selected item
1311 BOOL CMergeApp::OnOpenRecentFile(UINT nID)
1313 return LoadAndOpenProjectFile(static_cast<const TCHAR *>(m_pRecentFileList->m_arrNames[nID-ID_FILE_PROJECT_MRU_FIRST]));
1317 * @brief Return if doc is in Merging/Editing mode
1319 bool CMergeApp::GetMergingMode() const
1321 return m_bMergingMode;
1325 * @brief Set doc to Merging/Editing mode
1327 void CMergeApp::SetMergingMode(bool bMergingMode)
1329 m_bMergingMode = bMergingMode;
1330 GetOptionsMgr()->SaveOption(OPT_MERGE_MODE, m_bMergingMode);
1334 * @brief Switch Merging/Editing mode and update
1335 * buffer read-only states accordingly
1337 void CMergeApp::OnMergingMode()
1339 bool bMergingMode = GetMergingMode();
1342 LangMessageBox(IDS_MERGE_MODE, MB_ICONINFORMATION | MB_DONT_DISPLAY_AGAIN);
1343 SetMergingMode(!bMergingMode);
1347 * @brief Update Menuitem for Merging Mode
1349 void CMergeApp::OnUpdateMergingMode(CCmdUI* pCmdUI)
1351 pCmdUI->Enable(true);
1352 pCmdUI->SetCheck(GetMergingMode());
1356 * @brief Update MergingMode UI in statusbar
1358 void CMergeApp::OnUpdateMergingStatus(CCmdUI *pCmdUI)
1360 String text = theApp.LoadString(IDS_MERGEMODE_MERGING);
1361 pCmdUI->SetText(text.c_str());
1362 pCmdUI->Enable(GetMergingMode());
1365 UINT CMergeApp::GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault)
1367 COptionsMgr *pOptions = GetOptionsMgr();
1368 String name = strutils::format(_T("%s/%s"), lpszSection, lpszEntry);
1369 if (!pOptions->Get(name).IsInt())
1370 pOptions->InitOption(name, nDefault);
1371 return pOptions->GetInt(name);
1374 BOOL CMergeApp::WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue)
1376 COptionsMgr *pOptions = GetOptionsMgr();
1377 String name = strutils::format(_T("%s/%s"), lpszSection, lpszEntry);
1378 if (!pOptions->Get(name).IsInt())
1379 pOptions->InitOption(name, nValue);
1380 return pOptions->SaveOption(name, nValue) == COption::OPT_OK;
1383 CString CMergeApp::GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault)
1385 COptionsMgr *pOptions = GetOptionsMgr();
1386 String name = strutils::format(_T("%s/%s"), lpszSection, lpszEntry);
1387 if (!pOptions->Get(name).IsString())
1388 pOptions->InitOption(name, lpszDefault ? lpszDefault : _T(""));
1389 return pOptions->GetString(name).c_str();
1392 BOOL CMergeApp::WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue)
1394 COptionsMgr *pOptions = GetOptionsMgr();
1395 if (lpszEntry != nullptr)
1397 String name = strutils::format(_T("%s/%s"), lpszSection, lpszEntry);
1398 if (!pOptions->Get(name).IsString())
1399 pOptions->InitOption(name, lpszValue ? lpszValue : _T(""));
1400 return pOptions->SaveOption(name, lpszValue ? lpszValue : _T("")) == COption::OPT_OK;
1404 String name = strutils::format(_T("%s/"), lpszSection);
1405 pOptions->RemoveOption(name);