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