GBA002/Delta/Extensions/UIAlertController+Importing.swift
Riley Testut 93493534e0 Adds support for GBC games
Adds System enum to represent supported game systems, simplifying the process to add future game systems.
2017-04-30 21:39:13 -07:00

82 lines
2.6 KiB
Swift

//
// UIAlertController+Importing.swift
// Delta
//
// Created by Riley Testut on 1/13/17.
// Copyright © 2017 Riley Testut. All rights reserved.
//
import UIKit
import Roxas
extension UIAlertController
{
enum ImportType
{
case games
case controllerSkins
}
class func alertController(for importType: ImportType, with errors: Set<DatabaseManager.ImportError>) -> UIAlertController
{
let title: String
switch importType
{
case .games: title = NSLocalizedString("Error Importing Games", comment: "")
case .controllerSkins: title = NSLocalizedString("Error Importing Controller Skins", comment: "")
}
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .alert)
var urls = Set<URL>()
for error in errors
{
switch error
{
case .doesNotExist(let url): urls.insert(url)
case .invalid(let url): urls.insert(url)
case .unsupported(let url): urls.insert(url)
case .unknown(let url, _): urls.insert(url)
case .saveFailed(let errorURLs, _): urls.formUnion(errorURLs)
}
}
let filenames = urls.map{ $0.lastPathComponent }.sorted()
if filenames.count > 0
{
var message: String
switch importType
{
case .games: message = NSLocalizedString("The following game files could not be imported:", comment: "") + "\n"
case .controllerSkins: message = NSLocalizedString("The following controller skin files could not be imported:", comment: "") + "\n"
}
for filename in filenames
{
message += "\n" + filename
}
alertController.message = message
}
else
{
// This branch can be executed when there are no input URLs when importing, but there is an error saving the database anyway.
switch importType
{
case .games: alertController.message = NSLocalizedString("Delta was unable to import games. Please try again later.", comment: "")
case .controllerSkins: alertController.message = NSLocalizedString("Delta was unable to import controller skins. Please try again later.", comment: "")
}
}
alertController.addAction(UIAlertAction(title: RSTSystemLocalizedString("OK"), style: .cancel, handler: nil))
return alertController
}
}