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