Skip to content

Commit ea9b6a7

Browse files
committed
make file information initializers failable
1 parent af5a42c commit ea9b6a7

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

jmc/AlbumFileLocationViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ class AlbumFilePathTree: NSObject {
162162
func getNodesForObjects(objects: Set<NSObject>) -> Set<AlbumFilePathNode> {
163163
var nodeSet = Set<AlbumFilePathNode>()
164164
for object in objects {
165-
nodeSet.insert(self.rootNode.getLowestChildWithObject(object: object)!)
165+
if let lowestChild = self.rootNode.getLowestChildWithObject(object: object) {
166+
nodeSet.insert(lowestChild)
167+
}
166168
}
167169
return nodeSet
168170
}

jmc/Other Windows/TagEditorWindow.swift

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class TagEditorWindow: NSWindowController, NSTextFieldDelegate, NSWindowDelegate
527527
@IBOutlet weak var locationPathControl: NSPathControl!
528528

529529
func populateFileInfo() {
530-
//todo correct tags if inconsistent
530+
//todo touch the actual file if we have to
531531
let url = NSURL(string: self.currentTrack!.location!)!
532532
self.locationPathControl.url = url as URL
533533

@@ -537,17 +537,29 @@ class TagEditorWindow: NSWindowController, NSTextFieldDelegate, NSWindowDelegate
537537
flacMDItem?.initForMetadata()
538538
}
539539
let kind = MDItemCopyAttribute(mdItem, kMDItemKind) as? String
540-
kindLabel.stringValue = kind!
541-
let duration = MDItemCopyAttribute(mdItem, kMDItemDurationSeconds) as? Int ?? (Int(flacMDItem!.totalFrames / flacMDItem!.sampleRate!))
542-
durationLabel.stringValue = getTimeAsString(Double(duration))!
543-
let size = MDItemCopyAttribute(mdItem, kMDItemFSSize) as! Int
544-
sizeLabel.stringValue = fileSizeFormatter.string(fromByteCount: Int64(size))
545-
let bitRateCheck = (MDItemCopyAttribute(mdItem, kMDItemAudioBitRate) as? Int ?? (((size ) * 8) / 1000) / duration) / 1000
546-
bitRateLabel.stringValue = bitRateFormatter.string(for: bitRateCheck)!
547-
let sampleRateCheck = MDItemCopyAttribute(mdItem, kMDItemAudioSampleRate) as? Int ?? Int(flacMDItem!.sampleRate!)
548-
sampleRateLabel.stringValue = sampleRateFormatter.string(for: sampleRateCheck)!
549-
let channels = MDItemCopyAttribute(mdItem, kMDItemAudioChannelCount) as? Int ?? Int(flacMDItem!.channels!)
550-
channelsLabel.stringValue = String(describing: channels)
540+
if let kind = kind {
541+
kindLabel.stringValue = kind
542+
}
543+
let duration = MDItemCopyAttribute(mdItem, kMDItemDurationSeconds) as? Int ?? (flacMDItem != nil ? (Int(flacMDItem!.totalFrames / flacMDItem!.sampleRate!)) : nil)
544+
if let duration = duration {
545+
durationLabel.stringValue = getTimeAsString(Double(duration))!
546+
}
547+
let size = MDItemCopyAttribute(mdItem, kMDItemFSSize) as? Int
548+
if let size = size {
549+
sizeLabel.stringValue = fileSizeFormatter.string(fromByteCount: Int64(size))
550+
}
551+
let bitRateCheck = MDItemCopyAttribute(mdItem, kMDItemAudioBitRate) as? Int ?? (size != nil && duration != nil ? ((((size!) * 8) / 1000) / duration!) / 1000 : nil)
552+
if let bitRateCheck = bitRateCheck {
553+
bitRateLabel.stringValue = bitRateFormatter.string(for: bitRateCheck)!
554+
}
555+
let sampleRateCheck = MDItemCopyAttribute(mdItem, kMDItemAudioSampleRate) as? Int ?? (flacMDItem != nil ? Int(flacMDItem!.sampleRate!) : nil)
556+
if let sampleRateCheck = sampleRateCheck {
557+
sampleRateLabel.stringValue = sampleRateFormatter.string(for: sampleRateCheck)!
558+
}
559+
let channels = MDItemCopyAttribute(mdItem, kMDItemAudioChannelCount) as? Int ?? (flacMDItem != nil ? Int(flacMDItem!.channels!) : nil)
560+
if let channels = channels {
561+
channelsLabel.stringValue = String(describing: channels)
562+
}
551563
let encoder = MDItemCopyAttribute(mdItem, kMDItemAudioEncodingApplication) as? String
552564
encoderLabel.stringValue = encoder != nil ? encoder! : "No encoder information available."
553565
let dateModified = MDItemCopyAttribute(mdItem, kMDItemContentModificationDate) as? NSDate

0 commit comments

Comments
 (0)