source: trunk/dll/rename.c@ 1395

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

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

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