| 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(&fileNode); |
| 183 | char fileTypeStr[256]; |
| 184 | nodeInfo.GetType(fileTypeStr); |
| 185 | |
| 186 | BMimeType fileType(fileTypeStr); |
| 187 | |
| 188 | // Check for malformed or inexistant mime type |
| 189 | if (!fileType.IsValid()){ |
| 190 | char fileName[B_FILE_NAME_LENGTH]; |
| 191 | entry.GetName(fileName); |
| 192 | BString alertText; |
| 193 | alertText << "Sorry! Can't open \"" << fileName << "\"!\nStyledEdit can't determine the type of the file!"; |
| 194 | BAlert* alert = new BAlert("StyledEdit Load Failed", alertText.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); |
| 195 | alert->SetShortcut(0, B_ESCAPE); |
| 196 | alert->Go(); |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | BMimeType desiredSuperType("text"); |
| 201 | |
| 202 | if (desiredSuperType.Contains(&fileType)) { |
| 203 | return true; |
| 204 | } else { |
| 205 | char fileName[B_FILE_NAME_LENGTH]; |
| 206 | entry.GetName(fileName); |
| 207 | BString alertText; |
| 208 | alertText << "Sorry! Can't open \"" << fileName << "\"!\nStyledEdit can't load files of type \"" << fileTypeStr << "\"!"; |
| 209 | BAlert* alert = new BAlert("StyledEdit Load Failed", alertText.String(), "Ok", 0, 0, B_WIDTH_AS_USUAL, B_EVEN_SPACING, B_STOP_ALERT); |
| 210 | alert->SetShortcut(0, B_ESCAPE); |
| 211 | alert->Go(); |
| 212 | return false; |
| 213 | } |
| 214 | } |
| 215 | |