Commit f071e83d authored by Carola Nitz's avatar Carola Nitz Committed by Felix Paul Kühne

migration code for new coredata model

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent f81f86f9
......@@ -27,6 +27,7 @@
#import "UINavigationController+Theme.h"
#import "VLCHTTPUploaderController.h"
#import "VLCMenuTableViewController.h"
#import "VLCMigrationViewController.h"
#import "BWQuincyManager.h"
#import "VLCAlertView.h"
#import <BoxSDK/BoxSDK.h>
......@@ -39,6 +40,7 @@
int _networkActivityCounter;
VLCMovieViewController *_movieViewController;
BOOL _passcodeValidated;
BOOL _isRunningMigration;
}
@end
......@@ -88,33 +90,76 @@
// Init the HTTP Server
self.uploadController = [[VLCHTTPUploaderController alloc] init];
// enable crash preventer
[[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// enable crash preventer
void (^setupBlock)() = ^ {
[[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
_playlistViewController = [[VLCPlaylistViewController alloc] init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_playlistViewController];
[navCon loadTheme];
_revealController = [[GHRevealViewController alloc] initWithNibName:nil bundle:nil];
_revealController.wantsFullScreenLayout = YES;
_menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
_revealController.sidebarViewController = _menuViewController;
_revealController.contentViewController = navCon;
self.window.rootViewController = self.revealController;
// necessary to avoid navbar blinking in VLCOpenNetworkStreamViewController & VLCDownloadViewController
_revealController.contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
[self.window makeKeyAndVisible];
VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
[discoverer addObserver:self];
[discoverer startDiscovering:[self directoryPath]];
[self validatePasscode];
};
NSError *error = nil;
if ([self migrationNeeded:&error]){
_isRunningMigration = YES;
VLCMigrationViewController *migrationController = [[VLCMigrationViewController alloc] initWithNibName:@"VLCMigrationViewController" bundle:nil];
migrationController.completionHandler = ^{
//migrate
setupBlock();
_isRunningMigration = NO;
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
[self updateMediaList];
};
_playlistViewController = [[VLCPlaylistViewController alloc] init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:_playlistViewController];
[navCon loadTheme];
self.window.rootViewController = migrationController;
[self.window makeKeyAndVisible];
_revealController = [[GHRevealViewController alloc] initWithNibName:nil bundle:nil];
_revealController.wantsFullScreenLayout = YES;
_menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
_revealController.sidebarViewController = _menuViewController;
_revealController.contentViewController = navCon;
} else {
if (error != nil) {
NSLog(@"removed persistentStore since it was corrupt");
NSURL *storeURL = ((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL;
[[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
}
setupBlock();
}
return YES;
}
self.window.rootViewController = self.revealController;
// necessary to avoid navbar blinking in VLCOpenNetworkStreamViewController & VLCDownloadViewController
_revealController.contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
[self.window makeKeyAndVisible];
- (BOOL)migrationNeeded:(NSError **) migrationCheckError {
VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
[discoverer addObserver:self];
[discoverer startDiscovering:[self directoryPath]];
BOOL migrationNeeded = NO;
[self validatePasscode];
if ([[NSFileManager defaultManager] fileExistsAtPath:((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL.path]) {
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType
URL:((MLMediaLibrary *)[MLMediaLibrary sharedMediaLibrary]).persistentStoreURL
error:migrationCheckError];
if (*migrationCheckError) {
return NO;
}
NSManagedObjectModel *destinationModel = [[MLMediaLibrary sharedMediaLibrary] managedObjectModel];
migrationNeeded = ![destinationModel isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
}
return YES;
return migrationNeeded;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
......@@ -220,8 +265,10 @@
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
[self updateMediaList];
if (!_isRunningMigration) {
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
[self updateMediaList];
}
}
- (void)applicationWillTerminate:(UIApplication *)application
......
//
// VLCMigrationViewController.h
// VLC for iOS
//
// Created by Carola Nitz on 17/02/15.
// Copyright (c) 2015 VideoLAN. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface VLCMigrationViewController : UIViewController
@property(nonatomic) IBOutlet UILabel *statusLabel;
@property(nonatomic) IBOutlet UIActivityIndicatorView *spinner;
@property(nonatomic, copy) void (^completionHandler)();
@end
//
// VLCMigrationViewController.m
// VLC for iOS
//
// Created by Carola Nitz on 17/02/15.
// Copyright (c) 2015 VideoLAN. All rights reserved.
//
#import "VLCMigrationViewController.h"
@implementation VLCMigrationViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
}
return self;
}
- (void)viewDidLoad {
[self.statusLabel setText:NSLocalizedString(@"UPGRADING_LIBRARY", "")];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"migrating coredata");
[[MLMediaLibrary sharedMediaLibrary] persistentStoreCoordinator];
dispatch_async(dispatch_get_main_queue(), ^{
self.completionHandler();
});
});
}
@end
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6750" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6735"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCMigrationViewController">
<connections>
<outlet property="spinner" destination="fpv-c5-Rki" id="DTQ-qu-gs5"/>
<outlet property="statusLabel" destination="136-Pe-Q8J" id="P9t-YV-OZB"/>
<outlet property="view" destination="iN0-l3-epB" id="B77-0U-NV6"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="white" translatesAutoresizingMaskIntoConstraints="NO" id="fpv-c5-Rki">
<rect key="frame" x="290" y="290" width="20" height="20"/>
</activityIndicatorView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="136-Pe-Q8J" userLabel="statusLabel">
<rect key="frame" x="0.0" y="320" width="600" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.92549019610000005" green="0.43529411759999997" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.12156862745098039" green="0.12156862745098039" blue="0.12156862745098039" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="fpv-c5-Rki" secondAttribute="centerX" id="CTX-3y-XxT"/>
<constraint firstAttribute="trailing" secondItem="136-Pe-Q8J" secondAttribute="trailing" id="Lnd-xE-pw0"/>
<constraint firstAttribute="centerY" secondItem="fpv-c5-Rki" secondAttribute="centerY" id="VrE-Yq-Dbc"/>
<constraint firstItem="136-Pe-Q8J" firstAttribute="top" secondItem="fpv-c5-Rki" secondAttribute="bottom" constant="10" id="cgf-EH-VnL"/>
<constraint firstItem="136-Pe-Q8J" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="naH-BA-sxq"/>
</constraints>
</view>
</objects>
</document>
......@@ -51,6 +51,8 @@
4115E5FF197977850071C4B9 /* tableViewIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4115E5FD197977850071C4B9 /* tableViewIcon@2x.png */; };
4115E60219797B660071C4B9 /* collectionViewIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4115E60019797B660071C4B9 /* collectionViewIcon.png */; };
4115E60319797B660071C4B9 /* collectionViewIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4115E60119797B660071C4B9 /* collectionViewIcon@2x.png */; };
41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */; };
41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */; };
4144C4661A0ED6C700918C89 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784E6183A99E1009EE944 /* Reachability.m */; };
4171D35018A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 4171D34F18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m */; };
4171D35818A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 4171D35718A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.m */; };
......@@ -580,6 +582,9 @@
4115E5FD197977850071C4B9 /* tableViewIcon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tableViewIcon@2x.png"; sourceTree = "<group>"; };
4115E60019797B660071C4B9 /* collectionViewIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = collectionViewIcon.png; sourceTree = "<group>"; };
4115E60119797B660071C4B9 /* collectionViewIcon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "collectionViewIcon@2x.png"; sourceTree = "<group>"; };
41273A391A955C4100A2EF77 /* VLCMigrationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCMigrationViewController.h; path = Sources/VLCMigrationViewController.h; sourceTree = SOURCE_ROOT; };
41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCMigrationViewController.m; path = Sources/VLCMigrationViewController.m; sourceTree = SOURCE_ROOT; };
41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCMigrationViewController.xib; path = Sources/VLCMigrationViewController.xib; sourceTree = SOURCE_ROOT; };
4171D34E18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCFolderCollectionViewFlowLayout.h; path = Sources/VLCFolderCollectionViewFlowLayout.h; sourceTree = SOURCE_ROOT; };
4171D34F18A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCFolderCollectionViewFlowLayout.m; path = Sources/VLCFolderCollectionViewFlowLayout.m; sourceTree = SOURCE_ROOT; };
4171D35618A2D90200A16EF9 /* LXReorderableCollectionViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LXReorderableCollectionViewFlowLayout.h; sourceTree = "<group>"; };
......@@ -2218,6 +2223,8 @@
7D94FCE416DE7D1000F2623B /* Classes */ = {
isa = PBXGroup;
children = (
41273A391A955C4100A2EF77 /* VLCMigrationViewController.h */,
41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */,
7D6B08BB174A72A900A05173 /* VLCConstants.h */,
7DBBF180183AB3B80009A339 /* VLCAppDelegate.h */,
7DBBF181183AB3B80009A339 /* VLCAppDelegate.m */,
......@@ -2265,6 +2272,7 @@
7DADC55C1704FAA8001DAC63 /* XIBs */ = {
isa = PBXGroup;
children = (
41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */,
7DC19AF41868CDB800810BF7 /* First Steps */,
7D6BEF1D19E027A100DF3972 /* Cloud */,
7D6BEF1F19E027DA00DF3972 /* Download & Network */,
......@@ -2949,6 +2957,7 @@
7D47D70F1760CD8700E86BAD /* ratioButtonHighlight.png in Resources */,
7D47D7101760CD8700E86BAD /* ratioButtonHighlight@2x.png in Resources */,
260B41DE1A75006300DA89C9 /* OneDrive@3x.png in Resources */,
41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */,
7D9870561A3DEE4B009CF27D /* download@3x.png in Resources */,
7D27EC1A19DF30CB00EF0370 /* sidebar-cutout.png in Resources */,
7D47D7151760CD8700E86BAD /* knobSlider.png in Resources */,
......@@ -3274,6 +3283,7 @@
7D3784E9183A9A15009EE944 /* main.m in Sources */,
7D30F3C2183AB24C00FFC021 /* VLCHTTPConnection.m in Sources */,
7D30F3C3183AB24C00FFC021 /* VLCHTTPFileDownloader.m in Sources */,
41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */,
7D30F3C4183AB24C00FFC021 /* VLCHTTPUploaderController.m in Sources */,
7D30F3C7183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m in Sources */,
7D5CAA8C1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m in Sources */,
......
......@@ -13,7 +13,7 @@ NONETWORK=no
SKIPLIBVLCCOMPILATION=no
TESTEDVLCKITHASH=754265a32
TESTEDMEDIALIBRARYKITHASH=a229be5b8f
TESTEDMEDIALIBRARYKITHASH=012364f6c9133
usage()
{
......
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