source: trunk/dll/rename.c@ 1160

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

Ticket 187: Draft 1: Functions only

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