xref: /aosp_15_r20/external/lzma/CPP/7zip/UI/FileManager/FSFolder.h (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
1 // FSFolder.h
2 
3 #ifndef ZIP7_INC_FS_FOLDER_H
4 #define ZIP7_INC_FS_FOLDER_H
5 
6 #include "../../../Common/MyCom.h"
7 #include "../../../Common/MyBuffer.h"
8 
9 #include "../../../Windows/FileFind.h"
10 
11 #include "../../Archive/IArchive.h"
12 
13 #include "IFolder.h"
14 #include "TextPairs.h"
15 
16 namespace NFsFolder {
17 
18 class CFSFolder;
19 
20 #define FS_SHOW_LINKS_INFO
21 // #define FS_SHOW_CHANGE_TIME
22 
23 struct CDirItem: public NWindows::NFile::NFind::CFileInfo
24 {
25 #ifndef UNDER_CE
26   UInt64 PackSize;
27 #endif
28 
29 #ifdef FS_SHOW_LINKS_INFO
30   FILETIME ChangeTime;
31   UInt64 FileIndex;
32   UInt32 NumLinks;
33   bool FileInfo_Defined;
34   bool FileInfo_WasRequested;
35   bool ChangeTime_Defined;
36   bool ChangeTime_WasRequested;
37 #endif
38 
39 #ifndef UNDER_CE
40   bool PackSize_Defined;
41 #endif
42 
43   bool FolderStat_Defined;
44   int Parent;
45 
46 #ifndef UNDER_CE
47   CByteBuffer Reparse;
48 #endif
49 
50   UInt64 NumFolders;
51   UInt64 NumFiles;
52 };
53 
54 /*
55 struct CAltStream
56 {
57   UInt64 Size;
58   UInt64 PackSize;
59   bool PackSize_Defined;
60   int Parent;
61   UString Name;
62 };
63 */
64 
65 struct CFsFolderStat
66 {
67   UInt64 NumFolders;
68   UInt64 NumFiles;
69   UInt64 Size;
70   IProgress *Progress;
71   FString Path;
72 
CFsFolderStatCFsFolderStat73   CFsFolderStat(): NumFolders(0), NumFiles(0), Size(0), Progress(NULL) {}
74   CFsFolderStat(const FString &path, IProgress *progress = NULL):
75       NumFolders(0), NumFiles(0), Size(0), Progress(progress), Path(path) {}
76 
77   HRESULT Enumerate();
78 };
79 
80 class CFSFolder Z7_final:
81   public IFolderFolder,
82   public IArchiveGetRawProps,
83   public IFolderCompare,
84   #ifdef USE_UNICODE_FSTRING
85   public IFolderGetItemName,
86   #endif
87   public IFolderWasChanged,
88   public IFolderOperations,
89   // public IFolderOperationsDeleteToRecycleBin,
90   public IFolderCalcItemFullSize,
91   public IFolderClone,
92   public IFolderGetSystemIconIndex,
93   public IFolderSetFlatMode,
94   // public IFolderSetShowNtfsStreamsMode,
95   public CMyUnknownImp
96 {
97   Z7_COM_QI_BEGIN2(IFolderFolder)
98     Z7_COM_QI_ENTRY(IArchiveGetRawProps)
99     Z7_COM_QI_ENTRY(IFolderCompare)
100     #ifdef USE_UNICODE_FSTRING
101     Z7_COM_QI_ENTRY(IFolderGetItemName)
102     #endif
103     Z7_COM_QI_ENTRY(IFolderWasChanged)
104     // Z7_COM_QI_ENTRY(IFolderOperationsDeleteToRecycleBin)
105     Z7_COM_QI_ENTRY(IFolderOperations)
106     Z7_COM_QI_ENTRY(IFolderCalcItemFullSize)
107     Z7_COM_QI_ENTRY(IFolderClone)
108     Z7_COM_QI_ENTRY(IFolderGetSystemIconIndex)
109     Z7_COM_QI_ENTRY(IFolderSetFlatMode)
110     // Z7_COM_QI_ENTRY(IFolderSetShowNtfsStreamsMode)
111   Z7_COM_QI_END
112   Z7_COM_ADDREF_RELEASE
113 
114   Z7_IFACE_COM7_IMP(IFolderFolder)
115   Z7_IFACE_COM7_IMP(IArchiveGetRawProps)
116   Z7_IFACE_COM7_IMP(IFolderCompare)
117   #ifdef USE_UNICODE_FSTRING
118   Z7_IFACE_COM7_IMP(IFolderGetItemName)
119   #endif
120   Z7_IFACE_COM7_IMP(IFolderWasChanged)
121   Z7_IFACE_COM7_IMP(IFolderOperations)
122   Z7_IFACE_COM7_IMP(IFolderCalcItemFullSize)
123   Z7_IFACE_COM7_IMP(IFolderClone)
124   Z7_IFACE_COM7_IMP(IFolderGetSystemIconIndex)
125   Z7_IFACE_COM7_IMP(IFolderSetFlatMode)
126   // Z7_IFACE_COM7_IMP(IFolderSetShowNtfsStreamsMode)
127 
128   bool _flatMode;
129   bool _commentsAreLoaded;
130   // bool _scanAltStreams;
131 
132   FString _path;
133   CObjectVector<CDirItem> Files;
134   FStringVector Folders;
135   // CObjectVector<CAltStream> Streams;
136   // CMyComPtr<IFolderFolder> _parentFolder;
137 
138   CPairsStorage _comments;
139 
140   #ifdef _WIN32
141   NWindows::NFile::NFind::CFindChangeNotification _findChangeNotification;
142   #endif
143 
144   // HRESULT GetItemFullSize(unsigned index, UInt64 &size, IProgress *progress);
145   void GetAbsPath(const wchar_t *name, FString &absPath);
146   HRESULT BindToFolderSpec(CFSTR name, IFolderFolder **resultFolder);
147 
148   bool LoadComments();
149   bool SaveComments();
150   HRESULT LoadSubItems(int dirItem, const FString &path);
151 
152   #ifdef FS_SHOW_LINKS_INFO
153   bool ReadFileInfo(CDirItem &di);
154   void ReadChangeTime(CDirItem &di);
155   #endif
156 
157 public:
158   HRESULT Init(const FString &path /* , IFolderFolder *parentFolder */);
159   #if !defined(_WIN32) || defined(UNDER_CE)
InitToRoot()160   HRESULT InitToRoot() { return Init((FString) FSTRING_PATH_SEPARATOR /* , NULL */); }
161   #endif
162 
CFSFolder()163   CFSFolder():
164     _flatMode(false),
165     _commentsAreLoaded(false)
166     // , _scanAltStreams(false)
167     {}
168 
GetFullPath(const CDirItem & item,FString & path)169   void GetFullPath(const CDirItem &item, FString &path) const
170   {
171     // FString prefix;
172     // GetPrefix(item, prefix);
173     path = _path;
174     if (item.Parent >= 0)
175       path += Folders[item.Parent];
176     path += item.Name;
177   }
178 
179   // void GetPrefix(const CDirItem &item, FString &prefix) const;
180 
181   FString GetRelPath(const CDirItem &item) const;
182 
Clear()183   void Clear()
184   {
185     Files.Clear();
186     Folders.Clear();
187     // Streams.Clear();
188   }
189 };
190 
191 struct CCopyStateIO
192 {
193   IProgress *Progress;
194   UInt64 TotalSize;
195   UInt64 StartPos;
196   UInt64 CurrentSize;
197   bool DeleteSrcFile;
198 
199   int ErrorFileIndex;
200   UString ErrorMessage;
201 
CCopyStateIOCCopyStateIO202   CCopyStateIO(): TotalSize(0), StartPos(0), DeleteSrcFile(false) {}
203 
204   HRESULT MyCopyFile(CFSTR inPath, CFSTR outPath, DWORD attrib = INVALID_FILE_ATTRIBUTES);
205 };
206 
207 HRESULT SendLastErrorMessage(IFolderOperationsExtractCallback *callback, const FString &fileName);
208 
209 /* destDirPrefix is allowed to be:
210    "full_path\" or "full_path:" for alt streams */
211 
212 HRESULT CopyFileSystemItems(
213     const UStringVector &itemsPaths,
214     const FString &destDirPrefix,
215     bool moveMode,
216     IFolderOperationsExtractCallback *callback);
217 
218 }
219 
220 #endif
221