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";
if ([ret rangeOfString:documentFolderPath].location != NSNotFound)
return ret;
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);
return ret;
......
......@@ -662,19 +662,37 @@ static NSString *kDecrapifyTitles = @"MLDecrapifyTitles";
NSString *documentFolderPath = [[MLMediaLibrary sharedMediaLibrary] documentFolderPath];
// Prepare a fetch request for all items
NSArray *pathComponents;
NSUInteger componentCount;
for (NSString *path in filepaths) {
#if TARGET_OS_IPHONE
NSString *urlString;
urlString = [NSString stringWithFormat:@"%@/%@", documentFolderPath, [path lastPathComponent]];
NSString *componentString = @"";
#if TARGET_OS_IPHONE
/* check for the end of a path only, since parts of the path components may change
* while it is still the same file
* of course, this is only true for the flat file structure we use on iOS */
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url ENDSWITH %@", [urlString lastPathComponent]]];
pathComponents = [path componentsSeparatedByString:@"/"];
componentCount = pathComponents.count;
if ([pathComponents[componentCount - 2] isEqualToString:@"Documents"])
componentString = [path 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
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url == %@", urlString]];
[fetchPredicates addObject:[NSPredicate predicateWithFormat:@"url == %@", path]];
#endif
[urlToObject setObject:path forKey:urlString];
}
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