Allows explicitly downloading corrupted record versions from RecordVersionsViewController
This commit is contained in:
parent
be047b28a6
commit
061f5abd3e
@ -23,6 +23,12 @@ public class GameSave: _GameSave
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension GameSave
|
||||||
|
{
|
||||||
|
// Hacky, but YOLO I'm under time crunch.
|
||||||
|
public static var ignoredCorruptedIDs = Set<String>()
|
||||||
|
}
|
||||||
|
|
||||||
extension GameSave: Syncable
|
extension GameSave: Syncable
|
||||||
{
|
{
|
||||||
public static var syncablePrimaryKey: AnyKeyPath {
|
public static var syncablePrimaryKey: AnyKeyPath {
|
||||||
@ -70,6 +76,8 @@ extension GameSave: Syncable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func awakeFromSync(_ record: AnyRecord) throws
|
public func awakeFromSync(_ record: AnyRecord) throws
|
||||||
|
{
|
||||||
|
do
|
||||||
{
|
{
|
||||||
guard let game = self.game else { throw SyncValidationError.incorrectGame(nil) }
|
guard let game = self.game else { throw SyncValidationError.incorrectGame(nil) }
|
||||||
|
|
||||||
@ -94,4 +102,21 @@ extension GameSave: Syncable
|
|||||||
throw SyncValidationError.incorrectGame(game.name)
|
throw SyncValidationError.incorrectGame(game.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch let error as SyncValidationError
|
||||||
|
{
|
||||||
|
guard GameSave.ignoredCorruptedIDs.contains(self.identifier) else { throw error }
|
||||||
|
|
||||||
|
let fetchRequest = Game.fetchRequest()
|
||||||
|
fetchRequest.predicate = NSPredicate(format: "%K == %@", #keyPath(Game.identifier), self.identifier)
|
||||||
|
|
||||||
|
if let correctGame = try self.managedObjectContext?.fetch(fetchRequest).first
|
||||||
|
{
|
||||||
|
self.game = correctGame
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw ValidationError.nilRelationshipObjects(keys: [#keyPath(GameSave.game)])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -258,6 +258,8 @@ private extension RecordVersionsViewController
|
|||||||
{
|
{
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
|
GameSave.ignoredCorruptedIDs.remove(self.record.recordID.identifier)
|
||||||
|
|
||||||
CATransaction.begin()
|
CATransaction.begin()
|
||||||
|
|
||||||
CATransaction.setCompletionBlock {
|
CATransaction.setCompletionBlock {
|
||||||
@ -287,6 +289,22 @@ private extension RecordVersionsViewController
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
switch error
|
||||||
|
{
|
||||||
|
case RecordError.other(let record, let error as SyncValidationError):
|
||||||
|
// Only allow restoring corrupted records with incorrect games.
|
||||||
|
guard case .incorrectGame = error else { fallthrough }
|
||||||
|
|
||||||
|
let message = NSLocalizedString("Would you like to download this version anyway?", comment: "")
|
||||||
|
let alertController = UIAlertController(title: NSLocalizedString("Record Version Corrupted", comment: ""), message: message, preferredStyle: .alert)
|
||||||
|
alertController.addAction(.cancel)
|
||||||
|
alertController.addAction(UIAlertAction(title: NSLocalizedString("Download Anyway", comment: ""), style: .destructive) { _ in
|
||||||
|
GameSave.ignoredCorruptedIDs.insert(record.recordID.identifier)
|
||||||
|
self.restoreVersion()
|
||||||
|
})
|
||||||
|
self.present(alertController, animated: true, completion: nil)
|
||||||
|
|
||||||
|
default:
|
||||||
let title: String
|
let title: String
|
||||||
|
|
||||||
switch self.mode
|
switch self.mode
|
||||||
@ -299,6 +317,7 @@ private extension RecordVersionsViewController
|
|||||||
alertController.addAction(.ok)
|
alertController.addAction(.ok)
|
||||||
self.present(alertController, animated: true, completion: nil)
|
self.present(alertController, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CATransaction.commit()
|
CATransaction.commit()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user