copy file: trigger desktop notification in case of error (close #1794)
[far2l.git] / far2l / src / copy.hpp
blob33df41d677ce9356a004c205f6e272ab81f13b9a
1 #pragma once
3 /*
4 copy.hpp
6 class ShellCopy - Копирование файлов
7 */
8 /*
9 Copyright (c) 1996 Eugene Roshal
10 Copyright (c) 2000 Far Group
11 All rights reserved.
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16 1. Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 2. Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 3. The name of the authors may not be used to endorse or promote products
22 derived from this software without specific prior written permission.
24 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "dizlist.hpp"
37 #include "udlist.hpp"
38 #include "flink.hpp"
39 class Panel;
41 #include <WinCompat.h>
42 #include "FARString.hpp"
44 enum COPY_CODES
46 COPY_CANCEL,
47 COPY_NEXT,
48 COPY_NOFILTER, // не считать размеры, т.к. файл не прошел по фильтру
49 COPY_FAILURE,
50 COPY_FAILUREREAD,
51 COPY_SUCCESS,
52 COPY_SUCCESS_MOVE,
53 COPY_RETRY,
56 enum COPY_SYMLINK
58 COPY_SYMLINK_ASIS = 0,
59 COPY_SYMLINK_SMART = 1, // Copy symbolics links content instead of making new links
60 COPY_SYMLINK_ASFILE = 2 // Copy remote (to this copy operation) symbolics links content,
61 // make relative links for local ones
64 struct COPY_FLAGS
66 inline COPY_FLAGS() { memset(this, 0, sizeof(*this)); }
68 bool CURRENTONLY : 1; // Только текщий?
69 bool ONLYNEWERFILES : 1; // Copy only newer files
70 bool OVERWRITENEXT : 1; // Overwrite all
71 bool LINK : 1; // создание линков
72 bool MOVE : 1; // перенос/переименование
73 bool DIZREAD : 1; //
74 bool COPYACCESSMODE : 1; // [x] Copy files access mode
75 bool WRITETHROUGH : 1; // disable write cache
76 bool COPYXATTR : 1; // copy extended attributes
77 bool SPARSEFILES : 1; // allow producing sparse files
78 bool USECOW : 1; // enable COW funcionality if FS supports it
79 bool COPYLASTTIME : 1; // При копировании в несколько каталогов устанавливается для последнего.
80 bool UPDATEPPANEL : 1; // необходимо обновить пассивную панель
81 COPY_SYMLINK SYMLINK : 2;
82 DWORD ErrorMessageFlags; // MSG_WARNING | MSG_ERRORTYPE [| MSG_DISPLAYNOTIFY if Opt.NotifOpt.OnFileOperation ]
85 class ShellCopyFileExtendedAttributes
87 FileExtendedAttributes _xattr;
88 bool _apply;
90 public:
91 ShellCopyFileExtendedAttributes(File &f);
92 void ApplyToCopied(File &f);
95 struct ShellCopyBuffer
97 ShellCopyBuffer();
98 ~ShellCopyBuffer();
100 const DWORD Capacity;
102 DWORD Size;
104 private:
105 char *const Buffer;
107 public:
108 char *const Ptr;
111 class ShellFileTransfer
113 const wchar_t *_SrcName;
114 const FARString &_strDestName;
115 ShellCopyBuffer &_CopyBuffer;
116 COPY_FLAGS &_Flags;
117 const FAR_FIND_DATA_EX &_SrcData;
119 clock_t _Stopwatch = 0;
120 int64_t _AppendPos = -1;
121 DWORD _DstFlags = 0;
122 DWORD _ModeToCreateWith;
124 File _SrcFile, _DestFile;
125 bool _LastWriteWasHole = false;
126 bool _Done = false;
127 std::unique_ptr<ShellCopyFileExtendedAttributes> _XAttrCopyPtr;
129 void Undo();
130 void RetryCancel(const wchar_t *Text, const wchar_t *Object);
131 DWORD PieceWrite(const void *Data, DWORD Size);
132 DWORD PieceWriteHole(DWORD Size);
133 DWORD PieceCopy();
135 public:
136 ShellFileTransfer(const wchar_t *SrcName, const FAR_FIND_DATA_EX &SrcData, const FARString &strDestName,
137 bool Append, ShellCopyBuffer &CopyBuffer, COPY_FLAGS &Flags);
138 ~ShellFileTransfer();
140 void Do();
143 class ShellCopy
145 COPY_FLAGS Flags;
146 Panel *SrcPanel, *DestPanel;
147 int SrcPanelMode, DestPanelMode;
148 DizList DestDiz;
149 FARString strDestDizPath;
150 FARString strCopiedName;
151 FARString strRenamedName;
152 FARString strRenamedFilesPath;
153 int OvrMode;
154 int ReadOnlyOvrMode;
155 int ReadOnlyDelMode;
156 int SkipMode; // ...для пропуска при копировании залоченных файлов.
157 int SkipDeleteMode;
158 int SelectedFolderNameLength;
159 UserDefinedList DestList;
160 // тип создаваемого репарспоинта.
161 // при AltF6 будет то, что выбрал юзер в диалоге,
162 // в остальных случаях - RP_EXACTCOPY - как у источника
163 ReparsePointTypes RPT;
164 ShellCopyBuffer CopyBuffer;
166 std::vector<FARString> SelectedPanelItems;
167 struct CopiedDirectory
169 std::string Path;
170 FILETIME ftUnixAccessTime;
171 FILETIME ftUnixModificationTime;
172 DWORD dwUnixMode;
175 std::vector<CopiedDirectory> DirectoriesAttributes;
176 void EnqueueDirectoryAttributes(const FAR_FIND_DATA_EX &SrcData, FARString &strDest);
177 void SetEnqueuedDirectoriesAttributes();
179 bool IsSymlinkTargetAlsoCopied(const wchar_t *SymLink);
181 COPY_CODES CopyFileTree(const wchar_t *Dest);
182 COPY_CODES ShellCopyOneFile(const wchar_t *Src, const FAR_FIND_DATA_EX &SrcData, FARString &strDest,
183 int KeepPathPos, int Rename);
184 COPY_CODES ShellCopyOneFileNoRetry(const wchar_t *Src, const FAR_FIND_DATA_EX &SrcData,
185 FARString &strDest, int KeepPathPos, int Rename);
187 int ShellCopyFile(const wchar_t *SrcName, const FAR_FIND_DATA_EX &SrcData, FARString &strDestName,
188 int Append);
190 int DeleteAfterMove(const wchar_t *Name, DWORD Attr);
191 void SetDestDizPath(const wchar_t *DestPath);
192 int AskOverwrite(const FAR_FIND_DATA_EX &SrcData, const wchar_t *SrcName, const wchar_t *DestName,
193 DWORD DestAttr, int SameName, int Rename, int AskAppend, int &Append, FARString &strNewName,
194 int &RetCode);
195 bool CalcTotalSize();
197 COPY_CODES
198 CreateSymLink(const char *ExistingName, const wchar_t *NewName, const FAR_FIND_DATA_EX &SrcData);
199 COPY_CODES
200 CopySymLink(const wchar_t *ExistingName, const wchar_t *NewName, const FAR_FIND_DATA_EX &SrcData);
202 public:
203 ShellCopy(Panel *SrcPanel, int Move, int Link, int CurrentOnly, int Ask, int &ToPlugin,
204 const wchar_t *PluginDestPath, bool ToSubdir = false);
205 ~ShellCopy();
208 LONG_PTR WINAPI CopyDlgProc(HANDLE hDlg, int Msg, int Param1, LONG_PTR Param2);