📄 macos.c
字号:
{ OSErr err; if (fileno(G.outfile) == 1) return; /* don't attempt to close or set time on stdout */ err = (OSErr)fclose(G.outfile); /* finally set FinderInfo */ if (MacZipMode >= JohnnyLee_EF) { err = SetFinderInfo(&CurrentFile, &newExtraField); printerr("close_outfile SetFinderInfo ", err, err, __LINE__, __FILE__, G.filename); } else /* unknown extra field, set at least file time/dates */ { err = SetFileTime(); }#ifndef SwitchZIPITefSupportOff if ((MacZipMode == TomBrownZipIt1_EF) || (MacZipMode == TomBrownZipIt2_EF)) { if(FSpIsMacBinary(&CurrentFile)) { Info(slide, 0, ((char *)slide, LoadFarString(MacBinaryMsg))); err = DecodeMacBinaryFile(&CurrentFile); printerr("close_outfile DecodeMacBinaryFile ", err, err, __LINE__, __FILE__, G.filename); } }#endif /* set read-only perms if needed */ if ((err == noErr) && G.pInfo->read_only) { err = FSpSetFLock(&CurrentFile); printerr("FSpSetFLock",err,err,__LINE__,__FILE__,G.filename); } if (malloced_attrbuff != NULL) { attrbuff = malloced_attrbuff; }} /* end function close_outfile() *//****************************//* Function SetFileTime() *//****************************/static OSErr SetFileTime(void){#ifdef USE_EF_UT_TIME iztimes z_utime; unsigned eb_izux_flg;#endif OSErr err; CInfoPBRec fpb; fpb.hFileInfo.ioNamePtr = CurrentFile.name; fpb.hFileInfo.ioVRefNum = CurrentFile.vRefNum; fpb.hFileInfo.ioDirID = CurrentFile.parID; fpb.hFileInfo.ioFDirIndex = 0; err = PBGetCatInfoSync((CInfoPBPtr)&fpb); printerr("PBGetCatInfoSync", err, err, __LINE__, __FILE__, G.filename); if ((MacZipMode == UnKnown_EF) || UseUT_ExtraField ) {#ifdef USE_EF_UT_TIME eb_izux_flg = ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime, &z_utime, NULL); if (G.extra_field && (eb_izux_flg & EB_UT_FL_MTIME)) { fpb.hFileInfo.ioFlMdDat = UnixFtime2MacFtime(z_utime.mtime); fpb.hFileInfo.ioFlCrDat = UnixFtime2MacFtime(z_utime.ctime); }#ifdef DEBUG_TIME { struct tm *tp = gmtime(&z_utime.ctime); printf( "SetFileTime: Unix e.f. creat. time = %d/%2d/%2d %2d:%2d:%2d -> %lu UTC\n", tp->tm_year, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, z_utime.ctime); tp = gmtime(&z_utime.mtime); printf( "SetFileTime: Unix e.f. modif. time = %d/%2d/%2d %2d:%2d:%2d -> %lu UTC\n", tp->tm_year, tp->tm_mon+1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, z_utime.mtime); }#endif /* DEBUG_TIME */ else /* no Unix time field found - use dostime */#endif /* !USE_EF_UT_TIME */ { TTrace((stderr, "SetFileTime: using DOS-Datetime ! \n", z_utime.mtime)); fpb.hFileInfo.ioFlMdDat = dos_to_unix_time(G.lrec.last_mod_dos_datetime); UNIX_TO_MACOS(fpb.hFileInfo.ioFlMdDat); fpb.hFileInfo.ioFlCrDat = fpb.hFileInfo.ioFlMdDat; } /* Restore ioDirID field in pb which was changed by PBGetCatInfoSync */ fpb.hFileInfo.ioDirID = CurrentFile.parID; if (err == noErr) { err = PBSetCatInfoSync((CInfoPBPtr)&fpb); printerr("PBSetCatInfoSync",err,err,__LINE__,__FILE__,G.filename); } if (err != noErr) Info(slide, 0x201, ((char *)slide, LoadFarString(ErrNoTimeSet), FnFilter1(G.filename))); }return err;} /* end function SetFileTime() */#ifndef SFX/************************//* Function version() *//************************/void version(__G) __GDEF{/*ZCONST char Far CompiledWith[] = "Compiled with %s%s for %s%s%s%s.\n\n"; */char DateTime[50];#ifdef __MWERKS__char CompVer[10];sprintf(CompVer, "%x", __MWERKS__);#endif sprintf(DateTime,"%s %s",__DATE__, __TIME__); sprintf((char *)slide, LoadFarString(CompiledWith),#ifdef __MWERKS__ " Metrowerks CodeWarrior version ",CompVer,#else " ", " ",#endif#ifdef __MC68K__ " MC68K Processor",#else " PowerPC Processor",#endif#ifdef __DATE__ "\n compile time: ", DateTime, ""#else "", "", ""#endif ); (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);} /* end function version() */#endif /* !SFX *//***********************//* Function macmkdir() *//***********************/int macmkdir(char *path){ OSErr err = -1; OSErr err_rc; char CompletePath[NAME_MAX], CompletePath2[NAME_MAX]; Boolean isDirectory = false; short CurrentFork; unsigned pathlen; long dirID; AssertStr(path, path) GetExtraFieldData(&MacZipMode, &newExtraField); if (MacZipMode >= JohnnyLee_EF) { RfDfFilen2Real(CompletePath, G.filename, MacZipMode, (newExtraField.flags & EB_M3_FL_NOCHANGE), &CurrentFork); if (CurrentFork == ResourceFork) /* don't build a 'XtraStuf.mac:' dir */ return 0; } if (!IgnoreEF_Macfilename) { pathlen = strlen(path); strcpy(CompletePath, uO.exdir); strcat(CompletePath, newExtraField.FullPath); CompletePath[pathlen] = 0x00; } else { strcpy(CompletePath, path); } GetCompletePath(CompletePath2, CompletePath, &CurrentFile, &err); printerr("GetCompletePath", (err != -43) && (err != -120) && (err != 0), err, __LINE__, __FILE__, CompletePath2); err = FSpGetDirectoryID(&CurrentFile, &dirID, &isDirectory); printerr("macmkdir FSpGetDirectoryID ", (err != -43) && (err != 0), err, __LINE__, __FILE__, CompletePath2); if (err != -43) /* -43 = file/directory not found */ return 0; else { HParamBlockRec hpbr; hpbr.fileParam.ioCompletion = NULL; hpbr.fileParam.ioNamePtr = CurrentFile.name; hpbr.fileParam.ioVRefNum = CurrentFile.vRefNum; hpbr.fileParam.ioDirID = CurrentFile.parID; err = PBDirCreateSync(&hpbr); printerr("macmkdir PBDirCreateSync ", err, err, __LINE__, __FILE__, CompletePath2); /* finally set FinderInfo */ if (MacZipMode >= JohnnyLee_EF) { err_rc = SetFinderInfo(&CurrentFile, &newExtraField); printerr("macmkdir SetFinderInfo ", err_rc, err_rc, __LINE__, __FILE__, CompletePath2); } } return (int)err;} /* macmkdir *//**********************//* Function macopen() *//**********************/short macopen(char *sz, short nFlags){ OSErr err; char chPerms = (!nFlags) ? fsRdPerm : fsRdWrPerm; short nFRefNum; AssertStr(sz, sz) /* we only need the filespec of the zipfile; filespec of the other files (to be extracted) will be determined by open_outfile() */ if (OpenZipFile) { char CompletePath[NAME_MAX]; FSSpec zipfile; GetCompletePath(CompletePath, sz, &zipfile, &err); printerr("GetCompletePath", (err != -43) && (err != 0), err, __LINE__, __FILE__, sz); if (CheckMountedVolumes(CompletePath) > 1) DoWarnUserDupVol(CompletePath); err = HOpen(zipfile.vRefNum, zipfile.parID, zipfile.name, chPerms, &nFRefNum); printerr("Zipfile HOpen", err, err, __LINE__, __FILE__, sz); OpenZipFile = false; } else /* open zipfile entries */ { if (nFlags > 1) { err = HOpenRF(CurrentFile.vRefNum, CurrentFile.parID, CurrentFile.name, chPerms, &nFRefNum); printerr("HOpenRF", (err != -43) && (err != 0) && (err != -54), err, __LINE__, __FILE__, sz); } else { err = HOpen(CurrentFile.vRefNum, CurrentFile.parID, CurrentFile.name, chPerms, &nFRefNum); printerr("HOpen", (err != -43) && (err != 0), err, __LINE__, __FILE__, sz); } } if ( err || (nFRefNum == 1) ) { printerr("macopen", err, err, __LINE__, __FILE__, (char *) CurrentFile.name); return -1; } else { if ( nFlags ) SetEOF( nFRefNum, 0 ); return nFRefNum; }}/***********************//* Function maccreat() *//***********************/short maccreat(char *sz){ OSErr err; char scriptTag = newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript; static char Num = 0; sz = sz; /* Set fdScript in FXInfo * The negative script constants (smSystemScript, smCurrentScript, * and smAllScripts) don't make sense on disk. So only use scriptTag * if scriptTag >= smRoman (smRoman is 0). * fdScript is valid if high bit is set (see IM-6, page 9-38) */ scriptTag = (scriptTag >= smRoman) ? ((char)scriptTag | (char)0x80) : (smRoman); newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript = scriptTag; err = FSpCreate(&CurrentFile, newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdCreator, newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdType, newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript); /* -37 = bad filename; make the filename shorter and try again */ /* filename must not be longer than 32 chars */ if (err == -37) { strcpy((char *)CurrentFile.name, MakeFilenameShorter(P2CStr(CurrentFile.name))); Info(slide, 0x401, ((char *)slide, LoadFarString(FilenameToLong), FnFilter1((char *)CurrentFile.name))); C2PStr((char *)CurrentFile.name); err = FSpCreate(&CurrentFile, newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdCreator, newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdType, newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript); } err = printerr("FSpCreate maccreat ", (err != -48) && (err != 0), err, __LINE__, __FILE__, G.filename); if (err == noErr) return noErr; else return -1;}/**********************//* Function macread() *//**********************/short macread(short nFRefNum, char *pb, unsigned cb){ long lcb = cb; (void)FSRead( nFRefNum, &lcb, pb ); return (short)lcb;}/***********************//* Function macwrite() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -