[Sandbox] Automatically save folder bookmarks
Signed-off-by: Christopher Snowhill <kode54@gmail.com>lastfm
parent
6f126f4857
commit
f5bde75eda
|
@ -39,6 +39,8 @@
|
||||||
|
|
||||||
#import "RedundantPlaylistDataStore.h"
|
#import "RedundantPlaylistDataStore.h"
|
||||||
|
|
||||||
|
#import "SandboxBroker.h"
|
||||||
|
|
||||||
@import Firebase;
|
@import Firebase;
|
||||||
|
|
||||||
extern NSMutableDictionary<NSString *, AlbumArtwork *> *kArtworkDictionary;
|
extern NSMutableDictionary<NSString *, AlbumArtwork *> *kArtworkDictionary;
|
||||||
|
@ -394,6 +396,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
||||||
if([[NSFileManager defaultManager] fileExistsAtPath:[url path] isDirectory:&isDir]) {
|
if([[NSFileManager defaultManager] fileExistsAtPath:[url path] isDirectory:&isDir]) {
|
||||||
if(isDir == YES) {
|
if(isDir == YES) {
|
||||||
// Get subpaths
|
// Get subpaths
|
||||||
|
[[SandboxBroker sharedSandboxBroker] addFolderIfMissing:url];
|
||||||
[expandedURLs addObjectsFromArray:[self fileURLsAtPath:[url path]]];
|
[expandedURLs addObjectsFromArray:[self fileURLsAtPath:[url path]]];
|
||||||
} else {
|
} else {
|
||||||
[expandedURLs addObject:[NSURL fileURLWithPath:[url path]]];
|
[expandedURLs addObject:[NSURL fileURLWithPath:[url path]]];
|
||||||
|
|
|
@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
- (id)init;
|
- (id)init;
|
||||||
- (void)shutdown;
|
- (void)shutdown;
|
||||||
|
|
||||||
|
- (void)addFolderIfMissing:(NSURL *)folderUrl;
|
||||||
|
|
||||||
- (const void *)beginFolderAccess:(NSURL *)fileUrl;
|
- (const void *)beginFolderAccess:(NSURL *)fileUrl;
|
||||||
- (void)endFolderAccess:(const void *)handle;
|
- (void)endFolderAccess:(const void *)handle;
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,47 @@ static SandboxBroker *kSharedSandboxBroker = nil;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)addFolderIfMissing:(NSURL *)folderUrl {
|
||||||
|
if(![folderUrl isFileURL]) return;
|
||||||
|
|
||||||
|
@synchronized (self) {
|
||||||
|
SandboxEntry *_entry = nil;
|
||||||
|
|
||||||
|
for(SandboxEntry *entry in storage) {
|
||||||
|
if(entry.path && [SandboxBroker isPath:folderUrl aSubdirectoryOf:[NSURL fileURLWithPath:entry.path]]) {
|
||||||
|
_entry = entry;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_entry) {
|
||||||
|
_entry = [self recursivePathTest:folderUrl];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!_entry) {
|
||||||
|
NSError *err = nil;
|
||||||
|
NSData *bookmark = [folderUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&err];
|
||||||
|
if(!bookmark && err) {
|
||||||
|
ALog(@"Failed to add bookmark for URL: %@, with error: %@", folderUrl, [err localizedDescription]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSPersistentContainer *pc = [NSClassFromString(@"PlaylistController") sharedPersistentContainer];
|
||||||
|
|
||||||
|
SandboxToken *token = [NSEntityDescription insertNewObjectForEntityForName:@"SandboxToken" inManagedObjectContext:pc.viewContext];
|
||||||
|
|
||||||
|
if(token) {
|
||||||
|
token.path = [folderUrl path];
|
||||||
|
token.bookmark = bookmark;
|
||||||
|
[pc.viewContext save:&err];
|
||||||
|
if(err) {
|
||||||
|
ALog(@"Error saving bookmark: %@", [err localizedDescription]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (const void *)beginFolderAccess:(NSURL *)fileUrl {
|
- (const void *)beginFolderAccess:(NSURL *)fileUrl {
|
||||||
NSURL *folderUrl = [[SandboxBroker urlWithoutFragment:fileUrl] URLByDeletingLastPathComponent];
|
NSURL *folderUrl = [[SandboxBroker urlWithoutFragment:fileUrl] URLByDeletingLastPathComponent];
|
||||||
if(![folderUrl isFileURL]) return NULL;
|
if(![folderUrl isFileURL]) return NULL;
|
||||||
|
|
Loading…
Reference in New Issue