source: trunk/dll/rename.c@ 1401

Last change on this file since 1401 was 1400, checked in by Gregg Young, 17 years ago

Remainder of changes to rename commafmt.h/c (Ticket 28, 82); Additional strings moved to PCSZs in init.c (Ticket 6); Added WriteDetailsSwitches used it and LoadDetailsSwitches to consolidate inline code (Ticket 343, 344)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: rename.c 1400 2009-03-08 17:50:25Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[574]7 Copyright (c) 2004, 2007 Steven H.Levine
[123]8
[574]9 Revisions
10 01 Aug 04 SHL - Rework lstrip/rstrip usage
11 22 Mar 07 GKY Use QWL_USER
[793]12 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[846]13 27 Sep 07 SHL Correct ULONGLONG size formatting
[897]14 30 Dec 07 GKY Use TestFDates for comparing dates
[1358]15 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
[1395]16 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
17 07 Feb 09 GKY Add *DateFormat functions to format dates based on locale
[1400]18 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
[123]19
20***********************************************************************/
21
[907]22#include <string.h>
[1354]23#include <ctype.h>
[907]24
[2]25#define INCL_WIN
[841]26#define INCL_LONGLONG
[2]27
[1184]28#include "fm3dll.h"
[1226]29#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
30#include "worker.h" // typedef MOVEIT
31#include "rename.h"
[1212]32#include "notebook.h" // Data declaration(s)
33#include "init.h" // Data declaration(s)
[2]34#include "fm3dlg.h"
35#include "fm3str.h"
[907]36#include "errutil.h" // Dos_Error...
37#include "strutil.h" // GetPString
[1160]38#include "copyf.h" // AdjustWildcardName
39#include "valid.h" // TestFDates
[1184]40#include "mkdir.h" // SetDir
[1400]41#include "i18nutil.h" // CommaFmtULL
[1184]42#include "strips.h" // bstrip
[1354]43#include "info.h" // driveflags
[2]44
[551]45MRESULT EXPENTRY RenameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
46{
[2]47 MOVEIT *mv;
48
[551]49 switch (msg) {
50 case WM_INITDLG:
51 mv = (MOVEIT *) mp2;
[574]52 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mv);
[551]53 if (!mv || !mv->source) {
54 WinDismissDlg(hwnd, 0);
55 break;
56 }
57 WinSendDlgItemMsg(hwnd,
58 REN_SOURCE,
59 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
60 WinSendDlgItemMsg(hwnd,
61 REN_TARGET,
62 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
63 if (!*mv->target)
64 strcpy(mv->target, mv->source);
65 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
66 if (mv->rename || !stricmp(mv->target, mv->source)) {
[2]67
[846]68 CHAR *p = strrchr(mv->target, '\\');
[551]69 if (p) {
[2]70
[551]71 USHORT sello, selhi;
[2]72
[846]73 sello = p - mv->target + 1;
[551]74 selhi = strlen(mv->target);
[2]75
[551]76 WinSendDlgItemMsg(hwnd,
77 REN_TARGET,
78 EM_SETSEL, MPFROM2SHORT(sello, selhi), MPVOID);
79 }
80 WinShowWindow(WinWindowFromID(hwnd, REN_OVEROLD), FALSE);
81 WinShowWindow(WinWindowFromID(hwnd, REN_OVERNEW), FALSE);
82 }
83 break;
[2]84
[551]85 case UM_RESCAN:
86 {
[574]87 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]88 if (mv) {
[2]89
[841]90 FILESTATUS3L fs1, fs2;
[1397]91 CHAR s[CCHMAXPATH * 2], *p, chkname[CCHMAXPATH], szCmmaFmtFileSize[81], szDate[DATE_BUF_BYTES];
[551]92 INT sourceexists = 0, targetexists = 0,
[846]93 sourcenewer = 0, sourcesmaller = 0;
[2]94
[551]95 p = mv->target;
96 while (*p) {
97 if (*p == '/')
98 *p = '\\';
99 p++;
100 }
101 if (!MakeFullName(mv->target))
102 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
103 if (!MakeFullName(mv->source))
104 WinSetDlgItemText(hwnd, REN_SOURCE, mv->source);
[841]105 if (!DosQueryPathInfo(mv->source, FIL_STANDARDL, &fs1, sizeof(fs1))) {
[897]106 CommaFmtULL(szCmmaFmtFileSize,
107 sizeof(szCmmaFmtFileSize), fs1.cbFile, ' ');
[1395]108 FDateFormat(szDate, fs1.fdateLastWrite);
109 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
[846]110 fs1.attrFile & FILE_DIRECTORY ?
111 GetPString(IDS_DIRBRKTTEXT) : NullStr,
[897]112 szCmmaFmtFileSize,
[551]113 GetPString(IDS_BYTETEXT),
[1395]114 szDate,
115 fs1.ftimeLastWrite.hours, TimeSeparator,
116 fs1.ftimeLastWrite.minutes, TimeSeparator, fs1.ftimeLastWrite.twosecs * 2);
[551]117 WinSetDlgItemText(hwnd, REN_SOURCEINFO, s);
118 sourceexists = 1;
[846]119 if (fs1.attrFile & FILE_DIRECTORY)
[551]120 sourceexists = 3;
121 }
122 else
123 WinSetDlgItemText(hwnd,
124 REN_SOURCEINFO, GetPString(IDS_DOESNTEXIST2TEXT));
125 strcpy(chkname, mv->target);
126 p = strrchr(s, '\\');
127 if (p && (strchr(p, '*') || strchr(p, '?'))) {
128 if (!AdjustWildcardName(mv->target, chkname))
129 strcpy(chkname, mv->target);
130 }
[841]131 if (!DosQueryPathInfo(chkname, FIL_STANDARDL, &fs2, sizeof(fs2))) {
[897]132 CommaFmtULL(szCmmaFmtFileSize,
133 sizeof(szCmmaFmtFileSize), fs2.cbFile, ' ');
[1395]134 FDateFormat(szDate, fs2.fdateLastWrite);
135 sprintf(s, " %s%s %ss %s %02u%s%02u%s%02u",
[846]136 fs2.attrFile & FILE_DIRECTORY ?
137 GetPString(IDS_DIRBRKTTEXT) : NullStr,
[897]138 szCmmaFmtFileSize,
[551]139 GetPString(IDS_BYTETEXT),
[1395]140 szDate,
141 fs2.ftimeLastWrite.hours, TimeSeparator,
142 fs2.ftimeLastWrite.minutes, TimeSeparator, fs2.ftimeLastWrite.twosecs * 2);
[551]143 WinSetDlgItemText(hwnd, REN_TARGETINFO, s);
144 targetexists = 1;
145 if (fs2.attrFile & (FILE_DIRECTORY))
146 targetexists = 3;
147 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), TRUE);
148 }
149 else {
150 WinSetDlgItemText(hwnd,
151 REN_TARGETINFO, GetPString(IDS_DOESNTEXIST2TEXT));
152 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
153 }
154 *s = 0;
155 if (sourceexists)
156 sprintf(s,
157 GetPString(IDS_SOURCEISATEXT),
[846]158 sourceexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
159 GetPString(IDS_FILETEXT));
[551]160 {
161 FILE *fp = NULL;
[846]162 if (~sourceexists & 2)
[551]163 fp = fopen(mv->source, "ab");
[846]164 if ((!fp && ~sourceexists & 2) || !sourceexists)
[551]165 strcpy(s, GetPString(IDS_CANTACCESSSOURCETEXT));
166 if (fp)
167 fclose(fp);
168 }
169 if (targetexists && stricmp(mv->source, mv->target))
170 sprintf(&s[strlen(s)],
171 GetPString(IDS_TARGETEXISTSISATEXT),
[846]172 targetexists & 2 ? GetPString(IDS_DIRECTORYTEXT) :
173 GetPString(IDS_FILETEXT));
[551]174 if (targetexists && stricmp(mv->source, mv->target))
175 strcpy(&s[strlen(s)], GetPString(IDS_CLICKOVERWRITETEXT));
176 else if (targetexists && !stricmp(mv->source, mv->target))
177 strcpy(&s[strlen(s)], GetPString(IDS_ENTERNEWTARGETTEXT));
178 WinEnableWindow(WinWindowFromID(hwnd, REN_OVERWRITE),
[846]179 stricmp(mv->target, mv->source) &&
180 (!mv->rename || strcmp(mv->target, mv->source)));
[2]181
[551]182 if (targetexists == 1 && sourceexists == 1) {
[897]183 sourcenewer = TestFDates(NULL, NULL,
184 &fs1.fdateLastWrite, &fs1.ftimeLastWrite,
185 &fs2.fdateLastWrite, &fs2.ftimeLastWrite);
[846]186 sourcesmaller = (fs1.cbFile < fs2.cbFile) ? -1 :
[897]187 (fs1.cbFile > fs2.cbFile) ? 1 : 0;
[551]188 sprintf(&s[strlen(s)], GetPString(IDS_SOURCEISTEXT),
[846]189 (sourcenewer == -1) ? GetPString(IDS_NEWERTEXT) :
190 (sourcenewer == 1) ? GetPString(IDS_OLDERTEXT) :
191 GetPString(IDS_SAMEDATETEXT),
192 (sourcesmaller == -1) ? GetPString(IDS_SMALLERTEXT) :
193 (sourcesmaller == 1) ? GetPString(IDS_LARGERTEXT) :
194 GetPString(IDS_SAMESIZETEXT));
[551]195 }
196 WinSetDlgItemText(hwnd, REN_INFORMATION, s);
197 if (targetexists && stricmp(mv->source, mv->target)) {
198 if (WinQueryButtonCheckstate(hwnd, REN_DONTASK))
199 return 0;
200 return MRFROM2SHORT(1, 0);
201 }
202 else if (targetexists && !stricmp(mv->source, mv->target)) {
203 if (mv->rename && strcmp(mv->source, mv->target))
204 return 0;
205 WinEnableWindow(WinWindowFromID(hwnd, REN_RENEXIST), FALSE);
206 return MRFROM2SHORT(2, 0);
207 }
[2]208 }
[551]209 }
210 return 0;
[2]211
[551]212 case WM_COMMAND:
213 switch (SHORT1FROMMP(mp1)) {
214 case DID_CANCEL:
215 WinDismissDlg(hwnd, 0);
216 break;
[2]217
[551]218 case IDM_HELP:
219 if (hwndHelp)
220 WinSendMsg(hwndHelp,
221 HM_DISPLAY_HELP,
222 MPFROM2SHORT(HELP_RENAME, 0), MPFROMSHORT(HM_RESOURCEID));
223 break;
[2]224
[551]225 case REN_SKIP:
[574]226 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]227 if (mv) {
228 mv->skip = TRUE;
229 *mv->target = 0;
230 WinDismissDlg(hwnd, 2);
231 }
232 else
233 WinDismissDlg(hwnd, 0);
234 break;
[2]235
[551]236 case REN_RENEXIST:
[574]237 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]238 if (mv) {
[2]239
[551]240 CHAR newexist[CCHMAXPATH], fullname[CCHMAXPATH];
241 INT was;
[1354]242 APIRET rc;
243 BOOL fResetVerify = FALSE;
[2]244
[551]245 *newexist = 0;
246 WinQueryDlgItemText(hwnd, REN_TARGET, CCHMAXPATH, newexist);
247 if (*newexist) {
248 if (DosQueryPathInfo(newexist,
249 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
250 strcpy(fullname, newexist);
251 was = IsFile(fullname);
[1354]252 if (was == -1) {
253 if (fVerify && (driveflags[toupper(*mv->target) - 'A'] & DRIVE_WRITEVERIFYOFF ||
254 driveflags[toupper(*fullname) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
255 DosSetVerify(FALSE);
256 fResetVerify = TRUE;
257 }
258 rc = docopyf(MOVE, mv->target, "%s", fullname);
259 if (fResetVerify) {
260 DosSetVerify(fVerify);
261 fResetVerify = FALSE;
262 }
[551]263 if (rc) {
264 if ((LONG) rc > 0)
265 Dos_Error(MB_CANCEL,
266 rc,
267 hwnd,
268 __FILE__,
269 __LINE__,
270 GetPString(IDS_COMPMOVEFAILEDTEXT),
271 mv->target, fullname);
272 else
273 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
274 hwnd,
275 GetPString(IDS_SORRYTEXT),
276 GetPString(IDS_COMPMOVEFAILEDTEXT),
277 mv->target, fullname);
278 }
279 else
280 saymsg(MB_ENTER,
281 hwnd,
282 GetPString(IDS_SUCCESSTEXT),
283 GetPString(IDS_WASMOVEDTOTEXT), mv->target, fullname);
284 }
285 else
286 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
287 hwnd,
288 GetPString(IDS_SORRYTEXT),
289 GetPString(IDS_EXISTSASATEXT),
290 fullname,
291 (was) ?
292 GetPString(IDS_FILETEXT) : GetPString(IDS_DIRECTORYTEXT));
293 }
294 WinSetDlgItemText(hwnd, REN_TARGET, mv->target);
295 }
296 break;
[2]297
[551]298 case REN_OVERWRITE:
299 case DID_OK:
[574]300 mv = WinQueryWindowPtr(hwnd, QWL_USER);
[551]301 if (mv) {
[2]302
[551]303 MRESULT mr;
[2]304
[551]305 if (WinQueryButtonCheckstate(hwnd, REN_DONTASK))
306 mv->dontask = TRUE;
307 if (WinQueryButtonCheckstate(hwnd, REN_OVEROLD))
308 mv->overold = TRUE;
309 if (WinQueryButtonCheckstate(hwnd, REN_OVERNEW))
310 mv->overnew = TRUE;
311 *mv->target = 0;
312 WinQueryDlgItemText(hwnd, REN_TARGET, CCHMAXPATH, mv->target);
313 bstrip(mv->target);
314 mr = WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
315 if (!mr ||
316 (SHORT1FROMMR(mr) != 2 && SHORT1FROMMP(mp1) == REN_OVERWRITE)) {
[2]317
[551]318 CHAR path[CCHMAXPATH], *p;
[2]319
[551]320 mv->overwrite = (SHORT1FROMMP(mp1) == REN_OVERWRITE);
321 strcpy(path, mv->target);
322 p = strrchr(path, '\\');
323 if (p) {
324 p++;
325 *p = 0;
326 if (SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
327 QW_OWNER), hwnd, path, 0)) {
[1395]328 if (!fAlertBeepOff)
329 DosBeep(250, 100);
[551]330 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
331 break;
332 }
333 }
334 WinDismissDlg(hwnd, 1);
335 }
336 else {
[1395]337 if (!fAlertBeepOff)
338 DosBeep(250, 100);
[551]339 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, REN_TARGET));
340 }
[2]341 }
[551]342 break;
343 }
344 return 0;
[2]345 }
[551]346 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]347}
[793]348
349#pragma alloc_text(FMRENAME,RenameProc)
Note: See TracBrowser for help on using the repository browser.