| 175 | if (entry.IsDirectory()) |
| 176 | return false; |
| 177 | |
| 178 | BNode fileNode(&entry); |
| 179 | if (fileNode.InitCheck() != B_OK) |
| 180 | return false; |
| 181 | |
| 182 | BNodeInfo *nodeInfo = new BNodeInfo(&fileNode); |
| 183 | char fileTypeStr[256]; |
| 184 | nodeInfo->GetType(fileTypeStr); |
| 185 | delete nodeInfo; |
| 186 | |
| 187 | printf("file type: %s \n",fileTypeStr); |
| 188 | BMimeType fileType(fileTypeStr); |
| 189 | |
| 190 | // Check for malformed or inexistant mime type |
| 191 | if (!fileType.IsValid()){ |
| 192 | char fileName[B_FILE_NAME_LENGTH]; |
| 193 | entry.GetName(fileName); |
| 194 | BString alertText; |
| 195 | alertText << "Sorry! Can't open \"" << fileName << "\"!\nStyledEdit can't determine the type of the file!"; |
| 196 | BAlert* alert = new BAlert("StyledEdit Load Failed", alertText.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); |
| 197 | alert->SetShortcut(0, B_ESCAPE); |
| 198 | alert->Go(); |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | BMimeType desiredSuperType("text"); |
| 203 | |
| 204 | if (desiredSuperType.Contains(&fileType)) { |
| 205 | return true; |
| 206 | } else { |
| 207 | char fileName[B_FILE_NAME_LENGTH]; |
| 208 | entry.GetName(fileName); |
| 209 | |
| 210 | BString alertText; |
| 211 | alertText << "Sorry! Can't open \"" << fileName << "\"!\nStyledEdit can't load files of type \"" << fileTypeStr << "\"!"; |
| 212 | |
| 213 | BAlert* alert = new BAlert("StyledEdit Load Failed", alertText.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); |
| 214 | alert->SetShortcut(0, B_ESCAPE); |
| 215 | alert->Go(); |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | |
| 220 | } |
| 221 | |