TagLib: Add exception handling
The TagLib C++ code was missing generic try/catch handling which could result in any generic errors throwing straight to a full crash. Add exception handling and logging, which will fix a logged crash regardless of whether the tags are read correctly or not by the newer TagLib version. Fixes #415 Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
61165a022a
commit
e9a17a8ba5
3 changed files with 257 additions and 237 deletions
|
@ -14,6 +14,8 @@
|
|||
#import <tag/tfilestream.h>
|
||||
#import <tag/tbytevectorstream.h>
|
||||
|
||||
#import "Logging.h"
|
||||
|
||||
@implementation TagLibID3v2Reader
|
||||
|
||||
+ (NSDictionary *)metadataForTag:(NSData *)tagBlock {
|
||||
|
@ -53,6 +55,7 @@
|
|||
//
|
||||
// }
|
||||
|
||||
try {
|
||||
TagLib::ByteVector vector((const char *)[tagBlock bytes], (unsigned int)[tagBlock length]);
|
||||
TagLib::ByteVectorStream vectorStream(vector);
|
||||
|
||||
|
@ -158,6 +161,10 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught processing ID3v2 tag with TagLib: %s", e.what());
|
||||
return [NSDictionary dictionary];
|
||||
}
|
||||
|
||||
return [NSDictionary dictionaryWithDictionary:dict];
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#import <tag/vorbisfile.h>
|
||||
#import <tag/xiphcomment.h>
|
||||
|
||||
#import "Logging.h"
|
||||
|
||||
#import "SandboxBroker.h"
|
||||
|
||||
@implementation TagLibMetadataReader
|
||||
|
@ -68,6 +70,7 @@
|
|||
//
|
||||
// }
|
||||
|
||||
try {
|
||||
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
||||
if(!f.isNull()) {
|
||||
const TagLib::Tag *tag = f.tag();
|
||||
|
@ -177,6 +180,11 @@
|
|||
[dict setObject:image forKey:@"albumArt"];
|
||||
}
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught reading file with TagLib: %s", e.what());
|
||||
[sandboxBroker endFolderAccess:sbHandle];
|
||||
return [NSDictionary dictionary];
|
||||
}
|
||||
|
||||
[sandboxBroker endFolderAccess:sbHandle];
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
|
||||
// int lYear = 0, lTrack = 0;
|
||||
|
||||
try {
|
||||
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
||||
if(!f.isNull()) {
|
||||
const TagLib::Tag *tag = f.tag();
|
||||
|
@ -69,6 +70,10 @@
|
|||
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
|
||||
*/
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
ALog(@"Exception caught writing with TagLib: %s", e.what());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue