Skip to content

Commit

Permalink
Simplify PEFile init
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Oct 27, 2023
1 parent 3c8eec0 commit 4546d65
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions WhiskyKit/PE/PortableExecutable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion WhiskyKit/Whisky/Program.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion WhiskyThumbnail/ThumbnailProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4546d65

Please sign in to comment.