home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / Downs.FileSystem / source / notification / Notify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-24  |  3.2 KB  |  136 lines  |  [TEXT/CWIE]

  1. #include "Notify.h"
  2.  
  3.  
  4. void HandleCreate( FWData theFWData )
  5. {
  6.     DoMakeAlias( theFWData );
  7. }
  8.  
  9.  
  10. OSErr DoMakeAlias( FWData theData )
  11. {
  12.     long        theParID, raFolderID;
  13.     short        fileRef, theVRefNum;
  14.     AliasHandle    alias;
  15.     FInfo        theFInfo, targetFInfo;
  16.     FSSpec        aliasSpec;
  17.     FSSpecPtr    theFSSpec;
  18.     OSErr        fileError;
  19.  
  20.     LogResult( theData );
  21.     
  22.     fileError = DoFindOneFolder( RECENT_ADDS_NAME_STRING, kAppleMenuFolderType, &raFolderID );
  23.  
  24.     if ( fileError != noErr ) {
  25.         //DebugStr( "\pUnable to locate folder." );
  26.         return fileError;
  27.     }
  28.  
  29.     if ( raFolderID == theData.theParID ) {
  30.         //DebugStr( "\pFolders match." );
  31.         return fileError;
  32.     }
  33.  
  34.     FSMakeFSSpec( theData.theVRefNum, theData.theParID, theData.theString, theFSSpec );
  35.  
  36.     fileError = NewAlias( 0L, theFSSpec, &alias );
  37.     if ( fileError )
  38.         return( fileError );
  39.  
  40.     fileError = FSpGetFInfo( theFSSpec, &targetFInfo );
  41.  
  42.     if ( targetFInfo.fdType == APPL_RES_TYPE )
  43.         targetFInfo.fdType = ADRP_RES_TYPE;
  44.  
  45.     if ( theFSSpec->name[ 0 ] > MAX_NAME_SIZE )
  46.         theFSSpec->name[ 0 ] = MAX_NAME_SIZE - SUFFIX_SIZE;
  47.  
  48.     BlockMove( theFSSpec->name, aliasSpec.name, theFSSpec->name[ 0 ] + 1 );
  49.     fileError = FindFolder( kOnSystemDisk, kAppleMenuFolderType, kDontCreateFolder, &aliasSpec.vRefNum, &aliasSpec.parID );
  50.  
  51.     aliasSpec.parID = raFolderID;
  52.  
  53.     fileError = FSpRstFLock( &aliasSpec );
  54.     if ( !( ( fileError == fnfErr ) || ( fileError == noErr ) ) )
  55.         return( fileError );
  56.     
  57.     if ( fileError == noErr ) {
  58.         fileError = FSpDelete( &aliasSpec );
  59.         if ( fileError )
  60.             return( fileError );
  61.     }
  62.  
  63.     FSpCreateResFile( &aliasSpec, targetFInfo.fdCreator, targetFInfo.fdType, smSystemScript );
  64.     fileError = ResError();
  65.     if ( fileError )
  66.         return( fileError );
  67.  
  68.     fileError = FSpGetFInfo( &aliasSpec, &theFInfo );
  69.     if ( fileError )
  70.         return( fileError );
  71.  
  72.     theFInfo.fdFlags = theFInfo.fdFlags | 0x8000;
  73.     FSpSetFInfo( &aliasSpec, &theFInfo );
  74.     
  75.     fileRef = FSpOpenResFile( &aliasSpec, fsCurPerm );
  76.     if ( fileRef == BAD_FILE_REF_NUM ) {
  77.         fileError = ResError();
  78.         return( fileError );
  79.     }
  80.  
  81.     AddResource( ( Handle )alias, rAliasType, 0, "\p" );
  82.  
  83.     fileError = ResError();
  84.     if ( fileError )
  85.         return( fileError );
  86.  
  87.     CloseResFile( fileRef );
  88.     
  89. //    fileError = FlushVol( NIL, aliasSpec.vRefNum );
  90.  
  91.     return( fileError );
  92. }
  93.  
  94.  
  95. OSErr DoFindOneFolder( 
  96.     Str255 theName, 
  97.     OSType theFolderType, 
  98.     long *theFolderID )
  99. {
  100.     FSSpec        theSpec;
  101.     OSErr        fileError;
  102.     CInfoPBPtr    thePBPtr;
  103.     
  104.     thePBPtr = ( CInfoPBPtr )NewPtrClear( sizeof( CInfoPBRec ) );
  105.  
  106.     *theFolderID = NIL;
  107.  
  108.     fileError = FindFolder( kOnSystemDisk, theFolderType, kCreateFolder, &theSpec.vRefNum, &theSpec.parID );
  109.  
  110.     if ( fileError == noErr ) {
  111.         if ( thePBPtr != NIL ) {
  112.             thePBPtr->dirInfo.ioCompletion = 0L;
  113.             thePBPtr->dirInfo.ioNamePtr = theName;
  114.             thePBPtr->dirInfo.ioVRefNum = theSpec.vRefNum;
  115.             thePBPtr->dirInfo.ioDrDirID = theSpec.parID;
  116.             thePBPtr->dirInfo.ioFDirIndex = 0;
  117.  
  118.             fileError = PBGetCatInfo( thePBPtr, true );
  119.  
  120.             while ( thePBPtr->dirInfo.ioResult == 1 ) {
  121.                 ;
  122.             }
  123.  
  124.             if ( ( thePBPtr->dirInfo.ioResult == noErr ) && ( fileError == noErr ) && ( thePBPtr->dirInfo.ioFlAttrib & 0x0010 ) )
  125.                 *theFolderID = thePBPtr->dirInfo.ioDrDirID;
  126.         }
  127.         else
  128.             fileError = BAD_FILE_REF_NUM;
  129.     }
  130.  
  131.     if ( thePBPtr != NIL )
  132.         DisposePtr( ( Ptr )thePBPtr );
  133.  
  134.     return( fileError );
  135. }
  136.