[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changing Finder attributes



 
Regarding my earlier posting of wanting to modify several Finder attributes for
a file simultaneously, in order to cut down on network/file server traffic, I
came up with my own answer.  This is apparently what happens when you finally
find the right paramblock and toolbox call to use (in other words, "RTFM,
Dan").
 
Below is the code I came up with.  The macro is something I used in the past
and is probably a kludge in this case.  It works, though.
 
Dan
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; %set-file-stuff
;;
;; Function used to change four Finder attributes for a file:  Date Created,
;; Date Modified, File Creator and File Type.
;;
(defun %set-file-stuff (path &key
                             (created nil) (modified nil)
                             (type nil) (creator nil))
  (when (and (probe-file path)
             (not (directory-pathname-p path))
             (or (numberp created) (numberp modified) type creator))
    (if (pathnamep path)
      (setf path (mac-namestring path)))
    (rlet ((cpb :cinfopbrec)
           (alt-cpb :cinfopbrec))
      (using-cinfopbrec (cpb path)
        (#_pbgetcatinfo cpb)
        (using-cinfopbrec (alt-cpb path)
          (setf (rref alt-cpb :cinfopbrec.ioFlFndrInfo)
                               (rref cpb :cinfopbrec.ioFlFndrInfo)
                (rref alt-cpb :cinfopbrec.ioFlBkDat)
                               (rref cpb :cinfopbrec.ioFlBkDat)
                (rref alt-cpb :cinfopbrec.ioFlXFndrInfo)
                               (rref cpb :cinfopbrec.ioFlXFndrInfo))
          (if created
            (setf (rref alt-cpb :cinfopbrec.ioFlCrDat)
                               (ccl::universal-to-mac-time created))
            (setf (rref alt-cpb :cinfopbrec.ioFlCrDat)
                               (rref cpb :cinfopbrec.ioFlCrDat)))
          (if modified
            (setf (rref alt-cpb :cinfopbrec.ioFlMdDat)
                               (ccl::universal-to-mac-time modified))
            (setf (rref alt-cpb :cinfopbrec.ioFlMdDat)
                               (rref cpb :cinfopbrec.ioFlMdDat)))
          (if type
            (setf (rref alt-cpb :cinfopbrec.ioFlFndrInfo.FDType) type))
          (if creator
            (setf (rref alt-cpb :cinfopbrec.ioFlFndrInfo.FDCreator) creator))
          (#_pbsetcatinfo alt-cpb))))))
 
(defmacro using-cinfopbrec ((cpb path) &body body)
  (let ((the-path (gensym)))
    `(let ((,the-path ,path))
       (if (pathnamep ,the-path)
         (setf ,the-path (mac-namestring ,the-path)))
       (with-pstrs ((pname ,the-path))
         (setf (pref ,cpb :cinfopbrec.ioNameptr) pname
               (pref ,cpb :cinfopbrec.ioVrefnum) 0
               (pref ,cpb :cinfopbrec.ioDrDirID) 0
               (pref ,cpb :cinfopbrec.ioFDirIndex) 0
               )
         ,@body))))