1 /* 2 * Copyright 2017, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Brian Hill, supernova@tycho.email 7 */ 8 9 #include "AppRefFilter.h" 10 11 #include <string.h> 12 13 14 /* This class filters only applications in an open file panel */ 15 AppRefFilter::AppRefFilter() 16 : 17 BRefFilter() 18 { 19 } 20 21 22 bool 23 AppRefFilter::Filter(const entry_ref *ref, BNode *node, 24 struct stat_beos *st, const char *filetype) 25 { 26 char* type = NULL; 27 const char *constFileType; 28 // resolve symlinks 29 bool isSymlink = strcmp("application/x-vnd.Be-symlink", filetype) == 0; 30 if (isSymlink) { 31 BEntry linkedEntry(ref, true); 32 if (linkedEntry.InitCheck()!=B_OK) 33 return false; 34 BNode linkedNode(&linkedEntry); 35 if (linkedNode.InitCheck()!=B_OK) 36 return false; 37 BNodeInfo linkedNodeInfo(&linkedNode); 38 if (linkedNodeInfo.InitCheck()!=B_OK) 39 return false; 40 type = new char[B_ATTR_NAME_LENGTH]; 41 if (linkedNodeInfo.GetType(type)!=B_OK) { 42 delete[] type; 43 return false; 44 } 45 constFileType = type; 46 } else 47 constFileType = filetype; 48 49 bool pass = false; 50 //folders 51 if (strcmp("application/x-vnd.Be-directory", constFileType) == 0) 52 pass = true; 53 //volumes 54 else if (strcmp("application/x-vnd.Be-volume", constFileType) == 0) 55 pass = true; 56 //apps 57 else if (strcmp("application/x-vnd.Be-elfexecutable", constFileType) == 0) 58 pass = true; 59 //hack for Haiku? Some apps are defined by MIME this way 60 else if (strcmp("application/x-vnd.be-elfexecutable", constFileType) == 0) 61 pass = true; 62 63 if (isSymlink) 64 delete[] type; 65 return pass; 66 } 67