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