Skip to content

Commit

Permalink
Bugfix for unhandled nil exception, and ratio.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarex committed May 31, 2021
1 parent ac97b30 commit 502a45b
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 45 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
32 changes: 16 additions & 16 deletions MediaInfo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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)";
Expand All @@ -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 = (
Expand All @@ -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)";
Expand All @@ -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;
Expand All @@ -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)";
Expand All @@ -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;
Expand All @@ -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)";
Expand Down Expand Up @@ -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 = (
Expand All @@ -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;
Expand All @@ -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 = (
Expand All @@ -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)";
Expand All @@ -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 = (
Expand All @@ -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;
Expand All @@ -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 = (
Expand All @@ -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)";
Expand Down
2 changes: 1 addition & 1 deletion MediaInfoHelperXPC/CGMediaUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 14 additions & 6 deletions MediaInfoHelperXPC/info/BaseInfoItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)"
}

Expand Down Expand Up @@ -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]]":
Expand Down
20 changes: 12 additions & 8 deletions MediaInfoHelperXPC/info/BaseOfficeInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion MediaInfoHelperXPC/info/ImageInfoItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 21 additions & 8 deletions MediaInfoHelperXPC/info/MediaInfoItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion MediaInfoHelperXPC/info/OfficeInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions MediaInfoHelperXPC/info/PDFInfoItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 502a45b

Please sign in to comment.