Welcome to mirror list, hosted at ThFree Co, Russian Federation.

copy.hpp « src « far2l - github.com/elfmz/far2l.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89779c186b66e45c07201da7d52edb018a76f7d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#pragma once

/*
copy.hpp

class ShellCopy - Копирование файлов
*/
/*
Copyright (c) 1996 Eugene Roshal
Copyright (c) 2000 Far Group
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
   derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "dizlist.hpp"
#include "udlist.hpp"
#include "flink.hpp"
class Panel;

#include <WinCompat.h>
#include "FARString.hpp"

enum COPY_CODES
{
	COPY_CANCEL,
	COPY_NEXT,
	COPY_NOFILTER,                              // не считать размеры, т.к. файл не прошел по фильтру
	COPY_FAILURE,
	COPY_FAILUREREAD,
	COPY_SUCCESS,
	COPY_SUCCESS_MOVE,
	COPY_RETRY,
};

enum COPY_SYMLINK
{
	COPY_SYMLINK_ASIS = 0,
	COPY_SYMLINK_SMART = 1,                 // Copy symbolics links content instead of making new links
	COPY_SYMLINK_ASFILE = 2    // Copy remote (to this copy operation) symbolics links content, make relative links for local ones
};

struct COPY_FLAGS
{
	inline COPY_FLAGS()
	{
		memset(this, 0, sizeof(*this));
	}

	bool CURRENTONLY : 1;        // Только текщий?
	bool ONLYNEWERFILES : 1;     // Copy only newer files
	bool OVERWRITENEXT : 1;      // Overwrite all
	bool LINK : 1;               // создание линков
	bool MOVE : 1;               // перенос/переименование
	bool DIZREAD : 1;            //
	bool COPYACCESSMODE : 1;     // [x] Copy files access mode
	bool WRITETHROUGH : 1;       // disable write cache
	bool COPYXATTR : 1;          // copy extended attributes
	bool SPARSEFILES : 1;        // allow producing sparse files
	bool USECOW : 1;             // enable COW funcionality if FS supports it
	bool COPYLASTTIME : 1;       // При копировании в несколько каталогов устанавливается для последнего.
	bool UPDATEPPANEL : 1;       // необходимо обновить пассивную панель
	COPY_SYMLINK SYMLINK : 2;
};

class ShellCopyFileExtendedAttributes
{
	FileExtendedAttributes _xattr;
	bool _apply;

	public:
	ShellCopyFileExtendedAttributes(File &f);
	void ApplyToCopied(File &f);
};

struct ShellCopyBuffer
{
	ShellCopyBuffer();
	~ShellCopyBuffer();

	const DWORD Capacity;

	DWORD Size;

private:
	char * const Buffer;

public:
	char *const Ptr;
};

class ShellFileTransfer
{
	const wchar_t *_SrcName;
	const FARString &_strDestName;
	ShellCopyBuffer &_CopyBuffer;
	COPY_FLAGS &_Flags;
	const FAR_FIND_DATA_EX &_SrcData;

	clock_t _Stopwatch = 0;
	int64_t _AppendPos = -1;
	DWORD _DstFlags = 0;
	DWORD _ModeToCreateWith;

	File _SrcFile, _DestFile;
	bool _LastWriteWasHole = false;
	bool _Done = false;
	std::unique_ptr<ShellCopyFileExtendedAttributes> _XAttrCopyPtr;

	void Undo();
	void RetryCancel(const wchar_t *Text, const wchar_t *Object);
	DWORD PieceWrite(const void *Data, DWORD Size);
	DWORD PieceWriteHole(DWORD Size);
	DWORD PieceCopy();

public:
	ShellFileTransfer(const wchar_t *SrcName, const FAR_FIND_DATA_EX &SrcData,
		const FARString &strDestName, bool Append, ShellCopyBuffer &CopyBuffer, COPY_FLAGS &Flags);
	~ShellFileTransfer();

	void Do();
};

class ShellCopy
{
		COPY_FLAGS Flags;
		Panel *SrcPanel,*DestPanel;
		int SrcPanelMode,DestPanelMode;
		int SrcDriveType,DestDriveType;
		DizList DestDiz;
		FARString strDestDizPath;
		FARString strCopiedName;
		FARString strRenamedName;
		FARString strRenamedFilesPath;
		int OvrMode;
		int ReadOnlyOvrMode;
		int ReadOnlyDelMode;
		int SkipMode;          // ...для пропуска при копировании залоченных файлов.
		int SkipDeleteMode;
		int SelectedFolderNameLength;
		UserDefinedList DestList;
		// тип создаваемого репарспоинта.
		// при AltF6 будет то, что выбрал юзер в диалоге,
		// в остальных случаях - RP_EXACTCOPY - как у источника
		ReparsePointTypes RPT;
		ShellCopyBuffer CopyBuffer;

		std::vector<FARString> SelectedPanelItems;
		struct CopiedDirectory
		{
			std::string Path;
			FILETIME ftUnixAccessTime;
			FILETIME ftUnixModificationTime;
			DWORD dwUnixMode;
		};

		std::vector<CopiedDirectory> DirectoriesAttributes;
		void EnqueueDirectoryAttributes(const FAR_FIND_DATA_EX &SrcData, FARString &strDest);
		void SetEnqueuedDirectoriesAttributes();

		bool IsSymlinkTargetAlsoCopied(const wchar_t *SymLink);

		COPY_CODES CopyFileTree(const wchar_t *Dest);
		COPY_CODES ShellCopyOneFile(const wchar_t *Src,
		                            const FAR_FIND_DATA_EX &SrcData,
		                            FARString &strDest,
		                            int KeepPathPos, int Rename);
		COPY_CODES ShellCopyOneFileNoRetry(const wchar_t *Src,
		                            const FAR_FIND_DATA_EX &SrcData,
		                            FARString &strDest,
		                            int KeepPathPos, int Rename);

		int  ShellCopyFile(const wchar_t *SrcName,const FAR_FIND_DATA_EX &SrcData,
		                   FARString &strDestName,int Append);

		int  DeleteAfterMove(const wchar_t *Name,DWORD Attr);
		void SetDestDizPath(const wchar_t *DestPath);
		int  AskOverwrite(const FAR_FIND_DATA_EX &SrcData,const wchar_t *SrcName,const wchar_t *DestName,
		                  DWORD DestAttr,int SameName,int Rename,int AskAppend,
		                  int &Append,FARString &strNewName,int &RetCode);
		bool CalcTotalSize();
		
		COPY_CODES CreateSymLink(const char *ExistingName, const wchar_t *NewName, const FAR_FIND_DATA_EX &SrcData);
		COPY_CODES CopySymLink(const wchar_t *ExistingName, const wchar_t *NewName, const FAR_FIND_DATA_EX &SrcData);

	public:
		ShellCopy(Panel *SrcPanel,int Move,int Link,int CurrentOnly,int Ask,
		          int &ToPlugin, const wchar_t *PluginDestPath, bool ToSubdir=false);
		~ShellCopy();
};

LONG_PTR WINAPI CopyDlgProc(HANDLE hDlg,int Msg,int Param1,LONG_PTR Param2);