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
b0414f4399
commit
7777e50f03
3 changed files with 257 additions and 237 deletions
|
@ -14,6 +14,8 @@
|
||||||
#import <tag/tfilestream.h>
|
#import <tag/tfilestream.h>
|
||||||
#import <tag/tbytevectorstream.h>
|
#import <tag/tbytevectorstream.h>
|
||||||
|
|
||||||
|
#import "Logging.h"
|
||||||
|
|
||||||
@implementation TagLibID3v2Reader
|
@implementation TagLibID3v2Reader
|
||||||
|
|
||||||
+ (NSDictionary *)metadataForTag:(NSData *)tagBlock {
|
+ (NSDictionary *)metadataForTag:(NSData *)tagBlock {
|
||||||
|
@ -53,6 +55,7 @@
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
TagLib::ByteVector vector((const char *)[tagBlock bytes], (unsigned int)[tagBlock length]);
|
TagLib::ByteVector vector((const char *)[tagBlock bytes], (unsigned int)[tagBlock length]);
|
||||||
TagLib::ByteVectorStream vectorStream(vector);
|
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];
|
return [NSDictionary dictionaryWithDictionary:dict];
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#import <tag/vorbisfile.h>
|
#import <tag/vorbisfile.h>
|
||||||
#import <tag/xiphcomment.h>
|
#import <tag/xiphcomment.h>
|
||||||
|
|
||||||
|
#import "Logging.h"
|
||||||
|
|
||||||
#import "SandboxBroker.h"
|
#import "SandboxBroker.h"
|
||||||
|
|
||||||
@implementation TagLibMetadataReader
|
@implementation TagLibMetadataReader
|
||||||
|
@ -68,6 +70,7 @@
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
try {
|
||||||
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
||||||
if(!f.isNull()) {
|
if(!f.isNull()) {
|
||||||
const TagLib::Tag *tag = f.tag();
|
const TagLib::Tag *tag = f.tag();
|
||||||
|
@ -177,6 +180,11 @@
|
||||||
[dict setObject:image forKey:@"albumArt"];
|
[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];
|
[sandboxBroker endFolderAccess:sbHandle];
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
|
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
|
||||||
// int lYear = 0, lTrack = 0;
|
// int lYear = 0, lTrack = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
|
||||||
if(!f.isNull()) {
|
if(!f.isNull()) {
|
||||||
const TagLib::Tag *tag = f.tag();
|
const TagLib::Tag *tag = f.tag();
|
||||||
|
@ -69,6 +70,10 @@
|
||||||
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
|
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
ALog(@"Exception caught writing with TagLib: %s", e.what());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue