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