misc/libphysfs/lzma/CPP/7zip/UI/Console/ConsoleClose.cpp
changeset 13904 99b265e0d1d0
parent 13903 5f819b90d479
child 13905 b172a5d40eee
equal deleted inserted replaced
13903:5f819b90d479 13904:99b265e0d1d0
     1 // ConsoleClose.cpp
       
     2 
       
     3 #include "StdAfx.h"
       
     4 
       
     5 #include "ConsoleClose.h"
       
     6 
       
     7 static int g_BreakCounter = 0;
       
     8 static const int kBreakAbortThreshold = 2;
       
     9 
       
    10 namespace NConsoleClose {
       
    11 
       
    12 static BOOL WINAPI HandlerRoutine(DWORD ctrlType)
       
    13 {
       
    14   if (ctrlType == CTRL_LOGOFF_EVENT)
       
    15   {
       
    16     // printf("\nCTRL_LOGOFF_EVENT\n");
       
    17     return TRUE;
       
    18   }
       
    19 
       
    20   g_BreakCounter++;
       
    21   if (g_BreakCounter < kBreakAbortThreshold)
       
    22     return TRUE;
       
    23   return FALSE;
       
    24   /*
       
    25   switch(ctrlType)
       
    26   {
       
    27     case CTRL_C_EVENT:
       
    28     case CTRL_BREAK_EVENT:
       
    29       if (g_BreakCounter < kBreakAbortThreshold)
       
    30       return TRUE;
       
    31   }
       
    32   return FALSE;
       
    33   */
       
    34 }
       
    35 
       
    36 bool TestBreakSignal()
       
    37 {
       
    38   /*
       
    39   if (g_BreakCounter > 0)
       
    40     return true;
       
    41   */
       
    42   return (g_BreakCounter > 0);
       
    43 }
       
    44 
       
    45 void CheckCtrlBreak()
       
    46 {
       
    47   if (TestBreakSignal())
       
    48     throw CCtrlBreakException();
       
    49 }
       
    50 
       
    51 CCtrlHandlerSetter::CCtrlHandlerSetter()
       
    52 {
       
    53   if(!SetConsoleCtrlHandler(HandlerRoutine, TRUE))
       
    54     throw "SetConsoleCtrlHandler fails";
       
    55 }
       
    56 
       
    57 CCtrlHandlerSetter::~CCtrlHandlerSetter()
       
    58 {
       
    59   if(!SetConsoleCtrlHandler(HandlerRoutine, FALSE))
       
    60     throw "SetConsoleCtrlHandler fails";
       
    61 }
       
    62 
       
    63 }