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