Browse Source

LastUpdateException counter

Source commit: d102d4207a1755727b37fa5c47b45423862364c7
Martin Prikryl 9 years ago
parent
commit
fc6215b681

+ 15 - 0
source/core/Exceptions.cpp

@@ -212,6 +212,21 @@ TStrings * __fastcall ExceptionToMoreMessages(Exception * E)
   return Result;
 }
 //---------------------------------------------------------------------------
+bool __fastcall ExceptionFullMessage(Exception * E, UnicodeString & Message)
+{
+  bool Result = ExceptionMessage(E, Message);
+  if (Result)
+  {
+    Message += L"\n";
+    ExtException * EE = dynamic_cast<ExtException *>(E);
+    if ((EE != NULL) && (EE->MoreMessages != NULL))
+    {
+      Message += EE->MoreMessages->Text + L"\n";
+    }
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 UnicodeString __fastcall GetExceptionHelpKeyword(Exception * E)
 {
   UnicodeString HelpKeyword;

+ 1 - 0
source/core/Exceptions.h

@@ -10,6 +10,7 @@
 bool __fastcall ShouldDisplayException(Exception * E);
 bool __fastcall ExceptionMessage(Exception * E, UnicodeString & Message);
 bool __fastcall ExceptionMessageFormatted(Exception * E, UnicodeString & Message);
+bool __fastcall ExceptionFullMessage(Exception * E, UnicodeString & Message);
 UnicodeString __fastcall SysErrorMessageForError(int LastError);
 UnicodeString __fastcall LastSysErrorMessage();
 TStrings * __fastcall ExceptionToMoreMessages(Exception * E);

+ 12 - 5
source/core/Usage.cpp

@@ -10,6 +10,7 @@
 #pragma package(smart_init)
 //---------------------------------------------------------------------------
 const UnicodeString LastInternalExceptionCounter(L"LastInternalException2");
+const UnicodeString LastUpdateExceptionCounter(L"LastUpdateException");
 //---------------------------------------------------------------------------
 __fastcall TUsage::TUsage(TConfiguration * Configuration)
 {
@@ -162,7 +163,7 @@ void __fastcall TUsage::Reset()
   TGuard Guard(FCriticalSection);
   UpdateLastReport();
   FPeriodCounters.clear();
-  ResetLastInternalException();
+  ResetLastExceptions();
 }
 //---------------------------------------------------------------------------
 void __fastcall TUsage::UpdateCurrentVersion()
@@ -187,22 +188,28 @@ void __fastcall TUsage::UpdateCurrentVersion()
 
     if (PrevVersion != CompoundVersion)
     {
-      ResetLastInternalException();
+      ResetLastExceptions();
     }
   }
   Set(L"CurrentVersion", CompoundVersion);
 }
 //---------------------------------------------------------------------------
-void __fastcall TUsage::ResetLastInternalException()
+void __fastcall TUsage::ResetValue(const UnicodeString & Key)
 {
-  TGuard Guard(FCriticalSection);
-  int Index = FValues->IndexOfName(LastInternalExceptionCounter);
+  int Index = FValues->IndexOfName(Key);
   if (Index >= 0)
   {
     FValues->Delete(Index);
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TUsage::ResetLastExceptions()
+{
+  TGuard Guard(FCriticalSection);
+  ResetValue(LastInternalExceptionCounter);
+  ResetValue(LastUpdateExceptionCounter);
+}
+//---------------------------------------------------------------------------
 void __fastcall TUsage::Inc(const UnicodeString & Key, int Increment)
 {
   if (Collect)

+ 3 - 1
source/core/Usage.h

@@ -51,9 +51,11 @@ private:
   void __fastcall SetMax(const UnicodeString & Key, int Value, TCounters & Counters);
   void __fastcall Serialize(UnicodeString& List,
     const UnicodeString & Name, const TCounters & Counters) const;
-  void __fastcall ResetLastInternalException();
+  void __fastcall ResetLastExceptions();
+  void __fastcall ResetValue(const UnicodeString & Key);
 };
 //---------------------------------------------------------------------------
 extern const UnicodeString LastInternalExceptionCounter;
+extern const UnicodeString LastUpdateExceptionCounter;
 //---------------------------------------------------------------------------
 #endif

+ 2 - 17
source/windows/ConsoleRunner.cpp

@@ -39,21 +39,6 @@ void TrimNewLine(UnicodeString & Str)
   }
 }
 //---------------------------------------------------------------------------
-static bool __fastcall ExceptionConsoleMessage(Exception * E, UnicodeString & Message)
-{
-  bool Result = ExceptionMessage(E, Message);
-  if (Result)
-  {
-    Message += L"\n";
-    ExtException * EE = dynamic_cast<ExtException *>(E);
-    if ((EE != NULL) && (EE->MoreMessages != NULL))
-    {
-      Message += EE->MoreMessages->Text + L"\n";
-    }
-  }
-  return Result;
-}
-//---------------------------------------------------------------------------
 class TConsole
 {
 public:
@@ -1796,7 +1781,7 @@ void __fastcall TConsoleRunner::DoShowException(TTerminal * Terminal, Exception
   }
 
   UnicodeString Message;
-  if (ExceptionConsoleMessage(E, Message))
+  if (ExceptionFullMessage(E, Message))
   {
     FCommandError = true;
     PrintMessage(Message);
@@ -2293,7 +2278,7 @@ void __fastcall BatchSettings(TConsole * Console, TProgramParams * Params)
 static int __fastcall HandleException(TConsole * Console, Exception & E)
 {
   UnicodeString Message;
-  if (ExceptionConsoleMessage(&E, Message))
+  if (ExceptionFullMessage(&E, Message))
   {
     Console->Print(Message);
   }

+ 5 - 0
source/windows/Setup.cpp

@@ -1085,6 +1085,11 @@ static void __fastcall DoQueryUpdates(bool CollectUsage)
   catch(Exception & E)
   {
     Configuration->Usage->Inc(L"UpdateChecksFailed");
+    UnicodeString Message;
+    if (DebugAlwaysTrue(ExceptionFullMessage(&E, Message)))
+    {
+      Configuration->Usage->Set(LastUpdateExceptionCounter, Message);
+    }
     throw ExtException(&E, MainInstructions(LoadStr(CHECK_FOR_UPDATES_ERROR)));
   }
 }