-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomplist.cpp
More file actions
1648 lines (1381 loc) · 48.3 KB
/
complist.cpp
File metadata and controls
1648 lines (1381 loc) · 48.3 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* Copyright (c) Microsoft Corporation. All Rights Reserved.
*/
/*
* complist.cpp
*
* supports a list of compitems, where each compitem represents
* a pair of matching files, or an unmatched file.
*
* We build lists of filenames from two pathnames (using the
* scandir module) and then traverse the two lists comparing names.
* Where the names match, we create a CompItem from the matching
* names. Where there is an unmatched name, we create a compitem for it.
*
* we may also be asked to create a complist for two individual files:
* here we create a single compitem for them as a matched pair even if
* the names don't match.
*
*/
#include "precomp.h"
#include "state.h"
#include "sdkdiff.h"
#include "wdiffrc.h"
#include "list.h"
#include "line.h"
#include "scandir.h"
#include "file.h"
#include "section.h"
#include "compitem.h"
#include "complist.h"
#include "view.h"
extern BOOL bAbort; /* in sdkdiff.cpp Read only here */
#ifdef trace
extern bTrace; /* in sdkdiff.cpp Read only here */
#endif
/*
* the COMPLIST handle is typedef-ed to be a pointer to one
* of these struct complist
*/
struct complist {
DIRLIST left; /* left list of files */
DIRLIST right; /* right list of files */
LIST items; /* list of COMPITEMs */
};
/* ---- module-wide data -------------------------------------*/
/* data for communicating between the SaveList dlg and complist_savelist() */
char dlg_file[MAX_PATH]; /* filename to save to */
BOOL dlg_sums = TRUE;
// have we read the dialog names yet?
BOOL SeenDialogNames = FALSE;
/* checkbox options */
BOOL dlg_identical, dlg_differ, dlg_left, dlg_right;
/* data for Directory, SaveList dialog box */
char dialog_leftname[MAX_PATH];
char dialog_rightname[MAX_PATH];
char dialog_servername[80];
BOOL dialog_recursive; // do whole tree
BOOL dialog_fastscan; // times and sizes only, no checksums
BOOL dialog_autocopy; // copy to update local directory
/*
* data used by dodlg_copyfiles
*/
UINT dlg_options;
BOOL dlg_IgnoreMarks;
BOOL dlg_IgnoreAttributes;
char dlg_root[MAX_PATH];
/*------------------------timing for performance measurements-----------------*/
static DWORD TickCount; /* time operation started, then time taken*/
/* --- forward declaration of internal functions ----------------------------*/
int FAR PASCAL complist_dodlg_savelist(HWND hDlg, UINT message,
UINT wParam, long lParam);
int FAR PASCAL complist_dodlg_copyfiles(HWND hDlg, UINT message,
UINT wParam, long lParam);
BOOL complist_match(COMPLIST cl, VIEW view, BOOL fDeep, BOOL fExact);
COMPLIST complist_new(void);
int FAR PASCAL complist_dodlg_dir(HWND hDlg, unsigned message,
UINT wParam, LONG lParam);
/* --- external functions ----------------------------------- */
/*
* query the user to select two files, then build the list from
* these files.
*/
COMPLIST
complist_filedialog(VIEW view)
{
COMPLIST cl = NULL;
char szPath1[MAX_PATH * 2];
char szPath2[MAX_PATH * 2];
char fname[MAX_PATH], FileExt[5], FileOpenSpec[15];
HRESULT hr;
/* ask for the filenames - using gfile standard dialogs */
hr = StringCchCopy(FileExt, 5, ".c");
if (FAILED(hr)) {
OutputError(hr, IDS_SAFE_COPY);
goto LError;
}
hr = StringCchCopy(FileOpenSpec, 5, "*.*");
if (FAILED(hr)) {
OutputError(hr, IDS_SAFE_COPY);
goto LError;
}
if (!gfile_open(hwndClient, LoadRcString(IDS_SELECT_FIRST_FILE), FileExt, FileOpenSpec, szPath1, NUMELMS(szPath1), fname) ){
goto LError;
}
if (!gfile_open(hwndClient, LoadRcString(IDS_SELECT_SECOND_FILE), FileExt, FileOpenSpec, szPath2, NUMELMS(szPath2), fname) ){
goto LError;
}
/* alloc a new structure */
cl = complist_new();
cl->left = dir_buildlist(szPath1, FALSE, TRUE);
cl->right = dir_buildlist(szPath2, FALSE, TRUE);
/* register with the view (must be done after the list is non-null) */
view_setcomplist(view, cl);
complist_match(cl, view, FALSE, TRUE);
LError:
return(cl);
}/* complist_filedialog */
void
complist_setdialogdefault(
LPSTR left,
LPSTR right,
BOOL fDeep)
{
HRESULT hr;
dialog_recursive = fDeep;
hr = StringCchCopy(dialog_leftname, MAX_PATH, left);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
hr = StringCchCopy(dialog_rightname, MAX_PATH, right);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
SeenDialogNames = TRUE;
}
/* build a new complist by querying the user for two directory
* names and scanning those in parallel.
*
* names that match in the same directory will be paired. unmatched
* names will go in a compitem on their own.
*/
COMPLIST
complist_dirdialog(VIEW view)
{
DLGPROC lpProc;
BOOL fOK;
/* put up a dialog for the two pathnames */
lpProc = (DLGPROC)MakeProcInstance((WINPROCTYPE)complist_dodlg_dir, hInst);
sdkdiff_UI(TRUE);
fOK = (BOOL)DialogBox(hInst, "Directory", hwndClient, lpProc);
sdkdiff_UI(FALSE);
FreeProcInstance(lpProc);
if (!fOK) {
return(NULL);
}
return complist_args( dialog_leftname, dialog_rightname
, view, dialog_recursive );
} /* complist_dirdialog */
/*
* given two pathname strings, scan the directories and traverse them
* in parallel comparing matching names.
*/
COMPLIST
complist_args(LPSTR p1, LPSTR p2, VIEW view, BOOL fDeep)
{
COMPLIST cl;
char msg[MAX_PATH+20];
HRESULT hr;
/* alloc a new complist */
cl = complist_new();
//
// accept \\server!path for a checksum server and
// pathname - assumes no \\server\share names have !
// within the server name.
{
cl->left = dir_buildlist(p1, FALSE, TRUE);
}
/* check that we could find the paths, and report if not */
if (cl->left == NULL) {
hr = StringCchPrintf(msg, (MAX_PATH+20), LoadRcString(IDS_COULDNT_FIND), p1);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
TRACE_ERROR(msg, FALSE);
complist_delete(cl);
cl = NULL;
goto LError;
}
{
cl->right = dir_buildlist(p2, FALSE, TRUE);
}
/* check that we could find the paths, and report if not */
if (cl->right == NULL) {
hr = StringCchPrintf(msg, (MAX_PATH+20), LoadRcString(IDS_COULDNT_FIND), p2);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
TRACE_ERROR(msg, FALSE);
complist_delete(cl);
cl = NULL;
goto LError;
}
if (!TrackLeftOnly) {
dir_setotherdirlist(cl->left, cl->right);
}
if (!TrackRightOnly) {
dir_setotherdirlist(cl->right, cl->left);
}
{
// remember these paths as defaults for the next dialog -
// get the normalised, absolute paths
LPSTR pleft = dir_getrootdescription(cl->left);
LPSTR pright = dir_getrootdescription(cl->right);
complist_setdialogdefault(pleft, pright, fDeep);
dir_freerootdescription(cl->left, pleft);
dir_freerootdescription(cl->right, pright);
}
/* register with the view (must be done after building lists) */
view_setcomplist(view, cl);
complist_match(cl, view, fDeep, TRUE);
LError:
return(cl);
} /* complist_args */
/*
* given two pathname strings, scan the directories and traverse them
* in parallel comparing matching names.
*/
void
complist_append(COMPLIST *pcl, LPCSTR p1, LPCSTR p2, int *psequence)
{
COMPLIST cl;
if (!*pcl)
{
/* alloc a new complist */
*pcl = complist_new();
}
cl = *pcl;
dir_appendlist(&cl->left, p1, FALSE, psequence);
dir_appendlist(&cl->right, p2, FALSE, psequence);
} /* complist_append */
/*
* finished appending files -- set custom descriptions (instead of calculating
* them based on directory names), register with view, and match the left and
* right sides of the complist.
*/
BOOL
complist_appendfinished(COMPLIST *pcl, LPCSTR pszLeft, LPCSTR pszRight, VIEW view)
{
BOOL fSuccess = FALSE;
COMPLIST cl;
char msg[MAX_PATH+20] = {0};
HRESULT hr;
if (!*pcl)
goto LError;
cl = *pcl;
if (!cl->left || !cl->right)
{
hr = StringCchCatN(msg, (MAX_PATH+20), LoadRcString(IDS_COULDNT_FIND_ANYTHING), sizeof(msg)-1);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_CAT);
TRACE_ERROR(msg, FALSE);
goto LError;
}
dir_setdescription(cl->left, pszLeft);
dir_setdescription(cl->right, pszRight);
if (!TrackLeftOnly)
dir_setotherdirlist(cl->left, cl->right);
if (!TrackRightOnly)
dir_setotherdirlist(cl->right, cl->left);
/* register with the view (must be done after building lists) */
view_setcomplist(view, cl);
complist_match(cl, view, FALSE, TRUE);
fSuccess = TRUE;
LError:
return fSuccess;
}
/*
* return a handle to the list of compitems in this complist
*/
LIST
complist_getitems(COMPLIST cl)
{
if (cl == NULL) {
return(NULL);
}
return(cl->items);
}
/* delete a complist and all associated compitems and dirlists
*/
void
complist_delete(COMPLIST cl)
{
COMPITEM item;
if (cl == NULL) {
return;
}
/* delete the two directory scan lists */
dir_delete(cl->left);
dir_delete(cl->right);
/* delete the compitems in the list */
for( item=(COMPITEM)List_First(cl->items); item!=NULL; item = (COMPITEM)List_Next((LPVOID)item)) {
compitem_delete(item);
}
/* delete the list itself */
List_Destroy(&cl->items);
HeapFree(GetProcessHeap(), NULL, (LPSTR) cl);
}
/*
* write out to a text file the list of compitems as relative filenames
* one per line.
*
* if savename is non-null, use this as the filename for output. otherwise
* query the user via a dialog for the filename and include options.
*
* There are hidden parameters (dlg_sums etc) from the dialog.
* Note that we never attempt to recalculate sums.
*/
void
complist_savelist(COMPLIST cl, LPSTR savename, UINT options)
{
DLGPROC lpProc;
static BOOL done_init = FALSE;
BOOL bOK;
HANDLE fh;
DWORD cbWritten;
int state;
char msg[2*MAX_PATH+100] = {0};
HCURSOR hcurs;
COMPITEM ci;
LPSTR pstr, lhead;
int nFiles = 0;
HRESULT hr;
if (!done_init) {
/* init the options once round - but keep the same options
* for the rest of the session.
*/
/* first init default options */
dlg_identical = (outline_include & INCLUDE_SAME);
dlg_differ = (outline_include & INCLUDE_LEFTONLY);
dlg_left = (outline_include & INCLUDE_RIGHTONLY);
dlg_right = (outline_include & INCLUDE_DIFFER);
dlg_IgnoreMarks = hide_markedfiles;
dlg_file[0] = '\0';
done_init = TRUE;
}
if (cl == NULL) {
return;
}
if (savename == NULL) {
/* store the left and right rootnames so that dodlg_savelist
* can display them in the dialog.
*/
pstr = dir_getrootdescription(cl->left);
hr = StringCchCopy(dialog_leftname, MAX_PATH, pstr);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
dir_freerootdescription(cl->left, pstr);
pstr = dir_getrootdescription(cl->right);
hr = StringCchCopy(dialog_rightname, MAX_PATH, pstr);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
dir_freerootdescription(cl->right, pstr);
lpProc = (DLGPROC)MakeProcInstance((WINPROCTYPE)complist_dodlg_savelist, hInst);
sdkdiff_UI(TRUE);
bOK = (BOOL)DialogBox(hInst, "SaveList", hwndClient, lpProc);
sdkdiff_UI(FALSE);
FreeProcInstance(lpProc);
if (!bOK) {
/* user cancelled from dialog box */
return;
}
savename = dlg_file;
} else {
dlg_identical = (options & INCLUDE_SAME);
dlg_differ = (options & INCLUDE_DIFFER);
dlg_left = (options & INCLUDE_LEFTONLY);
dlg_right = (options & INCLUDE_RIGHTONLY);
GetFullPathName(savename, sizeof(dlg_file), dlg_file, NULL);
}
/* try to open the file */
fh = CreateFile(savename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if (fh == INVALID_HANDLE_VALUE) {
hr = StringCchPrintf(msg, (2*MAX_PATH+100),LoadRcString(IDS_CANT_OPEN), savename);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
sdkdiff_UI(TRUE);
MessageBox(hwndClient, msg, "Sdkdiff", MB_ICONSTOP|MB_OK);
sdkdiff_UI(FALSE);
return;
}
hcurs = SetCursor(LoadCursor(NULL, IDC_WAIT));
/* write out the header line */
lhead = complist_getdescription(cl);
{
TCHAR szBuf1[20],szBuf2[20],szBuf3[20],szBuf4[20];
hr = StringCchCopy(szBuf1,20,(LPSTR)(dlg_identical ? LoadRcString(IDS_IDENTICAL_COMMA) : ""));
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
hr = StringCchCopy(szBuf2,20,(LPSTR)(dlg_left ? LoadRcString(IDS_LEFT_ONLY_COMMA) : ""));
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
hr = StringCchCopy(szBuf3,20,(LPSTR)(dlg_right ? LoadRcString(IDS_RIGHT_ONLY_COMMA) : ""));
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
hr = StringCchCopy(szBuf4,20,(LPSTR)(dlg_differ ? LoadRcString(IDS_DIFFERING) : ""));
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
hr = StringCchPrintf(msg, (2*MAX_PATH+100), LoadRcString(IDS_HEADER_LINE_STR),
lhead, szBuf1, szBuf2, szBuf3, szBuf4);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
WriteFile(fh, msg, lstrlen(msg), &cbWritten, NULL);
complist_freedescription(cl, lhead);
/* traverse the list of compitems looking for the
* ones we are supposed to include
*/
for( ci=(COMPITEM)List_First(cl->items); ci!=NULL; ci = (COMPITEM)List_Next((LPVOID)ci)) {
/* check if files of this type are to be listed */
state = compitem_getstate(ci);
if ((state == STATE_SAME) && (!dlg_identical)) {
continue;
} else if ((state == STATE_DIFFER) && (!dlg_differ)) {
continue;
} else if ((state == STATE_FILELEFTONLY) && (!dlg_left)) {
continue;
} else if ((state == STATE_FILERIGHTONLY) && (!dlg_right)) {
continue;
}
if (dlg_IgnoreMarks && compitem_getmark(ci)) {
continue;
}
nFiles++;
/* output the list line */
ZeroMemory(msg, sizeof(msg));
hr = StringCchCatN(msg, (2*MAX_PATH+100), compitem_gettext_tag(ci), sizeof(msg) - 1);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_CAT);
WriteFile(fh, msg, lstrlen(msg), &cbWritten, NULL);
/* write out the result of the comparison */
{ LPSTR p;
p = compitem_gettext_result(ci);
hr = StringCchPrintf( msg, (2*MAX_PATH+100), "\t%s"
, p ? p : "sdkdiff error"
);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
WriteFile(fh, msg, lstrlen(msg), &cbWritten, NULL);
if (dlg_sums) {
if (compitem_getleftfile(ci) != NULL) {
BOOL bValid;
DWORD cksum;
cksum = file_retrievechecksum(compitem_getleftfile(ci),&bValid);
if (bValid) {
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\t%8lx", cksum);
if (FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
else {
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\t????????");
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
} else {
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\t--------");
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
WriteFile(fh, msg, lstrlen(msg), &cbWritten, NULL);
if (compitem_getrightfile(ci) != NULL) {
BOOL bValid;
DWORD cksum;
cksum = file_retrievechecksum(compitem_getrightfile(ci),&bValid);
if (bValid) {
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\t%8lx", cksum);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
else {
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\t????????");
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
} else {
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\t--------");
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
WriteFile(fh, msg, lstrlen(msg), &cbWritten, NULL);
}
hr = StringCchPrintf(msg, (2*MAX_PATH+100), "\r\n");
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
WriteFile(fh, msg, (DWORD)strlen(msg), &cbWritten, NULL);
}
/* write tail line */
hr = StringCchPrintf(msg, (2*MAX_PATH+100), LoadRcString(IDS_FILES_LISTED), nFiles);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
WriteFile(fh, msg, (DWORD)lstrlen(msg), &cbWritten, NULL);
/* - close file and we are finished */
CloseHandle(fh);
SetCursor(hcurs);
} /* complist_savelist */
/*
* copy files to a new directory newroot. if newroot is NULL, query the user
* via a dialog to get the new dir name and options.
*
* options are either COPY_FROMLEFT or COPY_FROMRIGHT (indicating which
* tree is to be the source of the files, plus any or all of
* INCLUDE_SAME, INCLUDE_DIFFER and INCLUDE_LEFT (INCLUDE_LEFT
* and INCLUDE_RIGHT are treated the same here since the COPY_FROM* option
* indicates which side to copy from).
*/
void
complist_copyfiles(COMPLIST cl, LPSTR newroot, UINT options)
{
int nFiles = 0;
int nFails = 0;
static BOOL done_init = FALSE;
LPSTR pstr;
char buffer[MAX_PATH+20];
DIRITEM diritem;
DLGPROC lpProc;
BOOL bOK;
COMPITEM ci;
int state;
BOOL HitReadOnly = ((options©_HITREADONLY)==COPY_HITREADONLY);
BOOL CopyNoAttributes;
HRESULT hr;
if (!done_init) {
/*
* one-time initialisation of dialog defaults
*/
dlg_options = COPY_FROMLEFT|INCLUDE_LEFTONLY|INCLUDE_DIFFER;
dlg_root[0] = '\0';
// set the ignore-marked files option by default the same
// as the hide mark files menu option. If he doesn't want them
// visible, he probably doesn't want them copied.
dlg_IgnoreMarks = hide_markedfiles;
done_init = TRUE;
}
if (cl == NULL) {
return;
}
if (newroot == NULL) {
/*
* put up dialog to query rootname and options
*/
/* store the left and right rootnames so that the dlg proc
* can display them in the dialog.
*/
pstr = dir_getrootdescription(cl->left);
hr = StringCchCopy(dialog_leftname, MAX_PATH, pstr);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
dir_freerootdescription(cl->left, pstr);
pstr = dir_getrootdescription(cl->right);
hr = StringCchCopy(dialog_rightname, MAX_PATH, pstr);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
dir_freerootdescription(cl->right, pstr);
do {
lpProc = (DLGPROC)MakeProcInstance((WINPROCTYPE)complist_dodlg_copyfiles, hInst);
sdkdiff_UI(TRUE);
bOK = (BOOL)DialogBox(hInst, "CopyFiles", hwndClient, lpProc);
sdkdiff_UI(FALSE);
FreeProcInstance(lpProc);
if (!bOK) {
/* user cancelled from dialog box */
return;
}
if (lstrlen(dlg_root) == 0) {
sdkdiff_UI(TRUE);
MessageBox( hwndClient, LoadRcString(IDS_ENTER_DIR_NAME),
"Sdkdiff", MB_ICONSTOP|MB_OK);
sdkdiff_UI(FALSE);
}
} while (lstrlen(dlg_root) == 0);
} else {
// no dialog - all options passed in (eg from command line).
// note that in this case the dlg_IgnoreMarks is left as
// whatever the hide_markedfiles menu option is set to.
dlg_options = options;
hr = StringCchCopy(dlg_root, MAX_PATH, newroot);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
}
TickCount = GetTickCount();
/* this relies on the sumserver, server and share (if any) being the same for
all the things on the list. We set up the first one and then just check
that it doesn't change (within ss_client). If it turns out to be a local
copy these things turn into no-ops somewhere below us.
*/
if (dlg_options & COPY_FROMLEFT) {
if (!dir_startcopy(cl->left))
return;
} else {
if (!dir_startcopy(cl->right))
return;
}
CopyNoAttributes = dlg_IgnoreAttributes;
/*
* traverse the list of compitems copying files as necessary
*/
for( ci=(COMPITEM)List_First(cl->items); ci!=NULL; ci = (COMPITEM)List_Next((LPVOID)ci)) {
if (bAbort) {
break; /* fall into end_copy processing */
}
// ignore marked files totally if the option was
// set in the dialog.
if (dlg_IgnoreMarks && compitem_getmark(ci)) {
continue;
}
/* check if files of this type are to be copied */
state = compitem_getstate(ci);
if ((state == STATE_SAME) && !(dlg_options & INCLUDE_SAME)) {
continue;
} else if ((state == STATE_DIFFER) && !(dlg_options & INCLUDE_DIFFER)) {
continue;
} else if (state == STATE_FILELEFTONLY) {
if (dlg_options & COPY_FROMRIGHT) {
continue;
}
if ((dlg_options & (INCLUDE_LEFTONLY | INCLUDE_RIGHTONLY)) == 0) {
continue;
}
} else if (state == STATE_FILERIGHTONLY) {
if (dlg_options & COPY_FROMLEFT) {
continue;
}
if ((dlg_options & (INCLUDE_LEFTONLY | INCLUDE_RIGHTONLY)) == 0) {
continue;
}
}
if (dlg_options & COPY_FROMLEFT) {
diritem = file_getdiritem(compitem_getleftfile(ci));
} else {
diritem = file_getdiritem(compitem_getrightfile(ci));
}
/*
* copy the file to the new root directory
*/
if (dir_copy(diritem, dlg_root, HitReadOnly, CopyNoAttributes) == FALSE) {
nFails++;
pstr = dir_getrelname(diritem);
hr = StringCchPrintf(buffer, (MAX_PATH+20), LoadRcString(IDS_FAILED_TO_COPY), pstr);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
dir_freerelname(diritem, pstr);
if (!TRACE_ERROR(buffer, TRUE)) {
/* user pressed cancel - abort current operation*/
/* fall through to end-copy processing */
break;
}
} else {
nFiles++;
}
hr = StringCchPrintf(buffer, (MAX_PATH+20), LoadRcString(IDS_COPYING), nFiles);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
SetStatus(buffer);
/*
* allow user interface to continue
*/
if (Poll()) {
/* abort requested */
TickCount = GetTickCount()-TickCount;
sdkdiff_UI(TRUE);
MessageBox(hwndClient, LoadRcString(IDS_COPY_ABORTED),
"SdkDiff", MB_OK|MB_ICONINFORMATION);
sdkdiff_UI(FALSE);
break;
}
} /* traverse */
hr = StringCchPrintf(buffer, (MAX_PATH+20), LoadRcString(IDS_COPYING_NFILES), nFiles);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
SetStatus(buffer);
if (dlg_options & COPY_FROMLEFT) {
nFails = dir_endcopy(cl->left);
} else {
nFails = dir_endcopy(cl->right);
}
TickCount = GetTickCount()-TickCount;
if (nFails<0) {
hr = StringCchPrintf(buffer, (MAX_PATH+20), LoadRcString(IDS_COPY_FAILED), -nFails);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
} else {
hr = StringCchPrintf(buffer, (MAX_PATH+20), LoadRcString(IDS_COPY_COMPLETE), nFails);
if(FAILED(hr))
OutputError(hr, IDS_SAFE_PRINTF);
}
sdkdiff_UI(TRUE);
MessageBox(hwndClient, buffer, "SdkDiff", MB_OK|MB_ICONINFORMATION);
sdkdiff_UI(FALSE);
buffer[0] = '\0';
SetStatus(buffer);
} /* complist_copyfiles */
/*
* complist_togglemark
*
* each compitem has a BOOL mark state. This function inverts the value of
* this state for each compitem in the list.
*/
void
complist_togglemark(COMPLIST cl)
{
COMPITEM ci;
if (cl == NULL) {
return;
}
/*
* traverse the list of compitems copying files as necessary
*/
for( ci=(COMPITEM)List_First(cl->items); ci!=NULL; ci = (COMPITEM)List_Next((LPVOID)ci)) {
compitem_setmark(ci, !compitem_getmark(ci));
}
}
/*
* complist_itemcount
*
* return the number of items in the list
*/
UINT
complist_itemcount(COMPLIST cl)
{
UINT n = 0;
if (cl == NULL) {
return 0;
}
/*
* return the number of compitems in the list
*/
return List_Card(cl->items);
}
#ifdef USE_STD_REGEXP
#include <regex>
BOOL
complist_markpattern(COMPLIST cl)
{
TCHAR szBuff[40];
HRESULT hr = StringCchCopy(szBuff, 40, LoadRcString(IDS_MARK_FILES));
if (FAILED(hr)) {
OutputError(hr, IDS_SAFE_COPY);
return FALSE;
}
char previous_pat[1000];
GetProfileString(APPNAME, "Pattern", "\\.obj$", previous_pat, 1000);
sdkdiff_UI(TRUE);
char achPattern[1000];
BOOL bOK = StringInput(achPattern, sizeof(achPattern),
LoadRcString(IDS_ENTER_SUBSTRING1),
szBuff, previous_pat );
sdkdiff_UI(FALSE);
if (!bOK) {
return FALSE;
}
if (strcmp(previous_pat, achPattern) != 0) {
WriteProfileString(APPNAME, "Pattern", achPattern);
}
std::tr1::regex R(std::string(achPattern), std::tr1::regex::icase);
if (!cl) {
return FALSE;
}
COMPITEM ci;
for (ci=(COMPITEM)List_First(cl->items); ci != NULL; ci = (COMPITEM)List_Next((LPVOID)ci)) {
LPSTR ptag = compitem_gettext_tag(ci);
if (std::tr1::regex_search(ptag, R)) {
if (!compitem_getmark(ci)) {
bOK = TRUE;
compitem_setmark(ci, TRUE);
}
} else {
compitem_setmark(ci, FALSE);
}
}
return bOK;
}
#elif defined(USE_REGEXP)
#include "regexp.h"
/*
* query the user for a pattern to match.
* all compitems with this pattern in their tag string will be
* marked (the mark state will be set to TRUE);
*
* returns TRUE if any states changed
*/
BOOL
complist_markpattern(COMPLIST cl)
{
COMPITEM ci;
char achPattern[MAX_PATH];
BOOL bOK = FALSE;
LPSTR ptag;
HRESULT hr;
regexp *prog;
static char previous_pat[256]; /* allow for a big pattern ! */
static BOOL fInit = TRUE;
TCHAR szBuff[40];
hr = StringCchCopy(szBuff, 40, LoadRcString(IDS_MARK_FILES));
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
sdkdiff_UI(TRUE);
if ( fInit ) {
GetProfileString(APPNAME, "Pattern", "\\.obj$", previous_pat, 256);
fInit = FALSE;
}
bOK = StringInput(achPattern, sizeof(achPattern),
LoadRcString(IDS_ENTER_SUBSTRING1),
szBuff, previous_pat );
sdkdiff_UI(FALSE);
if (!bOK) {
return(FALSE);
}
/*
** Compile the specified regular expression
*/
if ((prog = regcomp(achPattern)) == NULL) {
return(FALSE);
}
/*
** only overwrite previous pattern with a known good pattern
*/
hr = StringCchCopy( previous_pat, 256, achPattern );
if(FAILED(hr))
OutputError(hr, IDS_SAFE_COPY);
WriteProfileString(APPNAME, "Pattern", previous_pat);
bOK = FALSE;
if (cl) {
for( ci=(COMPITEM)List_First(cl->items); ci!=NULL; ci = (COMPITEM)List_Next((LPVOID)ci)) {
ptag = compitem_gettext_tag(ci);
if ( regexec( prog, ptag, 0 ) ) { /* got a match */
if (!compitem_getmark(ci)) {
bOK = TRUE;
compitem_setmark(ci, TRUE);
}