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

FInding the System (preferences) folder...



   From: stevens@sigi.cs.colorado.edu (Curt Stevens)
   Newsgroups: comp.lang.lisp.mcl

   Could someone clue me in on the appropriate way to find the active system
   folder? I'm trying to put stuff into the preferences folder and figured
   that this was the best way to find it. Thanks very much.


I believe this is what you want.  Please excuse the fact that it uses
(at least one) undocumented function.  Also, it would be very simple
to modify this to locate other "magic folders".

    -andrew

-------cut here----

(in-package :ccl)

(defconstant $ioVRefNum #x16)
(defconstant $ioDirID #x30)

(defun pathname-from-dirid (vrefnum dirid)
  (%stack-iopb (pb name)
    ;should use records...
    (%put-word pb vrefnum $ioVRefNum)
    (%put-long pb dirid $ioDirId)
    (make-pathname :directory 
                   (pathname-directory (%path-from-iopb pb)))))

(defun preferences-folder-bits ()
  (let* ((can-do? (gestalt "fold")))
    (when (and can-do?
               (plusp can-do?))
      (rlet ((return-vrefnum :ptr)
             (return-dirid :ptr))
        (#_findfolder
         -1               ;system volume
         :|pref|          ;preferences file
         t                ;create the folder if it doesn't exist
         return-vrefnum
         return-dirid)
        (values (%get-signed-word return-vrefnum)
                (%get-long return-dirid))))))

(defun find-preferences-folder (&optional (default "ccl:"))
  (multiple-value-bind (vrefnum dirid)
                       (preferences-folder-bits)
    (if (and vrefnum dirid)
      (pathname-from-dirid vrefnum dirid)
      default)))

#+test
(find-preferences-folder)