Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Fix screenshot crash with long video title, iina#3334
Browse files Browse the repository at this point in the history
This commit will address review comments on the changes to the methods
MPVController.handleEvent and Utility.getLatestScreenshot.
  • Loading branch information
low-batt authored and CarterLi committed Feb 21, 2022
1 parent d7ccfe3 commit b7fb62f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions iina/MPVController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@ class MPVController: NSObject {
let reply = event.pointee.reply_userdata
if reply == MPVController.UserData.screenshot {
let code = event.pointee.error
guard 0 <= code else {
let error = String.init(cString: mpv_error_string(code))
guard code >= 0 else {
let error = String(cString: mpv_error_string(code))
Logger.log("Cannot take a screenshot, mpv API error: \(error), Return value: \(code)", level: .error)
// Unfortunately the mpv API does not provide any details on the failure. The error
// code returned maps to "error running command", so all the alert can report is
Expand Down
6 changes: 3 additions & 3 deletions iina/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ class Utility {
guard let contents = try? FileManager.default.contentsOfDirectory(
at: folder,
includingPropertiesForKeys: [.creationDateKey],
options: .skipsSubdirectoryDescendants), !contents.isEmpty else { return nil }

options: .skipsSubdirectoryDescendants),
var latestFile = contents.first else { return nil }

var latestDate = Date.distantPast
var latestFile: URL = contents[0]

for file in contents {
if let date = try? file.resourceValues(forKeys: [.creationDateKey]).creationDate, date > latestDate {
Expand Down

0 comments on commit b7fb62f

Please sign in to comment.