Selaa lähdekoodia

Do not consider "out of memory" error if user loads too large file, despite being warned, as an internal error

Source commit: 645a1eece6f4c48d4d97d663aa9d0da64dbd632a
Martin Prikryl 9 vuotta sitten
vanhempi
sitoutus
0028f4da63
3 muutettua tiedostoa jossa 44 lisäystä ja 10 poistoa
  1. 32 1
      source/core/Exceptions.cpp
  2. 1 0
      source/core/Interface.h
  3. 11 9
      source/forms/Editor.cpp

+ 32 - 1
source/core/Exceptions.cpp

@@ -9,9 +9,27 @@
 #include "Configuration.h"
 #include "CoreMain.h"
 #include "Interface.h"
+#include <StrUtils.hpp>
 //---------------------------------------------------------------------------
 #pragma package(smart_init)
 //---------------------------------------------------------------------------
+static std::unique_ptr<TCriticalSection> IgnoredExceptionsCriticalSection(new TCriticalSection());
+typedef std::set<UnicodeString> TIgnoredExceptions;
+static TIgnoredExceptions IgnoredExceptions;
+//---------------------------------------------------------------------------
+static UnicodeString __fastcall NormalizeClassName(const UnicodeString & ClassName)
+{
+  return ReplaceStr(ClassName, L".", L"::").LowerCase();
+}
+//---------------------------------------------------------------------------
+void __fastcall IgnoreException(const std::type_info & ExceptionType)
+{
+  TGuard Guard(IgnoredExceptionsCriticalSection.get());
+  // We should better use type_index as a key, instead of a class name,
+  // but type_index is not available in 32-bit version of STL in XE6.
+  IgnoredExceptions.insert(NormalizeClassName(UnicodeString(AnsiString(ExceptionType.name()))));
+}
+//---------------------------------------------------------------------------
 static bool __fastcall WellKnownException(
   Exception * E, UnicodeString * AMessage, const wchar_t ** ACounterName, Exception ** AClone, bool Rethrow)
 {
@@ -19,10 +37,23 @@ static bool __fastcall WellKnownException(
   const wchar_t * CounterName;
   std::unique_ptr<Exception> Clone;
 
+
   bool Result = true;
+  bool IgnoreException;
+
+  if (!IgnoredExceptions.empty())
+  {
+    TGuard Guard(IgnoredExceptionsCriticalSection.get());
+    UnicodeString ClassName = NormalizeClassName(E->QualifiedClassName());
+    IgnoreException = (IgnoredExceptions.find(ClassName) != IgnoredExceptions.end());
+  }
 
+  if (IgnoreException)
+  {
+    Result = false;
+  }
   // EAccessViolation is EExternal
-  if (dynamic_cast<EAccessViolation*>(E) != NULL)
+  else if (dynamic_cast<EAccessViolation*>(E) != NULL)
   {
     if (Rethrow)
     {

+ 1 - 0
source/core/Interface.h

@@ -32,6 +32,7 @@ TOptions * __fastcall GetGlobalOptions();
 
 void __fastcall ShowExtendedException(Exception * E);
 bool __fastcall AppendExceptionStackTraceAndForget(TStrings *& MoreMessages);
+void __fastcall IgnoreException(const std::type_info & ExceptionType);
 
 UnicodeString __fastcall GetCompanyRegistryKey();
 UnicodeString __fastcall GetRegistryKey();

+ 11 - 9
source/forms/Editor.cpp

@@ -1343,16 +1343,16 @@ void __fastcall TEditorForm::CheckFileSize()
 {
   TEditorConfiguration EditorConfiguration = WinConfiguration->Editor;
 
-  if (EditorConfiguration.WarnOrLargeFileSize)
-  {
-    TWin32FileAttributeData FileAttributeData;
-    if (GetFileAttributesEx(ApiPath(FFileName).c_str(), GetFileExInfoStandard, &FileAttributeData))
+  TWin32FileAttributeData FileAttributeData;
+  if (GetFileAttributesEx(ApiPath(FFileName).c_str(), GetFileExInfoStandard, &FileAttributeData))
+  {
+    const __int64 MaxSize = 100 * 1024 * 1024;
+    __int64 Size =
+      (static_cast<__int64>(FileAttributeData.nFileSizeHigh) << 32) +
+      FileAttributeData.nFileSizeLow;
+    if (Size > MaxSize)
     {
-      const __int64 MaxSize = 100 * 1024 * 1024;
-      __int64 Size =
-        (static_cast<__int64>(FileAttributeData.nFileSizeHigh) << 32) +
-        FileAttributeData.nFileSizeLow;
-      if (Size > MaxSize)
+      if (EditorConfiguration.WarnOrLargeFileSize)
       {
         TMessageParams Params(mpNeverAskAgainCheck);
         unsigned int Answer =
@@ -1378,6 +1378,8 @@ void __fastcall TEditorForm::CheckFileSize()
             DebugFail();
         }
       }
+
+      IgnoreException(typeid(EOutOfMemory));
     }
   }
 }