mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-08 22:33:26 +01:00
[AltBackup]: Fixes for swift compile errors
This commit is contained in:
69
AltBackup/BackupController.swift
Normal file → Executable file
69
AltBackup/BackupController.swift
Normal file → Executable file
@@ -26,37 +26,65 @@ extension Error
|
||||
|
||||
struct BackupError: ALTLocalizedError
|
||||
{
|
||||
enum Code
|
||||
enum Code: ALTErrorEnum, RawRepresentable
|
||||
{
|
||||
case invalidBundleID
|
||||
case appGroupNotFound(String?)
|
||||
case randomError // Used for debugging.
|
||||
|
||||
// Provide failure reason for each error code
|
||||
var errorFailureReason: String {
|
||||
switch self {
|
||||
case .invalidBundleID:
|
||||
return NSLocalizedString("The bundle identifier is invalid.", comment: "")
|
||||
case .appGroupNotFound(let appGroup):
|
||||
if let appGroup = appGroup {
|
||||
return String(format: NSLocalizedString("The app group “%@” could not be found.", comment: ""), appGroup)
|
||||
} else {
|
||||
return NSLocalizedString("The AltStore app group could not be found.", comment: "")
|
||||
}
|
||||
case .randomError:
|
||||
return NSLocalizedString("A random error occurred.", comment: "")
|
||||
}
|
||||
}
|
||||
|
||||
static var errorDomain: String {
|
||||
return "com.sidestore.BackupError"
|
||||
}
|
||||
|
||||
// Add a raw value for RawRepresentable conformance
|
||||
var rawValue: Int {
|
||||
switch self {
|
||||
case .invalidBundleID: return 0
|
||||
case .appGroupNotFound: return 1
|
||||
case .randomError: return 2
|
||||
}
|
||||
}
|
||||
|
||||
// Initializer for RawRepresentable
|
||||
init?(rawValue: Int) {
|
||||
switch rawValue {
|
||||
case 0: self = .invalidBundleID
|
||||
case 1: self = .appGroupNotFound(nil)
|
||||
case 2: self = .randomError
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let code: Code
|
||||
|
||||
let sourceFile: String
|
||||
let sourceFileLine: Int
|
||||
|
||||
var failure: String?
|
||||
|
||||
var errorTitle: String?
|
||||
var errorFailure: String?
|
||||
|
||||
var failureReason: String? {
|
||||
switch self.code
|
||||
{
|
||||
case .invalidBundleID: return NSLocalizedString("The bundle identifier is invalid.", comment: "")
|
||||
case .appGroupNotFound(let appGroup):
|
||||
if let appGroup = appGroup
|
||||
{
|
||||
return String(format: NSLocalizedString("The app group “%@” could not be found.", comment: ""), appGroup)
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSLocalizedString("The AltStore app group could not be found.", comment: "")
|
||||
}
|
||||
case .randomError: return NSLocalizedString("A random error occured.", comment: "")
|
||||
}
|
||||
return self.code.errorFailureReason
|
||||
}
|
||||
|
||||
// Conforming to the userInfo required by ALTLocalizedError
|
||||
var errorUserInfo: [String : Any] {
|
||||
let userInfo: [String: Any?] = [NSLocalizedDescriptionKey: self.errorDescription,
|
||||
NSLocalizedFailureReasonErrorKey: self.failureReason,
|
||||
@@ -66,12 +94,19 @@ struct BackupError: ALTLocalizedError
|
||||
return userInfo.compactMapValues { $0 }
|
||||
}
|
||||
|
||||
// Implement description for CustomStringConvertible
|
||||
var description: String {
|
||||
return "\(errorTitle ?? "Unknown Error"): \(failureReason ?? "No reason available")"
|
||||
}
|
||||
|
||||
init(_ code: Code, description: String? = nil, file: String = #file, line: Int = #line)
|
||||
{
|
||||
self.code = code
|
||||
self.failure = description
|
||||
self.sourceFile = file
|
||||
self.sourceFileLine = line
|
||||
self.errorTitle = NSLocalizedString("Backup Error", comment: "")
|
||||
self.errorFailure = description
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
Shared/Errors/ALTLocalizedError.swift
Normal file → Executable file
6
Shared/Errors/ALTLocalizedError.swift
Normal file → Executable file
@@ -58,8 +58,8 @@ public extension ALTLocalizedError
|
||||
{
|
||||
var errorCode: Int { self.code.rawValue }
|
||||
var errorDescription: String? {
|
||||
guard (self as NSError).localizedFailure == nil else {
|
||||
// Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason.
|
||||
guard (self as NSError).localizedFailureReason == nil else {
|
||||
// Error has localizedFailureReason, so return nil to construct localizedDescription from it + localizedFailureReason.
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public extension ALTLocalizedError
|
||||
}
|
||||
|
||||
var description: String {
|
||||
let description = "\(self.localizedErrorCode) “\(self.localizedDescription)”"
|
||||
let description = "\(self.errorCode) “\(self.localizedDescription)”"
|
||||
return description
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user