source: trunk/dll/rename.c@ 1184

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

Ticket 187: Draft 2: Move remaining function declarations

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