other-licenses/7zstub/src/7zip/FileManager/Resource/ProgressDialog/ProgressDialog.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 // ProgressDialog.h
     3 #ifndef __PROGRESSDIALOG_H
     4 #define __PROGRESSDIALOG_H
     6 #include "resource.h"
     8 #include "Windows/Control/Dialog.h"
     9 #include "Windows/Control/ProgressBar.h"
    10 #include "Windows/Synchronization.h"
    12 class CProgressSynch
    13 {
    14   NWindows::NSynchronization::CCriticalSection _criticalSection;
    15   bool _stopped;
    16   bool _paused;
    17   UINT64 _total;
    18   UINT64 _completed;
    19 public:
    20   CProgressSynch(): _stopped(false), _paused(false), _total(1), _completed(0) {}
    22   bool GetStopped()
    23   {
    24     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    25     return _stopped;
    26   }
    27   void SetStopped(bool value)
    28   {
    29     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    30     _stopped = value;
    31   }
    32   bool GetPaused()
    33   {
    34     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    35     return _paused;
    36   }
    37   void SetPaused(bool value)
    38   {
    39     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    40     _paused = value;
    41   }
    42   void SetProgress(UINT64 total, UINT64 completed)
    43   {
    44     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    45     _total = total;
    46     _completed = completed;
    47   }
    48   void SetPos(UINT64 completed)
    49   {
    50     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    51     _completed = completed;
    52   }
    53   void GetProgress(UINT64 &total, UINT64 &completed)
    54   {
    55     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
    56     total = _total;
    57     completed = _completed;
    58   }
    59 };
    61 class CU64ToI32Converter
    62 {
    63   UINT64 _numShiftBits;
    64 public:
    65   void Init(UINT64 _range);
    66   int Count(UINT64 aValue);
    67 };
    69 // class CProgressDialog: public NWindows::NControl::CModelessDialog
    71 class CProgressDialog: public NWindows::NControl::CModalDialog
    72 {
    73 private:
    74   UINT_PTR _timer;
    76   UString _title;
    77   CU64ToI32Converter _converter;
    78   UINT64 _peviousPos;
    79   UINT64 _range;
    80 	NWindows::NControl::CProgressBar m_ProgressBar;
    82   int _prevPercentValue;
    84   bool OnTimer(WPARAM timerID, LPARAM callback);
    85   void SetRange(UINT64 range);
    86   void SetPos(UINT64 pos);
    87 	virtual bool OnInit();
    88 	virtual void OnCancel();
    89   NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent;
    90   #ifndef _SFX
    91   void AddToTitle(LPCWSTR string);
    92   #endif
    93   bool OnButtonClicked(int buttonID, HWND buttonHWND);
    94 public:
    95   CProgressSynch ProgressSynch;
    97   #ifndef _SFX
    98   HWND MainWindow;
    99   UString MainTitle;
   100   UString MainAddTitle;
   101   ~CProgressDialog();
   102   #endif
   104   CProgressDialog(): _timer(0)
   105     #ifndef _SFX
   106     ,MainWindow(0) 
   107     #endif
   108   {}
   110   void WaitCreating() { _dialogCreatedEvent.Lock(); }
   113   INT_PTR Create(const UString &title, HWND wndParent = 0)
   114   { 
   115     _title = title;
   116     return CModalDialog::Create(IDD_DIALOG_PROGRESS, wndParent); 
   117   }
   119   static const UINT kCloseMessage;
   121   virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
   123   void MyClose()
   124   {
   125     PostMessage(kCloseMessage);
   126   };
   127 };
   129 #endif

mercurial