⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macstuff.c

📁 完整的解压zip文件的源码。包含密码功能
💻 C
📖 第 1 页 / 共 4 页
字号:
                pb.dirInfo.ioNamePtr = tempSpec.name;                pb.dirInfo.ioVRefNum = tempSpec.vRefNum;                pb.dirInfo.ioDrParID = tempSpec.parID;                do  /* loop until we have an error or find the root directory */                {                    pb.dirInfo.ioFDirIndex = -1;                    pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;                    result = PBGetCatInfoSync(&pb);                    if ( result == noErr )                    {                        /* Append colon to directory name */                        ++tempSpec.name[0];                        tempSpec.name[tempSpec.name[0]] = ':';                        /* Add directory name to beginning of fullPath */                        (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1],                                      tempSpec.name[0]);                        result = MemError();                    }                } while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) );            }        }    }    if ( result == noErr )    {        /* Return the length */        *fullPathLength = InlineGetHandleSize(*fullPath);        result = realResult;    /* return realResult in case it was fnfErr */    }    else    {        /* Dispose of the handle and return NULL and zero length */        if ( *fullPath != NULL )        {            DisposeHandle(*fullPath);        }        *fullPath = NULL;        *fullPathLength = 0;    }    return ( result );}/*****************************************************************************/pascal OSErr FSpLocationFromFullPath(short fullPathLength,                                     const void *fullPath,                                     FSSpec *spec){    AliasHandle alias;    OSErr       result;    Boolean     wasChanged;    Str32       nullString;    /* Create a minimal alias from the full pathname */    nullString[0] = 0;  /* null string to indicate no zone or server name */    result = NewAliasMinimalFromFullPath(fullPathLength, fullPath, nullString,                                         nullString, &alias);    if ( result == noErr )    {        /* Let the Alias Manager resolve the alias. */        result = ResolveAlias(NULL, alias, spec, &wasChanged);        DisposeHandle((Handle)alias);   /* Free up memory used */    }    return ( result );}/*****************************************************************************/pascal  OSErr   GetFullPath(short vRefNum,                            long dirID,                            ConstStr255Param name,                            short *fullPathLength,                            Handle *fullPath){    OSErr       result;    FSSpec      spec;    *fullPathLength = 0;    *fullPath = NULL;    result = FSMakeFSSpecCompat(vRefNum, dirID, name, &spec);    if ( (result == noErr) || (result == fnfErr) )    {        result = FSpGetFullPath(&spec, fullPathLength, fullPath);    }    return ( result );}/*****************************************************************************/pascal  OSErr   ChangeCreatorType(short vRefNum,                                  long dirID,                                  ConstStr255Param name,                                  OSType creator,                                  OSType fileType){    CInfoPBRec pb;    OSErr error;    short realVRefNum;    long parID;    pb.hFileInfo.ioNamePtr = (StringPtr)name;    pb.hFileInfo.ioVRefNum = vRefNum;    pb.hFileInfo.ioDirID = dirID;    pb.hFileInfo.ioFDirIndex = 0;   /* use ioNamePtr and ioDirID */    error = PBGetCatInfoSync(&pb);    if ( error == noErr )    {        if ( (pb.hFileInfo.ioFlAttrib & ioDirMask) == 0 )   /* if file */        {                            /* save parent dirID for BumpDate call */            parID = pb.hFileInfo.ioFlParID;            /* If creator not 0x00000000, change creator */            if ( creator != (OSType)0x00000000 )            {                pb.hFileInfo.ioFlFndrInfo.fdCreator = creator;            }            /* If fileType not 0x00000000, change fileType */            if ( fileType != (OSType)0x00000000 )            {                pb.hFileInfo.ioFlFndrInfo.fdType = fileType;            }            pb.hFileInfo.ioDirID = dirID;            error = PBSetCatInfoSync(&pb);  /* now, save the new information                                               back to disk */            if ( (error == noErr) && (parID != fsRtParID) ) /* can't                                                            bump fsRtParID */            {                /* get the real vRefNum in case a full pathname was passed */                error = DetermineVRefNum(name, vRefNum, &realVRefNum);                if ( error == noErr )                {                    error = BumpDate(realVRefNum, parID, NULL);                        /* and bump the parent directory's mod date to wake                           up the Finder */                        /* to the change we just made */                }            }        }        else        {            /* it was a directory, not a file */            error = notAFileErr;        }    }    return ( error );}/*****************************************************************************/pascal  OSErr   FSpChangeCreatorType(const FSSpec *spec,                                     OSType creator,                                     OSType fileType){    return ( ChangeCreatorType(spec->vRefNum, spec->parID, spec->name,             creator, fileType) );}/*****************************************************************************/pascal  OSErr   BumpDate(short vRefNum,                         long dirID,                         ConstStr255Param name)/* Given a file or directory, change its modification date to the   current date/time. */{    CInfoPBRec pb;    Str31 tempName;    OSErr error;    unsigned long secs;    /* Protection against File Sharing problem */    if ( (name == NULL) || (name[0] == 0) )    {        tempName[0] = 0;        pb.hFileInfo.ioNamePtr = tempName;        pb.hFileInfo.ioFDirIndex = -1;  /* use ioDirID */    }    else    {        pb.hFileInfo.ioNamePtr = (StringPtr)name;        pb.hFileInfo.ioFDirIndex = 0;   /* use ioNamePtr and ioDirID */    }    pb.hFileInfo.ioVRefNum = vRefNum;    pb.hFileInfo.ioDirID = dirID;    error = PBGetCatInfoSync(&pb);    if ( error == noErr )    {        GetDateTime(&secs);        /* set mod date to current date, or one second into the future            if mod date = current date */        pb.hFileInfo.ioFlMdDat =                          (secs == pb.hFileInfo.ioFlMdDat) ? (++secs) : (secs);        if ( pb.dirInfo.ioNamePtr == tempName )        {            pb.hFileInfo.ioDirID = pb.hFileInfo.ioFlParID;        }        else        {            pb.hFileInfo.ioDirID = dirID;        }        error = PBSetCatInfoSync(&pb);    }    return ( error );}/*****************************************************************************/pascal  OSErr   FSpBumpDate(const FSSpec *spec){    return ( BumpDate(spec->vRefNum, spec->parID, spec->name) );}/*****************************************************************************/pascal  OSErr   OnLine(FSSpecPtr volumes,                       short reqVolCount,                       short *actVolCount,                       short *volIndex){    HParamBlockRec pb;    OSErr error = noErr;    FSSpec *endVolArray;    if ( *volIndex > 0 )    {        *actVolCount = 0;        for ( endVolArray = volumes + reqVolCount;              (volumes < endVolArray) && (error == noErr); ++volumes )        {            pb.volumeParam.ioNamePtr = (StringPtr) & volumes->name;            pb.volumeParam.ioVolIndex = *volIndex;            error = PBHGetVInfoSync(&pb);            if ( error == noErr )            {                volumes->parID = fsRtParID;     /* the root directory's                                                   parent is 1 */                volumes->vRefNum = pb.volumeParam.ioVRefNum;                ++*volIndex;                ++*actVolCount;            }        }    }    else    {        error = paramErr;    }    return ( error );}/*****************************************************************************/pascal  OSErr   DTGetComment(short vRefNum,                             long dirID,                             ConstStr255Param name,                             Str255 comment){    DTPBRec pb;    OSErr error;    short dtRefNum;    Boolean newDTDatabase;    if (comment != NULL)    {        comment[0] = 0; /* return nothing by default */        /* attempt to open the desktop database */        error = DTOpen(name, vRefNum, &dtRefNum, &newDTDatabase);        if ( error == noErr )        {            /* There was a desktop database and it's now open */            if ( !newDTDatabase )            {                pb.ioDTRefNum = dtRefNum;                pb.ioNamePtr = (StringPtr)name;                pb.ioDirID = dirID;                pb.ioDTBuffer = (Ptr)&comment[1];                /*                **  IMPORTANT NOTE #1: Inside Macintosh says that comments                **  are up to 200 characters. While that may be correct for                **  the HFS file system's Desktop Manager, other file                **  systems (such as Apple Photo Access) return up to                **  255 characters. Make sure the comment buffer is a Str255                **  or you'll regret it.                **                **  IMPORTANT NOTE #2: Although Inside Macintosh doesn't                **  mention it, ioDTReqCount is a input field to                **  PBDTGetCommentSync. Some file systems (like HFS) ignore                **  ioDTReqCount and always return the full comment --                **  others (like AppleShare) respect ioDTReqCount and only                **  return up to ioDTReqCount characters of the comment.                */                pb.ioDTReqCount = sizeof(Str255) - 1;                error = PBDTGetCommentSync(&pb);                if (error == noErr)                {                    comment[0] = (unsigned char)pb.ioDTActCount;                }            }        }        else        {            /* There is no desktop database - try the Desktop file */            error = GetCommentFromDesktopFile(vRefNum, dirID, name, comment);            if ( error != noErr )            {                error = afpItemNotFound;    /* return an expected error */            }        }    }    else    {        error = paramErr;    }    return (error);}/*****************************************************************************/pascal  OSErr   FSpDTGetComment(const FSSpec *spec,                              Str255 comment){    return (DTGetComment(spec->vRefNum, spec->parID, spec->name, comment));}/*****************************************************************************/pascal  OSErr   DTSetComment(short vRefNum,                             long dirID,                             ConstStr255Param name,                             ConstStr255Param comment){    DTPBRec pb;    OSErr error;    short dtRefNum;    Boolean newDTDatabase;    error = DTOpen(name, vRefNum, &dtRefNum, &newDTDatabase);    if ( error == noErr )    {        pb.ioDTRefNum = dtRefNum;        pb.ioNamePtr = (StringPtr)name;        pb.ioDirID = dirID;        pb.ioDTBuffer = (Ptr)&comment[1];        /* Truncate the comment to 200 characters just in case */        /* some file system doesn't range check */        if ( comment[0] <= 200 )        {            pb.ioDTReqCount = comment[0];        }        else        {            pb.ioDTReqCount = 200;        }        error = PBDTSetCommentSync(&pb);    }    return (error);}/*****************************************************************************/pascal  OSErr   FSpDTSetComment(const FSSpec *spec,                              ConstStr255Param comment){    return (DTSetComment(spec->vRefNum, spec->parID, spec->name, comment));}/*****************************************************************************/pascal  OSErr   DTOpen(ConstStr255Param volName,                       short vRefNum,                       short *dtRefNum,                       Boolean *newDTDatabase){    OSErr error;    GetVolParmsInfoBuffer volParmsInfo;    long infoSize;    DTPBRec pb;    /* Check for volume Desktop Manager support before calling */    infoSize = sizeof(GetVolParmsInfoBuffer);    error = HGetVolParms(volName, vRefNum, &volParmsInfo, &infoSize);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -