source: trunk/dll/rename.c@ 1212

Last change on this file since 1212 was 1212, checked in by John Small, 17 years ago

Ticket 187: Move data declarations/definitions out of fm3dll.h

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