| [29] | 1 | 
 | 
|---|
 | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: copyf.c 1785 2014-07-19 21:18:34Z gyoung $
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Copy functions
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| [1443] | 9 |   Copyright (c) 2001, 2009 Steven H.Levine
 | 
|---|
| [29] | 10 | 
 | 
|---|
| [173] | 11 |   14 Sep 02 SHL Drop obsolete debug code
 | 
|---|
 | 12 |   14 Oct 02 SHL Drop obsolete debug code
 | 
|---|
 | 13 |   10 Nov 02 SHL docopyf - don't forget to terminate longname
 | 
|---|
| [1472] | 14 |                 optimize longname logic
 | 
|---|
| [173] | 15 |   01 Aug 04 SHL Rework lstrip/rstrip usage
 | 
|---|
 | 16 |   28 May 05 SHL Drop debug code
 | 
|---|
| [347] | 17 |   14 Jul 06 SHL Use Runtime_Error
 | 
|---|
| [793] | 18 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
| [827] | 19 |   01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
 | 
|---|
| [985] | 20 |   29 Feb 08 GKY Use xfree where appropriate
 | 
|---|
| [1082] | 21 |   19 Jul 08 GKY Modify MakeTempName for use making temp directory names
 | 
|---|
| [1402] | 22 |   08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
 | 
|---|
| [1438] | 23 |   28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
 | 
|---|
| [1480] | 24 |   12 Jul 09 GKY Add xDosQueryAppType and xDosAlloc... to allow FM/2 to load in high memory
 | 
|---|
| [1443] | 25 |   13 Jul 09 SHL Drop obsolete code
 | 
|---|
| [1444] | 26 |   22 Jul 09 GKY Delete .LONGNAME EA if it becomes the filename on a copy or move.
 | 
|---|
| [1472] | 27 |   19 Oct 09 SHL Correct copyf regression when moving to save volume
 | 
|---|
| [1502] | 28 |   31 Mar 10 JBS Correct copyf which was creating 8.4, not 8.3, temporary names
 | 
|---|
| [1627] | 29 |   26 Aug 11 GKY Add a low mem version of xDosAlloc* wrappers; move error checking into all the
 | 
|---|
 | 30 |                 xDosAlloc* wrappers.
 | 
|---|
| [1664] | 31 |   04 Aug 12 GKY Changes to use Unlock to unlock files if Unlock.exe is in path both from menu/toolbar and as part of copy, move and
 | 
|---|
 | 32 |                 delete operations
 | 
|---|
 | 33 |   04 Aug 12 GKY Changes to allow copy and move over readonly files with a warning dialog; also added a warning dialog for delete of
 | 
|---|
 | 34 |                 readonly files
 | 
|---|
| [1686] | 35 |   10 Mar 13 GKY Improvrd readonly check on delete to allow cancel and don't ask again options
 | 
|---|
| [1712] | 36 |   09 Feb 14 GKY Modified wipeallf to allow suppression of the readonly warning on delete
 | 
|---|
 | 37 |                 of temporary files
 | 
|---|
| [1722] | 38 |   16 Feb 14 GKY Rework readonly check on delete code so it actually works in a logical way
 | 
|---|
 | 39 |                 and so it works with move to trashcan inabled.
 | 
|---|
| [1740] | 40 |   22 Feb 14 GKY Fix wipeallf to recurss properly
 | 
|---|
| [1741] | 41 |   22 Feb 14 GKY Fix warn readonly yes don't ask to work when recursing directories.
 | 
|---|
| [1785] | 42 |   19 Jul 14 GKY Fix redundant error message following selection of no for unlocking a file
 | 
|---|
| [29] | 43 | 
 | 
|---|
 | 44 | ***********************************************************************/
 | 
|---|
 | 45 | 
 | 
|---|
| [907] | 46 | #include <stdlib.h>
 | 
|---|
 | 47 | #include <string.h>
 | 
|---|
 | 48 | #include <stdarg.h>
 | 
|---|
 | 49 | #include <ctype.h>
 | 
|---|
 | 50 | 
 | 
|---|
| [2] | 51 | #define INCL_DOS
 | 
|---|
 | 52 | #define INCL_DOSERRORS
 | 
|---|
 | 53 | #define INCL_WIN
 | 
|---|
| [841] | 54 | #define INCL_LONGLONG
 | 
|---|
| [2] | 55 | 
 | 
|---|
| [1188] | 56 | #include "fm3dll.h"
 | 
|---|
| [1222] | 57 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc.
 | 
|---|
| [1206] | 58 | #include "killproc.h"                   // Data declaration(s)
 | 
|---|
 | 59 | #include "notebook.h"                   // Data declaration(s)
 | 
|---|
 | 60 | #include "info.h"                       // Data declaration(s)
 | 
|---|
 | 61 | #include "init.h"                       // Data declaration(s)
 | 
|---|
 | 62 | #include "arccnrs.h"
 | 
|---|
| [907] | 63 | #include "fm3str.h"
 | 
|---|
| [1472] | 64 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
 | 65 | #include "strutil.h"                    // GetPString
 | 
|---|
| [1163] | 66 | #include "copyf.h"
 | 
|---|
| [1472] | 67 | #include "literal.h"                    // fixup
 | 
|---|
| [1188] | 68 | #include "misc.h"                       // Broadcast
 | 
|---|
 | 69 | #include "valid.h"                      // MakeFullName
 | 
|---|
 | 70 | #include "wrappers.h"                   // xDosSetPathInfo
 | 
|---|
 | 71 | #include "strips.h"                     // bstrip
 | 
|---|
| [1472] | 72 | #include "fortify.h"
 | 
|---|
 | 73 | #include "pathutil.h"                   // AddBackslashToPath
 | 
|---|
| [1664] | 74 | #include "worker.h"
 | 
|---|
 | 75 | #include "systemf.h"
 | 
|---|
| [2] | 76 | 
 | 
|---|
| [347] | 77 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
 | 78 | 
 | 
|---|
| [1188] | 79 | static CHAR *GetLongName(CHAR * oldname, CHAR * buffer);
 | 
|---|
 | 80 | static CHAR *TruncName(CHAR * oldname, CHAR * buffer);
 | 
|---|
 | 81 | 
 | 
|---|
| [1741] | 82 | BOOL ignorereadonly = FALSE;
 | 
|---|
 | 83 | 
 | 
|---|
| [1163] | 84 | //static CHAR default_disk(VOID);
 | 
|---|
 | 85 | //static INT unlink_allf(CHAR * string, ...);
 | 
|---|
 | 86 | 
 | 
|---|
| [2] | 87 | #ifndef WinMoveObject
 | 
|---|
| [551] | 88 | HOBJECT APIENTRY WinMoveObject(HOBJECT hObjectofObject,
 | 
|---|
| [1472] | 89 |                                HOBJECT hObjectofDest, ULONG ulReserved);
 | 
|---|
| [2] | 90 | #endif
 | 
|---|
 | 91 | #ifndef WinCopyObject
 | 
|---|
| [551] | 92 | HOBJECT APIENTRY WinCopyObject(HOBJECT hObjectofObject,
 | 
|---|
| [1472] | 93 |                                HOBJECT hObjectofDest, ULONG ulReserved);
 | 
|---|
| [2] | 94 | #endif
 | 
|---|
 | 95 | 
 | 
|---|
| [1472] | 96 | /**
 | 
|---|
 | 97 |  * Make temporary file name
 | 
|---|
 | 98 |  * @param buffer is input directory name and output file name buffer
 | 
|---|
 | 99 |  * @param temproot is filename root used by type 2
 | 
|---|
 | 100 |  * @param type is name style
 | 
|---|
 | 101 |  * @return pointer to name in buffer or NULL if failed
 | 
|---|
 | 102 |  * @note not MT safe
 | 
|---|
 | 103 |  */
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | PSZ MakeTempName(PSZ buffer, PSZ temproot, INT type)
 | 
|---|
| [347] | 106 | {
 | 
|---|
| [843] | 107 |   FILESTATUS3 fs3;
 | 
|---|
| [551] | 108 |   APIRET rc;
 | 
|---|
| [1472] | 109 |   PSZ p;
 | 
|---|
 | 110 |   PSZ o;
 | 
|---|
| [2] | 111 | 
 | 
|---|
| [1472] | 112 |   if (strlen(buffer) > 3)
 | 
|---|
| [1438] | 113 |     AddBackslashToPath(buffer);
 | 
|---|
| [2] | 114 |   p = o = buffer + strlen(buffer);
 | 
|---|
| [1082] | 115 |   switch (type) {
 | 
|---|
 | 116 |   case 0:
 | 
|---|
| [1520] | 117 |     sprintf(p, "%08lx.%03lx", (UINT)mypid, (UINT)rand() & 4095L);               // 4095 = 0x0FFF
 | 
|---|
| [1082] | 118 |     break;
 | 
|---|
 | 119 |   case 1:
 | 
|---|
| [1520] | 120 |     sprintf(p, "%s%04lx.%03lx", "$FM2", (UINT)mypid, (UINT)rand() & 4095L);     // 4095 = 0x0FFF
 | 
|---|
| [1082] | 121 |     break;
 | 
|---|
 | 122 |   case 2:
 | 
|---|
| [1520] | 123 |     sprintf(p, "%s.%03x", temproot, (UINT)(rand() & 4095));                     // 4095 = 0x0FFF
 | 
|---|
| [1082] | 124 |     break;
 | 
|---|
 | 125 |   default:
 | 
|---|
 | 126 |     break;
 | 
|---|
 | 127 |   }
 | 
|---|
| [2] | 128 |   p = buffer + (strlen(buffer) - 1);
 | 
|---|
| [551] | 129 |   for (;;) {
 | 
|---|
| [2] | 130 |     DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [843] | 131 |     rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
 | 
|---|
| [551] | 132 |     if (rc == ERROR_DISK_CHANGE) {
 | 
|---|
| [2] | 133 |       DosError(FERR_ENABLEHARDERR);
 | 
|---|
| [843] | 134 |       rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
 | 
|---|
| [2] | 135 |     }
 | 
|---|
| [551] | 136 |     if (rc)
 | 
|---|
| [2] | 137 |       break;
 | 
|---|
| [551] | 138 |   Loop:
 | 
|---|
 | 139 |     if (p < o) {
 | 
|---|
| [2] | 140 |       *buffer = 0;
 | 
|---|
 | 141 |       return NULL;
 | 
|---|
 | 142 |     }
 | 
|---|
| [551] | 143 |     if ((*p) + 1 < 'Z' + 1) {
 | 
|---|
| [2] | 144 |       (*p)++;
 | 
|---|
| [551] | 145 |       while (strchr("*?<>\":/\\|+=;,[]. ", *p))
 | 
|---|
| [1472] | 146 |         (*p)++;
 | 
|---|
| [2] | 147 |       *p = toupper(*p);
 | 
|---|
 | 148 |     }
 | 
|---|
 | 149 |     else {
 | 
|---|
 | 150 |       p--;
 | 
|---|
| [551] | 151 |       if (p >= o && *p == '.')
 | 
|---|
| [1472] | 152 |         p--;
 | 
|---|
| [2] | 153 |       goto Loop;
 | 
|---|
 | 154 |     }
 | 
|---|
 | 155 |   }
 | 
|---|
 | 156 |   return buffer;
 | 
|---|
 | 157 | }
 | 
|---|
 | 158 | 
 | 
|---|
| [551] | 159 | CHAR *TruncName(CHAR * oldname, CHAR * buffer)
 | 
|---|
| [347] | 160 | {
 | 
|---|
| [551] | 161 |   CHAR *p, *f, *s, *o;
 | 
|---|
| [843] | 162 |   FILESTATUS3 fs3;
 | 
|---|
| [551] | 163 |   APIRET rc;
 | 
|---|
| [2] | 164 | 
 | 
|---|
| [551] | 165 |   if (!buffer || !oldname || !*oldname) {
 | 
|---|
 | 166 |     if (buffer)
 | 
|---|
| [2] | 167 |       *buffer = 0;
 | 
|---|
 | 168 |     return NULL;
 | 
|---|
 | 169 |   }
 | 
|---|
| [551] | 170 |   strcpy(buffer, oldname);
 | 
|---|
 | 171 |   f = strrchr(buffer, '\\');
 | 
|---|
 | 172 |   if (!f)
 | 
|---|
 | 173 |     f = strrchr(buffer, '/');
 | 
|---|
 | 174 |   if (!f)
 | 
|---|
| [2] | 175 |     f = buffer;
 | 
|---|
 | 176 |   else
 | 
|---|
 | 177 |     f++;
 | 
|---|
 | 178 |   p = f;
 | 
|---|
 | 179 |   o = p;
 | 
|---|
 | 180 |   f = oldname + (f - buffer);
 | 
|---|
 | 181 |   strupr(buffer);
 | 
|---|
| [1472] | 182 |   while (*f == '.')
 | 
|---|
 | 183 |     f++;                // skip leading '.'s
 | 
|---|
| [2] | 184 |   s = f;
 | 
|---|
| [1472] | 185 |   // skip past rootname
 | 
|---|
 | 186 |   while (*f && *f != '.' && f < s + 8) {
 | 
|---|
| [2] | 187 |     *p = toupper(*f);
 | 
|---|
 | 188 |     p++;
 | 
|---|
 | 189 |     f++;
 | 
|---|
 | 190 |   }
 | 
|---|
| [551] | 191 |   while (*f == '.')
 | 
|---|
| [2] | 192 |     f++;
 | 
|---|
 | 193 |   s = f;
 | 
|---|
| [551] | 194 |   f = strrchr(f, '.');
 | 
|---|
 | 195 |   if (f) {
 | 
|---|
 | 196 |     while (*f == '.')
 | 
|---|
| [2] | 197 |       f++;
 | 
|---|
 | 198 |   }
 | 
|---|
| [551] | 199 |   if (f && *(f + 1))
 | 
|---|
| [2] | 200 |     s = f;
 | 
|---|
 | 201 |   else
 | 
|---|
 | 202 |     f = s;
 | 
|---|
| [551] | 203 |   if (*f) {
 | 
|---|
| [2] | 204 |     *p = '.';
 | 
|---|
 | 205 |     p++;
 | 
|---|
| [551] | 206 |     while (*f && *f != '.' && f < s + 3) {
 | 
|---|
| [2] | 207 |       *p = toupper(*f);
 | 
|---|
 | 208 |       p++;
 | 
|---|
 | 209 |       f++;
 | 
|---|
 | 210 |     }
 | 
|---|
 | 211 |   }
 | 
|---|
 | 212 |   *p = 0;
 | 
|---|
 | 213 | 
 | 
|---|
 | 214 |   p = o;
 | 
|---|
| [551] | 215 |   while (*p) {
 | 
|---|
 | 216 |     if (strchr("*?<>\":/\\|+=;,[] ", *p) || *p < 0x20)
 | 
|---|
| [2] | 217 |       *p = '_';
 | 
|---|
| [551] | 218 |     if (*p == '.' && *(p + 1) == '.')
 | 
|---|
| [2] | 219 |       *(p + 1) = '_';
 | 
|---|
 | 220 |     p++;
 | 
|---|
 | 221 |   }
 | 
|---|
 | 222 | 
 | 
|---|
 | 223 |   p = o + (strlen(o) - 1);
 | 
|---|
| [551] | 224 |   for (;;) {
 | 
|---|
| [2] | 225 |     DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [843] | 226 |     rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
 | 
|---|
| [551] | 227 |     if (rc == ERROR_DISK_CHANGE) {
 | 
|---|
| [2] | 228 |       DosError(FERR_ENABLEHARDERR);
 | 
|---|
| [843] | 229 |       rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
 | 
|---|
| [2] | 230 |     }
 | 
|---|
| [551] | 231 |     if (rc)
 | 
|---|
| [2] | 232 |       break;
 | 
|---|
| [551] | 233 |   Loop:
 | 
|---|
 | 234 |     if (p < o) {
 | 
|---|
| [2] | 235 |       *buffer = 0;
 | 
|---|
 | 236 |       return NULL;
 | 
|---|
 | 237 |     }
 | 
|---|
| [551] | 238 |     if ((*p) + 1 < 'Z' + 1) {
 | 
|---|
| [2] | 239 |       (*p)++;
 | 
|---|
| [551] | 240 |       while (strchr("*?<>\":/\\|+=;,[]. ", *p))
 | 
|---|
| [1472] | 241 |         (*p)++;
 | 
|---|
| [2] | 242 |       *p = toupper(*p);
 | 
|---|
 | 243 |     }
 | 
|---|
 | 244 |     else {
 | 
|---|
 | 245 |       p--;
 | 
|---|
| [551] | 246 |       if (p >= o && *p == '.')
 | 
|---|
| [1472] | 247 |         p--;
 | 
|---|
| [2] | 248 |       goto Loop;
 | 
|---|
 | 249 |     }
 | 
|---|
 | 250 |   }
 | 
|---|
 | 251 |   return buffer;
 | 
|---|
 | 252 | }
 | 
|---|
 | 253 | 
 | 
|---|
| [551] | 254 | CHAR *GetLongName(CHAR * oldname, CHAR * longname)
 | 
|---|
| [347] | 255 | {
 | 
|---|
| [551] | 256 |   if (!longname)
 | 
|---|
| [2] | 257 |     return NULL;
 | 
|---|
 | 258 |   *longname = 0;
 | 
|---|
| [551] | 259 |   if (!oldname || !*oldname)
 | 
|---|
| [2] | 260 |     return NULL;
 | 
|---|
| [551] | 261 |   if (IsFullName(oldname)) {
 | 
|---|
| [2] | 262 | 
 | 
|---|
| [551] | 263 |     APIRET rc;
 | 
|---|
 | 264 |     EAOP2 eaop;
 | 
|---|
| [2] | 265 |     PGEA2LIST pgealist;
 | 
|---|
 | 266 |     PFEA2LIST pfealist;
 | 
|---|
| [551] | 267 |     PGEA2 pgea;
 | 
|---|
 | 268 |     PFEA2 pfea;
 | 
|---|
 | 269 |     CHAR *value;
 | 
|---|
| [2] | 270 | 
 | 
|---|
| [551] | 271 |     strcpy(longname, oldname);
 | 
|---|
| [2] | 272 |     value = longname;
 | 
|---|
| [551] | 273 |     while (*value) {
 | 
|---|
 | 274 |       if (*value == '/')
 | 
|---|
| [1472] | 275 |         *value = '\\';
 | 
|---|
| [2] | 276 |       value++;
 | 
|---|
 | 277 |     }
 | 
|---|
| [551] | 278 |     value = strrchr(longname, '\\');
 | 
|---|
 | 279 |     if (value) {
 | 
|---|
| [2] | 280 |       value++;
 | 
|---|
 | 281 |       *value = 0;
 | 
|---|
 | 282 |     }
 | 
|---|
| [551] | 283 |     pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
 | 
|---|
| [347] | 284 |     if (pgealist) {
 | 
|---|
| [2] | 285 |       pgea = &pgealist->list[0];
 | 
|---|
| [551] | 286 |       strcpy(pgea->szName, LONGNAME);
 | 
|---|
| [2] | 287 |       pgea->cbName = strlen(pgea->szName);
 | 
|---|
 | 288 |       pgea->oNextEntryOffset = 0L;
 | 
|---|
 | 289 |       pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
 | 
|---|
| [551] | 290 |       pfealist = xmallocz(1536, pszSrcFile, __LINE__);
 | 
|---|
| [347] | 291 |       if (pfealist) {
 | 
|---|
| [1472] | 292 |         pfealist->cbList = 1024;
 | 
|---|
 | 293 |         eaop.fpGEA2List = pgealist;
 | 
|---|
 | 294 |         eaop.fpFEA2List = pfealist;
 | 
|---|
 | 295 |         eaop.oError = 0L;
 | 
|---|
 | 296 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 297 |         rc = DosQueryPathInfo(oldname,
 | 
|---|
 | 298 |                               FIL_QUERYEASFROMLIST,
 | 
|---|
 | 299 |                               (PVOID) & eaop, (ULONG) sizeof(EAOP2));
 | 
|---|
 | 300 |         if (!rc) {
 | 
|---|
 | 301 |           pfea = &eaop.fpFEA2List->list[0];
 | 
|---|
 | 302 |           value = pfea->szName + pfea->cbName + 1;
 | 
|---|
 | 303 |           value[pfea->cbValue] = 0;
 | 
|---|
 | 304 |           if (*(USHORT *) value == EAT_ASCII)
 | 
|---|
 | 305 |             strncat(longname,
 | 
|---|
 | 306 |                     value + (sizeof(USHORT) * 2),
 | 
|---|
 | 307 |                     CCHMAXPATH - strlen(longname));
 | 
|---|
 | 308 |           longname[CCHMAXPATH - 1] = 0;
 | 
|---|
 | 309 |         }
 | 
|---|
 | 310 |         free(pfealist);
 | 
|---|
| [2] | 311 |       }
 | 
|---|
| [1039] | 312 |       free(pgealist);
 | 
|---|
| [2] | 313 |     }
 | 
|---|
 | 314 |   }
 | 
|---|
 | 315 |   return longname;
 | 
|---|
 | 316 | }
 | 
|---|
 | 317 | 
 | 
|---|
| [1472] | 318 | BOOL ZapLongName(PSZ filename)
 | 
|---|
| [347] | 319 | {
 | 
|---|
| [1438] | 320 |   return WriteLongName(filename, NullStr);
 | 
|---|
| [2] | 321 | }
 | 
|---|
 | 322 | 
 | 
|---|
| [551] | 323 | BOOL WriteLongName(CHAR * filename, CHAR * longname)
 | 
|---|
| [347] | 324 | {
 | 
|---|
| [551] | 325 |   APIRET rc;
 | 
|---|
 | 326 |   EAOP2 eaop;
 | 
|---|
| [2] | 327 |   PFEA2LIST pfealist = NULL;
 | 
|---|
| [551] | 328 |   ULONG ealen;
 | 
|---|
 | 329 |   USHORT len;
 | 
|---|
 | 330 |   CHAR *eaval, *p;
 | 
|---|
| [2] | 331 | 
 | 
|---|
| [551] | 332 |   if (!filename || !*filename || !longname)
 | 
|---|
| [2] | 333 |     return FALSE;
 | 
|---|
| [551] | 334 |   p = strrchr(longname, '\\');
 | 
|---|
 | 335 |   if (p)
 | 
|---|
 | 336 |     memmove(longname, p + 1, strlen(p + 1) + 1);
 | 
|---|
 | 337 |   p = strrchr(longname, '/');
 | 
|---|
 | 338 |   if (p)
 | 
|---|
 | 339 |     memmove(longname, p + 1, strlen(p + 1) + 1);
 | 
|---|
| [123] | 340 |   bstrip(longname);
 | 
|---|
| [2] | 341 |   len = strlen(longname);
 | 
|---|
| [551] | 342 |   if (len)
 | 
|---|
| [2] | 343 |     ealen = sizeof(FEA2LIST) + 10 + len + 4;
 | 
|---|
 | 344 |   else
 | 
|---|
 | 345 |     ealen = sizeof(FEALIST) + 10;
 | 
|---|
| [1628] | 346 |   if (xDosAllocMem((PPVOID) &pfealist, ealen + 32L, pszSrcFile, __LINE__))
 | 
|---|
| [1627] | 347 |     return FALSE;
 | 
|---|
| [347] | 348 |   else {
 | 
|---|
| [551] | 349 |     memset(pfealist, 0, ealen + 1);
 | 
|---|
| [2] | 350 |     pfealist->cbList = ealen;
 | 
|---|
| [841] | 351 |     pfealist->list[0].oNextEntryOffset = 0;
 | 
|---|
| [2] | 352 |     pfealist->list[0].fEA = 0;
 | 
|---|
 | 353 |     pfealist->list[0].cbName = 9;
 | 
|---|
| [551] | 354 |     strcpy(pfealist->list[0].szName, LONGNAME);
 | 
|---|
 | 355 |     if (len) {
 | 
|---|
| [2] | 356 |       eaval = pfealist->list[0].szName + 10;
 | 
|---|
| [551] | 357 |       *(USHORT *) eaval = (USHORT) EAT_ASCII;
 | 
|---|
| [2] | 358 |       eaval += sizeof(USHORT);
 | 
|---|
| [551] | 359 |       *(USHORT *) eaval = (USHORT) len;
 | 
|---|
| [2] | 360 |       eaval += sizeof(USHORT);
 | 
|---|
| [551] | 361 |       memcpy(eaval, longname, len);
 | 
|---|
| [2] | 362 |       pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
 | 
|---|
 | 363 |     }
 | 
|---|
 | 364 |     else
 | 
|---|
 | 365 |       pfealist->list[0].cbValue = 0;
 | 
|---|
| [551] | 366 |     eaop.fpGEA2List = (PGEA2LIST) 0;
 | 
|---|
| [2] | 367 |     eaop.fpFEA2List = pfealist;
 | 
|---|
 | 368 |     eaop.oError = 0L;
 | 
|---|
 | 369 |     DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [827] | 370 |     rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
 | 
|---|
| [1472] | 371 |                          &eaop, sizeof(eaop), DSPI_WRTTHRU);
 | 
|---|
| [2] | 372 |     DosFreeMem(pfealist);
 | 
|---|
| [551] | 373 |     if (rc)
 | 
|---|
| [2] | 374 |       return FALSE;
 | 
|---|
 | 375 |   }
 | 
|---|
 | 376 |   return TRUE;
 | 
|---|
 | 377 | }
 | 
|---|
 | 378 | 
 | 
|---|
| [551] | 379 | BOOL AdjustWildcardName(CHAR * oldname, CHAR * newname)
 | 
|---|
| [347] | 380 | {
 | 
|---|
| [2] | 381 |   BOOL ret = FALSE;
 | 
|---|
 | 382 | 
 | 
|---|
| [1472] | 383 |   // NOTE: newname should be CCHMAXPATH chars long!
 | 
|---|
| [2] | 384 | 
 | 
|---|
| [551] | 385 |   if (strchr(newname, '*') || strchr(newname, '?')) {
 | 
|---|
| [2] | 386 | 
 | 
|---|
| [551] | 387 |     CHAR srce[CCHMAXPATHCOMP], dest[CCHMAXPATHCOMP], result[CCHMAXPATHCOMP],
 | 
|---|
| [1321] | 388 |          *p;
 | 
|---|
| [2] | 389 | 
 | 
|---|
| [551] | 390 |     p = strrchr(newname, '\\');
 | 
|---|
 | 391 |     if (p && *(p + 1)) {
 | 
|---|
 | 392 |       strcpy(dest, p + 1);
 | 
|---|
 | 393 |       p = strrchr(oldname, '\\');
 | 
|---|
 | 394 |       if (p && *(p + 1)) {
 | 
|---|
| [1472] | 395 |         strcpy(srce, p + 1);
 | 
|---|
 | 396 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 397 |         if (!DosEditName(1L, srce, dest, (PBYTE)result, (ULONG)sizeof(result))) {
 | 
|---|
 | 398 |           p = strrchr(newname, '\\');
 | 
|---|
 | 399 |           p++;
 | 
|---|
 | 400 |           strcpy(p, result);
 | 
|---|
 | 401 |           ret = TRUE;
 | 
|---|
 | 402 |         }
 | 
|---|
| [2] | 403 |       }
 | 
|---|
 | 404 |     }
 | 
|---|
 | 405 |   }
 | 
|---|
 | 406 |   return ret;
 | 
|---|
 | 407 | }
 | 
|---|
 | 408 | 
 | 
|---|
| [1472] | 409 | /** Copy/move file
 | 
|---|
 | 410 |  * @param type is copy/move type
 | 
|---|
 | 411 |  * @param oldname is fully qualified source file name
 | 
|---|
 | 412 |  * @param newname is fully qualified destination file name
 | 
|---|
 | 413 |  * @return
 | 
|---|
 | 414 |  *   0:  success
 | 
|---|
 | 415 |  *  -1:  bad parameter(s)
 | 
|---|
 | 416 |  *  -2:  source does not exist
 | 
|---|
 | 417 |  *  -3:  bad copy/move type
 | 
|---|
 | 418 |  *   anything else: API return
 | 
|---|
 | 419 |  */
 | 
|---|
 | 420 | 
 | 
|---|
| [1402] | 421 | APIRET docopyf(INT type, CHAR *oldname, CHAR *newname)
 | 
|---|
| [347] | 422 | {
 | 
|---|
| [1402] | 423 |   CHAR longname[CCHMAXPATH], shortname[CCHMAXPATH];
 | 
|---|
| [551] | 424 |   CHAR olddisk, newdisk, dir[CCHMAXPATH], *p, *pp;
 | 
|---|
 | 425 |   APIRET ret = -1, rc;
 | 
|---|
| [841] | 426 |   FILESTATUS3L st, st2, dummy;
 | 
|---|
| [551] | 427 |   BOOL diskchange = FALSE, zaplong = FALSE;
 | 
|---|
| [2] | 428 | 
 | 
|---|
| [1402] | 429 |   *shortname = *dir = 0;
 | 
|---|
| [2] | 430 | 
 | 
|---|
| [1472] | 431 |   if (!oldname || !*oldname || !*newname)
 | 
|---|
 | 432 |     return (APIRET)-1;                  // bad args
 | 
|---|
| [29] | 433 | 
 | 
|---|
| [2] | 434 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [841] | 435 |   if (DosQueryPathInfo(oldname, FIL_STANDARDL, &st, sizeof(FILESTATUS3L)))
 | 
|---|
| [1472] | 436 |     return (APIRET)-2;                  // can not access source
 | 
|---|
| [29] | 437 | 
 | 
|---|
| [1402] | 438 |   AdjustWildcardName(oldname, newname);
 | 
|---|
| [2] | 439 |   MakeFullName(oldname);
 | 
|---|
| [1402] | 440 |   MakeFullName(newname);
 | 
|---|
| [1472] | 441 |   olddisk = toupper(*oldname);          // source drive
 | 
|---|
 | 442 |   newdisk = toupper(*newname);          // destination drive
 | 
|---|
| [551] | 443 |   if (!(driveflags[toupper(*oldname) - 'A'] & DRIVE_NOLONGNAMES))
 | 
|---|
| [45] | 444 |     *longname = 0;
 | 
|---|
| [551] | 445 |   else {
 | 
|---|
| [45] | 446 |     GetLongName(oldname, longname);
 | 
|---|
| [551] | 447 |     if (*longname) {
 | 
|---|
| [2] | 448 |       p = RootName(longname);
 | 
|---|
| [551] | 449 |       if (p != longname)
 | 
|---|
| [1472] | 450 |         memmove(longname, p, strlen(p) + 1);
 | 
|---|
| [2] | 451 |     }
 | 
|---|
| [45] | 452 |   }
 | 
|---|
| [1472] | 453 |   // If root name changed make sure longname EA goes away
 | 
|---|
| [1444] | 454 |   if (*longname) {
 | 
|---|
 | 455 |     p = RootName(oldname);
 | 
|---|
 | 456 |     pp = RootName(longname);
 | 
|---|
 | 457 |     if (stricmp(p, pp)) {
 | 
|---|
 | 458 |       zaplong = TRUE;
 | 
|---|
 | 459 |     }
 | 
|---|
| [2] | 460 |   }
 | 
|---|
 | 461 | 
 | 
|---|
 | 462 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [551] | 463 |   switch (type) {
 | 
|---|
 | 464 |   case WPSMOVE:
 | 
|---|
 | 465 |     {
 | 
|---|
 | 466 |       HOBJECT hobjsrc;
 | 
|---|
 | 467 |       HOBJECT hobjdest;
 | 
|---|
| [2] | 468 | 
 | 
|---|
| [551] | 469 |       ret = ERROR_FILE_NOT_FOUND;
 | 
|---|
 | 470 |       hobjsrc = WinQueryObject(oldname);
 | 
|---|
 | 471 |       if (hobjsrc) {
 | 
|---|
| [1472] | 472 |         strcpy(dir, newname);
 | 
|---|
 | 473 |         p = strrchr(dir, '\\');
 | 
|---|
 | 474 |         if (p < dir + 3)
 | 
|---|
 | 475 |           p++;
 | 
|---|
 | 476 |         *p = 0;
 | 
|---|
 | 477 |         ret = ERROR_PATH_NOT_FOUND;
 | 
|---|
 | 478 |         hobjdest = WinQueryObject(dir);
 | 
|---|
 | 479 |         if (hobjdest) {
 | 
|---|
 | 480 |           ret = ERROR_GEN_FAILURE;
 | 
|---|
 | 481 |           hobjsrc = WinMoveObject(hobjsrc, hobjdest, 0);
 | 
|---|
 | 482 |           if (hobjsrc)
 | 
|---|
 | 483 |             ret = 0;
 | 
|---|
 | 484 |         }
 | 
|---|
| [2] | 485 |       }
 | 
|---|
| [551] | 486 |     }
 | 
|---|
 | 487 |     return ret;
 | 
|---|
| [2] | 488 | 
 | 
|---|
| [551] | 489 |   case WPSCOPY:
 | 
|---|
 | 490 |     {
 | 
|---|
 | 491 |       HOBJECT hobjsrc;
 | 
|---|
 | 492 |       HOBJECT hobjdest;
 | 
|---|
| [2] | 493 | 
 | 
|---|
| [551] | 494 |       ret = ERROR_FILE_NOT_FOUND;
 | 
|---|
 | 495 |       hobjsrc = WinQueryObject(oldname);
 | 
|---|
 | 496 |       if (hobjsrc) {
 | 
|---|
| [1472] | 497 |         strcpy(dir, newname);
 | 
|---|
 | 498 |         p = strrchr(dir, '\\');
 | 
|---|
 | 499 |         if (p < dir + 3)
 | 
|---|
 | 500 |           p++;
 | 
|---|
 | 501 |         *p = 0;
 | 
|---|
 | 502 |         ret = ERROR_PATH_NOT_FOUND;
 | 
|---|
 | 503 |         hobjdest = WinQueryObject(dir);
 | 
|---|
 | 504 |         if (hobjdest) {
 | 
|---|
 | 505 |           ret = ERROR_GEN_FAILURE;
 | 
|---|
 | 506 |           hobjsrc = WinCopyObject(hobjsrc, hobjdest, 0);
 | 
|---|
 | 507 |           if (hobjsrc)
 | 
|---|
 | 508 |             ret = 0;
 | 
|---|
 | 509 |         }
 | 
|---|
| [2] | 510 |       }
 | 
|---|
| [551] | 511 |     }
 | 
|---|
 | 512 |     return ret;
 | 
|---|
| [2] | 513 | 
 | 
|---|
| [551] | 514 |   case MOVE:
 | 
|---|
 | 515 |     *dir = 0;
 | 
|---|
| [1472] | 516 |     if (olddisk == newdisk) {
 | 
|---|
 | 517 |       // Moving to same drive
 | 
|---|
 | 518 |       // make temporary copy in case move fails
 | 
|---|
| [1402] | 519 |       if (IsFile(newname) != -1 && stricmp(oldname, newname)) {
 | 
|---|
| [1472] | 520 |         // 19 Oct 09 SHL correct regression
 | 
|---|
 | 521 |         strcpy(dir, newname);
 | 
|---|
 | 522 |         p = strrchr(dir, '\\');
 | 
|---|
 | 523 |         if (p)
 | 
|---|
 | 524 |           *p = 0;
 | 
|---|
 | 525 |         AddBackslashToPath(dir);
 | 
|---|
 | 526 |         MakeTempName(dir, NULL, 0);
 | 
|---|
 | 527 |         if (DosMove(newname, dir))
 | 
|---|
 | 528 |           *dir = 0;                     // Avoid trying to restore bad copy
 | 
|---|
| [2] | 529 |       }
 | 
|---|
| [551] | 530 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1472] | 531 |       ret = DosMove(oldname, newname);  // move it
 | 
|---|
 | 532 |       if (ret && *dir) {                // failed -- clean up
 | 
|---|
 | 533 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 534 |         if (!DosMove(dir, newname))
 | 
|---|
 | 535 |           Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
 | 
|---|
| [551] | 536 |       }
 | 
|---|
 | 537 |       else if (!ret && *dir) {
 | 
|---|
| [1472] | 538 |         if (!IsFile(dir)) {
 | 
|---|
 | 539 |           if (!strchr(dir, '?') && !strchr(dir, '*'))
 | 
|---|
| [1741] | 540 |             wipeallf(TRUE, "%s\\*", dir);
 | 
|---|
| [1472] | 541 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 542 |           if (DosDeleteDir(dir)) {
 | 
|---|
| [1686] | 543 |             make_deleteable(dir, -1, TRUE);
 | 
|---|
| [1472] | 544 |             DosDeleteDir(dir);
 | 
|---|
 | 545 |           }
 | 
|---|
 | 546 |         }
 | 
|---|
| [1664] | 547 |         else if (IsFile(dir) > 0) {
 | 
|---|
 | 548 |           APIRET error;
 | 
|---|
 | 549 | 
 | 
|---|
 | 550 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 551 |           error = DosForceDelete(dir);
 | 
|---|
 | 552 |           if (error) {
 | 
|---|
| [1722] | 553 |             make_deleteable(dir, error, TRUE);
 | 
|---|
| [1472] | 554 |             DosForceDelete(dir);
 | 
|---|
 | 555 |           }
 | 
|---|
 | 556 |           if (zaplong) {
 | 
|---|
 | 557 |             ret = ZapLongName(dir);
 | 
|---|
 | 558 |           }
 | 
|---|
 | 559 |           Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
 | 
|---|
 | 560 |         }
 | 
|---|
| [551] | 561 |       }
 | 
|---|
 | 562 |     }
 | 
|---|
| [1472] | 563 |     else {
 | 
|---|
 | 564 |       // Moving to different drive
 | 
|---|
| [551] | 565 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1472] | 566 |       ret = DosCopy(oldname, newname, DCPY_EXISTING);   // <=-NOTE!
 | 
|---|
| [551] | 567 |       if (ret == ERROR_DISK_CHANGE) {
 | 
|---|
| [1472] | 568 |         DosError(FERR_ENABLEHARDERR);
 | 
|---|
 | 569 |         ret = DosCopy(oldname, newname, DCPY_EXISTING);
 | 
|---|
 | 570 |         diskchange = TRUE;
 | 
|---|
| [551] | 571 |       }
 | 
|---|
 | 572 |       if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) {
 | 
|---|
| [1472] | 573 |         if (TruncName(newname, shortname)) {
 | 
|---|
 | 574 |           // make 8.3 filename
 | 
|---|
 | 575 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 576 |           ret = DosCopy(oldname, shortname, DCPY_EXISTING);
 | 
|---|
 | 577 |           if (!ret) {
 | 
|---|
 | 578 |             // success -- write longname ea
 | 
|---|
 | 579 |             WriteLongName(shortname, newname);
 | 
|---|
 | 580 |             strcpy(newname, shortname);
 | 
|---|
 | 581 |             // broadcast fixup msg to windows
 | 
|---|
 | 582 |             Broadcast((HAB) 0,
 | 
|---|
 | 583 |                       hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
 | 
|---|
 | 584 |           }
 | 
|---|
 | 585 |         }
 | 
|---|
| [551] | 586 |       }
 | 
|---|
 | 587 |       else if (!ret && *longname) {
 | 
|---|
| [2] | 588 | 
 | 
|---|
| [1472] | 589 |         CHAR fixname[CCHMAXPATH];
 | 
|---|
| [2] | 590 | 
 | 
|---|
| [1472] | 591 |         strcpy(fixname, newname);
 | 
|---|
 | 592 |         p = strrchr(fixname, '\\');
 | 
|---|
 | 593 |         if (p) {
 | 
|---|
 | 594 |           p++;
 | 
|---|
 | 595 |           *p = 0;
 | 
|---|
 | 596 |         }
 | 
|---|
 | 597 |         strcat(fixname, longname);
 | 
|---|
 | 598 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 599 |         DosMove(newname, fixname);
 | 
|---|
 | 600 |         strcpy(newname, fixname);
 | 
|---|
 | 601 |         if (zaplong)
 | 
|---|
 | 602 |           ZapLongName(fixname);
 | 
|---|
 | 603 |         Broadcast((HAB) 0,
 | 
|---|
 | 604 |                   hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
 | 
|---|
| [2] | 605 |       }
 | 
|---|
| [1472] | 606 |       if (!ret) {
 | 
|---|
 | 607 |         // double-check success
 | 
|---|
 | 608 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 609 |         rc = DosQueryPathInfo(newname,
 | 
|---|
 | 610 |                               FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
 | 
|---|
 | 611 |         if (rc == ERROR_DISK_CHANGE) {
 | 
|---|
 | 612 |           DosError(FERR_ENABLEHARDERR);
 | 
|---|
 | 613 |           rc = DosQueryPathInfo(newname,
 | 
|---|
 | 614 |                                 FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
 | 
|---|
 | 615 |         }
 | 
|---|
 | 616 |         if (!rc && st2.cbFile == st.cbFile) {
 | 
|---|
 | 617 |           // seems to have worked...
 | 
|---|
 | 618 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 619 |           if (diskchange) {
 | 
|---|
 | 620 |             DosError(FERR_ENABLEHARDERR);
 | 
|---|
 | 621 |             DosQueryPathInfo(oldname, FIL_STANDARDL, &dummy, sizeof(FILESTATUS3L));     // force disk change
 | 
|---|
 | 622 |           }
 | 
|---|
 | 623 |           if (!(st2.attrFile & FILE_DIRECTORY))
 | 
|---|
 | 624 |             unlinkf(oldname);           // erase file
 | 
|---|
 | 625 |           else {
 | 
|---|
 | 626 |             // remove directory
 | 
|---|
| [1741] | 627 |             wipeallf(TRUE, "%s\\*", oldname);
 | 
|---|
| [1472] | 628 |             DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 629 |             if (DosDeleteDir(oldname)) {
 | 
|---|
| [1686] | 630 |               make_deleteable(oldname, -1, TRUE);
 | 
|---|
| [1472] | 631 |               DosDeleteDir(oldname);
 | 
|---|
 | 632 |             }
 | 
|---|
 | 633 |           }
 | 
|---|
 | 634 |         }
 | 
|---|
| [551] | 635 |       }
 | 
|---|
 | 636 |     }
 | 
|---|
 | 637 |     return ret;
 | 
|---|
| [2] | 638 | 
 | 
|---|
| [551] | 639 |   case COPY:
 | 
|---|
 | 640 |     DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1472] | 641 |     ret = DosCopy(oldname, newname, DCPY_EXISTING);     // <=-NOTE!
 | 
|---|
| [551] | 642 |     if (ret == ERROR_DISK_CHANGE) {
 | 
|---|
 | 643 |       DosError(FERR_ENABLEHARDERR);
 | 
|---|
| [1402] | 644 |       ret = DosCopy(oldname, newname, DCPY_EXISTING);
 | 
|---|
| [551] | 645 |       diskchange = TRUE;
 | 
|---|
 | 646 |     }
 | 
|---|
 | 647 |     if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) {
 | 
|---|
| [1402] | 648 |       if (TruncName(newname, shortname)) {
 | 
|---|
| [1472] | 649 |         DosError((diskchange) ? FERR_ENABLEHARDERR : FERR_DISABLEHARDERR);
 | 
|---|
 | 650 |         ret = DosCopy(oldname, shortname, DCPY_EXISTING);
 | 
|---|
 | 651 |         if (!ret) {
 | 
|---|
 | 652 |           WriteLongName(shortname, newname);
 | 
|---|
 | 653 |           strcpy(newname, shortname);
 | 
|---|
 | 654 |           Broadcast((HAB) 0,
 | 
|---|
 | 655 |                     hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
 | 
|---|
 | 656 |         }
 | 
|---|
| [2] | 657 |       }
 | 
|---|
| [551] | 658 |     }
 | 
|---|
 | 659 |     else if (!ret && *longname) {
 | 
|---|
| [2] | 660 | 
 | 
|---|
| [551] | 661 |       CHAR fixname[CCHMAXPATH];
 | 
|---|
| [2] | 662 | 
 | 
|---|
| [1402] | 663 |       strcpy(fixname, newname);
 | 
|---|
| [551] | 664 |       p = strrchr(fixname, '\\');
 | 
|---|
 | 665 |       if (p) {
 | 
|---|
| [1472] | 666 |         p++;
 | 
|---|
 | 667 |         *p = 0;
 | 
|---|
| [2] | 668 |       }
 | 
|---|
| [551] | 669 |       strcat(fixname, longname);
 | 
|---|
 | 670 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1402] | 671 |       DosMove(newname, fixname);
 | 
|---|
| [551] | 672 |       if (zaplong)
 | 
|---|
| [1472] | 673 |         ZapLongName(fixname);
 | 
|---|
| [551] | 674 |       Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
 | 
|---|
 | 675 |     }
 | 
|---|
 | 676 |     return ret;
 | 
|---|
| [2] | 677 | 
 | 
|---|
| [1472] | 678 |   default:
 | 
|---|
 | 679 |     // shouldn't happen
 | 
|---|
| [551] | 680 |     Runtime_Error(pszSrcFile, __LINE__, "bad case %u", type);
 | 
|---|
 | 681 |     break;
 | 
|---|
| [1472] | 682 |   } // switch type
 | 
|---|
 | 683 |   Runtime_Error(pszSrcFile, __LINE__, "copy/move type %u unexpected", type);
 | 
|---|
 | 684 |   return (APIRET)-3;                    // bad copy/move type
 | 
|---|
| [2] | 685 | }
 | 
|---|
 | 686 | 
 | 
|---|
| [1686] | 687 | INT make_deleteable(CHAR * filename, INT error, BOOL Dontcheckreadonly)
 | 
|---|
| [347] | 688 | {
 | 
|---|
| [1664] | 689 |   APIRET rc;
 | 
|---|
| [2] | 690 |   INT ret = -1;
 | 
|---|
| [1664] | 691 |   INT retrn;
 | 
|---|
| [847] | 692 |   FILESTATUS3 fsi;
 | 
|---|
| [2] | 693 | 
 | 
|---|
| [1686] | 694 |   //DbgMsg(pszSrcFile, __LINE__, "error %i ", error);
 | 
|---|
| [2] | 695 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1664] | 696 |   rc = DosQueryPathInfo(filename, FIL_STANDARD, &fsi, sizeof(fsi));
 | 
|---|
 | 697 |   if (!rc) {
 | 
|---|
 | 698 |     if (fsi.attrFile & 0x00000001) {
 | 
|---|
| [1686] | 699 |       if (fWarnReadOnly && !Dontcheckreadonly) {
 | 
|---|
| [1722] | 700 |       retrn = saymsg2(NULL, 3,
 | 
|---|
 | 701 |                      HWND_DESKTOP,
 | 
|---|
 | 702 |                      GetPString(IDS_READONLYFILEWARNINGTITLE),
 | 
|---|
 | 703 |                      GetPString(IDS_READONLYFILEWARNING),
 | 
|---|
 | 704 |                       filename);
 | 
|---|
 | 705 |       //DbgMsg(pszSrcFile, __LINE__, "retrn %x ", retrn);
 | 
|---|
 | 706 |       ret = retrn;
 | 
|---|
 | 707 |       if (retrn == SM2_YES || retrn == SM2_DONTASK)
 | 
|---|
 | 708 |         fsi.attrFile = 0;
 | 
|---|
 | 709 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 710 |         if (xDosSetPathInfo(filename, FIL_STANDARD, &fsi, sizeof(fsi), 0))
 | 
|---|
 | 711 |           ret = -1; // failed
 | 
|---|
| [1664] | 712 |       }
 | 
|---|
| [1722] | 713 |       else {
 | 
|---|
| [1664] | 714 |         fsi.attrFile = 0;
 | 
|---|
 | 715 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 716 |         if (!xDosSetPathInfo(filename, FIL_STANDARD, &fsi, sizeof(fsi), 0))
 | 
|---|
 | 717 |           ret = 0;
 | 
|---|
| [1722] | 718 |       }
 | 
|---|
| [1664] | 719 |     }
 | 
|---|
| [2] | 720 |   }
 | 
|---|
| [1686] | 721 |   if (error ==  ERROR_SHARING_VIOLATION && fUnlock) {
 | 
|---|
 | 722 |     retrn = saymsg(MB_YESNO | MB_DEFBUTTON2,
 | 
|---|
 | 723 |                  HWND_DESKTOP,
 | 
|---|
 | 724 |                  GetPString(IDS_LOCKEDFILEWARNINGTITLE),
 | 
|---|
 | 725 |                  GetPString(IDS_LOCKEDFILEWARNING),
 | 
|---|
 | 726 |                  filename);
 | 
|---|
 | 727 |     if (retrn == MBID_YES) {
 | 
|---|
 | 728 |       runemf2(SEPARATE | INVISIBLE | BACKGROUND | WAIT,
 | 
|---|
 | 729 |               HWND_DESKTOP, pszSrcFile, __LINE__,
 | 
|---|
 | 730 |               NULL, NULL, "%s %s", PCSZ_UNLOCKEXE, filename);
 | 
|---|
 | 731 |     }
 | 
|---|
| [1784] | 732 |     else
 | 
|---|
 | 733 |       ret = SM2_NO;
 | 
|---|
| [1686] | 734 |   }
 | 
|---|
| [1722] | 735 |   //DbgMsg(pszSrcFile, __LINE__, "retrn %x ", ret);
 | 
|---|
| [2] | 736 |   return ret;
 | 
|---|
 | 737 | }
 | 
|---|
 | 738 | 
 | 
|---|
| [1472] | 739 | /**
 | 
|---|
 | 740 |  * unlink everything from directory on down...
 | 
|---|
 | 741 |  */
 | 
|---|
 | 742 | 
 | 
|---|
| [1710] | 743 | INT wipeallf(BOOL ignorereadonly, CHAR *string, ...)
 | 
|---|
| [347] | 744 | {
 | 
|---|
| [847] | 745 |   FILEFINDBUF3 *f;
 | 
|---|
| [551] | 746 |   HDIR search_handle;
 | 
|---|
 | 747 |   ULONG num_matches;
 | 
|---|
 | 748 |   CHAR *p, *ss, *str;
 | 
|---|
 | 749 |   CHAR s[CCHMAXPATH], mask[257];
 | 
|---|
 | 750 |   va_list ap;
 | 
|---|
 | 751 |   INT rc;
 | 
|---|
| [2] | 752 | 
 | 
|---|
| [551] | 753 |   va_start(ap, string);
 | 
|---|
 | 754 |   vsprintf(s, string, ap);
 | 
|---|
| [2] | 755 |   va_end(ap);
 | 
|---|
 | 756 | 
 | 
|---|
| [551] | 757 |   if (!*s)
 | 
|---|
| [2] | 758 |     return -1;
 | 
|---|
 | 759 |   p = s;
 | 
|---|
| [551] | 760 |   while ((p = strchr(p, '/')) != NULL) {
 | 
|---|
| [2] | 761 |     *p = '\\';
 | 
|---|
 | 762 |     p++;
 | 
|---|
 | 763 |   }
 | 
|---|
 | 764 | 
 | 
|---|
| [551] | 765 |   str = xstrdup(s, pszSrcFile, __LINE__);
 | 
|---|
 | 766 |   if (!str)
 | 
|---|
| [2] | 767 |     return -1;
 | 
|---|
 | 768 | 
 | 
|---|
| [1472] | 769 |   {
 | 
|---|
 | 770 |     // safety net -- disallow deleting a root dir or partial name
 | 
|---|
| [2] | 771 |     CHAR temp;
 | 
|---|
| [551] | 772 |     p = strrchr(str, '\\');
 | 
|---|
 | 773 |     if (p) {
 | 
|---|
| [2] | 774 |       p++;
 | 
|---|
 | 775 |       temp = *p;
 | 
|---|
 | 776 |       *p = 0;
 | 
|---|
| [551] | 777 |       if (IsRoot(str) || !IsFullName(str)) {
 | 
|---|
| [1472] | 778 |         // under no circumstances!
 | 
|---|
 | 779 |         Runtime_Error(pszSrcFile, __LINE__, "bad name %s", str);
 | 
|---|
 | 780 |         free(str);
 | 
|---|
 | 781 |         return -1;
 | 
|---|
| [2] | 782 |       }
 | 
|---|
 | 783 |       *p = temp;
 | 
|---|
 | 784 |     }
 | 
|---|
 | 785 |   }
 | 
|---|
 | 786 | 
 | 
|---|
 | 787 |   p = s;
 | 
|---|
| [1472] | 788 |   p = strrchr(s, '\\');                 // strip s to just path
 | 
|---|
| [551] | 789 |   if (!p)
 | 
|---|
 | 790 |     p = strrchr(s, ':');
 | 
|---|
 | 791 |   if (p) {
 | 
|---|
| [2] | 792 |     p++;
 | 
|---|
| [551] | 793 |     strncpy(mask, p, 256);
 | 
|---|
| [2] | 794 |     mask[256] = 0;
 | 
|---|
 | 795 |     *p = 0;
 | 
|---|
 | 796 |   }
 | 
|---|
 | 797 |   else {
 | 
|---|
 | 798 |     *mask = 0;
 | 
|---|
 | 799 |     *s = 0;
 | 
|---|
 | 800 |   }
 | 
|---|
 | 801 | 
 | 
|---|
| [551] | 802 |   ss = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
 | 
|---|
| [847] | 803 |   f = xmalloc(sizeof(FILEFINDBUF3), pszSrcFile, __LINE__);
 | 
|---|
| [347] | 804 |   if (!ss || !f) {
 | 
|---|
| [1009] | 805 |     xfree(ss, pszSrcFile, __LINE__);
 | 
|---|
 | 806 |     xfree(f, pszSrcFile, __LINE__);
 | 
|---|
| [1039] | 807 |     free(str);
 | 
|---|
| [2] | 808 |     return -1;
 | 
|---|
 | 809 |   }
 | 
|---|
 | 810 | 
 | 
|---|
 | 811 |   search_handle = HDIR_CREATE;
 | 
|---|
| [841] | 812 |   num_matches = 1;
 | 
|---|
| [2] | 813 | 
 | 
|---|
 | 814 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [847] | 815 |   if (!DosFindFirst(str, &search_handle, FILE_NORMAL | FILE_DIRECTORY |
 | 
|---|
| [1472] | 816 |                      FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
 | 
|---|
 | 817 |                      f, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
 | 
|---|
| [2] | 818 | 
 | 
|---|
| [551] | 819 |     strcpy(ss, s);
 | 
|---|
| [2] | 820 |     p = &ss[strlen(ss)];
 | 
|---|
 | 821 | 
 | 
|---|
 | 822 |     do {
 | 
|---|
| [551] | 823 |       strcpy(p, f->achName);
 | 
|---|
 | 824 |       if (f->attrFile & FILE_DIRECTORY) {
 | 
|---|
| [1472] | 825 |         if (strcmp(f->achName, ".") && strcmp(f->achName, "..")) {
 | 
|---|
| [1740] | 826 |           wipeallf(ignorereadonly, "%s/%s", ss, mask);  // recurse to wipe files
 | 
|---|
| [1472] | 827 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 828 |           // remove directory
 | 
|---|
 | 829 |           if (DosDeleteDir(ss)) {
 | 
|---|
| [1686] | 830 |             make_deleteable(ss, -1, TRUE);      // Try harder
 | 
|---|
| [1472] | 831 |             DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 832 |             DosDeleteDir(ss);
 | 
|---|
 | 833 |           }
 | 
|---|
 | 834 |         }
 | 
|---|
| [2] | 835 |       }
 | 
|---|
 | 836 |       else {
 | 
|---|
| [1664] | 837 |         APIRET error;
 | 
|---|
 | 838 | 
 | 
|---|
 | 839 |         DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 840 |         error = DosForceDelete(ss);
 | 
|---|
| [1686] | 841 |         if (error) {
 | 
|---|
 | 842 |           INT retrn = 0;
 | 
|---|
 | 843 | 
 | 
|---|
 | 844 |           retrn = make_deleteable(ss, error, ignorereadonly);
 | 
|---|
| [1722] | 845 |           if (retrn == SM2_NO)
 | 
|---|
| [1686] | 846 |             continue;
 | 
|---|
| [1722] | 847 |           else if (retrn == SM2_DONTASK)
 | 
|---|
| [1686] | 848 |             ignorereadonly = TRUE;
 | 
|---|
| [1722] | 849 |           else if (retrn == SM2_CANCEL)
 | 
|---|
 | 850 |             break;
 | 
|---|
| [1472] | 851 |           DosError(FERR_DISABLEHARDERR);
 | 
|---|
 | 852 |           rc = (INT) DosForceDelete(ss);
 | 
|---|
 | 853 |           if (rc)
 | 
|---|
 | 854 |             return rc;
 | 
|---|
 | 855 |         }
 | 
|---|
| [2] | 856 |       }
 | 
|---|
| [847] | 857 |       num_matches = 1;
 | 
|---|
| [2] | 858 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [847] | 859 |     } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3),
 | 
|---|
| [1472] | 860 |                           &num_matches));
 | 
|---|
| [2] | 861 |     DosFindClose(search_handle);
 | 
|---|
 | 862 |   }
 | 
|---|
 | 863 | 
 | 
|---|
| [1039] | 864 |   free(f);
 | 
|---|
 | 865 |   free(ss);
 | 
|---|
 | 866 |   free(str);
 | 
|---|
| [1686] | 867 |   ignorereadonly = FALSE;
 | 
|---|
| [2] | 868 |   return 0;
 | 
|---|
 | 869 | }
 | 
|---|
 | 870 | 
 | 
|---|
| [1472] | 871 | #if 0 // JBS 11 Sep 08 fixme to be gone
 | 
|---|
| [551] | 872 | INT unlink_allf(CHAR * string, ...)
 | 
|---|
| [347] | 873 | {
 | 
|---|
| [1472] | 874 |   // wildcard delete
 | 
|---|
| [847] | 875 |   FILEFINDBUF3 *f;
 | 
|---|
| [551] | 876 |   HDIR search_handle;
 | 
|---|
| [2] | 877 |   ULONG num_matches;
 | 
|---|
| [551] | 878 |   CHAR *p, *ss, *str;
 | 
|---|
 | 879 |   CHAR s[CCHMAXPATH];
 | 
|---|
| [2] | 880 |   va_list ap;
 | 
|---|
| [551] | 881 |   va_start(ap, string);
 | 
|---|
 | 882 |   vsprintf(s, string, ap);
 | 
|---|
| [2] | 883 |   va_end(ap);
 | 
|---|
 | 884 | 
 | 
|---|
| [551] | 885 |   if (!*s)
 | 
|---|
| [2] | 886 |     return -1;
 | 
|---|
 | 887 |   p = s;
 | 
|---|
| [551] | 888 |   while ((p = strchr(p, '/')) != NULL) {
 | 
|---|
| [2] | 889 |     *p = '\\';
 | 
|---|
 | 890 |     p++;
 | 
|---|
 | 891 |   }
 | 
|---|
 | 892 | 
 | 
|---|
| [551] | 893 |   str = xstrdup(s, pszSrcFile, __LINE__);
 | 
|---|
| [347] | 894 |   if (!str)
 | 
|---|
| [2] | 895 |     return -1;
 | 
|---|
 | 896 | 
 | 
|---|
 | 897 |   p = s;
 | 
|---|
| [1472] | 898 |   p = strrchr(s, '\\');                 // strip s to just path
 | 
|---|
| [551] | 899 |   if (!p)
 | 
|---|
 | 900 |     p = strrchr(s, ':');
 | 
|---|
 | 901 |   if (p) {
 | 
|---|
| [2] | 902 |     p++;
 | 
|---|
 | 903 |     *p = 0;
 | 
|---|
 | 904 |   }
 | 
|---|
 | 905 |   else
 | 
|---|
 | 906 |     *s = 0;
 | 
|---|
 | 907 | 
 | 
|---|
| [551] | 908 |   ss = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
 | 
|---|
| [847] | 909 |   f = xmalloc(sizeof(FILEFINDBUF3), pszSrcFile, __LINE__);
 | 
|---|
| [347] | 910 |   if (!ss || !f) {
 | 
|---|
| [1009] | 911 |     xfree(ss, pszSrcFile, __LINE__);
 | 
|---|
 | 912 |     xfree(f, pszSrcFile, __LINE__);
 | 
|---|
| [1039] | 913 |     free(str);
 | 
|---|
| [2] | 914 |     return -1;
 | 
|---|
 | 915 |   }
 | 
|---|
 | 916 | 
 | 
|---|
 | 917 |   search_handle = HDIR_CREATE;
 | 
|---|
| [838] | 918 |   num_matches = 1;
 | 
|---|
| [2] | 919 | 
 | 
|---|
 | 920 |   DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [847] | 921 |   if (!DosFindFirst(str, &search_handle, FILE_NORMAL, f,
 | 
|---|
| [1472] | 922 |                     sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
 | 
|---|
| [2] | 923 | 
 | 
|---|
| [551] | 924 |     strcpy(ss, s);
 | 
|---|
| [2] | 925 |     p = &ss[strlen(ss)];
 | 
|---|
 | 926 | 
 | 
|---|
 | 927 |     do {
 | 
|---|
| [551] | 928 |       strcpy(p, f->achName);
 | 
|---|
 | 929 |       unlinkf("%s", ss);
 | 
|---|
| [838] | 930 |       num_matches = 1;
 | 
|---|
| [2] | 931 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [847] | 932 |     } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3),
 | 
|---|
| [1472] | 933 |                           &num_matches));
 | 
|---|
| [2] | 934 |     DosFindClose(search_handle);
 | 
|---|
 | 935 |   }
 | 
|---|
 | 936 | 
 | 
|---|
| [1039] | 937 |   free(f);
 | 
|---|
 | 938 |   free(ss);
 | 
|---|
 | 939 |   free(str);
 | 
|---|
| [2] | 940 |   return 0;
 | 
|---|
 | 941 | }
 | 
|---|
| [1163] | 942 | #endif
 | 
|---|
| [2] | 943 | 
 | 
|---|
| [1469] | 944 | /**
 | 
|---|
 | 945 |  * Delete file
 | 
|---|
 | 946 |  * @return OS/2 API error code or 0 if OK
 | 
|---|
 | 947 |  */
 | 
|---|
 | 948 | 
 | 
|---|
| [1402] | 949 | INT unlinkf(CHAR *string)
 | 
|---|
| [347] | 950 | {
 | 
|---|
| [1402] | 951 |   if (!strstr(string, ArcTempRoot)) {
 | 
|---|
| [2] | 952 |     DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1402] | 953 |     if (DosDelete(string)) {
 | 
|---|
| [1686] | 954 |       make_deleteable(string, -1, TRUE);
 | 
|---|
| [2] | 955 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1402] | 956 |       return DosDelete(string);
 | 
|---|
| [2] | 957 |     }
 | 
|---|
 | 958 |   }
 | 
|---|
 | 959 |   else {
 | 
|---|
| [1664] | 960 |     APIRET error;
 | 
|---|
| [1722] | 961 |     INT ret;
 | 
|---|
| [1664] | 962 | 
 | 
|---|
| [2] | 963 |     DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1664] | 964 |     error = DosForceDelete(string);
 | 
|---|
 | 965 |     if (error) {
 | 
|---|
| [1722] | 966 |       ret = make_deleteable(string, error, FALSE);
 | 
|---|
 | 967 |       if (ret == SM2_CANCEL || ret == SM2_NO)
 | 
|---|
 | 968 |         return 0;
 | 
|---|
| [2] | 969 |       DosError(FERR_DISABLEHARDERR);
 | 
|---|
| [1402] | 970 |       return DosForceDelete(string);
 | 
|---|
| [2] | 971 |     }
 | 
|---|
 | 972 |   }
 | 
|---|
 | 973 |   return 0;
 | 
|---|
 | 974 | }
 | 
|---|
| [793] | 975 | 
 | 
|---|
 | 976 | #pragma alloc_text(LONGNAMES,TruncName,GetLongName,WriteLongName)
 | 
|---|
 | 977 | #pragma alloc_text(LONGNAMES,ZapLongName,AdjustWildcardName)
 | 
|---|
| [1082] | 978 | #pragma alloc_text(COPYF,default_disk,docopyf,MakeTempName)
 | 
|---|
| [793] | 979 | #pragma alloc_text(UNLINKF,unlinkf,unlink_allf,make_deleteable,wipeallf)
 | 
|---|