2 Copyright © 2003-2012, 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>
22 #include "icon_intern.h"
27 #define ID_FAT12_DISK AROS_MAKE_ID('F','A','T',0) /* FAT12 */
28 #define ID_FAT16_DISK AROS_MAKE_ID('F','A','T',1) /* FAT16 */
29 #define ID_FAT32_DISK AROS_MAKE_ID('F','A','T',2) /* FAT32 */
32 #define ID_CDFS_DISK AROS_MAKE_ID('C','D','F','S') /* CDFS */
35 /*** Prototypes *************************************************************/
36 BOOL
__FindDeviceName_WB(STRPTR buffer
, LONG length
, BPTR lock
, APTR
*theDOSBase
);
37 struct DiskObject
*__GetDefaultIconFromName_WB(CONST_STRPTR name
, const struct TagItem
*tags
, struct IconBase
*IconBase
);
38 struct DiskObject
*__GetDefaultIconFromType_WB(LONG type
, const struct TagItem
*tags
, struct IconBase
*IconBase
);
39 LONG
__FindDiskType_WB(STRPTR volname
, BPTR lock
, struct IconBase
*IconBase
);
41 /*** Macros *****************************************************************/
42 #define FindDeviceName(buffer, length, volume) (__FindDeviceName_WB((buffer), (length), (volume), DOSBase))
43 #define GetDefaultIconFromName(name, tags) (__GetDefaultIconFromName_WB((name), (tags), IconBase))
44 #define GetDefaultIconFromType(type, tags) (__GetDefaultIconFromType_WB((type), (tags), IconBase))
45 #define FindDiskType(volname, lock) (__FindDiskType_WB((volname),(lock),IconBase))
46 /*** Functions **************************************************************/
47 LONG
__FindType_WB(BPTR lock
, struct IconBase
*IconBase
)
50 struct FileInfoBlock
*fib
= AllocDosObject(DOS_FIB
, TAG_DONE
);
54 if (Examine(lock
, fib
))
56 D(bug("[%s] Examine says: fib_DirEntryType=%d\n", __func__
, fib
->fib_DirEntryType
));
57 D(bug("[%s] Examine says: fib_Protection=%x\n", __func__
, fib
->fib_Protection
));
58 /* Identify object ---------------------------------------------*/
59 if (fib
->fib_DirEntryType
== ST_ROOT
)
61 /* It's a disk/volume/root ---------------------------------*/
64 else if (fib
->fib_DirEntryType
> 0)
66 /* It's a directory ----------------------------------------*/
71 /* It's a file ---------------------------------------------*/
72 if (DataTypesBase
!= NULL
)
74 /* Use datatypes to identify the file ------------------*/
75 struct DataType
*dt
= ObtainDataType
77 DTST_FILE
, (APTR
)lock
, TAG_DONE
82 struct DataTypeHeader
*dth
= dt
->dtn_Header
;
86 dth
->dth_GroupID
== GID_SYSTEM
87 && dth
->dth_ID
== ID_EXECUTABLE
90 /* It's an executable file */
95 /* It's a project file of some kind */
105 /* Fallback to a more primitive identification ---------*/
106 if ((fib
->fib_Protection
& FIBF_EXECUTE
) == 0)
119 FreeDosObject(DOS_FIB
, fib
);
125 struct DiskObject
*__FindDefaultIcon_WB
127 struct IconIdentifyMsg
*iim
, struct IconBase
*IconBase
130 struct DiskObject
*icon
= NULL
;
132 /* Identify object -----------------------------------------------------*/
133 if (iim
->iim_FIB
->fib_DirEntryType
== ST_ROOT
)
135 /* It's a disk/volume/root -------------------------------------*/
136 TEXT device
[MAXFILENAMELENGTH
];
142 device
, MAXFILENAMELENGTH
,
147 BPTR lock
= Lock(device
, SHARED_LOCK
);
148 LONG type
= FindDiskType(iim
->iim_FIB
->fib_FileName
, lock
);
150 if (strlen(device
) <= 5)
152 if (strcasecmp(device
, "RAM:") == 0)
154 icon
= GetDefaultIconFromName("RAM", iim
->iim_Tags
);
156 else if (strncasecmp(device
, "RAD", 3) == 0)
158 icon
= GetDefaultIconFromName("RAD", iim
->iim_Tags
);
160 else if (strncasecmp(device
, "DF", 2) == 0)
162 icon
= GetDefaultIconFromName("Floppy", iim
->iim_Tags
);
164 else if (strncasecmp(device
, "CD", 2) == 0)
166 icon
= GetDefaultIconFromName("CDROM", iim
->iim_Tags
);
170 strncasecmp(device
, "DH", 2) == 0
171 || strncasecmp(device
, "HD", 2) == 0
172 || strncasecmp(device
, "EMU", 3) == 0
175 icon
= GetDefaultIconFromName("Harddisk", iim
->iim_Tags
);
177 else if (strcasecmp(device
, "HOME") == 0)
179 icon
= GetDefaultIconFromName("Home", iim
->iim_Tags
);
183 D(bug("[icon] Identify Type: 0x%8x\n",type
));
190 icon
= GetDefaultIconFromName("FAT", iim
->iim_Tags
);
194 icon
= GetDefaultIconFromName("SFS", iim
->iim_Tags
);
197 case ID_INTER_DOS_DISK
:
198 case ID_INTER_FFS_DISK
:
199 case ID_FASTDIR_DOS_DISK
:
200 case ID_FASTDIR_FFS_DISK
:
201 icon
= GetDefaultIconFromName("ADF", iim
->iim_Tags
);
204 icon
= GetDefaultIconFromName("CDROM", iim
->iim_Tags
);
207 icon
= GetDefaultIconFromName("Disk", iim
->iim_Tags
);
212 else if (strncasecmp(device
, "USB", 3) ==0)
214 icon
= GetDefaultIconFromName("USB", iim
->iim_Tags
);
218 /* Fall back to generic harddisk icon */
221 icon
= GetDefaultIconFromName("Harddisk", iim
->iim_Tags
);
226 /* Fall back to generic disk icon */
229 icon
= GetDefaultIconFromType(WBDISK
, iim
->iim_Tags
);
234 /* Force the icon type */
235 icon
->do_Type
= WBDISK
;
238 else if (iim
->iim_FIB
->fib_DirEntryType
> 0)
240 /* It's a directory --------------------------------------------*/
241 /* Check if it is a trashcan directory */
242 if (iim
->iim_ParentLock
!= BNULL
)
244 /* Is iim_ParentLock a root? */
245 BPTR root
= ParentDir(iim
->iim_ParentLock
);
249 /* Yes, it's a root. See if it contains our trashcan. */
250 BPTR cd
= CurrentDir(iim
->iim_ParentLock
);
252 UBYTE buffer
[MAXFILENAMELENGTH
], buffer1
[MAXFILENAMELENGTH
];
254 /* SFS .recycled Trashcan */
255 BPTR lock
= Lock(".recycled", ACCESS_READ
);
256 NameFromLock(iim
->iim_FileLock
, buffer
, MAXFILENAMELENGTH
);
260 NameFromLock(lock
, buffer1
, MAXFILENAMELENGTH
);
261 if (strcasecmp(buffer
, buffer1
) == 0)
263 icon
= GetDefaultIconFromType(WBGARBAGE
, iim
->iim_Tags
);
275 /* Fall back to generic drawer icon */
278 icon
= GetDefaultIconFromType(WBDRAWER
, iim
->iim_Tags
);
283 /* Force the icon type */
284 icon
->do_Type
= WBDRAWER
;
289 /* It's a file -----------------------------------------------------*/
290 if (DataTypesBase
!= NULL
)
292 /* Use datatypes to identify the file --------------------------*/
293 struct DataType
*dt
= ObtainDataType
295 DTST_FILE
, (APTR
)iim
->iim_FileLock
, TAG_DONE
300 struct DataTypeHeader
*dth
= dt
->dtn_Header
;
304 dth
->dth_GroupID
== GID_SYSTEM
305 && dth
->dth_ID
== ID_EXECUTABLE
308 /* It's an executable file -----------------------------*/
309 icon
= GetDefaultIconFromType(WBTOOL
, iim
->iim_Tags
);
313 /* Force the icon type */
314 icon
->do_Type
= WBTOOL
;
319 /* It's a project file of some kind --------------------*/
320 icon
= GetDefaultIconFromName(dth
->dth_Name
, iim
->iim_Tags
);
322 /* Fall back to generic filetype group icon */
327 switch (dth
->dth_GroupID
)
329 case GID_SYSTEM
: name
= "System"; break;
330 case GID_TEXT
: name
= "Text"; break;
331 case GID_DOCUMENT
: name
= "Document"; break;
332 case GID_SOUND
: name
= "Sound"; break;
333 case GID_INSTRUMENT
: name
= "Instrument"; break;
334 case GID_MUSIC
: name
= "Music"; break;
335 case GID_PICTURE
: name
= "Picture"; break;
336 case GID_ANIMATION
: name
= "Animation"; break;
337 case GID_MOVIE
: name
= "Movie"; break;
342 icon
= GetDefaultIconFromName(name
, iim
->iim_Tags
);
346 /* Fall back to generic project icon */
349 icon
= GetDefaultIconFromType(WBPROJECT
, iim
->iim_Tags
);
354 /* Force the icon type */
355 icon
->do_Type
= WBPROJECT
;
365 /* Fallback to a more primitive identification -----------------*/
366 if ((iim
->iim_FIB
->fib_Protection
& FIBF_EXECUTE
) == 0)
368 /* It's an executable files --------------------------------*/
369 icon
= GetDefaultIconFromType(WBTOOL
, iim
->iim_Tags
);
373 /* Force the icon type */
374 icon
->do_Type
= WBTOOL
;
379 /* It's a project file of some kind ------------------------*/
380 icon
= GetDefaultIconFromType(WBPROJECT
, iim
->iim_Tags
);
384 /* Force the icon type */
385 icon
->do_Type
= WBPROJECT
;
394 /*** Support functions ******************************************************/
395 LONG
__FindDiskType_WB(STRPTR volname
, BPTR lock
, struct IconBase
*IconBase
)
397 LONG disktype
= ID_NO_DISK_PRESENT
;
398 struct DosList
*dl
, *dn
;
400 dl
= LockDosList(LDF_VOLUMES
|LDF_READ
);
403 dn
= FindDosEntry(dl
, volname
, LDF_VOLUMES
);
406 disktype
= dn
->dol_misc
.dol_volume
.dol_DiskType
;
408 UnLockDosList(LDF_VOLUMES
|LDF_READ
);
411 if (disktype
== 0) //FFS workaround (dol_DiskType == 0)
413 struct InfoData
*id
= AllocMem(sizeof(struct InfoData
), MEMF_PUBLIC
|MEMF_CLEAR
);
418 disktype
= id
->id_DiskType
;
420 FreeMem(id
,sizeof(struct InfoData
));
426 BOOL __FindDeviceName_WB
428 STRPTR device
, LONG length
, BPTR lock
,
433 #define DOSBase theDOSBase
434 struct DosList
*dl
= LockDosList(LDF_DEVICES
| LDF_READ
);
435 BOOL success
= FALSE
;
439 struct DosList
*dol
= dl
;
440 struct MsgPort
*port
= ((struct FileLock
*) BADDR(lock
))->fl_Task
;
442 while ((dol
= NextDosEntry(dol
, LDF_DEVICES
| LDF_READ
)) != NULL
)
444 STRPTR devname
= AROS_BSTR_ADDR(dol
->dol_Name
);
445 ULONG len
= AROS_BSTR_strlen(dol
->dol_Name
);
447 if (dol
->dol_Task
== port
) {
448 CopyMem(devname
, device
, len
);
457 UnLockDosList(LDF_DEVICES
| LDF_READ
);
463 struct DiskObject
*__GetDefaultIconFromName_WB
465 CONST_STRPTR name
, const struct TagItem
*tags
, struct IconBase
*IconBase
471 ICONGETA_GetDefaultName
, (IPTR
) name
,
476 struct DiskObject
*__GetDefaultIconFromType_WB
478 LONG type
, const struct TagItem
*tags
, struct IconBase
*IconBase
484 ICONGETA_GetDefaultType
, type
,