FIX: Crash on start with corrupted doublecmd.xml (issue #2430)

(cherry picked from commit d1623e070d)
This commit is contained in:
Alexander Koblov 2025-07-31 18:16:28 +03:00
commit aa16eef676
2 changed files with 28 additions and 8 deletions

View file

@ -195,6 +195,7 @@ begin
LoadWindowsSpecialDir; // Load the list with special path. *Must* be located AFTER "LoadPaths" and BEFORE "InitGlobs"
if InitGlobs then
begin
//-- NOTE: before, only IsInstanceAllowed was called, and all the magic on creation
// new instance or sending params to the existing server happened inside
// IsInstanceAllowed() function as a side effect.
@ -238,7 +239,7 @@ begin
begin
DCDebug('Another instance of DC is already running. Exiting.');
end;
end;
uKeyboard.CleanupKeyboard;
DCDebug('Finished Double Commander');
end.

View file

@ -742,7 +742,7 @@ uses
uGlobsPaths, uLng, uShowMsg, uFileProcs, uOSUtils, uFindFiles, uEarlyConfig,
dmHigh, uDCUtils, fMultiRename, uDCVersion, uDebug, uFileFunctions,
uDefaultPlugins, Lua, uKeyboard, DCOSUtils, DCStrUtils, uPixMapManager,
FileUtil, uSynDiffControls
FileUtil, uSynDiffControls, InterfaceBase
{$IF DEFINED(MSWINDOWS)}
, ShlObj
{$ENDIF}
@ -843,14 +843,30 @@ begin
end;
function AskUserOnError(var ErrorMessage: String): Boolean;
var
Button: TDialogButton;
Buttons: TDialogButtons;
begin
// Show error messages.
if ErrorMessage <> EmptyStr then
begin
Result := QuestionDlg(Application.Title + ' - ' + rsMsgErrorLoadingConfiguration,
ErrorMessage, mtWarning,
[1, rsDlgButtonContinue, 'isdefault',
2, rsDlgButtonExitProgram], 0) = 1;
Buttons:= TDialogButtons.Create(TDialogButton);
try
Button:= Buttons.Add;
Button.Default:= True;
Button.ModalResult:= mrOK;
Button.Caption:= rsDlgButtonContinue;
Button:= Buttons.Add;
Button.Cancel:= True;
Button.ModalResult:= mrAbort;
Button.Caption:= rsDlgButtonExitProgram;
Result := DefaultQuestionDialog(Application.Title + ' - ' + rsMsgErrorLoadingConfiguration,
ErrorMessage, idDialogWarning, Buttons, 0) = mrOK;
finally
Buttons.Free;
end;
// Reset error message.
ErrorMessage := '';
end
@ -2267,8 +2283,11 @@ begin
begin
if mbFileAccess(gpGlobalCfgDir + 'doublecmd.xml', fmOpenRead or fmShareDenyWrite) then
begin
LoadConfigCheckErrors(@LoadGlobalConfig, gpGlobalCfgDir + 'doublecmd.xml', ErrorMessage);
if gConfig.TryGetValue(gConfig.RootNode, 'Configuration/UseConfigInProgramDir', gUseConfigInProgramDir) then
if not LoadConfigCheckErrors(@LoadGlobalConfig, gpGlobalCfgDir + 'doublecmd.xml', ErrorMessage) then
begin
if not gUseConfigInProgramDir then ErrorMessage := EmptyStr;
end
else if gConfig.TryGetValue(gConfig.RootNode, 'Configuration/UseConfigInProgramDir', gUseConfigInProgramDir) then
begin
gConfig.DeleteNode(gConfig.RootNode, 'Configuration/UseConfigInProgramDir');
if not gUseConfigInProgramDir then