72 lines
2.6 KiB
Swift
72 lines
2.6 KiB
Swift
//
|
|
// Document.swift
|
|
// Converter
|
|
//
|
|
// Created by Kilian Hofmann on 20.06.17.
|
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
import Cocoa
|
|
|
|
class Document: NSDocument {
|
|
|
|
var file: FileWrapper!
|
|
|
|
override class func autosavesInPlace() -> Bool {
|
|
return false
|
|
}
|
|
|
|
override func makeWindowControllers() {
|
|
// Returns the Storyboard that contains your Document window.
|
|
let storyboard = NSStoryboard(name: "Main", bundle: nil)
|
|
let windowController = storyboard.instantiateController(withIdentifier: "Document Window Controller") as! NSWindowController
|
|
self.addWindowController(windowController)
|
|
windowController.window?.delegate = self
|
|
|
|
var Files: [String : [String : FileWrapper]] = [:]
|
|
|
|
var months: Int = (file.fileWrappers?.count)!
|
|
if (file.fileWrappers?.contains(where: {$0.0 == ".DS_Store" }))! {
|
|
months -= 1
|
|
}
|
|
(windowControllers.first?.contentViewController as! ViewController).months.stringValue = "\(months)"
|
|
var days: Int = 0
|
|
var files: Int = 0
|
|
for months in file.fileWrappers! {
|
|
guard months.value.isDirectory else { continue }
|
|
days += (months.value.fileWrappers?.count)!
|
|
if (months.value.fileWrappers?.contains(where: {$0.0 == ".DS_Store" }))! {
|
|
days -= 1
|
|
}
|
|
for days in months.value.fileWrappers! {
|
|
guard days.value.isDirectory else { continue }
|
|
files += (days.value.fileWrappers?.count)!
|
|
if (days.value.fileWrappers?.contains(where: {$0.0 == ".DS_Store" }))! {
|
|
files -= 1
|
|
}
|
|
if (days.value.fileWrappers?.contains(where: {$0.0 == "Content.plist" }))! {
|
|
files -= 1
|
|
}
|
|
Files[months.key] = (months.value.fileWrappers!)
|
|
}
|
|
}
|
|
(windowControllers.first?.contentViewController as! ViewController).days.stringValue = "\(days)"
|
|
(windowControllers.first?.contentViewController as! ViewController).files.stringValue = "\(files)"
|
|
(windowControllers.first?.contentViewController as! ViewController).fileWrappers = Files
|
|
(windowControllers.first?.contentViewController as! ViewController).filesTotal = files
|
|
}
|
|
|
|
override func read(from fileWrapper: FileWrapper, ofType typeName: String) throws {
|
|
file = fileWrapper
|
|
}
|
|
}
|
|
|
|
extension Document: NSWindowDelegate {
|
|
|
|
func windowShouldClose(_ sender: Any) -> Bool {
|
|
guard (NSApp.delegate as! AppDelegate).isConverting else { return true }
|
|
return false
|
|
}
|
|
}
|
|
|