|
|
| version 1.1.1.1, 2003/10/16 17:59:37 | version 1.5, 2005/05/20 17:25:03 |
|---|---|
| Line 48 FILEH file_create(const char *path) { | Line 48 FILEH file_create(const char *path) { |
| FILEH ret; | FILEH ret; |
| FSSpec fss; | FSSpec fss; |
| Str255 fname; | Str255 fname; |
| OSType creator = '????'; | OSType creator = kUnknownType; |
| OSType fileType = '????'; | OSType fileType = kUnknownType; |
| mkstr255(fname, path); | mkstr255(fname, path); |
| FSMakeFSSpec(0, 0, fname, &fss); | FSMakeFSSpec(0, 0, fname, &fss); |
| Line 144 UINT file_getsize(FILEH handle) { | Line 144 UINT file_getsize(FILEH handle) { |
| } | } |
| } | } |
| static void cnvdatetime(UTCDateTime *dt, DOSDATE *dosdate, DOSTIME *dostime) { | |
| LocalDateTime ldt; | |
| DateTimeRec dtr; | |
| ZeroMemory(&dtr, sizeof(dtr)); | |
| ConvertUTCToLocalDateTime(dt, &ldt); | |
| SecondsToDate(ldt.lowSeconds, &dtr); | |
| if (dosdate) { | |
| dosdate->year = dtr.year; | |
| dosdate->month = (UINT8)dtr.month; | |
| dosdate->day = (UINT8)dtr.day; | |
| } | |
| if (dostime) { | |
| dostime->hour = (UINT8)dtr.hour; | |
| dostime->minute = (UINT8)dtr.minute; | |
| dostime->second = (UINT8)dtr.second; | |
| } | |
| } | |
| short file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime) { | short file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime) { |
| #ifdef TARGET_API_MAC_CARBON | #ifdef TARGET_API_MAC_CARBON |
| FSRef ref; | FSRef ref; |
| FSCatalogInfo fsci; | FSCatalogInfo fsci; |
| LocalDateTime ldt; | |
| DateTimeRec dtr; | |
| ZeroMemory(&dtr, sizeof(dtr)); | |
| if ((FSGetForkCBInfo(handle, 0, NULL, NULL, NULL, &ref, NULL) != noErr) || | if ((FSGetForkCBInfo(handle, 0, NULL, NULL, NULL, &ref, NULL) != noErr) || |
| (FSGetCatalogInfo(&ref, kFSCatInfoContentMod, &fsci, NULL, NULL, NULL) | (FSGetCatalogInfo(&ref, kFSCatInfoContentMod, &fsci, NULL, NULL, NULL) |
| != noErr)) { | != noErr)) { |
| return(-1); | return(-1); |
| } | } |
| ConvertUTCToLocalDateTime(&fsci.contentModDate, &ldt); | cnvdatetime(&fsci.contentModDate, dosdate, dostime); |
| SecondsToDate(ldt.lowSeconds, &dtr); | |
| if (dosdate) { | |
| dosdate->year = dtr.year; | |
| dosdate->month = (BYTE)dtr.month; | |
| dosdate->day = (BYTE)dtr.day; | |
| } | |
| if (dostime) { | |
| dostime->hour = (BYTE)dtr.hour; | |
| dostime->minute = (BYTE)dtr.minute; | |
| dostime->second = (BYTE)dtr.second; | |
| } | |
| return(0); | return(0); |
| #else | #else |
| (void)handle; | (void)handle; |
| Line 193 short file_delete(const char *path) { | Line 199 short file_delete(const char *path) { |
| short file_attr(const char *path) { | short file_attr(const char *path) { |
| #ifdef TARGET_API_MAC_CARBON | |
| Str255 fname; | Str255 fname; |
| FSSpec fss; | FSSpec fss; |
| FSRef fsr; | FSRef fsr; |
| FSCatalogInfo fsci; | FSCatalogInfo fsci; |
| short ret; | |
| mkstr255(fname, path); | mkstr255(fname, path); |
| if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) || | if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) || |
| Line 206 short file_attr(const char *path) { | Line 212 short file_attr(const char *path) { |
| NULL, NULL, NULL) != noErr)) { | NULL, NULL, NULL) != noErr)) { |
| return(-1); | return(-1); |
| } | } |
| else if (fsci.nodeFlags & kFSNodeIsDirectoryMask) { | if (fsci.nodeFlags & kFSNodeIsDirectoryMask) { |
| return(FILEATTR_DIRECTORY); | ret = FILEATTR_DIRECTORY; |
| } | } |
| else { | else { |
| return(FILEATTR_ARCHIVE); | ret = FILEATTR_ARCHIVE; |
| } | } |
| #else | if (fsci.nodeFlags & kFSNodeLockedMask) { |
| Str255 fname; | ret |= FILEATTR_READONLY; |
| FSSpec fss; | |
| CInfoPBRec pb; | |
| mkstr255(fname, path); | |
| FSMakeFSSpec(0, 0, fname, &fss); | |
| pb.dirInfo.ioNamePtr = fss.name; | |
| pb.dirInfo.ioVRefNum = fss.vRefNum; | |
| pb.dirInfo.ioDrDirID = fss.parID; | |
| if (fss.name[0] == 0) { | |
| pb.dirInfo.ioFDirIndex = -1; | |
| } | } |
| else { | return(ret); |
| pb.dirInfo.ioFDirIndex = 0; | |
| } | |
| if (PBGetCatInfo(&pb, false) != noErr) { | |
| return(-1); | |
| } | |
| if (pb.hFileInfo.ioFlAttrib & 0x10) { | |
| return(FILEATTR_DIRECTORY); | |
| } | |
| else { | |
| return(FILEATTR_ARCHIVE); | |
| } | |
| #endif | |
| } | } |
| short file_dircreate(const char *path) { | short file_dircreate(const char *path) { |
| Line 304 short file_attr_c(const char *path) { | Line 288 short file_attr_c(const char *path) { |
| return(file_attr(curpath)); | return(file_attr(curpath)); |
| } | } |
| typedef struct { | |
| BOOL eoff; | |
| FSIterator fsi; | |
| FSCatalogInfo fsci; | |
| HFSUniStr255 name; | |
| } _FLHDL, *FLHDL; | |
| static void char2str(char *dst, int size, const UniChar *uni, int unicnt) { | |
| CFStringRef cfsr; | |
| cfsr = CFStringCreateWithCharacters(NULL, uni, unicnt); | |
| CFStringGetCString(cfsr, dst, size, CFStringGetSystemEncoding()); | |
| CFRelease(cfsr); | |
| } | |
| void *file_list1st(const char *dir, FLINFO *fli) { | |
| FLISTH ret; | |
| Str255 fname; | |
| FSSpec fss; | |
| FSRef fsr; | |
| FSIterator fsi; | |
| mkstr255(fname, dir); | |
| if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) || | |
| (FSpMakeFSRef(&fss, &fsr) != noErr) || | |
| (FSOpenIterator(&fsr, kFSIterateFlat, &fsi) != noErr)) { | |
| goto ff1_err1; | |
| } | |
| ret = _MALLOC(sizeof(_FLHDL), dir); | |
| if (ret == NULL) { | |
| goto ff1_err2; | |
| } | |
| ((FLHDL)ret)->eoff = FALSE; | |
| ((FLHDL)ret)->fsi = fsi; | |
| if (file_listnext(ret, fli) == SUCCESS) { | |
| return(ret); | |
| } | |
| ff1_err2: | |
| FSCloseIterator(fsi); | |
| ff1_err1: | |
| return(NULL); | |
| } | |
| BOOL file_listnext(FLISTH hdl, FLINFO *fli) { | |
| FLHDL flhdl; | |
| ItemCount count; | |
| OSStatus r; | |
| UTCDateTime *dt; | |
| flhdl = (FLHDL)hdl; | |
| if ((flhdl == NULL) || (flhdl->eoff)) { | |
| goto ffn_err; | |
| } | |
| r = FSGetCatalogInfoBulk(flhdl->fsi, 1, &count, NULL, | |
| kFSCatInfoNodeFlags | kFSCatInfoDataSizes | | |
| kFSCatInfoAllDates, | |
| &flhdl->fsci, NULL, NULL, &flhdl->name); | |
| if (r != noErr) { | |
| flhdl->eoff = TRUE; | |
| if (r != errFSNoMoreItems) { | |
| goto ffn_err; | |
| } | |
| } | |
| if (count != 1) { | |
| flhdl->eoff = TRUE; | |
| goto ffn_err; | |
| } | |
| if (fli) { | |
| fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME; | |
| if (flhdl->fsci.nodeFlags & kFSNodeIsDirectoryMask) { | |
| fli->attr = FILEATTR_DIRECTORY; | |
| fli->size = 0; | |
| dt = &flhdl->fsci.createDate; | |
| } | |
| else { | |
| fli->attr = FILEATTR_ARCHIVE; | |
| fli->size = (UINT32)flhdl->fsci.dataLogicalSize; | |
| dt = &flhdl->fsci.contentModDate; | |
| } | |
| cnvdatetime(dt, &fli->date, &fli->time); | |
| char2str(fli->path, sizeof(fli->path), | |
| flhdl->name.unicode, flhdl->name.length); | |
| } | |
| return(SUCCESS); | |
| ffn_err: | |
| return(FAILURE); | |
| } | |
| void file_listclose(FLISTH hdl) { | |
| if (hdl) { | |
| FSCloseIterator(((FLHDL)hdl)->fsi); | |
| _MFREE(hdl); | |
| } | |
| } | |
| BOOL getLongFileName(char *dst, const char *path) { | |
| FSSpec fss; | |
| Str255 fname; | |
| FSRef fref; | |
| HFSUniStr255 name; | |
| if (*path == '\0') { | |
| return(false); | |
| } | |
| mkstr255(fname, path); | |
| FSMakeFSSpec(0, 0, fname, &fss); | |
| FSpMakeFSRef(&fss, &fref); | |
| if (FSGetCatalogInfo(&fref, kFSCatInfoNone, NULL, &name, NULL, NULL) | |
| != noErr) { | |
| return(false); | |
| } | |
| char2str(dst, 512, name.unicode, name.length); | |
| if (!dst) { | |
| return(false); | |
| } | |
| return(true); | |
| } | |
| void file_catname(char *path, const char *sjis, int maxlen) { | void file_catname(char *path, const char *sjis, int maxlen) { |
| char *p; | char *p; |
| Line 327 void file_catname(char *path, const char | Line 438 void file_catname(char *path, const char |
| } | } |
| } | } |
| char *file_getname(char *path) { | char *file_getname(const char *path) { |
| char *ret; | const char *ret; |
| ret = path; | ret = path; |
| while(*path != '\0') { | while(*path != '\0') { |
| Line 337 char *file_getname(char *path) { | Line 448 char *file_getname(char *path) { |
| ret = path; | ret = path; |
| } | } |
| } | } |
| return(ret); | return((char *)ret); |
| } | } |
| void file_cutname(char *path) { | void file_cutname(char *path) { |
| Line 348 void file_cutname(char *path) { | Line 459 void file_cutname(char *path) { |
| p[0] = '\0'; | p[0] = '\0'; |
| } | } |
| char *file_getext(char *path) { | char *file_getext(const char *path) { |
| char *p; | char *p; |
| char *q; | char *q; |