Simplify PEFile init

This commit is contained in:
Isaac Marovitz
2023-10-27 15:41:16 -04:00
parent 3c8eec038c
commit 4546d659f4
3 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -277,8 +277,8 @@ public struct PEFile: Hashable {
}
private let handle: FileHandle
public init(handle: FileHandle) throws {
self.handle = handle
public init(url: URL) throws {
self.handle = try FileHandle(forReadingFrom: url)
// Verify it is a PE file by checking for the PE header
let offsetToPEHeader = handle.extract(UInt32.self, offset: 0x3C) ?? 0
let peHeader = handle.extract(UInt32.self, offset: Int(offsetToPEHeader))
+1 -1
View File
@@ -41,7 +41,7 @@ public class Program: Hashable {
self.settings = ProgramSettings(bottleUrl: bottle.url, name: name)
self.pinned = bottle.settings.pins.contains(where: { $0.url == url })
do {
self.peFile = try PEFile(handle: FileHandle(forReadingFrom: url))
self.peFile = try PEFile(url: url)
} catch {
self.peFile = nil
}
+1 -1
View File
@@ -46,7 +46,7 @@ class ThumbnailProvider: QLThumbnailProvider {
do {
var image: NSImage?
let peFile = try PEFile(handle: try FileHandle(forReadingFrom: request.fileURL))
let peFile = try PEFile(url: request.fileURL)
image = peFile.bestIcon()
let reply: QLThumbnailReply = QLThumbnailReply.init(contextSize: thumbnailSize) { () -> Bool in