Explorar o código

Bug fix: Errors while mass-modifying sites were displayed in message box instead of console window

Source commit: f37b0c95dd58fdc65a32d5486422eb9303ecef58
Martin Prikryl %!s(int64=6) %!d(string=hai) anos
pai
achega
e689da0b44
Modificáronse 1 ficheiros con 55 adicións e 42 borrados
  1. 55 42
      source/windows/ConsoleRunner.cpp

+ 55 - 42
source/windows/ConsoleRunner.cpp

@@ -2288,65 +2288,78 @@ void __fastcall Usage(TConsole * Console)
   Console->WaitBeforeExit();
 }
 //---------------------------------------------------------------------------
-void __fastcall BatchSettings(TConsole * Console, TProgramParams * Params)
+int __fastcall HandleException(TConsole * Console, Exception & E)
 {
-  std::unique_ptr<TStrings> Arguments(new TStringList());
-  if (DebugAlwaysTrue(Params->FindSwitch(L"batchsettings", Arguments.get())))
+  UnicodeString Message;
+  if (ExceptionFullMessage(&E, Message))
   {
-    if (Arguments->Count < 1)
-    {
-      Console->PrintLine(LoadStr(BATCH_SET_NO_MASK));
-    }
-    else if (Arguments->Count < 2)
+    Console->Print(Message);
+  }
+  return RESULT_ANY_ERROR;
+}
+//---------------------------------------------------------------------------
+int __fastcall BatchSettings(TConsole * Console, TProgramParams * Params)
+{
+  int Result = RESULT_SUCCESS;
+  try
+  {
+    std::unique_ptr<TStrings> Arguments(new TStringList());
+    if (!DebugAlwaysTrue(Params->FindSwitch(L"batchsettings", Arguments.get())))
     {
-      Console->PrintLine(LoadStr(BATCH_SET_NO_SETTINGS));
+      Abort();
     }
     else
     {
-      TFileMasks Mask(Arguments->Strings[0]);
-      Arguments->Delete(0);
+      if (Arguments->Count < 1)
+      {
+        throw Exception(LoadStr(BATCH_SET_NO_MASK));
+      }
+      else if (Arguments->Count < 2)
+      {
+        throw Exception(LoadStr(BATCH_SET_NO_SETTINGS));
+      }
+      else
+      {
+        TFileMasks Mask(Arguments->Strings[0]);
+        Arguments->Delete(0);
 
-      std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Arguments.get(), false));
+        std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(Arguments.get(), false));
 
-      int Matches = 0;
-      int Changes = 0;
+        int Matches = 0;
+        int Changes = 0;
 
-      for (int Index = 0; Index < StoredSessions->Count; Index++)
-      {
-        TSessionData * Data = StoredSessions->Sessions[Index];
-        if (!Data->IsWorkspace &&
-            Mask.Matches(Data->Name, false, false))
+        for (int Index = 0; Index < StoredSessions->Count; Index++)
         {
-          Matches++;
-          std::unique_ptr<TSessionData> OriginalData(new TSessionData(L""));
-          OriginalData->Assign(Data);
-          Data->ApplyRawSettings(OptionsStorage.get());
-          bool Changed = !OriginalData->IsSame(Data, false);
-          if (Changed)
+          TSessionData * Data = StoredSessions->Sessions[Index];
+          if (!Data->IsWorkspace &&
+              Mask.Matches(Data->Name, false, false))
           {
-            Changes++;
+            Matches++;
+            std::unique_ptr<TSessionData> OriginalData(new TSessionData(L""));
+            OriginalData->Assign(Data);
+            Data->ApplyRawSettings(OptionsStorage.get());
+            bool Changed = !OriginalData->IsSame(Data, false);
+            if (Changed)
+            {
+              Changes++;
+            }
+            UnicodeString StateStr = LoadStr(Changed ? BATCH_SET_CHANGED : BATCH_SET_NOT_CHANGED);
+            Console->PrintLine(FORMAT(L"%s - %s", (Data->Name, StateStr)));
           }
-          UnicodeString StateStr = LoadStr(Changed ? BATCH_SET_CHANGED : BATCH_SET_NOT_CHANGED);
-          Console->PrintLine(FORMAT(L"%s - %s", (Data->Name, StateStr)));
         }
-      }
 
-      StoredSessions->Save(false, true); // explicit
-      Console->PrintLine(FMTLOAD(BATCH_SET_SUMMARY, (Matches, Changes)));
+        StoredSessions->Save(false, true); // explicit
+        Console->PrintLine(FMTLOAD(BATCH_SET_SUMMARY, (Matches, Changes)));
+      }
     }
-
-    Console->WaitBeforeExit();
   }
-}
-//---------------------------------------------------------------------------
-int __fastcall HandleException(TConsole * Console, Exception & E)
-{
-  UnicodeString Message;
-  if (ExceptionFullMessage(&E, Message))
+  catch (Exception & E)
   {
-    Console->Print(Message);
+    Result = HandleException(Console, E);
   }
-  return RESULT_ANY_ERROR;
+
+  Console->WaitBeforeExit();
+  return Result;
 }
 //---------------------------------------------------------------------------
 bool __fastcall FindPuttygenCompatibleSwitch(
@@ -2683,7 +2696,7 @@ int __fastcall Console(TConsoleMode Mode)
       if (CheckSafe(Params))
       {
         Configuration->Usage->Inc(L"BatchSettings");
-        BatchSettings(Console, Params);
+        Result = BatchSettings(Console, Params);
       }
     }
     else if (Mode == cmKeyGen)