Skip to content

Commit 35f76ec

Browse files
committed
Add "Sync delete to archive"
1 parent e05cce1 commit 35f76ec

File tree

11 files changed

+151
-0
lines changed

11 files changed

+151
-0
lines changed

src/cfg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
#define MAXLINKHASH_KEY "max_linkhash"
7676
#define ALLOWCONTFSIZE_KEY "allow_cont_fsize"
7777
#define RECREATE_KEY "recreate"
78+
#if 4032
79+
#define SYNC_DEL_TO_ARCHIVE_KEY "syncdeltoarchive"
80+
#endif
7881
#define EXTENDFILTER_KEY "extend_filter"
7982
#define WINPOS_KEY "win_pos"
8083
#define TASKBARMODE_KEY "taskbarMode"
@@ -360,6 +363,9 @@ BOOL Cfg::ReadIni(void *user_dir, void *virtual_dir)
360363
maxLinkHash = ini.GetInt(MAXLINKHASH_KEY, DEFAULT_LINKHASH);
361364
allowContFsize = ini.GetInt(ALLOWCONTFSIZE_KEY, DEFAULT_ALLOWCONTFSIZE);
362365
isReCreate = ini.GetInt(RECREATE_KEY, FALSE);
366+
#if 4032
367+
isSyncDelToArchive = ini.GetInt(SYNC_DEL_TO_ARCHIVE_KEY, FALSE);
368+
#endif
363369
isExtendFilter = ini.GetInt(EXTENDFILTER_KEY, FALSE);
364370
taskbarMode = ini.GetInt(TASKBARMODE_KEY, 0);
365371
infoSpan = ini.GetInt(INFOSPAN_KEY, DEFAULT_INFOSPAN);

src/cfg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class Cfg {
167167
int maxLinkHash;
168168
_int64 allowContFsize;
169169
BOOL isReCreate;
170+
#if 4032
171+
BOOL isSyncDelToArchive;
172+
#endif
170173
BOOL isExtendFilter;
171174
int taskbarMode; // 0: use tray, 1: use taskbar
172175
int infoSpan; // information update timing (0:250msec, 1:500msec, 2:1000sec)

src/fastcopy.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,9 @@ BOOL FastCopy::ReadProc(int dir_len, BOOL confirm_dir)
11471147
ret = DeleteFileProc(confirmDst, confirm_len, dstStat->cFileName, dstStat);
11481148
}
11491149
else {
1150+
#if 4032
1151+
DebugW(L"Delete req %s\n",dstStat->cFileName);
1152+
#endif
11501153
SendRequest(DELETE_FILES, 0, dstStat);
11511154
}
11521155
if (isAbort)
@@ -2350,6 +2353,86 @@ BOOL FastCopy::DeleteDirProc(void *path, int dir_len, void *fname, FileStat *sta
23502353
return ret;
23512354
}
23522355

2356+
#if 4032
2357+
BOOL IsFileExists(void * path)
2358+
{
2359+
HANDLE fh;
2360+
2361+
if ((fh = CreateFileV(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, 0,
2362+
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS , 0)) == INVALID_HANDLE_VALUE) {
2363+
return FALSE;
2364+
}
2365+
2366+
::CloseHandle(fh);
2367+
return TRUE;
2368+
}
2369+
2370+
BOOL CreateParentDirectory(void *path, int dirBaseLen)
2371+
{
2372+
WCHAR * dir = new WCHAR [MAX_PATH_EX];
2373+
int i, len;
2374+
2375+
strcpyV( dir, path);
2376+
len = strlenV(dir);
2377+
2378+
len --;
2379+
for( i= dirBaseLen-1; i< len ; i++) {
2380+
if( GetChar(dir,i) == '\\' ) {
2381+
SetChar(dir,i,'\0');
2382+
// Debug("Create dir %s\n",dir);
2383+
if( !CreateDirectoryV(dir,NULL) ) {
2384+
int err = ::GetLastError();
2385+
if( err != ERROR_ALREADY_EXISTS ) {
2386+
DebugW(L"err = %x\n", err);
2387+
}
2388+
}
2389+
SetChar(dir,i,'\\');
2390+
}
2391+
}
2392+
2393+
delete dir;
2394+
return TRUE;
2395+
}
2396+
2397+
2398+
BOOL FastCopy::MoveFileToArchive(void *path)
2399+
{
2400+
if( IsFileExists(path) ) {
2401+
WCHAR * archivePath = new WCHAR [MAX_PATH_EX];
2402+
int archive_len = strlenV(ARCHIVE_V);
2403+
2404+
//DebugW(L"MoveFileToArchive path=%s\n",path);
2405+
2406+
memcpy(archivePath, path, dstBaseLen * CHAR_LEN_V);
2407+
strcpyV(MakeAddr(archivePath, dstBaseLen -1 ),ARCHIVE_V);
2408+
strcpyV(MakeAddr(archivePath, dstBaseLen -1 + archive_len ),MakeAddr(path, dstBaseLen));
2409+
DebugW(L"archive path=%s\n",archivePath);
2410+
2411+
// delete old archive file
2412+
if (DeleteFileV(archivePath) == FALSE) {
2413+
int err = ::GetLastError();
2414+
if( err == ERROR_PATH_NOT_FOUND ) {
2415+
CreateParentDirectory(archivePath, dstBaseLen -1 + archive_len);
2416+
}
2417+
else if(err != ERROR_FILE_NOT_FOUND) {
2418+
DebugW(L"del err = %x\n", err);
2419+
}
2420+
}
2421+
2422+
if(MoveFileV(path,archivePath) == FALSE) {
2423+
int err = ::GetLastError();
2424+
if( err != ERROR_FILE_NOT_FOUND ) {
2425+
DebugW(L"move err = %x\n", err);
2426+
}
2427+
}
2428+
2429+
delete archivePath;
2430+
}
2431+
return TRUE;
2432+
}
2433+
2434+
#endif /* 4032 */
2435+
23532436
BOOL FastCopy::DeleteFileProc(void *path, int dir_len, void *fname, FileStat *stat)
23542437
{
23552438
int len = sprintfV(MakeAddr(path, dir_len), FMT_STR_V, fname);
@@ -2359,6 +2442,14 @@ BOOL FastCopy::DeleteFileProc(void *path, int dir_len, void *fname, FileStat *st
23592442
if (stat->dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
23602443
SetFileAttributesV(path, FILE_ATTRIBUTE_NORMAL);
23612444
}
2445+
#if 4032
2446+
if( info.mode == SYNCCP_MODE && (info.flags & SYNC_DEL_TO_ARCHIVE)) {
2447+
DebugW(L"DeleteFileProc %s\n",(char*)path);
2448+
MoveFileToArchive(path);
2449+
}
2450+
else
2451+
{
2452+
#endif
23622453
void *target = path;
23632454

23642455
if (info.mode == DELETE_MODE && (info.flags & (OVERWRITE_DELETE|OVERWRITE_DELETE_NSA))
@@ -2379,6 +2470,9 @@ BOOL FastCopy::DeleteFileProc(void *path, int dir_len, void *fname, FileStat *st
23792470
total.errFiles++;
23802471
return ConfirmErr("DeleteFile", MakeAddr(target, dstPrefixLen)), FALSE;
23812472
}
2473+
#if 4032
2474+
}
2475+
#endif
23822476
}
23832477
if (isListing) PutList(MakeAddr(path, dstPrefixLen), PL_DELETE|(is_reparse ? PL_REPARSE : 0));
23842478

@@ -3301,6 +3395,12 @@ BOOL FastCopy::WriteFileProc(int dst_len)
33013395

33023396
if (waitTick) Wait((waitTick + 9) / 10);
33033397

3398+
#if 4032
3399+
if( info.mode == SYNCCP_MODE && (info.flags & SYNC_DEL_TO_ARCHIVE)) {
3400+
DebugW(L"src = %s,%d \ndst = %s,%d \n",(char*)src,srcBaseLen,(char*)dst,dstBaseLen);
3401+
MoveFileToArchive(dst);
3402+
}
3403+
#endif
33043404
if (is_require_del) {
33053405
if (!DeleteFileV(dst) && ::GetLastError() != ERROR_FILE_NOT_FOUND) {
33063406
SetFileAttributesV(dst, FILE_ATTRIBUTE_NORMAL);

src/fastcopy.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ class FastCopy {
242242
DISABLE_COMPARE_LIST= 0x00100000,
243243
DEL_BEFORE_CREATE = 0x00200000,
244244
DELDIR_WITH_FILTER = 0x00400000,
245+
#if 4032
246+
SYNC_DEL_TO_ARCHIVE = 0x00800000,
247+
#endif
245248
LISTING = 0x01000000,
246249
VERIFY_MD5 = 0x02000000,
247250
OVERWRITE_PARANOIA = 0x04000000,
@@ -539,6 +542,9 @@ class FastCopy {
539542
BOOL DeleteProc(void *path, int dir_len);
540543
BOOL DeleteDirProc(void *path, int dir_len, void *fname, FileStat *stat);
541544
BOOL DeleteFileProc(void *path, int dir_len, void *fname, FileStat *stat);
545+
#if 4032
546+
BOOL MoveFileToArchive(void *path);
547+
#endif
542548

543549
void SetupRandomDataBuf(void);
544550
void GenRandomName(void *path, int fname_len, int ext_len);

src/fastcopy.rc

152 Bytes
Binary file not shown.

src/mainwin.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ TMainDlg::TMainDlg() : TDlg(MAIN_DIALOG), aboutDlg(this), setupDlg(&cfg, this),
113113
isReparse = cfg.isReparse;
114114
isLinkDest = cfg.isLinkDest;
115115
isReCreate = cfg.isReCreate;
116+
#if 4032
117+
isSyncDelToArchive = cfg.isSyncDelToArchive;
118+
#endif
116119
isExtendFilter = cfg.isExtendFilter;
117120
maxLinkHash = cfg.maxLinkHash;
118121
forceStart = cfg.forceStart;
@@ -1351,6 +1354,9 @@ BOOL TMainDlg::ExecCopy(DWORD exec_flags)
13511354
FastCopy::SERIAL_VERIFY_MOVE : 0)
13521355
| (isLinkDest ? FastCopy::RESTORE_HARDLINK : 0)
13531356
| (isReCreate ? FastCopy::DEL_BEFORE_CREATE : 0)
1357+
#if 4032
1358+
| (isSyncDelToArchive ? FastCopy::SYNC_DEL_TO_ARCHIVE : 0 )
1359+
#endif
13541360
| (diskMode == 0 ? 0 : diskMode == 1 ? FastCopy::FIX_SAMEDISK : FastCopy::FIX_DIFFDISK);
13551361
info.bufSize = GetDlgItemInt(BUFSIZE_EDIT) * 1024 * 1024;
13561362
info.maxTransSize = cfg.maxTransSize * 1024 * 1024;
@@ -2242,6 +2248,9 @@ BOOL TMainDlg::CommandLineExecV(int argc, void **argv)
22422248
void *STREAM_STR = GetLoadStrV(IDS_STREAM_OPT);
22432249
void *LINKDEST_STR = GetLoadStrV(IDS_LINKDEST_OPT);
22442250
void *RECREATE_STR = GetLoadStrV(IDS_RECREATE_OPT);
2251+
#if 4032
2252+
void *SYNC_DEL_TO_ARCHIVE_STR = GetLoadStrV(IDS_SYNC_DEL_TO_ARCHIVE_OPT);
2253+
#endif
22452254
void *SRCFILEW_STR = GetLoadStrV(IDS_SRCFILEW_OPT);
22462255
void *SRCFILE_STR = GetLoadStrV(IDS_SRCFILE_OPT);
22472256
void *FINACT_STR = GetLoadStrV(IDS_FINACT_OPT);
@@ -2354,6 +2363,11 @@ BOOL TMainDlg::CommandLineExecV(int argc, void **argv)
23542363
else if (strcmpiEx(*argv, RECREATE_STR, &len) == 0) {
23552364
isReCreate = GetArgOpt(MakeAddr(*argv, len), TRUE);
23562365
}
2366+
#if 4032
2367+
else if (strcmpiEx(*argv, SYNC_DEL_TO_ARCHIVE_STR, &len) == 0) {
2368+
isSyncDelToArchive = GetArgOpt(MakeAddr(*argv, len), TRUE);
2369+
}
2370+
#endif
23572371
else if (strcmpiEx(*argv, SRCFILEW_STR, &len) == 0) {
23582372
if (!MakeFileToPathArray(MakeAddr(*argv, len), &pathArray, TRUE)) {
23592373
MessageBoxW(FmtW(L"Can't open: %s", MakeAddr(*argv, len)), FASTCOPYW);

src/mainwin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class TMainDlg : public TDlg {
114114
BOOL isLinkDest;
115115
int maxLinkHash;
116116
BOOL isReCreate;
117+
#if 4032
118+
BOOL isSyncDelToArchive;
119+
#endif
117120
BOOL isExtendFilter;
118121
BOOL resultStatus;
119122

src/resource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
#define IDS_NOTEPAD 1146
143143
#define IDS_LINKDEST_OPT 1147
144144
#define IDS_RECREATE_OPT 1148
145+
#if 4032
146+
#define IDS_SYNC_DEL_TO_ARCHIVE_OPT 1165
147+
#endif
145148
#define IDS_FROMDATE_OPT 1149
146149
#define IDS_TODATE_OPT 1150
147150
#define IDS_MINSIZE_OPT 1151

src/tlib/tapi32v.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ void *DOTDOT_V; // ".."
127127
void *QUOTE_V; // "\""
128128
void *TRUE_V; // "true"
129129
void *FALSE_V; // "false"
130+
#if 4032
131+
void *ARCHIVE_V; // " - Archive\\"
132+
#endif
130133
int CHAR_LEN_V; // 2(WCHAR) or 1(char)
131134
int MAX_PATHLEN_V; // MAX_WCHAR or
132135
BOOL IS_WINNT_V; // MAX_WCHAR or
@@ -287,6 +290,9 @@ BOOL TLibInit_Win32V()
287290
QUOTE_V = L"\"";
288291
TRUE_V = L"true";
289292
FALSE_V = L"false";
293+
#if 4032
294+
ARCHIVE_V = L" - Archive\\";
295+
#endif
290296
}
291297
else {
292298
// Win32API(ANSI)
@@ -422,6 +428,9 @@ BOOL TLibInit_Win32V()
422428
QUOTE_V = "\"";
423429
TRUE_V = "true";
424430
FALSE_V = "false";
431+
#if 4032
432+
ARCHIVE_V = " - Archive\\";
433+
#endif
425434
}
426435
return TRUE;
427436
}

src/tlib/tapi32v.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ extern void *DOTDOT_V; // ".."
145145
extern void *QUOTE_V; // "\""
146146
extern void *TRUE_V; // "true"
147147
extern void *FALSE_V; // "false"
148+
#if 4032
149+
extern void *ARCHIVE_V; // " - Archive\\"
150+
#endif
148151
extern int CHAR_LEN_V; // 2(WCHAR) or 1(char)
149152
extern int MAX_PATHLEN_V;
150153
extern BOOL IS_WINNT_V;

0 commit comments

Comments
 (0)