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:
- Extend URL with a new optional computed property, creationDate
- Change the method Utility.getLatestScreenshot to use the array max method
  to find the latest screenshot file
  • Loading branch information
low-batt authored and CarterLi committed Feb 28, 2022
1 parent bc33feb commit 30a3032
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 4 additions & 0 deletions iina/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ extension NSMenuItem {


extension URL {
var creationDate: Date? {
(try? resourceValues(forKeys: [.creationDateKey]))?.creationDate
}

var isExistingDirectory: Bool {
return (try? self.resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory ?? false
}
Expand Down
13 changes: 2 additions & 11 deletions iina/Utility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,8 @@ class Utility {
at: folder,
includingPropertiesForKeys: [.creationDateKey],
options: .skipsSubdirectoryDescendants),
var latestFile = contents.first else { return nil }

var latestDate = Date.distantPast

for file in contents {
if let date = try? file.resourceValues(forKeys: [.creationDateKey]).creationDate, date > latestDate {
latestDate = date
latestFile = file
}
}
return latestFile
!contents.isEmpty else { return nil }
return contents.max { a, b in a.creationDate! < b.creationDate! }
}

// MARK: - Util classes
Expand Down

0 comments on commit 30a3032

Please sign in to comment.