[futurebasic] Re: Get Info Comments

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 1998 : Group Archive : Group : All Groups

From: <JoeAtTIME@...>
Date: Fri, 12 Jun 1998 12:14:11 EDT
In a message dated 6/11/98 9:17:41 AM, you wrote:

<<Hello.

I am trying to modify the comments of a file, the ones that show up in the
Get Info box. I looked through the file manager, and can't find anything
that even remotely deals with this. Not even GETFILEINFO(or whatever it is)
doesn't return something I can work with. Does anybody know a trick or haev
some code that will allow me to do this? I believe it's possible, for I've
seen other apps do it.

Thanks.

Forrest Blanton
>>

I had this same question a couple of years ago.  Rick Brown was kind enough to
put this demo together. Thanks again Rick. This has been very helpful to me.

Joe:
In response to your message to the FutureBASIC mailing list, here's a short
demo illustrating the use of those PBDT* functions.  Hope this is useful.

- Rick

'========================================================
'  This is a simple demo which illustrates the
'  use of routines which read & set Finder comments.
'  Because this demo uses a simple "File Open" dialog
'  to let the user select the file, it won't currently
'  handle comments for alias files, folders nor volumes.
'========================================================
COMPILE 0, _caseInsensitive
'================== constants =============
_ioDTRefNum = 24
_ioDTBuffer = 32
_ioDTReqCount = 36
_ioDTActCount = 40
'================== globals ===============
DIM gAction
END GLOBALS
'================== functions =============
LOCAL FN PBDTGetPath(pBlkPtr&)
  `     move.l  ^pBlkPtr&,a0    ;pblock
  `     moveq   #$20,d0         ;selector
  `     dc.w    $a260           ;HFSdispatch
  `     ext.l   d0              ;result comes back in DO.w
END FN 
'---------------------------------
LOCAL FN PBDTGetCommentSync(pBlkPtr&)
  `     move.l  ^pBlkPtr&,a0    ;pblock
  `     moveq   #$2a,d0         ;selector
  `     dc.w    $a260           ;HFSdispatch
  `     ext.l   d0              ;result comes back in DO.w
END FN 
'---------------------------------
LOCAL FN PBDTSetCommentSync(pBlkPtr&)
  `     move.l  ^pBlkPtr&,a0    ;pblock
  `     moveq   #$28,d0         ;selector
  `     dc.w    $a260           ;HFSdispatch
  `     ext.l   d0              ;result comes back in DO.w
END FN
'---------------------------------
LOCAL FN PBDTFlush(pBlkPtr&, async)
  LONG IF async
    `   move.l  ^pBlkPtr&,a0
    `   moveq   #$2b,d0
    `   dc.w    $a660           ;async version of HFSdispatch
    `   move.w  d0,^OSErr
  XELSE
    `   move.l  ^pBlkPtr&,a0
    `   moveq   #$2b,d0
    `   dc.w    $a260
    `   move.w  d0,^OSErr
  END IF
END FN = OSErr
'---------------------------------
LOCAL FN DoDialog
  evnt = DIALOG(0)
  id = DIALOG(evnt)
  SELECT CASE evnt
    CASE _btnClick
      SELECT CASE id
        CASE 1: gAction = 1                       '(set comment)
        CASE 2: gAction = 2                       '(cancel)
      END SELECT
  END SELECT
END FN
'================== main ================
DIM dtpb.104, commentBuffer.200, wdpb.52
WINDOW OFF
WINDOW 1, "Comment Demo", (0,0)-(250,150), _docNoGrow+_noGoAway
TEXT _monaco, 9
EDIT FIELD 1, "", (10,30)-(240,120), _framed
TEXT _geneva, 12
BUTTON 1, _enable, "Set Comments", (140,130)-(240,146)
BUTTON 2, _enable, "Cancel", (10,130)-(100,146)
ON DIALOG FN DoDialog
DO
  filename$ = FILES$(_fOpen, "",, vRefNum)
  LONG IF filename$ <> ""
    OSErr = 0
    CLS
    dtpb.ioCompletion& = _nil
    dtpb.ioNamePtr& = _nil
    dtpb.ioVRefNum% = vRefNum
    OSErr = FN PBDTGetPath(@dtpb)                 '(to fill in the ioDTRefNum
field)
    LONG IF OSErr = _noErr
      dtpb.ioNamePtr& = @filename$
      dtpb.ioDTBuffer& = @commentBuffer
      'Get the DirID corresponding to vRefNum:
      wdpb.ioCompletion& = _nil
      wdpb.ioNamePtr& = _nil
      wdpb.ioVRefNum% = vRefNum
      wdpb.ioWDIndex% = 0
      wdpb.ioWDProcID& = _nil
      wdpb.ioWDVRefNum% = 0                       '(I.M. fails to explain why
this is input!)
      OSErr = FN GETWDINFO(@wdpb)
      LONG IF OSErr = _noErr
        dtpb.ioDirID& = wdpb.ioWDDirID&
        OSErr = FN PBDTGetCommentSync(@dtpb)
        SELECT CASE OSErr
          CASE _noErr
            charCount = dtpb.ioDTActCount&
            POKE @theComment$, charCount
            BLOCKMOVE @commentBuffer, @theComment$+1, charCount
            EDIT$(1) = theComment$
          CASE _afpItemNotFound
            EDIT$(1) = ""                         '(no comment)
            OSErr = _noErr
          CASE ELSE
            BEEP: PRINT "PBDTGetCommentSync OSErr: "; OSErr
        END SELECT
      XELSE
        BEEP: PRINT "GetWDInfo OSErr: "; OSErr
      END IF
    XELSE
      BEEP: PRINT "PBDTGetPath OSErr: "; OSErr
    END IF
    gAction = 0
    DO
      HANDLEEVENTS
    UNTIL gAction <> 0
    LONG IF gAction = 1 AND OSErr = _noErr
      'Set Comments:
      theComment$ = LEFT$(EDIT$(1),200)
      IF LEN(theComment$) > 0 THEN BLOCKMOVE @theComment$+1, @commentBuffer,
LEN(theComment$)
      dtpb.ioDTReqCount& = LEN(theComment$)
      '(all the other required fields in dtpb are already filled in
      'from above calls to PBDTGetPath and PBDTGetCommentSync.  In
      'general, the following fields must be filled in, before calling
      'PBDTSetCommentSync: ioCompletion&, ioNamePtr&, ioDTRefNum%,
      'ioDTBuffer&, ioDTReqCount&, and ioDirID&.)
      OSErr = FN PBDTSetCommentSync(@dtpb)
      LONG IF OSErr = _noErr
        OSErr = FN PBDTFlush(@dtpb, _false)
        LONG IF OSErr
          BEEP: PRINT "PBDTFlush OSErr: "; OSErr
          DELAY 3000
        END IF
      XELSE
        BEEP: PRINT "PBDTSetComment OSErr: "; OSErr
        DELAY 3000
      END IF
    END IF
  END IF
UNTIL filename$ = ""