Browse Source

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

Alexander Koblov 1 month ago
parent
commit
d1623e070d
2 changed files with 28 additions and 8 deletions
  1. 2 1
      src/doublecmd.lpr
  2. 26 7
      src/uglobs.pas

+ 2 - 1
src/doublecmd.lpr

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

+ 26 - 7
src/uglobs.pas

@@ -750,7 +750,7 @@ uses
    uGlobsPaths, uLng, uShowMsg, uFileProcs, uOSUtils, uFindFiles, uEarlyConfig,
    uGlobsPaths, uLng, uShowMsg, uFileProcs, uOSUtils, uFindFiles, uEarlyConfig,
    dmHigh, uDCUtils, fMultiRename, uDCVersion, uDebug, uFileFunctions,
    dmHigh, uDCUtils, fMultiRename, uDCVersion, uDebug, uFileFunctions,
    uDefaultPlugins, Lua, uKeyboard, DCOSUtils, DCStrUtils, uPixMapManager,
    uDefaultPlugins, Lua, uKeyboard, DCOSUtils, DCStrUtils, uPixMapManager,
-   FileUtil, uSynDiffControls
+   FileUtil, uSynDiffControls, InterfaceBase
    {$IF DEFINED(MSWINDOWS)}
    {$IF DEFINED(MSWINDOWS)}
     , ShlObj
     , ShlObj
    {$ENDIF}
    {$ENDIF}
@@ -853,14 +853,30 @@ begin
 end;
 end;
 
 
 function AskUserOnError(var ErrorMessage: String): Boolean;
 function AskUserOnError(var ErrorMessage: String): Boolean;
+var
+  Button: TDialogButton;
+  Buttons: TDialogButtons;
 begin
 begin
   // Show error messages.
   // Show error messages.
   if ErrorMessage <> EmptyStr then
   if ErrorMessage <> EmptyStr then
   begin
   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.
     // Reset error message.
     ErrorMessage := '';
     ErrorMessage := '';
   end
   end
@@ -2304,8 +2320,11 @@ begin
       begin
       begin
         if mbFileAccess(gpGlobalCfgDir + 'doublecmd.xml', fmOpenRead or fmShareDenyWrite) then
         if mbFileAccess(gpGlobalCfgDir + 'doublecmd.xml', fmOpenRead or fmShareDenyWrite) then
         begin
         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
           begin
             gConfig.DeleteNode(gConfig.RootNode, 'Configuration/UseConfigInProgramDir');
             gConfig.DeleteNode(gConfig.RootNode, 'Configuration/UseConfigInProgramDir');
             if not gUseConfigInProgramDir then
             if not gUseConfigInProgramDir then