From 9bebfd6415dbbcbcb7176620b38ff3ab2b310dd2 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 25 Mar 2019 16:15:04 -0700 Subject: [PATCH] Resets previous Harmony beta database upon first launch --- Delta.xcodeproj/project.pbxproj | 15 ++++ .../Harmony.xcdatamodel/contents | 83 +++++++++++++++++++ Delta/Syncing/SyncManager.swift | 30 +++++++ 3 files changed, 128 insertions(+) create mode 100644 Delta/Database/Model/PreviousHarmony.xcdatamodeld/Harmony.xcdatamodel/contents diff --git a/Delta.xcodeproj/project.pbxproj b/Delta.xcodeproj/project.pbxproj index 5029b42..d87910a 100644 --- a/Delta.xcodeproj/project.pbxproj +++ b/Delta.xcodeproj/project.pbxproj @@ -103,6 +103,7 @@ BF6BF3271EB87EB8008E83CD /* PhotoLibraryImportOption.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6BF3261EB87EB8008E83CD /* PhotoLibraryImportOption.swift */; }; BF6EE5E91F7C5F860051AD6C /* _GameControllerInputMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6EE5E81F7C5F860051AD6C /* _GameControllerInputMapping.swift */; }; BF6EE5EB1F7C5F8F0051AD6C /* GameControllerInputMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF6EE5EA1F7C5F8F0051AD6C /* GameControllerInputMapping.swift */; }; + BF713C0822499ED4004A1A2B /* PreviousHarmony.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = BF713C0622499ED3004A1A2B /* PreviousHarmony.xcdatamodeld */; }; BF71CF871FE90006001F1613 /* AppIconShortcutsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF71CF861FE90006001F1613 /* AppIconShortcutsViewController.swift */; }; BF71CF8A1FE904B1001F1613 /* GameTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BF71CF891FE904B1001F1613 /* GameTableViewCell.xib */; }; BF797A2D1C2D339F00F1A000 /* UILabel+FontSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF797A2C1C2D339F00F1A000 /* UILabel+FontSize.swift */; }; @@ -277,6 +278,7 @@ BF6EE5E81F7C5F860051AD6C /* _GameControllerInputMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _GameControllerInputMapping.swift; sourceTree = ""; }; BF6EE5EA1F7C5F8F0051AD6C /* GameControllerInputMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameControllerInputMapping.swift; sourceTree = ""; }; BF70798B1B6B464B0019077C /* ZipZap.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ZipZap.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + BF713C0722499ED3004A1A2B /* Harmony.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Harmony.xcdatamodel; sourceTree = ""; }; BF71CF861FE90006001F1613 /* AppIconShortcutsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconShortcutsViewController.swift; sourceTree = ""; }; BF71CF891FE904B1001F1613 /* GameTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = GameTableViewCell.xib; sourceTree = ""; }; BF797A2C1C2D339F00F1A000 /* UILabel+FontSize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UILabel+FontSize.swift"; sourceTree = ""; }; @@ -485,6 +487,7 @@ BF5942711E09BC690051894B /* Model */ = { isa = PBXGroup; children = ( + BF713C0622499ED3004A1A2B /* PreviousHarmony.xcdatamodeld */, BF4828811F9027B600028B97 /* Delta.xcdatamodeld */, BF5942741E09BC740051894B /* Human */, BF5942751E09BC780051894B /* Machine */, @@ -877,6 +880,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -1069,6 +1073,7 @@ BF4828861F9028F500028B97 /* System.swift in Sources */, BF13A7561D5D29B0000BB055 /* PreviewGameViewController.swift in Sources */, BF6866171DCAC8B900BF2D06 /* ControllerSkin+Configuring.swift in Sources */, + BF713C0822499ED4004A1A2B /* PreviousHarmony.xcdatamodeld in Sources */, BF59427D1E09BC830051894B /* ControllerSkin.swift in Sources */, BFAB9F7D219A43380080EC7D /* SyncManager.swift in Sources */, BFCEA67E1D56FF640061A534 /* UIViewControllerContextTransitioning+Conveniences.swift in Sources */, @@ -1350,6 +1355,16 @@ sourceTree = ""; versionGroupType = wrapper.xcdatamodel; }; + BF713C0622499ED3004A1A2B /* PreviousHarmony.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + BF713C0722499ED3004A1A2B /* Harmony.xcdatamodel */, + ); + currentVersion = BF713C0722499ED3004A1A2B /* Harmony.xcdatamodel */; + path = PreviousHarmony.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; /* End XCVersionGroup section */ }; rootObject = BFFA71CF1AAC406100EE9DD1 /* Project object */; diff --git a/Delta/Database/Model/PreviousHarmony.xcdatamodeld/Harmony.xcdatamodel/contents b/Delta/Database/Model/PreviousHarmony.xcdatamodeld/Harmony.xcdatamodel/contents new file mode 100644 index 0000000..6b33e61 --- /dev/null +++ b/Delta/Database/Model/PreviousHarmony.xcdatamodeld/Harmony.xcdatamodel/contents @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Delta/Syncing/SyncManager.swift b/Delta/Syncing/SyncManager.swift index cf527ed..dd461c6 100644 --- a/Delta/Syncing/SyncManager.swift +++ b/Delta/Syncing/SyncManager.swift @@ -10,6 +10,11 @@ import Harmony import Harmony_Drive import Harmony_Dropbox +private extension UserDefaults +{ + @NSManaged var didValidateHarmonyBetaDatabase: Bool +} + extension SyncManager { enum RecordType: String, Hashable @@ -118,6 +123,31 @@ extension SyncManager guard let service = service else { return completionHandler(.success) } let coordinator = SyncCoordinator(service: service.service, persistentContainer: DatabaseManager.shared) + + if !UserDefaults.standard.didValidateHarmonyBetaDatabase + { + UserDefaults.standard.didValidateHarmonyBetaDatabase = true + + coordinator.deauthenticate { (result) in + do + { + try FileManager.default.removeItem(at: RecordController.defaultDirectoryURL()) + } + catch CocoaError.fileNoSuchFile + { + // Ignore + } + catch + { + print("Failed to remove Harmony database.", error) + } + + self.start(service: service, completionHandler: completionHandler) + } + + return + } + coordinator.start { (result) in do {