From 502a45bdd990ca0becd15bbd06863ecd1e04f356 Mon Sep 17 00:00:00 2001 From: sbarex Date: Mon, 31 May 2021 13:39:34 +0200 Subject: [PATCH] Bugfix for unhandled nil exception, and ratio. --- CHANGELOG.md | 5 +++ MediaInfo.xcodeproj/project.pbxproj | 32 ++++++++++---------- MediaInfoHelperXPC/CGMediaUtils.swift | 2 +- MediaInfoHelperXPC/info/BaseInfoItems.swift | 20 ++++++++---- MediaInfoHelperXPC/info/BaseOfficeInfo.swift | 20 +++++++----- MediaInfoHelperXPC/info/ImageInfoItem.swift | 4 ++- MediaInfoHelperXPC/info/MediaInfoItems.swift | 29 +++++++++++++----- MediaInfoHelperXPC/info/OfficeInfo.swift | 4 ++- MediaInfoHelperXPC/info/PDFInfoItem.swift | 11 ++++--- docs/appcast.xml | 14 +++++++++ 10 files changed, 96 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 078390c..e0bd47e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ======= +### 1.5.2 +- Bugfix on ratio. +- Bugfix of ffmpeg and metadata engine disabled. +- Bugfix for unhandled nil exception. + ### 1.5.1 - Bugfix on image print size. diff --git a/MediaInfo.xcodeproj/project.pbxproj b/MediaInfo.xcodeproj/project.pbxproj index 24d1741..cae17f3 100644 --- a/MediaInfo.xcodeproj/project.pbxproj +++ b/MediaInfo.xcodeproj/project.pbxproj @@ -11264,7 +11264,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -11281,7 +11281,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.MediaInfo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -11299,7 +11299,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; FRAMEWORK_SEARCH_PATHS = ( @@ -11316,7 +11316,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.MediaInfo; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -11332,7 +11332,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_ASSET_PATHS = "MediaInfo\\ Finder\\ Extension/Assets_menu.xcassets"; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; @@ -11347,7 +11347,7 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = "org.sbarex.MediaInfo.Finder-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -11364,7 +11364,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_ASSET_PATHS = "MediaInfo\\ Finder\\ Extension/Assets_menu.xcassets"; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; @@ -11379,7 +11379,7 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = "org.sbarex.MediaInfo.Finder-Extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -11439,7 +11439,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; HEADER_SEARCH_PATHS = ( @@ -11459,7 +11459,7 @@ "$(BUILT_PRODUCTS_DIR)/libwebp", "$(inherited)", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.MediaInfoHelperXPC; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -11477,7 +11477,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; HEADER_SEARCH_PATHS = ( @@ -11497,7 +11497,7 @@ "$(BUILT_PRODUCTS_DIR)/libwebp", "$(inherited)", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.MediaInfoHelperXPC; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -11514,7 +11514,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; HEADER_SEARCH_PATHS = ( @@ -11534,7 +11534,7 @@ "$(BUILT_PRODUCTS_DIR)/libwebp", "$(inherited)", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.MediaInfoSettingsXPC; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -11550,7 +11550,7 @@ CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 14; + CURRENT_PROJECT_VERSION = 15; DEVELOPMENT_TEAM = ""; ENABLE_HARDENED_RUNTIME = YES; HEADER_SEARCH_PATHS = ( @@ -11570,7 +11570,7 @@ "$(BUILT_PRODUCTS_DIR)/libwebp", "$(inherited)", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = org.sbarex.MediaInfoSettingsXPC; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/MediaInfoHelperXPC/CGMediaUtils.swift b/MediaInfoHelperXPC/CGMediaUtils.swift index 62d6896..79c0848 100644 --- a/MediaInfoHelperXPC/CGMediaUtils.swift +++ b/MediaInfoHelperXPC/CGMediaUtils.swift @@ -247,7 +247,7 @@ func getCMMediaInfo(forFile file: URL) -> MediaInfo? { engine: .coremedia ) return video - } else if let a = streams.first(where: {$0 is AudioTrackInfo }) as? AudioTrackInfo { + } else if let a = streams.first(where: {$0 is AudioTrackInfo }) as? AudioTrackInfo { let audio = AudioInfo( file: file, duration: CMTimeGetSeconds(asset.duration), start_time: -1, diff --git a/MediaInfoHelperXPC/info/BaseInfoItems.swift b/MediaInfoHelperXPC/info/BaseInfoItems.swift index 501eeb6..688c24a 100644 --- a/MediaInfoHelperXPC/info/BaseInfoItems.swift +++ b/MediaInfoHelperXPC/info/BaseInfoItems.swift @@ -375,7 +375,7 @@ protocol FileInfo: BaseInfo { func processFilePlaceholder(_ placeholder: String, settings: Settings, values: [String: Any]?, isFilled: inout Bool) -> String func encodeFileInfo(_ encoder: NSCoder) - static func decodeFileInfo(_ coder: NSCoder) -> (URL, Int64?) + static func decodeFileInfo(_ coder: NSCoder) -> (URL, Int64?)? } extension FileInfo { @@ -387,8 +387,11 @@ extension FileInfo { } } - static func decodeFileInfo(_ coder: NSCoder) -> (URL, Int64?) { - let file = URL(fileURLWithPath: coder.decodeObject(forKey: "file") as! String) + static func decodeFileInfo(_ coder: NSCoder) -> (URL, Int64?)? { + guard let u = coder.decodeObject(forKey: "file") as? String else { + return nil + } + let file = URL(fileURLWithPath: u) let fileSize = coder.decodeInt64(forKey: "fileSize") return (file, fileSize) } @@ -567,6 +570,10 @@ class DimensionalInfo: BaseInfo { let w = width / gcd let h = height / gcd + guard w <= 30 && h <= 30 else { + return nil + } + return "\(circa ? "~ " : "")\(w) : \(h)" } @@ -709,16 +716,17 @@ class DimensionalInfo: BaseInfo { } case "[[ratio]]": return format(value: [values?["width"] ?? width, values?["height"] ?? height], isFilled: &isFilled) { v, isFilled in - isFilled = true guard let dim = v as? [Int], dim.count == 2 else { isFilled = false return self.formatERR(useEmptyData: useEmptyData) } let width = dim[0] let height = dim[1] - guard let ratio = self.getRatio(approximate: !settings.isRatioPrecise) else { - return "\(width) : \(height)" + guard let ratio = Self.getRatio(width: width, height: height, approximate: !settings.isRatioPrecise) else { + isFilled = false + return "" } + isFilled = true return ratio } case "[[resolution]]": diff --git a/MediaInfoHelperXPC/info/BaseOfficeInfo.swift b/MediaInfoHelperXPC/info/BaseOfficeInfo.swift index ff82414..6df7463 100644 --- a/MediaInfoHelperXPC/info/BaseOfficeInfo.swift +++ b/MediaInfoHelperXPC/info/BaseOfficeInfo.swift @@ -47,19 +47,23 @@ class BaseOfficeInfo: BaseInfo, FileInfo { } required init?(coder: NSCoder) { - let r = Self.decodeFileInfo(coder) + guard let r = Self.decodeFileInfo(coder) else { + return nil + } self.file = r.0 self.fileSize = r.1 ?? -1 - self.creator = coder.decodeObject(forKey: "creator") as! String - self.title = coder.decodeObject(forKey: "title") as! String - self.subject = coder.decodeObject(forKey: "subject") as! String - self.description = coder.decodeObject(forKey: "description") as! String + self.creator = coder.decodeObject(forKey: "creator") as? String ?? "" + self.title = coder.decodeObject(forKey: "title") as? String ?? "" + self.subject = coder.decodeObject(forKey: "subject") as? String ?? "" + self.description = coder.decodeObject(forKey: "description") as? String ?? "" let n = coder.decodeInteger(forKey: "keywords_count") var keywords: [String] = [] for i in 0 ..< n { - keywords.append(coder.decodeObject(forKey: "keyword_\(i)") as! String) + if let k = coder.decodeObject(forKey: "keyword_\(i)") as? String { + keywords.append(k) + } } self.keywords = keywords @@ -74,9 +78,9 @@ class BaseOfficeInfo: BaseInfo, FileInfo { self.modificationDate = nil } - self.modified = coder.decodeObject(forKey: "modified") as! String + self.modified = coder.decodeObject(forKey: "modified") as? String ?? "" - self.application = coder.decodeObject(forKey: "application") as! String + self.application = coder.decodeObject(forKey: "application") as? String ?? "" super.init(coder: coder) } diff --git a/MediaInfoHelperXPC/info/ImageInfoItem.swift b/MediaInfoHelperXPC/info/ImageInfoItem.swift index 448c1df..57914da 100644 --- a/MediaInfoHelperXPC/info/ImageInfoItem.swift +++ b/MediaInfoHelperXPC/info/ImageInfoItem.swift @@ -51,7 +51,9 @@ class ImageInfo: DimensionalInfo, FileInfo, PaperInfo { } required init?(coder: NSCoder) { - let r = Self.decodeFileInfo(coder) + guard let r = Self.decodeFileInfo(coder) else { + return nil + } self.file = r.0 self.fileSize = r.1 ?? -1 diff --git a/MediaInfoHelperXPC/info/MediaInfoItems.swift b/MediaInfoHelperXPC/info/MediaInfoItems.swift index 252c838..eb52905 100644 --- a/MediaInfoHelperXPC/info/MediaInfoItems.swift +++ b/MediaInfoHelperXPC/info/MediaInfoItems.swift @@ -749,7 +749,10 @@ extension ChaptersInfo { let n = coder.decodeInteger(forKey: "chapters_count") var chapters: [Chapter] = [] for i in 0 ..< n { - if let chapter = Chapter(coder: coder.decodeObject(forKey: "chapter_\(i)") as! NSCoder) { + guard let c = coder.decodeObject(forKey: "chapter_\(i)") as? NSCoder else { + continue + } + if let chapter = Chapter(coder: c) { chapters.append(chapter) } } @@ -854,7 +857,7 @@ class VideoTrackInfo: DimensionalInfo, LanguageInfo, DurationInfo, CodecInfo { required init?(coder: NSCoder) { self.duration = coder.decodeDouble(forKey: "duration") self.start_time = coder.decodeDouble(forKey: "start_time") - self.codec_short_name = coder.decodeObject(forKey: "codec_short_name") as! String + self.codec_short_name = coder.decodeObject(forKey: "codec_short_name") as? String ?? "" self.codec_long_name = coder.decodeObject(forKey: "codec_long_name") as? String self.profile = coder.decodeObject(forKey: "profile") as? String self.pixel_format = VideoPixelFormat(rawValue: coder.decodeInteger(forKey: "pixel_format")) @@ -1045,9 +1048,12 @@ class VideoInfo: VideoTrackInfo, MediaInfo, ChaptersInfo { } required init?(coder: NSCoder) { - let r = Self.decodeFileInfo(coder) + guard let r = Self.decodeFileInfo(coder) else { + return nil + } self.file = r.0 self.fileSize = r.1 ?? -1 + self.engine = MediaEngine(rawValue: coder.decodeInteger(forKey: "engine"))! self.chapters = Self.decodeChapters(from: coder) @@ -1338,10 +1344,12 @@ class ImageVideoInfo: DimensionalInfo, CodecInfo, FileInfo { } required init?(coder: NSCoder) { - let r = Self.decodeFileInfo(coder) + guard let r = Self.decodeFileInfo(coder) else { + return nil + } self.file = r.0 self.fileSize = r.1 ?? -1 - self.codec_short_name = coder.decodeObject(forKey: "codec_short_name") as! String + self.codec_short_name = coder.decodeObject(forKey: "codec_short_name") as? String ?? "" self.codec_long_name = coder.decodeObject(forKey: "codec_long_name") as? String self.encoder = coder.decodeObject(forKey: "encoder") as? String self.isLossless = coder.decodeObject(forKey: "isLossless") as? Bool @@ -1399,7 +1407,7 @@ class AudioTrackInfo: BaseInfo, LanguageInfo, DurationInfo, CodecInfo { required init?(coder: NSCoder) { self.duration = coder.decodeDouble(forKey: "duration") self.start_time = coder.decodeDouble(forKey: "start_time") - self.codec_short_name = coder.decodeObject(forKey: "codec_short_name") as! String + self.codec_short_name = coder.decodeObject(forKey: "codec_short_name") as? String ?? "" self.codec_long_name = coder.decodeObject(forKey: "codec_long_name") as? String self.lang = coder.decodeObject(forKey: "lang") as? String self.bitRate = coder.decodeInt64(forKey: "bitRate") @@ -1478,11 +1486,16 @@ class AudioInfo: AudioTrackInfo, MediaInfo, ChaptersInfo { } required init?(coder: NSCoder) { - let r = Self.decodeFileInfo(coder) + guard let r = Self.decodeFileInfo(coder) else { + return nil + } self.file = r.0 self.fileSize = r.1 ?? -1 - self.engine = MediaEngine(rawValue: coder.decodeInteger(forKey: "engine"))! + guard let e = MediaEngine(rawValue: coder.decodeInteger(forKey: "engine")) else { + return nil + } + self.engine = e self.chapters = Self.decodeChapters(from: coder) diff --git a/MediaInfoHelperXPC/info/OfficeInfo.swift b/MediaInfoHelperXPC/info/OfficeInfo.swift index 2049187..26e06d1 100644 --- a/MediaInfoHelperXPC/info/OfficeInfo.swift +++ b/MediaInfoHelperXPC/info/OfficeInfo.swift @@ -155,7 +155,9 @@ class ExcelInfo: BaseOfficeInfo { let n = coder.decodeInteger(forKey: "sheets_count") var sheets: [String] = [] for i in 0 ..< n { - sheets.append(coder.decodeObject(forKey: "sheet_\(i)") as! String) + if let name = coder.decodeObject(forKey: "sheet_\(i)") as? String { + sheets.append(name) + } } self.sheets = sheets diff --git a/MediaInfoHelperXPC/info/PDFInfoItem.swift b/MediaInfoHelperXPC/info/PDFInfoItem.swift index c0f8377..da8294b 100644 --- a/MediaInfoHelperXPC/info/PDFInfoItem.swift +++ b/MediaInfoHelperXPC/info/PDFInfoItem.swift @@ -334,11 +334,13 @@ class PDFInfo: DimensionalInfo, FileInfo, PaperInfo { } required init?(coder: NSCoder) { - let r = Self.decodeFileInfo(coder) + guard let r = Self.decodeFileInfo(coder) else { + return nil + } self.file = r.0 self.fileSize = r.1 ?? -1 - self.version = coder.decodeObject(forKey: "version") as! String + self.version = coder.decodeObject(forKey: "version") as? String ?? "" self.author = coder.decodeObject(forKey: "author") as? String self.subject = coder.decodeObject(forKey: "subject") as? String self.title = coder.decodeObject(forKey: "title") as? String @@ -368,8 +370,9 @@ class PDFInfo: DimensionalInfo, FileInfo, PaperInfo { let n = coder.decodeInteger(forKey: "keywords_count") var keywords: [String] = [] for i in 0 ..< n { - let k = coder.decodeObject(forKey: "keyword_\(i)") as! String - keywords.append(k) + if let k = coder.decodeObject(forKey: "keyword_\(i)") as? String { + keywords.append(k) + } } self.keywords = keywords diff --git a/docs/appcast.xml b/docs/appcast.xml index cf4a28b..72556ea 100644 --- a/docs/appcast.xml +++ b/docs/appcast.xml @@ -42,5 +42,19 @@ ]]> + + 1.5.2 + sab, 29 Mag 2021 23:43:12 +0100 + 10.15 + + +
  • Bugfix on ratio.
  • +
  • Bugfix of ffmpeg and metadata engine disabled.
  • +
  • Bugfix for unhandled nil exception.
  • + + ]]> +
    +