• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Panel.h
2 
3 #ifndef ZIP7_INC_PANEL_H
4 #define ZIP7_INC_PANEL_H
5 
6 #include "../../../Common/MyWindows.h"
7 
8 #if defined(__MINGW32__) || defined(__MINGW64__)
9 #include <shlobj.h>
10 #else
11 #include <ShlObj.h>
12 #endif
13 
14 #include "../../../../C/Alloc.h"
15 
16 #include "../../../Common/Defs.h"
17 #include "../../../Common/MyCom.h"
18 
19 #include "../../../Windows/DLL.h"
20 #include "../../../Windows/FileDir.h"
21 #include "../../../Windows/FileFind.h"
22 #include "../../../Windows/FileName.h"
23 #include "../../../Windows/Handle.h"
24 #include "../../../Windows/PropVariantConv.h"
25 #include "../../../Windows/Synchronization.h"
26 
27 #include "../../../Windows/Control/ComboBox.h"
28 #include "../../../Windows/Control/Edit.h"
29 #include "../../../Windows/Control/ListView.h"
30 #include "../../../Windows/Control/ReBar.h"
31 #include "../../../Windows/Control/Static.h"
32 #include "../../../Windows/Control/StatusBar.h"
33 #include "../../../Windows/Control/ToolBar.h"
34 #include "../../../Windows/Control/Window2.h"
35 
36 #include "../../Archive/IArchive.h"
37 
38 #include "ExtractCallback.h"
39 
40 #include "AppState.h"
41 #include "IFolder.h"
42 #include "MyCom2.h"
43 #include "ProgressDialog2.h"
44 #include "SysIconUtils.h"
45 
46 #ifdef UNDER_CE
47 #define NON_CE_VAR(_v_)
48 #else
49 #define NON_CE_VAR(_v_) _v_
50 #endif
51 
52 const int kParentFolderID = 100;
53 
54 const unsigned kParentIndex = (unsigned)(int)-1;
55 const UInt32 kParentIndex_UInt32 = (UInt32)(Int32)kParentIndex;
56 
57 #if !defined(_WIN32) || defined(UNDER_CE)
58 #define ROOT_FS_FOLDER L"\\"
59 #else
60 #define ROOT_FS_FOLDER L"C:\\"
61 #endif
62 
63 #if !defined(Z7_WIN32_WINNT_MIN) || Z7_WIN32_WINNT_MIN < 0x0500  // < win2000
64 #define Z7_USE_DYN_ComCtl32Version
65 extern DWORD g_ComCtl32Version;
66 #endif
67 
68 Z7_PURE_INTERFACES_BEGIN
69 
DECLARE_INTERFACE(CPanelCallback)70 DECLARE_INTERFACE(CPanelCallback)
71 {
72   virtual void OnTab() = 0;
73   virtual void SetFocusToPath(unsigned index) = 0;
74   virtual void OnCopy(bool move, bool copyToSame) = 0;
75   virtual void OnSetSameFolder() = 0;
76   virtual void OnSetSubFolder() = 0;
77   virtual void PanelWasFocused() = 0;
78   virtual void DragBegin() = 0;
79   virtual void DragEnd() = 0;
80   virtual void RefreshTitle(bool always) = 0;
81 };
82 Z7_PURE_INTERFACES_END
83 
84 void PanelCopyItems();
85 
86 
87 struct CPropColumn
88 {
89   int Order;
90   PROPID ID;
91   VARTYPE Type;
92   bool IsVisible;
93   bool IsRawProp;
94   UInt32 Width;
95   UString Name;
96 
IsEqualToCPropColumn97   bool IsEqualTo(const CPropColumn &a) const
98   {
99     return Order == a.Order
100         && ID == a.ID
101         && Type == a.Type
102         && IsVisible == a.IsVisible
103         && IsRawProp == a.IsRawProp
104         && Width == a.Width
105         && Name == a.Name;
106   }
107 
CompareCPropColumn108   int Compare(const CPropColumn &a) const { return MyCompare(Order, a.Order); }
109 
Compare_NameFirstCPropColumn110   int Compare_NameFirst(const CPropColumn &a) const
111   {
112     if (ID == kpidName)
113     {
114       if (a.ID != kpidName)
115         return -1;
116     }
117     else if (a.ID == kpidName)
118       return 1;
119     return MyCompare(Order, a.Order);
120   }
121 };
122 
123 
124 class CPropColumns: public CObjectVector<CPropColumn>
125 {
126 public:
FindItem_for_PropID(PROPID id)127   int FindItem_for_PropID(PROPID id) const
128   {
129     FOR_VECTOR (i, (*this))
130       if ((*this)[i].ID == id)
131         return (int)i;
132     return -1;
133   }
134 
IsEqualTo(const CPropColumns & props)135   bool IsEqualTo(const CPropColumns &props) const
136   {
137     if (Size() != props.Size())
138       return false;
139     FOR_VECTOR (i, (*this))
140       if (!(*this)[i].IsEqualTo(props[i]))
141         return false;
142     return true;
143   }
144 };
145 
146 
147 struct CTempFileInfo
148 {
149   UInt32 FileIndex;  // index of file in folder
150   UString RelPath;   // Relative path of file from Folder
151   FString FolderPath;
152   FString FilePath;
153   NWindows::NFile::NFind::CFileInfo FileInfo;
154   bool NeedDelete;
155 
CTempFileInfoCTempFileInfo156   CTempFileInfo(): FileIndex((UInt32)(Int32)-1), NeedDelete(false) {}
DeleteDirAndFileCTempFileInfo157   void DeleteDirAndFile() const
158   {
159     if (NeedDelete)
160     {
161       NWindows::NFile::NDir::DeleteFileAlways(FilePath);
162       NWindows::NFile::NDir::RemoveDir(FolderPath);
163     }
164   }
WasChangedCTempFileInfo165   bool WasChanged(const NWindows::NFile::NFind::CFileInfo &newFileInfo) const
166   {
167     return newFileInfo.Size != FileInfo.Size ||
168         CompareFileTime(&newFileInfo.MTime, &FileInfo.MTime) != 0;
169   }
170 };
171 
172 struct CFolderLink: public CTempFileInfo
173 {
174   NWindows::NDLL::CLibrary Library;
175   CMyComPtr<IFolderFolder> ParentFolder; // can be NULL, if parent is FS folder (in _parentFolders[0])
176   UString ParentFolderPath; // including tail slash (doesn't include paths parts of parent in next level)
177   bool UsePassword;
178   UString Password;
179   bool IsVirtual;
180 
181   UString VirtualPath; // without tail slash
CFolderLinkCFolderLink182   CFolderLink(): UsePassword(false), IsVirtual(false) {}
183 
WasChangedCFolderLink184   bool WasChanged(const NWindows::NFile::NFind::CFileInfo &newFileInfo) const
185   {
186     return IsVirtual || CTempFileInfo::WasChanged(newFileInfo);
187   }
188 
189 };
190 
191 enum MyMessages
192 {
193   // we can use WM_USER, since we have defined new window class.
194   // so we don't need WM_APP.
195   kShiftSelectMessage = WM_USER + 1,
196   kReLoadMessage,
197   kSetFocusToListView,
198   kOpenItemChanged,
199   kRefresh_StatusBar
200   #ifdef UNDER_CE
201   , kRefresh_HeaderComboBox
202   #endif
203 };
204 
205 UString GetFolderPath(IFolderFolder *folder);
206 
207 class CPanel;
208 
209 class CMyListView Z7_final: public NWindows::NControl::CListView2
210 {
211   // ~CMyListView() ZIP7_eq_delete;
212   // CMyListView() ZIP7_eq_delete;
213 public:
214   // CMyListView() {}
215   // ~CMyListView() Z7_DESTRUCTOR_override {} // change it
216   CPanel *_panel;
217   LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam) Z7_override;
218 };
219 
220 /*
221 class CMyComboBox: public NWindows::NControl::CComboBoxEx
222 {
223 public:
224   WNDPROC _origWindowProc;
225   CPanel *_panel;
226   LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
227 };
228 */
229 class CMyComboBoxEdit: public NWindows::NControl::CEdit
230 {
231 public:
232   WNDPROC _origWindowProc;
233   CPanel *_panel;
234   LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
235 };
236 
237 struct CSelectedState
238 {
239   int FocusedItem;
240   bool SelectFocused;
241   bool FocusedName_Defined;
242   bool CalledFromTimer;
243   UString FocusedName;
244   UStringVector SelectedNames;
245 
CSelectedStateCSelectedState246   CSelectedState():
247       FocusedItem(-1),
248       SelectFocused(true),
249       FocusedName_Defined(false),
250       CalledFromTimer(false)
251     {}
252 };
253 
254 #ifdef UNDER_CE
255 #define MY_NMLISTVIEW_NMITEMACTIVATE NMLISTVIEW
256 #else
257 #define MY_NMLISTVIEW_NMITEMACTIVATE NMITEMACTIVATE
258 #endif
259 
260 struct CCopyToOptions
261 {
262   bool streamMode;
263   bool moveMode;
264   bool testMode;
265   bool includeAltStreams;
266   bool replaceAltStreamChars;
267   bool showErrorMessages;
268 
269   bool NeedRegistryZone;
270   NExtract::NZoneIdMode::EEnum ZoneIdMode;
271 
272   UString folder;
273 
274   UStringVector hashMethods;
275 
276   CVirtFileSystem *VirtFileSystemSpec;
277   ISequentialOutStream *VirtFileSystem;
278 
CCopyToOptionsCCopyToOptions279   CCopyToOptions():
280       streamMode(false),
281       moveMode(false),
282       testMode(false),
283       includeAltStreams(true),
284       replaceAltStreamChars(false),
285       showErrorMessages(false),
286       NeedRegistryZone(true),
287       ZoneIdMode(NExtract::NZoneIdMode::kNone),
288       VirtFileSystemSpec(NULL),
289       VirtFileSystem(NULL)
290       {}
291 };
292 
293 
294 
295 struct COpenResult
296 {
297   // bool needOpenArc;
298   // out:
299   bool ArchiveIsOpened;
300   bool Encrypted;
301   UString ErrorMessage;
302 
COpenResultCOpenResult303   COpenResult():
304       // needOpenArc(false),
305       ArchiveIsOpened(false), Encrypted(false) {}
306 };
307 
308 
309 
310 
311 class CPanel Z7_final: public NWindows::NControl::CWindow2
312 {
313   CExtToIconMap _extToIconMap;
314   UINT _baseID;
315   unsigned _comboBoxID;
316   UINT _statusBarID;
317 
318   CAppState *_appState;
319 
320   virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam, LRESULT &result) Z7_override;
321   virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam) Z7_override;
322   virtual bool OnCreate(CREATESTRUCT *createStruct) Z7_override;
323   virtual bool OnSize(WPARAM wParam, int xSize, int ySize) Z7_override;
324   virtual void OnDestroy() Z7_override;
325   virtual bool OnNotify(UINT controlID, LPNMHDR lParam, LRESULT &result) Z7_override;
326 
327   void AddComboBoxItem(const UString &name, int iconIndex, int indent, bool addToList);
328 
329   bool OnComboBoxCommand(UINT code, LPARAM param, LRESULT &result);
330 
331   #ifndef UNDER_CE
332 
333   LRESULT OnNotifyComboBoxEnter(const UString &s);
334   bool OnNotifyComboBoxEndEdit(PNMCBEENDEDITW info, LRESULT &result);
335   #ifndef _UNICODE
336   bool OnNotifyComboBoxEndEdit(PNMCBEENDEDIT info, LRESULT &result);
337   #endif
338 
339   #endif
340 
341   bool OnNotifyReBar(LPNMHDR lParam, LRESULT &result);
342   bool OnNotifyComboBox(LPNMHDR lParam, LRESULT &result);
343   void OnItemChanged(NMLISTVIEW *item);
344   void OnNotifyActivateItems();
345   bool OnNotifyList(LPNMHDR lParam, LRESULT &result);
346   void OnDrag(LPNMLISTVIEW nmListView, bool isRightButton = false);
347   bool OnKeyDown(LPNMLVKEYDOWN keyDownInfo, LRESULT &result);
348   BOOL OnBeginLabelEdit(LV_DISPINFOW * lpnmh);
349   BOOL OnEndLabelEdit(LV_DISPINFOW * lpnmh);
350   void OnColumnClick(LPNMLISTVIEW info);
351   bool OnCustomDraw(LPNMLVCUSTOMDRAW lplvcd, LRESULT &result);
352 
353 
354 public:
355   HWND _mainWindow;
356   CPanelCallback *_panelCallback;
357 
SysIconsWereChanged()358   void SysIconsWereChanged() { _extToIconMap.Clear(); }
359 
360   void DeleteItems(bool toRecycleBin);
361   void CreateFolder();
362   void CreateFile();
363   bool CorrectFsPath(const UString &path, UString &result);
364   // bool IsPathForPlugin(const UString &path);
365 
366 private:
367 
368   void ChangeWindowSize(int xSize, int ySize);
369 
370   HRESULT InitColumns();
371   void DeleteColumn(unsigned index);
372   void AddColumn(const CPropColumn &prop);
373 
374   void SetFocusedSelectedItem(int index, bool select);
375 
376   void OnShiftSelectMessage();
377   void OnArrowWithShift();
378 
379   void OnInsert();
380   // void OnUpWithShift();
381   // void OnDownWithShift();
382 public:
383   void UpdateSelection();
384   void SelectSpec(bool selectMode);
385   void SelectByType(bool selectMode);
386   void SelectAll(bool selectMode);
387   void InvertSelection();
388 private:
389 
390   // UString GetFileType(UInt32 index);
391   LRESULT SetItemText(LVITEMW &item);
392 
393   // CRecordVector<PROPID> m_ColumnsPropIDs;
394 
395 public:
396   NWindows::NControl::CReBar _headerReBar;
397   NWindows::NControl::CToolBar _headerToolBar;
398   NWindows::NControl::
399     #ifdef UNDER_CE
400     CComboBox
401     #else
402     CComboBoxEx
403     #endif
404     _headerComboBox;
405   UStringVector ComboBoxPaths;
406   // CMyComboBox _headerComboBox;
407   CMyComboBoxEdit _comboBoxEdit;
408   CMyListView _listView;
409   bool _thereAre_ListView_Items;
410   NWindows::NControl::CStatusBar _statusBar;
411   bool _lastFocusedIsList;
412   // NWindows::NControl::CStatusBar _statusBar2;
413 
414   DWORD _exStyle;
415   bool _showDots;
416   bool _showRealFileIcons;
417   // bool _virtualMode;
418   // CUIntVector _realIndices;
419   bool _enableItemChangeNotify;
420   bool _mySelectMode;
421 
422   int _timestampLevel;
423 
424 
RedrawListItems()425   void RedrawListItems()
426   {
427     _listView.RedrawAllItems();
428   }
429 
430 
431   CBoolVector _selectedStatusVector;
432 
433   CSelectedState _selectedState;
434   bool _thereAreDeletedItems;
435   bool _markDeletedItems;
436 
437   bool PanelCreated;
438 
DeleteListItems()439   void DeleteListItems()
440   {
441     if (_thereAre_ListView_Items)
442     {
443       bool b = _enableItemChangeNotify;
444       _enableItemChangeNotify = false;
445       _listView.DeleteAllItems();
446       _thereAre_ListView_Items = false;
447       _enableItemChangeNotify = b;
448     }
449   }
450 
451   HWND GetParent() const;
452 
GetRealIndex(const LVITEMW & item)453   UInt32 GetRealIndex(const LVITEMW &item) const
454   {
455     /*
456     if (_virtualMode)
457       return _realIndices[item.iItem];
458     */
459     return (UInt32)item.lParam;
460   }
461 
GetRealItemIndex(int indexInListView)462   unsigned GetRealItemIndex(int indexInListView) const
463   {
464     /*
465     if (_virtualMode)
466       return indexInListView;
467     */
468     LPARAM param;
469     if (!_listView.GetItemParam((unsigned)indexInListView, param))
470       throw 1;
471     return (unsigned)param;
472   }
473 
474   UInt32 _listViewMode;
475   int _xSize;
476 
477   bool _flatMode;
478   bool _flatModeForDisk;
479   bool _flatModeForArc;
480 
481   // bool _showNtfsStrems_Mode;
482   // bool _showNtfsStrems_ModeForDisk;
483   // bool _showNtfsStrems_ModeForArc;
484 
485   bool _dontShowMode;
486 
487 
488   UString _currentFolderPrefix;
489 
490   CObjectVector<CFolderLink> _parentFolders;
491   NWindows::NDLL::CLibrary _library;
492 
493   CMyComPtr<IFolderFolder> _folder;
494   CBoolVector _isDirVector;
495   CMyComPtr<IFolderCompare> _folderCompare;
496   CMyComPtr<IFolderGetItemName> _folderGetItemName;
497   CMyComPtr<IArchiveGetRawProps> _folderRawProps;
498   CMyComPtr<IFolderAltStreams> _folderAltStreams;
499   CMyComPtr<IFolderOperations> _folderOperations;
500 
501 
502   // for drag and drop highliting
503   int m_DropHighlighted_SelectionIndex;
504   // int m_SubFolderIndex;      // realIndex of item in m_Panel list (if drop cursor to that item)
505   UString m_DropHighlighted_SubFolderName;   // name of folder in m_Panel list (if drop cursor to that folder)
506 
507   void ReleaseFolder();
508   void SetNewFolder(IFolderFolder *newFolder);
509 
510   // CMyComPtr<IFolderGetSystemIconIndex> _folderGetSystemIconIndex;
511 
512   UStringVector _fastFolders;
513 
514   void GetSelectedNames(UStringVector &selectedNames);
515   void SaveSelectedState(CSelectedState &s);
516   HRESULT RefreshListCtrl(const CSelectedState &s);
517   HRESULT RefreshListCtrl_SaveFocused(bool onTimer = false);
518 
519   // UInt32 GetItem_Attrib(UInt32 itemIndex) const;
520 
521   bool GetItem_BoolProp(UInt32 itemIndex, PROPID propID) const;
522 
523   bool IsItem_Deleted(unsigned itemIndex) const;
524   bool IsItem_Folder(unsigned itemIndex) const;
525   bool IsItem_AltStream(unsigned itemIndex) const;
526 
527   UString GetItemName(unsigned itemIndex) const;
528   UString GetItemName_for_Copy(unsigned itemIndex) const;
529   void GetItemName(unsigned itemIndex, UString &s) const;
530   UString GetItemPrefix(unsigned itemIndex) const;
531   UString GetItemRelPath(unsigned itemIndex) const;
532   UString GetItemRelPath2(unsigned itemIndex) const;
533 
534   void Add_ItemRelPath2_To_String(unsigned itemIndex, UString &s) const;
535 
536   UString GetItemFullPath(unsigned itemIndex) const;
537   UInt64 GetItem_UInt64Prop(unsigned itemIndex, PROPID propID) const;
538   UInt64 GetItemSize(unsigned itemIndex) const;
539 
540   ////////////////////////
541   // PanelFolderChange.cpp
542 
543   void SetToRootFolder();
544   HRESULT BindToPath(const UString &fullPath, const UString &arcFormat, COpenResult &openRes); // can be prefix
545   HRESULT BindToPathAndRefresh(const UString &path);
546   void OpenDrivesFolder();
547 
548   void SetBookmark(unsigned index);
549   void OpenBookmark(unsigned index);
550 
551   void LoadFullPath();
552   void LoadFullPathAndShow();
553   void FoldersHistory();
554   void OpenParentFolder();
555   void CloseOneLevel();
556   void CloseOpenFolders();
557   void OpenRootFolder();
558 
559   UString GetParentDirPrefix() const;
560 
561   HRESULT Create(HWND mainWindow, HWND parentWindow,
562       UINT id,
563       const UString &currentFolderPrefix,
564       const UString &arcFormat,
565       CPanelCallback *panelCallback,
566       CAppState *appState,
567       bool needOpenArc,
568       COpenResult &openRes);
569 
570   void SetFocusToList();
571   void SetFocusToLastRememberedItem();
572 
573 
574   void SaveListViewInfo();
575 
CPanel()576   CPanel() :
577       _thereAre_ListView_Items(false),
578       _exStyle(0),
579       _showDots(false),
580       _showRealFileIcons(false),
581       // _virtualMode(flase),
582       _enableItemChangeNotify(true),
583       _mySelectMode(false),
584       _timestampLevel(kTimestampPrintLevel_MIN),
585 
586       _thereAreDeletedItems(false),
587       _markDeletedItems(true),
588       PanelCreated(false),
589 
590       _listViewMode(3),
591       _xSize(300),
592 
593       _flatMode(false),
594       _flatModeForDisk(false),
595       _flatModeForArc(false),
596 
597       // _showNtfsStrems_Mode(false),
598       // _showNtfsStrems_ModeForDisk(false),
599       // _showNtfsStrems_ModeForArc(false),
600 
601       _dontShowMode(false),
602 
603       m_DropHighlighted_SelectionIndex(-1),
604 
605       _needSaveInfo(false),
606       _startGroupSelect(0),
607       _selectionIsDefined(false)
608   {}
609 
SetExtendedStyle()610   void SetExtendedStyle()
611   {
612     if (_listView)
613       _listView.SetExtendedListViewStyle(_exStyle);
614   }
615 
616 
617   bool _needSaveInfo;
618   UString _typeIDString;
619   CListViewInfo _listViewInfo;
620 
621   CPropColumns _columns;
622   CPropColumns _visibleColumns;
623 
624   PROPID _sortID;
625   // int _sortIndex;
626   bool _ascending;
627   Int32 _isRawSortProp;
628 
629   void SetSortRawStatus();
630 
631   void Release();
632   ~CPanel() Z7_DESTRUCTOR_override;
633   void OnLeftClick(MY_NMLISTVIEW_NMITEMACTIVATE *itemActivate);
634   bool OnRightClick(MY_NMLISTVIEW_NMITEMACTIVATE *itemActivate, LRESULT &result);
635   void ShowColumnsContextMenu(int x, int y);
636 
637   void OnTimer();
638   void OnReload(bool onTimer = false);
639   bool OnContextMenu(HANDLE windowHandle, int xPos, int yPos);
640 
641   CMyComPtr<IContextMenu> _sevenZipContextMenu;
642   CMyComPtr<IContextMenu> _systemContextMenu;
643 
644   HRESULT CreateShellContextMenu(
645       const CRecordVector<UInt32> &operatedIndices,
646       CMyComPtr<IContextMenu> &systemContextMenu);
647 
648   void CreateSystemMenu(HMENU menu,
649       bool showExtendedVerbs,
650       const CRecordVector<UInt32> &operatedIndices,
651       CMyComPtr<IContextMenu> &systemContextMenu);
652 
653   void CreateSevenZipMenu(HMENU menu,
654       bool showExtendedVerbs,
655       const CRecordVector<UInt32> &operatedIndices,
656       int firstDirIndex,
657       CMyComPtr<IContextMenu> &sevenZipContextMenu);
658 
659   void CreateFileMenu(HMENU menu,
660       CMyComPtr<IContextMenu> &sevenZipContextMenu,
661       CMyComPtr<IContextMenu> &systemContextMenu,
662       bool programMenu);
663 
664   void CreateFileMenu(HMENU menu);
665   bool InvokePluginCommand(unsigned id);
666   bool InvokePluginCommand(unsigned id, IContextMenu *sevenZipContextMenu,
667       IContextMenu *systemContextMenu);
668 
669   void InvokeSystemCommand(const char *command);
670   void Properties();
671   void EditCut();
672   void EditCopy();
673   void EditPaste();
674 
675   int _startGroupSelect;
676 
677   bool _selectionIsDefined;
678   bool _selectMark;
679   int _prevFocusedItem;
680 
681 
682   // void SortItems(int index);
683   void SortItemsWithPropID(PROPID propID);
684 
685   void Get_ItemIndices_Selected(CRecordVector<UInt32> &indices) const;
686   void Get_ItemIndices_Operated(CRecordVector<UInt32> &indices) const;
687   void Get_ItemIndices_All(CRecordVector<UInt32> &indices) const;
688   void Get_ItemIndices_OperSmart(CRecordVector<UInt32> &indices) const;
689   // void GetOperatedListViewIndices(CRecordVector<UInt32> &indices) const;
690   void KillSelection();
691 
692   UString GetFolderTypeID() const;
693 
694   bool IsFolderTypeEqTo(const char *s) const;
695   bool IsRootFolder() const;
696   bool IsFSFolder() const;
697   bool IsFSDrivesFolder() const;
698   bool IsAltStreamsFolder() const;
699   bool IsArcFolder() const;
700   bool IsHashFolder() const;
701 
702   /*
703     c:\Dir
704     Computer\
705     \\?\
706     \\.\
707   */
Is_IO_FS_Folder()708   bool Is_IO_FS_Folder() const
709   {
710     return IsFSFolder() || IsFSDrivesFolder() || IsAltStreamsFolder();
711   }
712 
Is_Slow_Icon_Folder()713   bool Is_Slow_Icon_Folder() const
714   {
715     return IsFSFolder() || IsAltStreamsFolder();
716   }
717 
718   // bool IsFsOrDrivesFolder() const { return IsFSFolder() || IsFSDrivesFolder(); }
IsDeviceDrivesPrefix()719   bool IsDeviceDrivesPrefix() const { return _currentFolderPrefix == L"\\\\.\\"; }
IsSuperDrivesPrefix()720   bool IsSuperDrivesPrefix() const { return _currentFolderPrefix == L"\\\\?\\"; }
721 
722   /*
723     c:\Dir
724     Computer\
725     \\?\
726   */
IsFsOrPureDrivesFolder()727   bool IsFsOrPureDrivesFolder() const { return IsFSFolder() || (IsFSDrivesFolder() && !IsDeviceDrivesPrefix()); }
728 
729   /*
730     c:\Dir
731     Computer\
732     \\?\
733     \\SERVER\
734   */
IsFolder_with_FsItems()735   bool IsFolder_with_FsItems() const
736   {
737     if (IsFsOrPureDrivesFolder())
738       return true;
739     #if defined(_WIN32) && !defined(UNDER_CE)
740     FString prefix = us2fs(GetFsPath());
741     return (prefix.Len() == NWindows::NFile::NName::GetNetworkServerPrefixSize(prefix));
742     #else
743     return false;
744     #endif
745   }
746 
747   UString GetFsPath() const;
748   UString GetDriveOrNetworkPrefix() const;
749 
DoesItSupportOperations()750   bool DoesItSupportOperations() const { return _folderOperations != NULL; }
751   bool IsThereReadOnlyFolder() const;
752   bool CheckBeforeUpdate(UINT resourceID);
753 
754   bool _processTimer;
755   bool _processNotify;
756   bool _processStatusBar;
757 
758   class CDisableTimerProcessing
759   {
760     Z7_CLASS_NO_COPY(CDisableTimerProcessing)
761 
762     bool _processTimer;
763     CPanel &_panel;
764 
765     public:
766 
CDisableTimerProcessing(CPanel & panel)767     CDisableTimerProcessing(CPanel &panel): _panel(panel) { Disable(); }
~CDisableTimerProcessing()768     ~CDisableTimerProcessing() { Restore(); }
Disable()769     void Disable()
770     {
771       _processTimer = _panel._processTimer;
772       _panel._processTimer = false;
773     }
Restore()774     void Restore()
775     {
776       _panel._processTimer = _processTimer;
777     }
778   };
779 
780   class CDisableTimerProcessing2
781   {
782     Z7_CLASS_NO_COPY(CDisableTimerProcessing2)
783 
784     bool _processTimer;
785     CPanel *_panel;
786 
787     public:
788 
CDisableTimerProcessing2(CPanel * panel)789     CDisableTimerProcessing2(CPanel *panel): _processTimer(true), _panel(panel) { Disable(); }
~CDisableTimerProcessing2()790     ~CDisableTimerProcessing2() { Restore(); }
Disable()791     void Disable()
792     {
793       if (_panel)
794       {
795         _processTimer = _panel->_processTimer;
796         _panel->_processTimer = false;
797       }
798     }
Restore()799     void Restore()
800     {
801       if (_panel)
802       {
803         _panel->_processTimer = _processTimer;
804         _panel = NULL;
805       }
806     }
807   };
808 
809   class CDisableNotify
810   {
811     Z7_CLASS_NO_COPY(CDisableNotify)
812 
813     bool _processNotify;
814     bool _processStatusBar;
815 
816     CPanel &_panel;
817 
818     public:
819 
CDisableNotify(CPanel & panel)820     CDisableNotify(CPanel &panel): _panel(panel) { Disable(); }
~CDisableNotify()821     ~CDisableNotify() { Restore(); }
Disable()822     void Disable()
823     {
824       _processNotify = _panel._processNotify;
825       _processStatusBar = _panel._processStatusBar;
826       _panel._processNotify = false;
827       _panel._processStatusBar = false;
828     }
SetMemMode_Enable()829     void SetMemMode_Enable()
830     {
831       _processNotify = true;
832       _processStatusBar = true;
833     }
Restore()834     void Restore()
835     {
836       _panel._processNotify = _processNotify;
837       _panel._processStatusBar = _processStatusBar;
838     }
839   };
840 
InvalidateList()841   void InvalidateList() { _listView.InvalidateRect(NULL, true); }
842 
843   HRESULT RefreshListCtrl();
844 
845 
846   // void MessageBox_Info(LPCWSTR message, LPCWSTR caption) const;
847   // void MessageBox_Warning(LPCWSTR message) const;
848   void MessageBox_Error_Caption(LPCWSTR message, LPCWSTR caption) const;
849   void MessageBox_Error(LPCWSTR message) const;
850   void MessageBox_Error_HRESULT_Caption(HRESULT errorCode, LPCWSTR caption) const;
851   void MessageBox_Error_HRESULT(HRESULT errorCode) const;
852   void MessageBox_Error_2Lines_Message_HRESULT(LPCWSTR message, HRESULT errorCode) const;
853   void MessageBox_LastError(LPCWSTR caption) const;
854   void MessageBox_LastError() const;
855   void MessageBox_Error_LangID(UINT resourceID) const;
856   void MessageBox_Error_UnsupportOperation() const;
857   // void MessageBoxErrorForUpdate(HRESULT errorCode, UINT resourceID);
858 
859 
860   void OpenAltStreams();
861 
862   void OpenFocusedItemAsInternal(const wchar_t *type = NULL);
863   void OpenSelectedItems(bool internal);
864 
865   void OpenFolderExternal(unsigned index);
866 
867   void OpenFolder(unsigned index);
868   HRESULT OpenParentArchiveFolder();
869 
870   HRESULT OpenAsArc(IInStream *inStream,
871       const CTempFileInfo &tempFileInfo,
872       const UString &virtualFilePath,
873       const UString &arcFormat,
874       COpenResult &openRes);
875 
876   HRESULT OpenAsArc_Msg(IInStream *inStream,
877       const CTempFileInfo &tempFileInfo,
878       const UString &virtualFilePath,
879       const UString &arcFormat
880       // , bool showErrorMessage
881       );
882 
883   HRESULT OpenAsArc_Name(const UString &relPath, const UString &arcFormat
884       // , bool showErrorMessage
885       );
886   HRESULT OpenAsArc_Index(unsigned index, const wchar_t *type /* = NULL */
887       // , bool showErrorMessage
888       );
889 
890   void OpenItemInArchive(unsigned index, bool tryInternal, bool tryExternal,
891       bool editMode, bool useEditor, const wchar_t *type = NULL);
892 
893   HRESULT OnOpenItemChanged(UInt32 index, const wchar_t *fullFilePath, bool usePassword, const UString &password);
894   LRESULT OnOpenItemChanged(LPARAM lParam);
895 
896   bool IsVirus_Message(const UString &name);
897   void OpenItem(unsigned index, bool tryInternal, bool tryExternal, const wchar_t *type = NULL);
898   void EditItem(bool useEditor);
899   void EditItem(unsigned index, bool useEditor);
900 
901   void RenameFile();
902   void ChangeComment();
903 
904   void SetListViewMode(UInt32 index);
GetListViewMode()905   UInt32 GetListViewMode() const { return _listViewMode; }
GetSortID()906   PROPID GetSortID() const { return _sortID; }
907 
908   void ChangeFlatMode();
909   void Change_ShowNtfsStrems_Mode();
GetFlatMode()910   bool GetFlatMode() const { return _flatMode; }
911   // bool Get_ShowNtfsStrems_Mode() const { return _showNtfsStrems_Mode; }
912 
913   bool AutoRefresh_Mode;
Set_AutoRefresh_Mode(bool mode)914   void Set_AutoRefresh_Mode(bool mode)
915   {
916     AutoRefresh_Mode = mode;
917   }
918 
919   void Post_Refresh_StatusBar();
920   void Refresh_StatusBar();
921 
922   void AddToArchive();
923 
924   int FindDir_InOperatedList(const CRecordVector<UInt32> &indices) const;
925   void GetFilePaths(const CRecordVector<UInt32> &indices, UStringVector &paths) const;
926   void ExtractArchives();
927   void TestArchives();
928 
929 
930   HRESULT CopyTo(CCopyToOptions &options,
931       const CRecordVector<UInt32> &indices,
932       UStringVector *messages,
933       bool &usePassword, UString &password,
934       const UStringVector *filePaths = NULL);
935 
CopyTo(CCopyToOptions & options,const CRecordVector<UInt32> & indices,UStringVector * messages)936   HRESULT CopyTo(CCopyToOptions &options,
937       const CRecordVector<UInt32> &indices,
938       UStringVector *messages)
939   {
940     bool usePassword = false;
941     UString password;
942     if (_parentFolders.Size() > 0)
943     {
944       const CFolderLink &fl = _parentFolders.Back();
945       usePassword = fl.UsePassword;
946       password = fl.Password;
947     }
948     return CopyTo(options, indices, messages, usePassword, password);
949   }
950 
CopyFsItems(CCopyToOptions & options,const UStringVector & filePaths,UStringVector * messages)951   HRESULT CopyFsItems(CCopyToOptions &options,
952       const UStringVector &filePaths,
953       UStringVector *messages)
954   {
955     bool usePassword = false;
956     UString password;
957     CRecordVector<UInt32> indices;
958     return CopyTo(options, indices, messages, usePassword, password, &filePaths);
959   }
960 
961 
962   HRESULT CopyFrom(bool moveMode, const UString &folderPrefix, const UStringVector &filePaths,
963       bool showErrorMessages, UStringVector *messages);
964 
965   void CopyFromNoAsk(bool moveMode, const UStringVector &filePaths);
966 
967   void CompressDropFiles(
968       const UStringVector &filePaths,
969       const UString &folderPath,
970       bool createNewArchive,
971       bool moveMode,
972       UInt32 sourceFlags,
973       UInt32 &targetFlags);
974 
975   void RefreshTitle(bool always = false) { _panelCallback->RefreshTitle(always);  }
RefreshTitleAlways()976   void RefreshTitleAlways() { RefreshTitle(true);  }
977 
978   UString GetItemsInfoString(const CRecordVector<UInt32> &indices);
979 };
980 
981 class CMyBuffer
982 {
983   void *_data;
984 public:
CMyBuffer()985   CMyBuffer(): _data(NULL) {}
986   operator void *() { return _data; }
Allocate(size_t size)987   bool Allocate(size_t size)
988   {
989     if (_data)
990       return false;
991     _data = ::MidAlloc(size);
992     return _data != NULL;
993   }
~CMyBuffer()994   ~CMyBuffer() { ::MidFree(_data); }
995 };
996 
997 class CExitEventLauncher
998 {
999 public:
1000   NWindows::NSynchronization::CManualResetEvent _exitEvent;
1001   bool _needExit;
1002   CRecordVector< ::CThread > _threads;
1003   unsigned _numActiveThreads;
1004 
CExitEventLauncher()1005   CExitEventLauncher()
1006   {
1007     _needExit = false;
1008     if (_exitEvent.Create(false) != S_OK)
1009       throw 9387173;
1010     _needExit = true;
1011     _numActiveThreads = 0;
1012   }
1013 
~CExitEventLauncher()1014   ~CExitEventLauncher() { Exit(true); }
1015 
1016   void Exit(bool hardExit);
1017 };
1018 
1019 extern CExitEventLauncher g_ExitEventLauncher;
1020 
1021 #endif
1022