1
Fork 0

Throw error when not a valid NSKeyedArchive

This commit is contained in:
Joshua Goins 2022-02-14 12:36:08 -04:00
parent d8c3229394
commit 0c015e2327

View file

@ -77,6 +77,28 @@ class Document: NSDocument {
var remainderWidth: Int = 0 var remainderWidth: Int = 0
var remainderHeight: Int = 0 var remainderHeight: Int = 0
struct SilicaParsingError: Error, LocalizedError {
enum Kind {
case invalid
}
let kind: Kind
let filename: URL?
public var errorDescription: String? {
switch self.kind {
case .invalid:
return filename!.lastPathComponent + " is an invalid Silica Document."
}
}
}
func throwError(_ error: SilicaParsingError.Kind) {
DispatchQueue.main.sync {
let _ = presentError(SilicaParsingError(kind: error, filename: fileURL))
}
}
override init() { override init() {
super.init() super.init()
} }
@ -448,8 +470,6 @@ class Document: NSDocument {
let array = layersClass["NS.objects"] as! NSArray let array = layersClass["NS.objects"] as! NSArray
//dump(dict, indent: 5)
for object in array { for object in array {
let layerClassID = getClassID(id: object) let layerClassID = getClassID(id: object)
let layerClass = objectsArray[layerClassID] as! NSDictionary let layerClass = objectsArray[layerClassID] as! NSDictionary
@ -464,7 +484,7 @@ class Document: NSDocument {
// double check if this archive is really correct // double check if this archive is really correct
if let value = dict["$version"] { if let value = dict["$version"] {
if (value as! Int) != NSKeyedArchiveVersion { if (value as! Int) != NSKeyedArchiveVersion {
Swift.print("This is not a valid document!") throwError(.invalid)
return return
} }
@ -481,28 +501,6 @@ class Document: NSDocument {
} }
} }
struct SilicaParsingError: Error, LocalizedError {
enum Kind {
case invalid
}
let kind: Kind
let filename: URL?
public var errorDescription: String? {
switch self.kind {
case .invalid:
return filename!.lastPathComponent + " is an invalid Silica Document."
}
}
}
func throwError(_ error: SilicaParsingError.Kind) {
DispatchQueue.main.sync {
let _ = presentError(SilicaParsingError(kind: error, filename: fileURL))
}
}
override func read(from data: Data, ofType typeName: String) throws { override func read(from data: Data, ofType typeName: String) throws {
self.data = data self.data = data