6 class ShellCopy - Копирование файлов
9 Copyright (c) 1996 Eugene Roshal
10 Copyright (c) 2000 Far Group
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
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"
41 #include <WinCompat.h>
42 #include "FARString.hpp"
48 COPY_NOFILTER
, // не считать размеры, т.к. файл не прошел по фильтру
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
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; // перенос/переименование
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
;
91 ShellCopyFileExtendedAttributes(File
&f
);
92 void ApplyToCopied(File
&f
);
95 struct ShellCopyBuffer
100 const DWORD Capacity
;
111 class ShellFileTransfer
113 const wchar_t *_SrcName
;
114 const FARString
&_strDestName
;
115 ShellCopyBuffer
&_CopyBuffer
;
117 const FAR_FIND_DATA_EX
&_SrcData
;
119 clock_t _Stopwatch
= 0;
120 int64_t _AppendPos
= -1;
122 DWORD _ModeToCreateWith
;
124 File _SrcFile
, _DestFile
;
125 bool _LastWriteWasHole
= false;
127 std::unique_ptr
<ShellCopyFileExtendedAttributes
> _XAttrCopyPtr
;
130 void RetryCancel(const wchar_t *Text
, const wchar_t *Object
);
131 DWORD
PieceWrite(const void *Data
, DWORD Size
);
132 DWORD
PieceWriteHole(DWORD Size
);
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();
146 Panel
*SrcPanel
, *DestPanel
;
147 int SrcPanelMode
, DestPanelMode
;
149 FARString strDestDizPath
;
150 FARString strCopiedName
;
151 FARString strRenamedName
;
152 FARString strRenamedFilesPath
;
156 int SkipMode
; // ...для пропуска при копировании залоченных файлов.
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
170 FILETIME ftUnixAccessTime
;
171 FILETIME ftUnixModificationTime
;
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
,
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
,
195 bool CalcTotalSize();
198 CreateSymLink(const char *ExistingName
, const wchar_t *NewName
, const FAR_FIND_DATA_EX
&SrcData
);
200 CopySymLink(const wchar_t *ExistingName
, const wchar_t *NewName
, const FAR_FIND_DATA_EX
&SrcData
);
203 ShellCopy(Panel
*SrcPanel
, int Move
, int Link
, int CurrentOnly
, int Ask
, int &ToPlugin
,
204 const wchar_t *PluginDestPath
, bool ToSubdir
= false);
208 LONG_PTR WINAPI
CopyDlgProc(HANDLE hDlg
, int Msg
, int Param1
, LONG_PTR Param2
);