Remove old import code.
This commit is contained in:
4 files changed
+2
-106
No files matched your search
@@ -108,72 +108,3 @@ extension UserDefaults {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Old style map, to be removed next year
|
||||
|
||||
@objc(SBMetadataResultMapItem) private class SBMetadataResultMapItem : NSObject, NSSecureCoding {
|
||||
|
||||
let key: String
|
||||
let value: [String]
|
||||
|
||||
// MARK: NSSecureCoding
|
||||
|
||||
static var supportsSecureCoding: Bool { return true }
|
||||
|
||||
func encode(with aCoder: NSCoder) {}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
guard let key = aDecoder.decodeObject(of: NSString.self, forKey: "key") as String?,
|
||||
let value = aDecoder.decodeObject(of: [NSArray.self, NSString.self], forKey: "value") as? [String]
|
||||
else { return nil }
|
||||
self.key = key
|
||||
self.value = value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@objc(SBMetadataResultMap) private class SBMetadataResultMap : NSObject, NSSecureCoding {
|
||||
|
||||
var items: [SBMetadataResultMapItem]
|
||||
let type: MetadataType
|
||||
|
||||
// MARK: NSSecureCoding
|
||||
|
||||
static var supportsSecureCoding: Bool { return true }
|
||||
|
||||
func encode(with aCoder: NSCoder) {}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
guard let items = aDecoder.decodeObject(of: [NSArray.self, SBMetadataResultMapItem.self], forKey: "items") as? [SBMetadataResultMapItem],
|
||||
let type = MetadataType(rawValue: Int(aDecoder.decodeInt32(forKey: "type")))
|
||||
else { return nil }
|
||||
self.items = items
|
||||
self.type = type
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension UserDefaults {
|
||||
|
||||
func mapFromOldStylePrefs(forKey defaultName: String) -> MetadataResultMap? {
|
||||
guard let data = self.data(forKey: defaultName) else { return nil }
|
||||
|
||||
let unarchiver = NSKeyedUnarchiver(forReadingWith: data)
|
||||
unarchiver.requiresSecureCoding = true
|
||||
|
||||
if let oldMap = unarchiver.decodeObject(of: SBMetadataResultMap.self, forKey: NSKeyedArchiveRootObjectKey) {
|
||||
|
||||
let items = oldMap.items.map { (item: SBMetadataResultMapItem) -> MetadataResultMapItem in
|
||||
let tokens = item.value.map { Token(text: $0, isPlaceholder: MetadataResult.Key(rawValue: $0) != nil)}
|
||||
return MetadataResultMapItem(key: item.key, value: tokens)
|
||||
}
|
||||
let map = MetadataResultMap(items: items, type: oldMap.type)
|
||||
|
||||
return map
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,27 +21,6 @@ class PrefsWindowController: NSWindowController, NSWindowDelegate {
|
||||
let tvShowFormat = try? encoder.encode([Token(text: "{TV Show}"), Token(text: " s", isPlaceholder: false), Token(text: "{TV Season}"), Token(text: "e", isPlaceholder: false), Token(text: "{TV Episode #}")])
|
||||
|
||||
if defaults.integer(forKey: "SBUpgradeCheck") < 1 {
|
||||
|
||||
// Migrate 1.4.8 filename format settings
|
||||
let oldMovieFormat = defaults.tokenArrayFromOldStylePrefs(forKey: "SBMovieFormat")
|
||||
if oldMovieFormat.isEmpty == false {
|
||||
defaults.set(oldMovieFormat, forKey: "SBMovieFormatTokens")
|
||||
}
|
||||
|
||||
let oldTvShowFormat = defaults.tokenArrayFromOldStylePrefs(forKey: "SBTVShowFormat")
|
||||
if oldTvShowFormat.isEmpty == false {
|
||||
defaults.set(oldTvShowFormat, forKey: "SBTVShowFormatTokens")
|
||||
}
|
||||
|
||||
// Migrate 1.4.8 metadata map settings
|
||||
if let oldStyleMovieResultMap = defaults.mapFromOldStylePrefs(forKey: "SBMetadataMovieResultMap") {
|
||||
defaults.set(oldStyleMovieResultMap, forKey: "SBMetadataMovieResultMap2")
|
||||
}
|
||||
|
||||
if let oldStyleTvShowResultMap = defaults.mapFromOldStylePrefs(forKey: "SBMetadataTvShowResultMap") {
|
||||
defaults.set(oldStyleTvShowResultMap, forKey: "SBMetadataTvShowResultMap2")
|
||||
}
|
||||
|
||||
defaults.set(1, forKey: "SBUpgradeCheck")
|
||||
}
|
||||
|
||||
|
||||
@@ -178,8 +178,7 @@ class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate,
|
||||
do {
|
||||
try item.prepare()
|
||||
} catch {
|
||||
//FIXME
|
||||
print(error)
|
||||
self.presentError(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,8 +204,7 @@ class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate,
|
||||
self.updateUI()
|
||||
}
|
||||
} catch {
|
||||
//FIXME
|
||||
print(error)
|
||||
self.presentError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,16 +227,4 @@ extension UserDefaults {
|
||||
self.set(jsonData, forKey: defaultName)
|
||||
}
|
||||
|
||||
func tokenArrayFromOldStylePrefs(forKey defaultName: String) -> [Token] {
|
||||
guard let strings = UserDefaults.standard.stringArray(forKey: defaultName) else { return [] }
|
||||
var tokens: [Token] = Array()
|
||||
|
||||
for string in strings {
|
||||
let token = Token(text: string, isPlaceholder: string.hasPrefix("{") && string.hasSuffix("}"))
|
||||
tokens.append(token)
|
||||
}
|
||||
|
||||
return tokens
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user