[haiku-development] Re: How to Identify a file?

  • From: "Fredrik Holmqvist" <fredrik.holmqvist@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 18 Oct 2007 12:09:34 +0200

2007/10/18, Stephan Assmus <superstippi@xxxxxx>:
>
> [...]
>
> entry_ref ref;
> for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK;
> i++) {
>         BFile file(&ref, B_READ_ONLY);
>         BNodeInfo nodeInfo(&file);
>         char mimeString[B_MIME_TYPE_LENGTH];
>         if (nodeInfo->GetType(mimeString) == B_OK) {
>                 BMimeType fileType(mimeString);
>                 BMimeType superType;
>                 if (fileType->GetSupertype(&superType) == B_OK) {
>                         if (superType == "audio" || superType == "video")
>                                 AppendToPlaylistRecursive(ref, playlist);
>                 }
>         }
> }
>
> It could also be a lot less nested by using the continue keyword:
entry_ref ref;
for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++)
{
        BFile file(&ref, B_READ_ONLY);
        BNodeInfo nodeInfo(&file);
        char mimeString[B_MIME_TYPE_LENGTH];
         if (nodeInfo->GetType(mimeString) != B_OK)
             continue;

         BMimeType fileType(mimeString);
         BMimeType superType;
         if (fileType->GetSupertype( &superType) != B_OK)
             continue;

         if (superType == "audio" || superType == "video")
             AppendToPlaylistRecursive(ref, playlist);
}



-- 
Fredrik Holmqvist
Chaordic: things that thrive on the edge of chaos with just enough order to
give them pattern, but not so much to slow their adaptation and learning.

Other related posts: