Browse Source

migrate library to the shared group container

Tobias Conradi 10 years ago
parent
commit
1381492ce0
1 changed files with 21 additions and 0 deletions
  1. 21 0
      Sources/VLCAppDelegate.m

+ 21 - 0
Sources/VLCAppDelegate.m

@@ -118,6 +118,7 @@
     };
 
     NSError *error = nil;
+    [self pathMigrationToGroupsIfNeeded:&error];
     if ([self migrationNeeded:&error]){
         _isRunningMigration = YES;
 
@@ -144,6 +145,26 @@
     return YES;
 }
 
+- (void)pathMigrationToGroupsIfNeeded:(NSError **)migrationError
+{
+    MLMediaLibrary *mediaLibrary = [MLMediaLibrary sharedMediaLibrary];
+    NSURL *groupURL = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.org.videolan.vlc-ios"];
+
+    NSString *oldBasePath = [mediaLibrary libraryBasePath];
+    NSString *oldPersistentStorePath = [oldBasePath stringByAppendingPathComponent: @"MediaLibrary.sqlite"];
+
+    NSError *error = nil;
+    if (![[NSFileManager defaultManager] fileExistsAtPath:oldPersistentStorePath]) {
+        mediaLibrary.libraryBasePath = groupURL.path;
+    } else if (![mediaLibrary migrateLibraryToBasePath:groupURL.path error:&error]) {
+        NSLog(@"Failed to migrate Library to new location with error: %@", error);
+    }
+
+    if (migrationError && error) {
+        *migrationError = error;
+    }
+}
+
 - (BOOL)migrationNeeded:(NSError **) migrationCheckError {
 
     BOOL migrationNeeded = NO;