home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / libs / icon / getdiskobjectnew.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-07  |  2.4 KB  |  114 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: getdiskobjectnew.c,v 1.1 1997/02/03 13:34:33 digulla Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include <proto/dos.h>
  9. #include "icon_intern.h"
  10.  
  11. /*****************************************************************************
  12.  
  13.     NAME */
  14. #include <proto/icon.h>
  15.  
  16.     AROS_LH1(struct DiskObject *, GetDiskObjectNew,
  17.  
  18. /*  SYNOPSIS */
  19.     AROS_LHA(UBYTE *, name, A0),
  20.  
  21. /*  LOCATION */
  22.     struct Library *, IconBase, 22, Icon)
  23.  
  24. /*  FUNCTION
  25.     Tries to open the supplied info file via GetDiskObject(). If this
  26.     not succeeds it will try to read the default info file for
  27.     that type of file.
  28.  
  29.     INPUTS
  30.     name - name of the file to read an icon for.
  31.  
  32.     RESULT
  33.     DiskObject - pointer ta diskobject struct.
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.  
  41.     SEE ALSO
  42.     GetDiskObject(), GetDefDiskObject()
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.  
  48. *****************************************************************************/
  49. {
  50.     AROS_LIBFUNC_INIT
  51.     AROS_LIBBASE_EXT_DECL(struct Library *,IconBase)
  52.     struct DiskObject     * dobject;
  53.     struct FileInfoBlock * fib;
  54.  
  55.     BPTR lock,
  56.      parentlock;
  57.     LONG def_type = NULL; /* Hopefully NULL != any of the possibel constants
  58.                 (WBDISK, etc) */
  59.  
  60.     /* First try to see if name.info exists */
  61.     if ( (dobject = GetDiskObject (name)) )
  62.     return (dobject);
  63.     else
  64.     {
  65.     /* Try to get the default icon of the file, but first we must find
  66.        out the type of file (or directory) */
  67.  
  68.     if ( (lock = Lock (name, ACCESS_READ)) )
  69.     {
  70.         /* Can we get the parent of the lock or Does the file have
  71.            .info at the end of it ? */
  72.         if ((!(parentlock=ParentDir (lock)) )
  73.         && !strcmp (name + strlen (name) - 4, "Disk")
  74.         )
  75.         def_type = WBDISK;
  76.         else
  77.         {
  78.         /* We do not need the lock of the parent anymore */
  79.         UnLock(parentlock);
  80.  
  81.         /* Now we should exmine the file-attributes */
  82.         if ( (fib = AllocDosObject (DOS_FIB, TAG_DONE)) )
  83.         {
  84.             if (Examine(lock, fib))
  85.             {
  86.             /* Do we have a directory ? */
  87.             if (fib->fib_DirEntryType > 0)
  88.                 def_type = WBDRAWER;
  89.             else if (fib->fib_DirEntryType < 0) /* or a file ? */
  90.             {
  91.                 /* executable ? */
  92.                 if (fib->fib_Protection & FIBF_EXECUTE)
  93.                 def_type = WBTOOL;
  94.                 else
  95.                 /* Project is default */
  96.                 def_type = WBPROJECT;
  97.             }
  98.             }
  99.  
  100.             FreeDosObject(DOS_FIB,fib);
  101.         }
  102.         }
  103.  
  104.         UnLock(lock);
  105.     }
  106.  
  107.     /* Try to open the default icon */
  108.     return(GetDefDiskObject(def_type));
  109.     }
  110.  
  111.     return (FALSE);
  112.     AROS_LIBFUNC_EXIT
  113. } /* GetDiskObjectNew */
  114.