source: trunk/dll/rename.c@ 1402

Last change on this file since 1402 was 1402, checked in by Gregg Young, 16 years ago

Remove variable aurgs from docopy & unlinkf (not used); Move more strings to PCSZs and string table; Move PCSZs to compile time initialization; Fix hang on startup caused by a drive scan and a dircnr scan trying to update a drive in the tree at the same time (related to the "treeswitch options); Code cleanup mainly removal of old printfs, SayMsgs, DbgMsg and unneeded %s.

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