ソースを参照

【fix】【注释】工具栏 - 图片注释,选择损坏的图片,必现崩溃

tangchao 5 ヶ月 前
コミット
79a3ce25e7

+ 15 - 2
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -3234,8 +3234,20 @@ extension KMMainViewController {
                     }
                 }
                 
-                let image = NSImage(contentsOfFile: url.path)
-                let isDamageImage: Bool = self.isDamageImage(image!, imagePath: url.path)
+                guard let image = NSImage(contentsOfFile: url.path) else {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), url.lastPathComponent)
+                    alert.informativeText = NSLocalizedString("It may be damaged or use a file format that PDF Reader Pro doesn’t recognize.", comment: "")
+                    alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
+                    alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
+                        if response == .alertFirstButtonReturn {
+                            // Handle cancel button clicked
+                        }
+                    }
+                    return
+                }
+                let isDamageImage: Bool = self.isDamageImage(image, imagePath: url.path)
                 if isDamageImage {
                     let alert = NSAlert()
                     alert.alertStyle = .critical
@@ -3247,6 +3259,7 @@ extension KMMainViewController {
                             // Handle cancel button clicked
                         }
                     }
+                    return
                 }
                 let isRemoveBGColor = accessoryCtr.selectedButton.state == .on
                 listView.addAnnotation(with: image, isRemoveBGColor: isRemoveBGColor)