2 Copyright © 2003-2008, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
9 #include <dos/dosextens.h>
10 #include <workbench/workbench.h>
11 #include <workbench/icon.h>
12 #include <datatypes/datatypes.h>
13 #include <datatypes/datatypesclass.h>
14 #include <utility/hooks.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
18 #include <proto/icon.h>
19 #include <proto/utility.h>
20 #include <proto/datatypes.h>
25 /*** Prototypes *************************************************************/
26 BOOL
__FindDeviceName_WB(STRPTR buffer
, LONG length
, CONST_STRPTR volume
, struct DosLibrary
*DOSBase
);
27 struct DiskObject
*__GetDefaultIconFromName_WB(CONST_STRPTR name
, const struct TagItem
*tags
, struct Library
*IconBase
);
28 struct DiskObject
*__GetDefaultIconFromType_WB(LONG type
, const struct TagItem
*tags
, struct Library
*IconBase
);
30 /*** Macros *****************************************************************/
31 #define FindDeviceName(buffer, length, volume) (__FindDeviceName_WB((buffer), (length), (volume), DOSBase))
32 #define GetDefaultIconFromName(name, tags) (__GetDefaultIconFromName_WB((name), (tags), IconBase))
33 #define GetDefaultIconFromType(type, tags) (__GetDefaultIconFromType_WB((type), (tags), IconBase))
35 /*** Functions **************************************************************/
36 LONG
__FindType_WB(BPTR lock
, struct Library
*IconBase
)
39 struct FileInfoBlock
*fib
= AllocDosObject(DOS_FIB
, TAG_DONE
);
43 if (Examine(lock
, fib
))
45 /* Identify object ---------------------------------------------*/
46 if (fib
->fib_DirEntryType
== ST_ROOT
)
48 /* It's a disk/volume/root ---------------------------------*/
51 else if (fib
->fib_DirEntryType
> 0)
53 /* It's a directory ----------------------------------------*/
58 /* It's a file ---------------------------------------------*/
59 if (DataTypesBase
!= NULL
)
61 /* Use datatypes to identify the file ------------------*/
62 struct DataType
*dt
= ObtainDataType
64 DTST_FILE
, lock
, TAG_DONE
69 struct DataTypeHeader
*dth
= dt
->dtn_Header
;
73 dth
->dth_GroupID
== GID_SYSTEM
74 && dth
->dth_ID
== ID_EXECUTABLE
77 /* It's a executable file */
82 /* It's a project file of some kind */
92 /* Fallback to a more primitive identification ---------*/
93 if ((fib
->fib_Protection
& FIBF_EXECUTE
) == 0)
106 FreeDosObject(DOS_FIB
, fib
);
112 struct DiskObject
*__FindDefaultIcon_WB
114 struct IconIdentifyMsg
*iim
, struct Library
*IconBase
117 struct DiskObject
*icon
= NULL
;
119 /* Identify object -----------------------------------------------------*/
120 if (iim
->iim_FIB
->fib_DirEntryType
== ST_ROOT
)
122 /* It's a disk/volume/root -------------------------------------*/
123 TEXT device
[MAXFILENAMELENGTH
];
129 device
, MAXFILENAMELENGTH
,
130 iim
->iim_FIB
->fib_FileName
134 if (strlen(device
) <= 5)
136 if (strcasecmp(device
, "RAM:") == 0)
138 icon
= GetDefaultIconFromName("RAM", iim
->iim_Tags
);
140 else if (strncasecmp(device
, "RAD", 3) == 0)
142 icon
= GetDefaultIconFromName("RAD", iim
->iim_Tags
);
144 else if (strncasecmp(device
, "DF", 2) == 0)
146 icon
= GetDefaultIconFromName("Floppy", iim
->iim_Tags
);
148 else if (strncasecmp(device
, "CD", 2) == 0)
150 icon
= GetDefaultIconFromName("CDROM", iim
->iim_Tags
);
154 strncasecmp(device
, "DH", 2) == 0
155 || strncasecmp(device
, "HD", 2) == 0
156 || strncasecmp(device
, "EMU", 3) == 0
159 icon
= GetDefaultIconFromName("Harddisk", iim
->iim_Tags
);
161 else if (strcasecmp(device
, "HOME:") == 0)
163 icon
= GetDefaultIconFromName("Home", iim
->iim_Tags
);
168 /* Fall back to generic harddisk icon */
171 icon
= GetDefaultIconFromName("Harddisk", iim
->iim_Tags
);
176 /* Fall back to generic disk icon */
179 icon
= GetDefaultIconFromType(WBDISK
, iim
->iim_Tags
);
184 /* Force the icon type */
185 icon
->do_Type
= WBDISK
;
188 else if (iim
->iim_FIB
->fib_DirEntryType
> 0)
190 /* It's a directory --------------------------------------------*/
191 /* Check if it is a trashcan directory */
192 if (iim
->iim_ParentLock
!= NULL
)
194 /* Is iim_ParentLock a root? */
195 BPTR root
= ParentDir(iim
->iim_ParentLock
);
199 /* Yes, it's a root. See if it contains our trashcan. */
200 BPTR cd
= CurrentDir(iim
->iim_ParentLock
);
202 UBYTE buffer
[MAXFILENAMELENGTH
], buffer1
[MAXFILENAMELENGTH
];
204 /* SFS .recycled Trashcan */
205 BPTR lock
= Lock(".recycled", ACCESS_READ
);
206 NameFromLock(iim
->iim_FileLock
, buffer
, MAXFILENAMELENGTH
);
210 NameFromLock(lock
, buffer1
, MAXFILENAMELENGTH
);
211 if (strcasecmp(buffer
, buffer1
) == 0)
213 icon
= GetDefaultIconFromType(WBGARBAGE
, iim
->iim_Tags
);
225 /* Fall back to generic drawer icon */
228 icon
= GetDefaultIconFromType(WBDRAWER
, iim
->iim_Tags
);
233 /* Force the icon type */
234 icon
->do_Type
= WBDRAWER
;
239 /* It's a file -----------------------------------------------------*/
240 if (DataTypesBase
!= NULL
)
242 /* Use datatypes to identify the file --------------------------*/
243 struct DataType
*dt
= ObtainDataType
245 DTST_FILE
, iim
->iim_FileLock
, TAG_DONE
250 struct DataTypeHeader
*dth
= dt
->dtn_Header
;
254 dth
->dth_GroupID
== GID_SYSTEM
255 && dth
->dth_ID
== ID_EXECUTABLE
258 /* It's a executable file ------------------------------*/
259 icon
= GetDefaultIconFromType(WBTOOL
, iim
->iim_Tags
);
263 /* Force the icon type */
264 icon
->do_Type
= WBTOOL
;
269 /* It's a project file of some kind --------------------*/
270 icon
= GetDefaultIconFromName(dth
->dth_Name
, iim
->iim_Tags
);
272 /* Fall back to generic filetype group icon */
277 switch (dth
->dth_GroupID
)
279 case GID_SYSTEM
: name
= "System"; break;
280 case GID_TEXT
: name
= "Text"; break;
281 case GID_DOCUMENT
: name
= "Document"; break;
282 case GID_SOUND
: name
= "Sound"; break;
283 case GID_INSTRUMENT
: name
= "Instrument"; break;
284 case GID_MUSIC
: name
= "Music"; break;
285 case GID_PICTURE
: name
= "Picture"; break;
286 case GID_ANIMATION
: name
= "Animation"; break;
287 case GID_MOVIE
: name
= "Movie"; break;
292 icon
= GetDefaultIconFromName(name
, iim
->iim_Tags
);
296 /* Fall back to generic project icon */
299 icon
= GetDefaultIconFromType(WBPROJECT
, iim
->iim_Tags
);
304 /* Force the icon type */
305 icon
->do_Type
= WBPROJECT
;
315 /* Fallback to a more primitive identification -----------------*/
316 if ((iim
->iim_FIB
->fib_Protection
& FIBF_EXECUTE
) == 0)
318 /* It's an executable files --------------------------------*/
319 icon
= GetDefaultIconFromType(WBTOOL
, iim
->iim_Tags
);
323 /* Force the icon type */
324 icon
->do_Type
= WBTOOL
;
329 /* It's a project file of some kind ------------------------*/
330 icon
= GetDefaultIconFromType(WBPROJECT
, iim
->iim_Tags
);
334 /* Force the icon type */
335 icon
->do_Type
= WBPROJECT
;
344 /*** Support functions ******************************************************/
345 BOOL __FindDeviceName_WB
347 STRPTR buffer
, LONG length
, CONST_STRPTR volume
,
348 struct DosLibrary
*DOSBase
351 struct DosList
*dl
= LockDosList(LDF_DEVICES
| LDF_READ
);
352 BOOL success
= FALSE
;
356 struct DosList
*dol
= dl
;
358 while ((dol
= NextDosEntry(dol
, LDF_DEVICES
| LDF_READ
)) != NULL
)
360 TEXT device
[MAXFILENAMELENGTH
];
362 strlcpy(device
, dol
->dol_Ext
.dol_AROS
.dol_DevName
, MAXFILENAMELENGTH
);
364 if (strlcat(device
, ":", MAXFILENAMELENGTH
) < MAXFILENAMELENGTH
)
371 && (lock
= Lock(device
, ACCESS_READ
)) != NULL
374 if (NameFromLock(lock
, buffer
, length
))
376 buffer
[strlen(buffer
) - 1] = '\0'; /* Remove trailing ':' */
377 if (strcasecmp(volume
, buffer
) == 0)
379 if (strlcpy(buffer
, device
, length
) < length
)
393 UnLockDosList(LDF_DEVICES
| LDF_READ
);
399 struct DiskObject
*__GetDefaultIconFromName_WB
401 CONST_STRPTR name
, const struct TagItem
*tags
, struct Library
*IconBase
407 ICONGETA_GetDefaultName
, (IPTR
) name
,
408 TAG_MORE
, (IPTR
) tags
412 struct DiskObject
*__GetDefaultIconFromType_WB
414 LONG type
, const struct TagItem
*tags
, struct Library
*IconBase
420 ICONGETA_GetDefaultType
, type
,
421 TAG_MORE
, (IPTR
) tags