Commit 096253a6 authored by Felix Paul Kühne's avatar Felix Paul Kühne

fix issue which was leading to duplicated library entries on iOS 7 & 8

parent 1e9783d0
...@@ -223,7 +223,16 @@ NSString *kMLFileTypeAudio = @"audio"; ...@@ -223,7 +223,16 @@ NSString *kMLFileTypeAudio = @"audio";
if ([ret rangeOfString:documentFolderPath].location != NSNotFound) if ([ret rangeOfString:documentFolderPath].location != NSNotFound)
return ret; return ret;
ret = [NSString stringWithFormat:@"%@/%@", documentFolderPath, [ret lastPathComponent]]; NSArray *pathComponents = [ret componentsSeparatedByString:@"/"];
NSUInteger componentCount = pathComponents.count;
if ([pathComponents[componentCount - 2] isEqualToString:@"Documents"])
ret = [NSString stringWithFormat:@"%@/%@", documentFolderPath, [ret lastPathComponent]];
else {
NSUInteger firstElement = [pathComponents indexOfObject:@"Documents"] + 1;
ret = documentFolderPath;
for (NSUInteger x = 0; x < componentCount - firstElement; x++)
ret = [ret stringByAppendingFormat:@"/%@", pathComponents[firstElement + x]];
}
APLog(@"returning modified URL! will return %@", ret); APLog(@"returning modified URL! will return %@", ret);
return ret; return ret;
......
...@@ -662,19 +662,37 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles"; ...@@ -662,19 +662,37 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
NSString *documentFolderPath = [[MLMediaLibrary sharedMediaLibrary] documentFolderPath]; NSString *documentFolderPath = [[MLMediaLibrary sharedMediaLibrary] documentFolderPath];
// Prepare a fetch request for all items // Prepare a fetch request for all items
NSArray *pathComponents;
NSUInteger componentCount;
for (NSString *path in filepaths) { for (NSString *path in filepaths) {
#if TARGET_OS_IPHONE
NSString *urlString; NSString *urlString;
urlString = [NSString stringWithFormat:@"%@/%@", documentFolderPath, [path lastPathComponent]]; NSString *componentString = @"";
#if TARGET_OS_IPHONE pathComponents = [path componentsSeparatedByString:@"/"];
/* check for the end of a path only, since parts of the path components may change componentCount = pathComponents.count;
* while it is still the same file if ([pathComponents[componentCount - 2] isEqualToString:@"Documents"])
* of course, this is only true for the flat file structure we use on iOS */ componentString = [path lastPathComponent];
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url ENDSWITH %@", [urlString lastPathComponent]]]; else {
NSUInteger firstElement = [pathComponents indexOfObject:@"Documents"] + 1;
for (NSUInteger x = 0; x < componentCount - firstElement; x++) {
if (x == 0)
componentString = [componentString stringByAppendingFormat:@"%@", pathComponents[firstElement + x]];
else
componentString = [componentString stringByAppendingFormat:@"/%@", pathComponents[firstElement + x]];
}
}
/* compose and escape string */
urlString = [[NSString stringWithFormat:@"%@/%@", documentFolderPath, componentString] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
/* check for the end of the paths */
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url CONTAINS %@", [urlString lastPathComponent]]];
[urlToObject setObject:path forKey:urlString];
#else #else
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url == %@", urlString]]; [fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url == %@", path]];
#endif #endif
[urlToObject setObject:path forKey:urlString];
} }
NSFetchRequest *request = [self fetchRequestForEntity:@"File"]; NSFetchRequest *request = [self fetchRequestForEntity:@"File"];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment