Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / icon / identify.c
blobe3870159f6a1498ca1b7e43887b647b549fc6a48
1 /*
2 Copyright © 2003-2008, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #define DEBUG 0
6 #include <aros/debug.h>
8 #include <dos/dos.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 <string.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)
38 LONG type = -1;
39 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, TAG_DONE);
41 if (fib != NULL)
43 if (Examine(lock, fib))
45 /* Identify object ---------------------------------------------*/
46 if (fib->fib_DirEntryType == ST_ROOT)
48 /* It's a disk/volume/root ---------------------------------*/
49 type = WBDISK;
51 else if (fib->fib_DirEntryType > 0)
53 /* It's a directory ----------------------------------------*/
54 type = WBDRAWER;
56 else
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
67 if (dt != NULL)
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 */
78 type = WBTOOL;
80 else
82 /* It's a project file of some kind */
83 type = WBPROJECT;
86 ReleaseDataType(dt);
90 if (type == -1)
92 /* Fallback to a more primitive identification ---------*/
93 if ((fib->fib_Protection & FIBF_EXECUTE) == 0)
95 type = WBTOOL;
97 else
99 type = WBPROJECT;
106 FreeDosObject(DOS_FIB, fib);
109 return type;
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];
127 FindDeviceName
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);
152 else if
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);
166 else
168 /* Fall back to generic harddisk icon */
169 if (icon == NULL)
171 icon = GetDefaultIconFromName("Harddisk", iim->iim_Tags);
176 /* Fall back to generic disk icon */
177 if (icon == NULL)
179 icon = GetDefaultIconFromType(WBDISK, iim->iim_Tags);
182 if (icon != NULL)
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);
197 if (root == NULL)
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);
208 if (lock != NULL)
210 NameFromLock(lock, buffer1, MAXFILENAMELENGTH);
211 if (strcasecmp(buffer, buffer1) == 0)
213 icon = GetDefaultIconFromType(WBGARBAGE, iim->iim_Tags);
215 UnLock(lock);
217 CurrentDir(cd);
219 else
221 UnLock(root);
225 /* Fall back to generic drawer icon */
226 if (icon == NULL)
228 icon = GetDefaultIconFromType(WBDRAWER, iim->iim_Tags);
231 if (icon != NULL)
233 /* Force the icon type */
234 icon->do_Type = WBDRAWER;
237 else
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
248 if (dt != NULL)
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);
261 if (icon != NULL)
263 /* Force the icon type */
264 icon->do_Type = WBTOOL;
267 else
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 */
273 if (icon == NULL)
275 STRPTR name = NULL;
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;
290 if (name != NULL)
292 icon = GetDefaultIconFromName(name, iim->iim_Tags);
296 /* Fall back to generic project icon */
297 if (icon == NULL)
299 icon = GetDefaultIconFromType(WBPROJECT, iim->iim_Tags);
302 if (icon != NULL)
304 /* Force the icon type */
305 icon->do_Type = WBPROJECT;
309 ReleaseDataType(dt);
313 if (icon == NULL)
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);
321 if (icon != NULL)
323 /* Force the icon type */
324 icon->do_Type = WBTOOL;
327 else
329 /* It's a project file of some kind ------------------------*/
330 icon = GetDefaultIconFromType(WBPROJECT, iim->iim_Tags);
332 if (icon != NULL)
334 /* Force the icon type */
335 icon->do_Type = WBPROJECT;
341 return icon;
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;
354 if (dl != NULL)
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)
366 BPTR lock;
370 IsFileSystem(device)
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)
381 success = TRUE;
383 UnLock(lock);
384 break;
388 UnLock(lock);
393 UnLockDosList(LDF_DEVICES | LDF_READ);
396 return success;
399 struct DiskObject *__GetDefaultIconFromName_WB
401 CONST_STRPTR name, const struct TagItem *tags, struct Library *IconBase
404 return GetIconTags
406 NULL,
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
417 return GetIconTags
419 NULL,
420 ICONGETA_GetDefaultType, type,
421 TAG_MORE, (IPTR) tags