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:
79
AltBackup/BackupController.swift
Normal file → Executable file
79
AltBackup/BackupController.swift
Normal file → Executable file
@@ -26,37 +26,65 @@ extension Error
|
|||||||
|
|
||||||
struct BackupError: ALTLocalizedError
|
struct BackupError: ALTLocalizedError
|
||||||
{
|
{
|
||||||
enum Code
|
enum Code: ALTErrorEnum, RawRepresentable
|
||||||
{
|
{
|
||||||
case invalidBundleID
|
case invalidBundleID
|
||||||
case appGroupNotFound(String?)
|
case appGroupNotFound(String?)
|
||||||
case randomError // Used for debugging.
|
case randomError // Used for debugging.
|
||||||
}
|
|
||||||
|
// Provide failure reason for each error code
|
||||||
let code: Code
|
var errorFailureReason: String {
|
||||||
|
switch self {
|
||||||
let sourceFile: String
|
case .invalidBundleID:
|
||||||
let sourceFileLine: Int
|
return NSLocalizedString("The bundle identifier is invalid.", comment: "")
|
||||||
|
case .appGroupNotFound(let appGroup):
|
||||||
var failure: String?
|
if let appGroup = appGroup {
|
||||||
|
return String(format: NSLocalizedString("The app group “%@” could not be found.", comment: ""), appGroup)
|
||||||
var failureReason: String? {
|
} else {
|
||||||
switch self.code
|
return NSLocalizedString("The AltStore app group could not be found.", comment: "")
|
||||||
{
|
}
|
||||||
case .invalidBundleID: return NSLocalizedString("The bundle identifier is invalid.", comment: "")
|
case .randomError:
|
||||||
case .appGroupNotFound(let appGroup):
|
return NSLocalizedString("A random error occurred.", comment: "")
|
||||||
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: "")
|
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
|
||||||
}
|
}
|
||||||
case .randomError: return NSLocalizedString("A random error occured.", comment: "")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let code: Code
|
||||||
|
let sourceFile: String
|
||||||
|
let sourceFileLine: Int
|
||||||
|
var failure: String?
|
||||||
|
|
||||||
|
var errorTitle: String?
|
||||||
|
var errorFailure: String?
|
||||||
|
|
||||||
|
var failureReason: String? {
|
||||||
|
return self.code.errorFailureReason
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conforming to the userInfo required by ALTLocalizedError
|
||||||
var errorUserInfo: [String : Any] {
|
var errorUserInfo: [String : Any] {
|
||||||
let userInfo: [String: Any?] = [NSLocalizedDescriptionKey: self.errorDescription,
|
let userInfo: [String: Any?] = [NSLocalizedDescriptionKey: self.errorDescription,
|
||||||
NSLocalizedFailureReasonErrorKey: self.failureReason,
|
NSLocalizedFailureReasonErrorKey: self.failureReason,
|
||||||
@@ -65,6 +93,11 @@ struct BackupError: ALTLocalizedError
|
|||||||
ErrorUserInfoKey.sourceFileLine: self.sourceFileLine]
|
ErrorUserInfoKey.sourceFileLine: self.sourceFileLine]
|
||||||
return userInfo.compactMapValues { $0 }
|
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)
|
init(_ code: Code, description: String? = nil, file: String = #file, line: Int = #line)
|
||||||
{
|
{
|
||||||
@@ -72,6 +105,8 @@ struct BackupError: ALTLocalizedError
|
|||||||
self.failure = description
|
self.failure = description
|
||||||
self.sourceFile = file
|
self.sourceFile = file
|
||||||
self.sourceFileLine = line
|
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 errorCode: Int { self.code.rawValue }
|
||||||
var errorDescription: String? {
|
var errorDescription: String? {
|
||||||
guard (self as NSError).localizedFailure == nil else {
|
guard (self as NSError).localizedFailureReason == nil else {
|
||||||
// Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason.
|
// Error has localizedFailureReason, so return nil to construct localizedDescription from it + localizedFailureReason.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ public extension ALTLocalizedError
|
|||||||
}
|
}
|
||||||
|
|
||||||
var description: String {
|
var description: String {
|
||||||
let description = "\(self.localizedErrorCode) “\(self.localizedDescription)”"
|
let description = "\(self.errorCode) “\(self.localizedDescription)”"
|
||||||
return description
|
return description
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user