|
|
| version 1.1, 2003/10/23 07:20:43 | version 1.3, 2004/01/23 06:03:40 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "dosio.h" | #include "dosio.h" |
| #ifndef NP2GCC | |
| #ifdef TARGET_API_MAC_CARBON | |
| #include <CFString.h> | |
| #endif | |
| #endif | |
| static char curpath[MAX_PATH] = ":"; | static char curpath[MAX_PATH] = ":"; |
| Line 144 UINT file_getsize(FILEH handle) { | Line 149 UINT file_getsize(FILEH handle) { |
| } | } |
| } | } |
| short file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime) { | |
| #ifdef TARGET_API_MAC_CARBON | #ifdef TARGET_API_MAC_CARBON |
| static void cnvdatetime(UTCDateTime *dt, DOSDATE *dosdate, DOSTIME *dostime) { | |
| FSRef ref; | |
| FSCatalogInfo fsci; | |
| LocalDateTime ldt; | LocalDateTime ldt; |
| DateTimeRec dtr; | DateTimeRec dtr; |
| ZeroMemory(&dtr, sizeof(dtr)); | ZeroMemory(&dtr, sizeof(dtr)); |
| if ((FSGetForkCBInfo(handle, 0, NULL, NULL, NULL, &ref, NULL) != noErr) || | ConvertUTCToLocalDateTime(dt, &ldt); |
| (FSGetCatalogInfo(&ref, kFSCatInfoContentMod, &fsci, NULL, NULL, NULL) | |
| != noErr)) { | |
| return(-1); | |
| } | |
| ConvertUTCToLocalDateTime(&fsci.contentModDate, &ldt); | |
| SecondsToDate(ldt.lowSeconds, &dtr); | SecondsToDate(ldt.lowSeconds, &dtr); |
| if (dosdate) { | if (dosdate) { |
| dosdate->year = dtr.year; | dosdate->year = dtr.year; |
| dosdate->month = (BYTE)dtr.month; | dosdate->month = (UINT8)dtr.month; |
| dosdate->day = (BYTE)dtr.day; | dosdate->day = (UINT8)dtr.day; |
| } | } |
| if (dostime) { | if (dostime) { |
| dostime->hour = (BYTE)dtr.hour; | dostime->hour = (UINT8)dtr.hour; |
| dostime->minute = (BYTE)dtr.minute; | dostime->minute = (UINT8)dtr.minute; |
| dostime->second = (BYTE)dtr.second; | dostime->second = (UINT8)dtr.second; |
| } | } |
| } | |
| #else | |
| static void cnvdatetime(unsigned long s, DOSDATE *dosdate, DOSTIME *dostime) { | |
| DateTimeRec dtr; | |
| ZeroMemory(&dtr, sizeof(dtr)); | |
| SecondsToDate(s, &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; | |
| } | |
| } | |
| #endif | |
| short file_getdatetime(FILEH handle, DOSDATE *dosdate, DOSTIME *dostime) { | |
| #ifdef TARGET_API_MAC_CARBON | |
| FSRef ref; | |
| FSCatalogInfo fsci; | |
| if ((FSGetForkCBInfo(handle, 0, NULL, NULL, NULL, &ref, NULL) != noErr) || | |
| (FSGetCatalogInfo(&ref, kFSCatInfoContentMod, &fsci, NULL, NULL, NULL) | |
| != noErr)) { | |
| return(-1); | |
| } | |
| cnvdatetime(&fsci.contentModDate, dosdate, dostime); | |
| return(0); | return(0); |
| #else | #else |
| (void)handle; | (void)handle; |
| Line 198 short file_attr(const char *path) { | Line 229 short file_attr(const char *path) { |
| 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 238 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; |
| } | |
| if (fsci.nodeFlags & kFSNodeLockedMask) { | |
| ret |= FILEATTR_READONLY; | |
| } | } |
| return(ret); | |
| #else | #else |
| Str255 fname; | Str255 fname; |
| FSSpec fss; | FSSpec fss; |
| CInfoPBRec pb; | CInfoPBRec pb; |
| short ret; | |
| mkstr255(fname, path); | mkstr255(fname, path); |
| FSMakeFSSpec(0, 0, fname, &fss); | FSMakeFSSpec(0, 0, fname, &fss); |
| Line 231 short file_attr(const char *path) { | Line 268 short file_attr(const char *path) { |
| if (PBGetCatInfo(&pb, false) != noErr) { | if (PBGetCatInfo(&pb, false) != noErr) { |
| return(-1); | return(-1); |
| } | } |
| if (pb.hFileInfo.ioFlAttrib & 0x10) { | if (pb.hFileInfo.ioFlAttrib & ioDirMask) { |
| return(FILEATTR_DIRECTORY); | ret = FILEATTR_DIRECTORY; |
| } | } |
| else { | else { |
| return(FILEATTR_ARCHIVE); | ret = FILEATTR_ARCHIVE; |
| } | |
| if (pb.hFileInfo.ioFlAttrib & kioFlAttribLockedMask) { | |
| ret |= FILEATTR_READONLY; | |
| } | } |
| return(ret); | |
| #endif | #endif |
| } | } |
| Line 304 short file_attr_c(const char *path) { | Line 345 short file_attr_c(const char *path) { |
| return(file_attr(curpath)); | return(file_attr(curpath)); |
| } | } |
| #ifdef TARGET_API_MAC_CARBON | |
| 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; | |
| } | |
| if (flhdl->fsci.nodeFlags & kFSNodeLockedMask) { | |
| fli->attr |= FILEATTR_READONLY; | |
| } | |
| 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); | |
| } | |
| #else | |
| typedef struct { | |
| BOOL eoff; | |
| short index; | |
| CInfoPBRec pb; | |
| long tagid; | |
| } _FLHDL, *FLHDL; | |
| FLISTH file_list1st(const char *dir, FLINFO *fli) { | |
| Str255 fname; | |
| FSSpec fss; | |
| FLHDL ret; | |
| mkstr255(fname, dir); | |
| FSMakeFSSpec(0, 0, fname, &fss); | |
| ret = (FLHDL)_MALLOC(sizeof(_FLHDL), dir); | |
| if (ret == NULL) { | |
| goto ff1_err1; | |
| } | |
| ret->pb.dirInfo.ioNamePtr = fss.name; | |
| ret->pb.dirInfo.ioVRefNum = fss.vRefNum; | |
| ret->pb.dirInfo.ioDrDirID = fss.parID; | |
| if (fss.name[0] == 0) { | |
| ret->pb.dirInfo.ioFDirIndex = -1; | |
| } | |
| else { | |
| ret->pb.dirInfo.ioFDirIndex = 0; | |
| } | |
| if (PBGetCatInfo(&ret->pb, false) != noErr) { | |
| goto ff1_err2; | |
| } | |
| if (ret->pb.hFileInfo.ioFlAttrib & 0x10) { | |
| ret->tagid = ret->pb.dirInfo.ioDrDirID; | |
| } | |
| else { | |
| ret->tagid = ret->pb.hFileInfo.ioFlParID; | |
| } | |
| ret->eoff = FALSE; | |
| ret->index = 1; | |
| if (file_listnext((FLISTH)ret, fli) == SUCCESS) { | |
| return((FLISTH)ret); | |
| } | |
| ff1_err2: | |
| _MFREE(ret); | |
| ff1_err1: | |
| return(NULL); | |
| } | |
| BOOL file_listnext(FLISTH hdl, FLINFO *fli) { | |
| FLHDL flhdl; | |
| Str255 fname; | |
| unsigned long dt; | |
| flhdl = (FLHDL)hdl; | |
| if ((flhdl == NULL) || (flhdl->eoff)) { | |
| goto ffn_err; | |
| } | |
| fname[0] = 0; | |
| flhdl->pb.dirInfo.ioNamePtr = fname; | |
| flhdl->pb.dirInfo.ioDrDirID = flhdl->tagid; | |
| flhdl->pb.dirInfo.ioFDirIndex = flhdl->index; | |
| flhdl->pb.dirInfo.ioACUser = 0; | |
| if (PBGetCatInfo(&flhdl->pb, false) != noErr) { | |
| flhdl->eoff = TRUE; | |
| goto ffn_err; | |
| } | |
| flhdl->index++; | |
| if (fli) { | |
| fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME; | |
| if (flhdl->pb.hFileInfo.ioFlAttrib & ioDirMask) { | |
| fli->attr = FILEATTR_DIRECTORY; | |
| fli->size = 0; | |
| dt = flhdl->pb.dirInfo.ioDrCrDat; | |
| } | |
| else { | |
| fli->attr = FILEATTR_ARCHIVE; | |
| fli->size = flhdl->pb.hFileInfo.ioFlLgLen; | |
| dt = flhdl->pb.hFileInfo.ioFlMdDat; | |
| } | |
| if (flhdl->pb.hFileInfo.ioFlAttrib & kioFlAttribLockedMask) { | |
| fli->attr |= FILEATTR_READONLY; | |
| } | |
| cnvdatetime(dt, &fli->date, &fli->time); | |
| mkcstr(fli->path, sizeof(fli->path), fname); | |
| } | |
| return(SUCCESS); | |
| ffn_err: | |
| return(FAILURE); | |
| } | |
| void file_listclose(FLISTH hdl) { | |
| if (hdl) { | |
| _MFREE(hdl); | |
| } | |
| } | |
| BOOL getLongFileName(char *dst, const char *path) { | |
| (void)dst; | |
| (void)path; | |
| return(false); | |
| } | |
| #endif | |
| void file_catname(char *path, const char *sjis, int maxlen) { | void file_catname(char *path, const char *sjis, int maxlen) { |
| char *p; | char *p; |