MT Count Folder Items : Source

Name:MT Count Folder Items
Event Class:XUVJ
Event ID:cdim
Resource:AEVTXUVJcdim

Source

--- This source is written in HyperTalk for CompileIt!

global theAEEvent:R,theReply:R, handerRefCon:LongInt

codeResource "osax"

pascal function countDirItems:I theAEEvent:R, theReply:R, handerRefCon:L

  put AESizeOfParam(theAEEvent@,keyDirectObject,myType,mySize) into err

  if err <> 0 then
    return err
  end if

  put NewPtrClear(434) into myWorkPtr
  put myWorkPtr into myFssPtr
  put myWorkPtr+70 into myPbPtr
  put myWorkPtr + 178 into myNmPtr

  if myType = "TEXT" then

    if mySize > 255 then
      DisposPtr myWorkPtr
      return -1708
    end if

    put myNmPtr+1 into aPtr
    put AEGetParamPtr(theAEEvent@,keyDirectObject,"TEXT",typeCode,aPtr,mySize,myactSize) into err
    if err <> 0 then
      DisPosPtr myWorkPtr
      return err
    end if

    put NumToChar(mySize) into myNmPtr@.charType
    put myNmPtr@.Str255Type into myFname
    put FSMakeFSSpec(0, 0, myFname, myFssPtr@) into err
    if err <> 0 then
      DisPosPtr myWorkPtr
      return err
    end if

  else

    put AEGetParamPtr(theAEEvent@,keyDirectObject,typeFSS,typeCode,myFssPtr,70,myactSize) into err

    if err <> 0 then
      DisPosPtr myWorkPtr
      return err
    end if

  end if

  put myFssPtr@.IntegerType into myPbPtr@.ioVRefNum
  put myFssPtr+2 into aPtr
  put aPtr@.LongIntType into myPbPtr@.ioDrDirID
  put myFssPtr+6 into myPbPtr@.ioNamePtr

  put PBGetCatInfo(myPbPtr) into err
  if err <> 0 then
    DisPosPtr myWorkPtr
    return err
  end if

  put myPbPtr + 30 into aPtr
  if not BitTst(aPtr,3) then
    put myPbPtr+40 into aPtr
    if BitTst(aPtr,0) then
      myResolver myFssPtr
      put myFssPtr@.IntegerType into myPbPtr@.ioVRefNum
      put myFssPtr+2 into aPtr
      put aPtr@.LongIntType into myPbPtr@.ioDrDirID
      put myFssPtr+6 into myPbPtr@.ioNamePtr

      put PBGetCatInfo(myPbPtr) into err
      put myPbPtr + 30 into aPtr
      if not BitTst(aPtr,3) then
        DisposPtr myWorkPtr
        return -35
      end if
    else
      DisposPtr myWorkPtr
      return -35
    end if
  end if

  put myPbPtr+ 52 into aPtr

  if theReply@.descriptorType <> typeNull then
    put AEPutParamPtr(theReply@, keyDirectObject, typeShortInteger,aPtr,2) into err
  end if

  DisposPtr myWorkPtr


  return err

end countDirItems


on myResolver myFssptr

  put FSpOpenResFile(myFssPtr@,fsCurPerm) into myRefNum
  if myRefNum < 0 then
    exit myResolver
  end if

  put Get1IndResource("alis",1) into myAliasHandle
  if myAliasHandle = nil then
    CloseResFile myRefNum
    exit myResolver
  end if

  put ResolveAlias(nil,myAliasHandle,myFssPtr@,wasChanged) into err
  CloseResFile myRefNum


end myResolver




Tanaka's osax : Source
Tanaka's osax