/
wfcopy.c
3780 lines (2906 loc) · 101 KB
/
wfcopy.c
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
/********************************************************************
wfcopy.c
Windows File System File Copying Routines
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
********************************************************************/
#include "winfile.h"
#include "lfn.h"
#include "wfcopy.h"
BOOL *pbConfirmAll;
BOOL *pbConfirmReadOnlyAll;
INT ManySource;
VOID wfYield(VOID);
INT CopyMoveRetry(LPTSTR, INT, PBOOL);
DWORD CopyError(LPTSTR, LPTSTR, DWORD, DWORD, INT, BOOL, BOOL);
BOOL IsRootDirectory(LPTSTR pPath);
DWORD ConfirmDialog(
HWND hDlg, DWORD dlg,
LPTSTR pFileDest, PLFNDTA pDTADest,
LPTSTR pFileSource, PLFNDTA pDTASource,
BOOL bConfirmByDefault, BOOL *pbAll,
BOOL bConfirmReadOnlyByDefault, BOOL *pbReadOnlyAll);
DWORD IsInvalidPath(LPTSTR pPath);
DWORD GetNextPair(PCOPYROOT pcr, LPTSTR pFrom, LPTSTR pToPath, LPTSTR pToSpec, DWORD dwFunc, PDWORD pdwError, BOOL bIsLFNDriveDest);
INT CheckMultiple(LPTSTR pInput);
VOID DialogEnterFileStuff(HWND hwnd);
DWORD SafeFileRemove(LPTSTR szFileOEM);
BOOL IsWindowsFile(LPTSTR szFileOEM);
INT_PTR CALLBACK ReplaceDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
BOOL
IsValidChar(TUCHAR ch, BOOL fPath, BOOL bLFN)
{
switch (ch) {
case CHAR_SEMICOLON: // terminator
case CHAR_COMMA: // terminator
return bLFN;
case CHAR_PIPE: // pipe
case CHAR_GREATER: // redir
case CHAR_LESS: // redir
case CHAR_DQUOTE: // quote
return FALSE;
case CHAR_QUESTION: // wc we only do wilds here because they're
case CHAR_STAR: // wc legal for qualifypath
case CHAR_BACKSLASH: // path separator
case CHAR_COLON: // drive colon
case CHAR_SLASH: // path sep
case CHAR_SPACE: // space: valid on NT FAT, but winball can't use.
return fPath;
}
//
// cannot be a control character or space
//
return ch > CHAR_SPACE;
}
//--------------------------------------------------------------------------
//
// StripColon() -
//
// removes trailing colon if not a drive letter.
// this is to support DOS character devices (CON:, COM1: LPT1:). DOS
// can't deal with these things having a colon on the end (so we strip it).
//
//--------------------------------------------------------------------------
LPTSTR
StripColon(LPTSTR pPath)
{
INT cb = lstrlen(pPath);
if (cb > 2 && pPath[cb-1] == CHAR_COLON)
pPath[cb-1] = CHAR_NULL;
return pPath;
}
/*--------------------------------------------------------------------------*/
/* */
/* FindFileName() - */
/* */
/*--------------------------------------------------------------------------*/
/* Returns a pointer to the last component of a path string. */
LPTSTR
FindFileName(LPTSTR pPath)
{
LPTSTR pT;
for (pT=pPath; *pPath; pPath++) {
if ((pPath[0] == CHAR_BACKSLASH || pPath[0] == CHAR_COLON) && pPath[1])
pT = pPath+1;
}
return(pT);
}
/*--------------------------------------------------------------------------*/
/* */
/* AppendToPath() - */
/* */
/*--------------------------------------------------------------------------*/
/* Appends a filename to a path. Checks the \ problem first
* (which is why one can't just use lstrcat())
* Also don't append a \ to : so we can have drive-relative paths...
* this last bit is no longer appropriate since we qualify first!
*
* is this relative junk needed anymore? if not this can be
* replaced with AddBackslash(); lstrcat()
*/
VOID
AppendToPath(LPTSTR pPath, LPCTSTR pMore)
{
/* Don't append a \ to empty paths. */
if (*pPath)
{
while (*pPath)
pPath++;
if (pPath[-1]!=CHAR_BACKSLASH)
*pPath++=CHAR_BACKSLASH;
}
/* Skip any initial terminators on input. */
while (*pMore == CHAR_BACKSLASH)
pMore++;
lstrcpy(pPath, pMore);
}
/*--------------------------------------------------------------------------*/
/* */
/* RemoveLast() - */
/* */
/*--------------------------------------------------------------------------*/
// Deletes the last component of a filename in a string.
//
// Warning: assumes BACKSLASH or : exists in string
UINT
RemoveLast(LPTSTR pFile)
{
LPTSTR pT;
UINT uChars = 0;
for (pT=pFile; *pFile; pFile++) {
if (*pFile == CHAR_BACKSLASH) {
pT = pFile;
uChars = 0;
} else if (*pFile == CHAR_COLON) {
if (pFile[1] ==CHAR_BACKSLASH) {
pFile++;
}
pT = pFile + 1;
uChars = 0;
continue;
}
uChars++;
}
*pT = CHAR_NULL;
return uChars;
}
/////////////////////////////////////////////////////////////////////
//
// Name: QualifyPath
//
// Synopsis: Qualify a DOS/LFN file name based on current window
//
// INOUT lpszPath -- Filename to qualify: turns into path
// INC bClearDots -- When set, clears trailing dots/spaces
//
// Return: BOOL T/F Valid/Invalid path
//
//
// Assumes:
//
// Effects:
//
//
// Notes: Drive based on current active window
//
//
// BUGBUG !!!
//
// Almost all of this code can be replaced with one call to
// the Win32 GetFullPathName() api!
//
/////////////////////////////////////////////////////////////////////
BOOL
QualifyPath(LPTSTR lpszPath)
{
INT cb, nSpaceLeft, i, j;
TCHAR szTemp[MAXPATHLEN];
DRIVE drive = 0;
LPTSTR pOrig, pT;
BOOL flfn = FALSE;
BOOL fQuote = FALSE;
TCHAR szDrive[] = SZ_ACOLONSLASH;
LPTSTR lpszDot;
UINT uLen;
JAPANBEGIN
//
// Adapted from [#1743 28-Aug-93 v-katsuy]
//
// We must do a conversion to DBCS for FAT and HPFS since they
// store characters as DBCS. Since a character may be 2 bytes,
// an 8.3 name that the user types in may actually take more space.
//
// Therefore, we must do nSpaceLeft calculations based on DBCS
// sizing. We can still do copying using UNICODE since the conversion
// will be done later also.
//
// !! BUGBUG !!
// 1. We really don't know when we're using HPFS, so this case isn't
// handled.
//
// 2. We don't correctly handle the case "\joker\..\doc.foo" where
// "joker" takes > lstrlen("joker"). This is because RemoveLast
// calculates size using lstrlen, and doesn't consider DBCS.
//
// Allocate enough space for 8.3 conversion to DBCS here (each
// part done individually, so 8 chars is enough).
//
LPSTR pOrigA = NULL;
CHAR szOrigA[8*2];
JAPANEND
//
// Save it away.
//
StrNCpy(szTemp, lpszPath, COUNTOF(szTemp));
CheckSlashes(szTemp);
StripColon(szTemp);
nSpaceLeft = MAXPATHLEN - 1;
//
// Strip off Surrounding Quotes
//
for( pT = pOrig = szTemp; *pOrig; pOrig++ ) {
if (*pOrig != CHAR_DQUOTE) {
*pT++ = *pOrig;
} else {
fQuote = TRUE;
}
}
pOrig = szTemp;
if (ISUNCPATH(pOrig)) {
//
// Stop at"\\foo\bar"
//
for (i=0, j=2, pOrig+=2; *pOrig && i<2; pOrig++, j++) {
if (CHAR_BACKSLASH == *pOrig)
i++;
}
//
// "\\foo" is an invalid path, but "\\foo\bar" is ok
//
if (!i)
return FALSE;
flfn = IsLFNDrive(lpszPath);
//
// If i == 2, then we found the trailing \, axe it off
//
if (2 == i) {
j--;
lpszPath[j] = CHAR_NULL;
}
nSpaceLeft -= j;
goto GetComps;
}
if (pOrig[0] && CHAR_COLON == pOrig[1]) {
//
// Check for valid pOrig[1]!
// Else seg fault off of search window
//
if ( !(pOrig[0] >= CHAR_A && pOrig[0] <= CHAR_Z) &&
!(pOrig[0] >= CHAR_a && pOrig[0] <= TEXT('z')) ) {
//
// Invalid drive string; return FALSE!
//
return FALSE;
}
drive = DRIVEID(pOrig);
//
// Skip over the drive letter.
//
pOrig += 2;
} else {
drive = GetSelectedDrive();
}
DRIVESET(szDrive,drive);
flfn = IsLFNDrive(szDrive);
//
// on FAT _AND_ lfn devices, replace any illegal chars with underscores
//
for (pT = pOrig; *pT; pT++) {
if (!IsValidChar(*pT,TRUE, flfn))
*pT = CHAR_UNDERSCORE;
}
if (fQuote) {
lpszPath[0] = CHAR_DQUOTE;
lpszPath++;
}
if (CHAR_BACKSLASH == pOrig[0]) {
lpszPath[0] = (TCHAR)drive + (TCHAR)'A';
lpszPath[1] = CHAR_COLON;
lpszPath[2] = CHAR_BACKSLASH;
lpszPath[3] = CHAR_NULL;
nSpaceLeft -= 3;
pOrig++;
} else {
//
// Get current dir of drive in path. Also returns drive.
//
GetSelectedDirectory(drive+1, lpszPath);
nSpaceLeft -= lstrlen(lpszPath);
}
GetComps:
while (*pOrig && nSpaceLeft > 0) {
//
// If the component is parent dir, go up one dir.
// If its the current dir, skip it, else add it normally
//
if (CHAR_DOT == pOrig[0]) {
if (CHAR_DOT == pOrig[1]) {
if (CHAR_BACKSLASH == pOrig[2] || !pOrig[2]) {
nSpaceLeft += RemoveLast(lpszPath);
} else {
goto AddComponent;
}
} else if (pOrig[1] && CHAR_BACKSLASH != pOrig[1])
goto AddComponent;
while (*pOrig && CHAR_BACKSLASH != *pOrig)
pOrig++;
if (*pOrig)
pOrig++;
} else {
LPTSTR pT, pTT = NULL;
AddComponent:
uLen = AddBackslash(lpszPath);
nSpaceLeft = MAXPATHLEN - 1 - uLen;
pT = lpszPath + uLen;
if (flfn) {
lpszDot = NULL;
//
// copy the component
//
while (*pOrig && CHAR_BACKSLASH != *pOrig && nSpaceLeft > 0) {
//
// Keep track of last dot here.
//
if (
#ifdef KEEPTRAILSPACE
#else
CHAR_SPACE == *pOrig ||
#endif
CHAR_DOT == *pOrig) {
//
// Let this be a dot only if there isn't one
// already, and the previous character wasn't
// a "*"
//
if (!lpszDot && CHAR_STAR != pT[-1])
lpszDot = pT;
} else {
lpszDot = NULL;
}
*pT++ = *pOrig++;
nSpaceLeft--;
}
//
// If the last character was a {dot|space}+, then axe them
// off and restore nSpaceLeft.
//
if (lpszDot) {
nSpaceLeft += (INT)(pT-lpszDot);
pT = lpszDot;
}
} else {
if (bJAPAN) {
if (!WideCharToMultiByte(CP_ACP,
0,
pOrig,
8,
szOrigA,
sizeof(szOrigA),
NULL,
NULL)) {
return FALSE;
}
pOrigA = szOrigA;
}
//
// copy the filename (up to 8 chars)
//
for (cb = 0;
*pOrig && CHAR_BACKSLASH != *pOrig &&
CHAR_DOT != *pOrig && nSpaceLeft > 0;
pOrig++) {
if (bJAPAN && IsDBCSLeadByte(*pOrigA)) {
if (cb < 7) {
cb+=2;
*pT++ = *pOrig;
nSpaceLeft-=2;
}
pOrigA+=2;
} else {
if (cb < 8) {
cb++;
*pT++ = *pOrig;
nSpaceLeft--;
}
pOrigA++;
}
}
//
// if there's an extension, copy it, up to 3 chars
//
if (CHAR_DOT == *pOrig && nSpaceLeft > 0) {
*pT++ = CHAR_DOT;
nSpaceLeft--;
pOrig++;
if (bJAPAN) {
if (!WideCharToMultiByte(CP_ACP,
0,
pOrig,
3,
szOrigA,
sizeof(szOrigA),
NULL,
NULL)) {
return FALSE;
}
pOrigA = szOrigA;
}
for (cb = 0;
*pOrig && CHAR_BACKSLASH != *pOrig && nSpaceLeft > 0;
pOrig++) {
if (CHAR_DOT == *pOrig)
cb = 3;
if (bJAPAN && IsDBCSLeadByte(*pOrigA)) {
if (cb < 2) {
cb+=2;
*pT++ = *pOrig;
nSpaceLeft-=2;
}
pOrigA+=2;
} else {
if (cb < 3) {
cb++;
*pT++ = *pOrig;
nSpaceLeft--;
}
pOrigA++;
}
}
//
// Get rid of extra dots
//
if (CHAR_DOT == pT[-1] && CHAR_STAR != pT[-2]) {
nSpaceLeft++;
pT--;
}
}
}
//
// skip the backslash
//
if (*pOrig)
pOrig++;
//
// null terminate for next pass...
//
*pT = CHAR_NULL;
}
}
StripBackslash(lpszPath);
if (fQuote) {
lpszPath--;
pOrig = lpszPath + lstrlen(lpszPath);
*(pOrig++) = CHAR_DQUOTE;
*pOrig = CHAR_NULL;
}
return TRUE;
}
/*--------------------------------------------------------------------------*/
/* */
/* IsRootDirectory() - */
/* */
/*--------------------------------------------------------------------------*/
BOOL
IsRootDirectory(LPTSTR pPath)
{
if (!lstrcmpi(pPath+1, TEXT(":\\")))
return(TRUE);
if (!lstrcmpi(pPath, SZ_BACKSLASH))
return(TRUE);
if (!lstrcmpi(pPath+1, SZ_COLON))
return(TRUE);
// checking unc!
if (*pPath == CHAR_BACKSLASH && *(pPath+1) == CHAR_BACKSLASH) { /* some sort of UNC name */
LPTSTR p;
int cBackslashes=0;
for (p=pPath+2; *p; ) {
if (*p == CHAR_BACKSLASH && (++cBackslashes > 1))
return FALSE; /* not a bare UNC name, therefore not a root dir */
p++;
}
return TRUE; /* end of string with only 1 more backslash */
/* must be a bare UNC, which looks like a root dir */
}
return(FALSE);
}
// returns:
// TRUE if pPath is a directory, including the root and
// relative paths "." and ".."
// FALSE not a dir
BOOL
IsDirectory(LPTSTR pPath)
{
LPTSTR pT;
TCHAR szTemp[MAXPATHLEN];
if (IsRootDirectory(pPath))
return TRUE;
// check for "." and ".."
pT = FindFileName(pPath);
if (ISDOTDIR(pT)) {
return TRUE;
}
lstrcpy(szTemp, pPath);
//
// QualifyPath
//
QualifyPath(szTemp);
return WFIsDir(szTemp);
}
//
// note: this has the side effect of setting the
// current drive to the new disk if it is successful
//
// Return values:
// 0 = fail (general)
// 1 = succeed
BOOL
IsTheDiskReallyThere(
HWND hwnd,
LPTSTR pPath,
DWORD dwFunc,
BOOL bModal)
{
DRIVE drive;
TCHAR szTemp[MAXMESSAGELEN];
TCHAR szMessage[MAXMESSAGELEN];
TCHAR szTitle[128];
INT err = 0;
DWORD dwError;
BOOL bTriedRoot = FALSE;
TCHAR szDrive[] = SZ_ACOLONSLASH;
HCURSOR hCursor;
STKCHK();
if (pPath[1]==CHAR_COLON)
drive = DRIVEID(pPath);
else
return 1;
// First chance error if drive is busy (format/diskcopy)
if (aDriveInfo[drive].iBusy) {
LoadString(hAppInstance, aDriveInfo[drive].iBusy, szTemp, COUNTOF(szTemp));
LoadString(hAppInstance, IDS_COPYERROR + FUNC_SETDRIVE, szTitle,
COUNTOF(szTitle));
wsprintf(szMessage, szTemp, drive + CHAR_A);
MessageBox(hwnd, szMessage, szTitle, MB_ICONHAND);
return 0;
}
Retry:
// Put up the hourglass cursor since this
// could take a long time
hCursor = LoadCursor(NULL, IDC_WAIT);
if (hCursor)
hCursor = SetCursor(hCursor);
ShowCursor(TRUE);
err = !GetDriveDirectory(drive + 1, szTemp);
if (hCursor)
SetCursor(hCursor);
ShowCursor(FALSE);
if (err) {
goto DiskNotThere;
}
return 1;
DiskNotThere:
dwError = GetLastError();
switch (dwError) {
case ERROR_PATH_NOT_FOUND:
case ERROR_FILE_NOT_FOUND:
if (bTriedRoot)
break;
//
// The directory may have been removed.
// Go to the root directory and try once.
//
bTriedRoot = TRUE;
DRIVESET(szDrive, drive);
SetCurrentDirectory(szDrive);
goto Retry;
case ERROR_INVALID_PARAMETER:
// Handle INVALID PARAMETER from GetDriveDirectory from GetFileAttributes
dwError = ERROR_NOT_READY;
break;
case ERROR_ACCESS_DENIED:
//
// If failed due to security, return 2
// (this is non-zero which means sorta error)
//
// old: return 2;
break;
case ERROR_NOT_READY:
//
// WAS ERROR_NO_MEDIA_IN_DRIVE, but changed back due to
// wow incompatibilities.
//
// drive not ready (no disk in the drive)
//
LoadString(hAppInstance, IDS_COPYERROR + dwFunc, szTitle, COUNTOF(szTitle));
LoadString(hAppInstance, IDS_DRIVENOTREADY, szTemp, COUNTOF(szTemp));
wsprintf(szMessage, szTemp, drive + CHAR_A);
if (MessageBox(hwnd, szMessage, szTitle, MB_ICONEXCLAMATION | MB_RETRYCANCEL) == IDRETRY)
goto Retry;
else
return 0;
case ERROR_BAD_NET_NAME:
MyMessageBox(hwnd, IDS_BADNETNAMETITLE, IDS_BADNETNAME, MB_OK|MB_ICONEXCLAMATION);
return 0;
case ERROR_UNRECOGNIZED_VOLUME: // 0x1F huh? What's this?
// general failure (disk not formatted)
LoadString(hAppInstance, IDS_COPYERROR + dwFunc, szTitle, COUNTOF(szTitle));
// If NOT copying or formatting now,
// AND we are removable, then put up format dlg
if (!CancelInfo.hCancelDlg && IsRemovableDrive(drive)) {
LoadString(hAppInstance, IDS_UNFORMATTED, szTemp, COUNTOF(szTemp));
wsprintf(szMessage, szTemp, drive + CHAR_A);
if (MessageBox(hwnd, szMessage, szTitle, MB_ICONEXCLAMATION| MB_YESNO) == IDYES) {
// No more hwndSave stuff since format no longer uses the same
// dialog box (ala hdlgProgress). There IS a global CancelInfo,
// but it is shared only between disk:copy and disk:format.
// Neither of these routines will call FormatDiskette()
// after they have started (naturally, disk:format will call it once).
//
// nLastDriveInd is replaced by CancelInfo
CancelInfo.Info.Format.fFlags = FF_PRELOAD | FF_ONLYONE; // do preload
CancelInfo.Info.Format.iFormatDrive = drive; // present drive
CancelInfo.Info.Format.fmMediaType = -1; // no premedia selection
CancelInfo.Info.Format.szLabel[0] = CHAR_NULL; // no label
FormatDiskette(hwnd, bModal);
// If we were modal, let us retry.
if (bModal && CancelInfo.fmifsSuccess)
goto Retry;
// No matter what, return 0.
// originally checked CancelInfo.fmifsSuccess and
// goto'd Retry on success, but since it's now modeless,
// return error to abort copy or disk change
// If we returned success, the would confuse the user.
return 0;
} else {
//
// Tweak: no extra error dialog
//
return 0;
}
}
// Either already formatting/copying or not removable!
// put up error & ret 0.
FormatError(TRUE, szTemp, COUNTOF(szTemp), ERROR_UNRECOGNIZED_VOLUME);
MessageBox(hwnd, szTemp, szTitle, MB_OK | MB_ICONSTOP);
return 0;
default:
break;
}
LoadString(hAppInstance, IDS_COPYERROR + dwFunc, szTitle, COUNTOF(szTitle));
FormatError(TRUE, szTemp, COUNTOF(szTemp), dwError);
MessageBox(hwnd, szTemp, szTitle, MB_OK | MB_ICONSTOP);
return 0;
}
VOID
BuildDateLine(LPTSTR szTemp, PLFNDTA plfndta)
{
wsprintf(szTemp, szBytes, plfndta->fd.nFileSizeLow);
lstrcat(szTemp, szSpace);
PutDate(&plfndta->fd.ftLastWriteTime, szTemp + lstrlen(szTemp));
lstrcat(szTemp, szSpace);
PutTime(&plfndta->fd.ftLastWriteTime, szTemp + lstrlen(szTemp));
}
typedef struct {
LPTSTR pFileDest;
LPTSTR pFileSource;
PLFNDTA plfndtaDest;
PLFNDTA plfndtaSrc;
INT bWriteProtect;
BOOL bNoAccess;
} PARAM_REPLACEDLG, FAR *LPPARAM_REPLACEDLG;
VOID
SetDlgItemPath(HWND hDlg, INT id, LPTSTR pszPath)
{
RECT rc;
HDC hdc;
HFONT hFont;
TCHAR szPath[MAXPATHLEN+1]; // can have one extra TCHAR
HWND hwnd;
hwnd = GetDlgItem(hDlg, id);
if (!hwnd)
return;
lstrcpy(szPath, pszPath);
GetClientRect(hwnd, &rc);
hdc = GetDC(hDlg);
if (bJAPAN) {
CompactPath(hdc, szPath, rc.right);
} else {
hFont = (HANDLE)SendMessage(hwnd, WM_GETFONT, 0, 0L);
if (hFont = SelectObject(hdc, hFont)) {
CompactPath(hdc, szPath, rc.right);
SelectObject(hdc, hFont);
}
}
ReleaseDC(hDlg, hdc);
SetWindowText(hwnd, szPath);
}
INT_PTR
CALLBACK
ReplaceDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
WCHAR szMessage[MAXMESSAGELEN];
switch (wMsg) {
case WM_INITDIALOG:
{
LPPARAM_REPLACEDLG lpdlgparams = (LPPARAM_REPLACEDLG)lParam;
if (lpdlgparams->bWriteProtect) {
LoadString(hAppInstance, IDS_WRITEPROTECTFILE, szMessage, COUNTOF(szMessage));
SetDlgItemText(hDlg, IDD_STATUS, szMessage);
LoadString(hAppInstance, IDS_ALLFILES, szMessage, COUNTOF(szMessage));
SetDlgItemText(hDlg, IDD_OTHER, szMessage);
}
EnableWindow(GetDlgItem(hDlg, IDD_YESALL),
!lpdlgparams->bNoAccess && ManySource);
EnableWindow(GetDlgItem(hDlg, IDCANCEL), !lpdlgparams->bNoAccess);
lstrcpy(szMessage, lpdlgparams->pFileSource);
lstrcat(szMessage, SZ_QUESTION);
SetDlgItemPath(hDlg, IDD_FROM, szMessage);
if (lpdlgparams->pFileDest) {
BuildDateLine(szMessage, lpdlgparams->plfndtaSrc);
SetDlgItemText(hDlg, IDD_DATE2, szMessage);
SetDlgItemPath(hDlg, IDD_TO, lpdlgparams->pFileDest);
BuildDateLine(szMessage, lpdlgparams->plfndtaDest);
SetDlgItemText(hDlg, IDD_DATE1, szMessage);
}
SetWindowLongPtr(hDlg, GWLP_USERDATA, (LPARAM)lpdlgparams);
break;
}
case WM_COMMAND:
{
WORD id;
id = GET_WM_COMMAND_ID(wParam, lParam);
switch (id) {
#if 0
case IDD_HELP:
goto DoHelp;
#endif
case IDD_FLAGS:
break;
case IDD_YESALL:
*pbConfirmAll = TRUE;
if (((LPPARAM_REPLACEDLG)GetWindowLongPtr(hDlg, GWLP_USERDATA))->bWriteProtect) {
*pbConfirmReadOnlyAll = TRUE;