Fixed critical bug in loss logging functions (pointer realloced to early)

Implemented Converter tool -> needs refactoring toward non document based
This commit is contained in:
2017-06-21 23:36:33 +02:00
parent 086c8a0f94
commit ca171e44f3
19 changed files with 944 additions and 34 deletions
+29
View File
@@ -0,0 +1,29 @@
//
// AppDelegate.swift
// Converter
//
// Created by Kilian Hofmann on 20.06.17.
// Copyright © 2017 Kilian Hofmann. All rights reserved.
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var isConverting: Bool = false
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplicationTerminateReply {
guard isConverting else { return NSApplicationTerminateReply.terminateNow }
return NSApplicationTerminateReply.terminateCancel
}
}
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
+225
View File
@@ -0,0 +1,225 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G16b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Application-->
<scene sceneID="JPo-4y-FX3">
<objects>
<application id="hnw-xV-0zn" sceneMemberID="viewController">
<menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
<items>
<menuItem title="Converter" id="1Xt-HY-uBw">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Converter" systemMenu="apple" id="uQy-DD-JDr">
<items>
<menuItem title="About Converter" id="5kV-Vb-QxS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Hide Converter" keyEquivalent="h" id="Olw-nP-bQN">
<connections>
<action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/>
</connections>
</menuItem>
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/>
</connections>
</menuItem>
<menuItem title="Show All" id="Kd2-mp-pUS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
<menuItem title="Quit Converter" keyEquivalent="q" id="4sb-4s-VLi">
<connections>
<action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="File" id="dMs-cI-mzQ">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="File" id="bib-Uj-vzu">
<items>
<menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
<connections>
<action selector="openDocument:" target="Ady-hI-5gd" id="bVn-NM-KNZ"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Window" id="aUF-d1-5bR">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
<items>
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
<connections>
<action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/>
</connections>
</menuItem>
<menuItem title="Zoom" id="R4o-n2-Eq4">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items>
</menu>
<connections>
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Converter" customModuleProvider="target"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController storyboardIdentifier="Document Window Controller" id="jGA-0Y-lOj" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="Ckk-yw-fiv">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
</window>
<connections>
<segue destination="5gI-5U-AMq" kind="relationship" relationship="window.shadowedContentViewController" id="nsd-lR-9xd"/>
</connections>
</windowController>
<customObject id="6f7-a7-6o1" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="250"/>
</scene>
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="5gI-5U-AMq" customClass="ViewController" customModule="Converter" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="ERx-hH-rdd">
<rect key="frame" x="0.0" y="0.0" width="227" height="297"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hzt-CW-CBb">
<rect key="frame" x="18" y="260" width="90" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Months in file:" id="TqK-dx-p75">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Fu9-FO-AvC">
<rect key="frame" x="18" y="235" width="74" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Days in file:" id="0Oc-SD-wvm">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QiI-iy-HKb">
<rect key="frame" x="18" y="210" width="132" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Total amount of files:" id="rGw-YE-Eg4">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="v8x-Dd-KVt">
<rect key="frame" x="10" y="174" width="89" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="push" title="Convert" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="SeP-bt-Zu9">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="convertWithSender:" target="5gI-5U-AMq" id="n9e-uo-hco"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="li2-hD-gp8">
<rect key="frame" x="101" y="181" width="108" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="File %d out of %d" id="XNh-EM-ytf">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="XDX-Xk-VvX">
<rect key="frame" x="158" y="210" width="49" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="4xa-6K-g1m">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="R5m-y0-Wxj">
<rect key="frame" x="158" y="235" width="51" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="QEa-E3-1AL">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="N3D-YL-UMx">
<rect key="frame" x="158" y="260" width="49" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Label" id="Xn7-If-8GA">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" allowsCharacterPickerTouchBarItem="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jdB-hN-Uzl">
<rect key="frame" x="16" y="151" width="189" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="Zmq-Ps-mau">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
<connections>
<outlet property="convert" destination="v8x-Dd-KVt" id="fRt-s9-UZj"/>
<outlet property="days" destination="R5m-y0-Wxj" id="5zG-pX-1UY"/>
<outlet property="files" destination="XDX-Xk-VvX" id="UK2-tq-iol"/>
<outlet property="inPath" destination="jdB-hN-Uzl" id="gE1-Nh-rtC"/>
<outlet property="months" destination="N3D-YL-UMx" id="Inh-DW-egq"/>
<outlet property="progress" destination="li2-hD-gp8" id="CMp-XL-Cka"/>
</connections>
</viewController>
<customObject id="2Tp-Fl-jBw" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-51.5" y="668.5"/>
</scene>
</scenes>
</document>
+71
View File
@@ -0,0 +1,71 @@
//
// 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
}
}
+53
View File
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>docsisplist2</string>
</array>
<key>CFBundleTypeIconFile</key>
<string></string>
<key>CFBundleTypeName</key>
<string>DocumentType</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>????</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>NSDocumentClass</key>
<string>$(PRODUCT_MODULE_NAME).Document</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 Kilian Hofmann. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
+114
View File
@@ -0,0 +1,114 @@
//
// ViewController.swift
// Converter
//
// Created by Kilian Hofmann on 20.06.17.
// Copyright © 2017 Kilian Hofmann. All rights reserved.
//
import Cocoa
class ViewController: NSViewController {
@IBOutlet var months: NSTextField!
@IBOutlet var days: NSTextField!
@IBOutlet var files: NSTextField!
@IBOutlet var progress: NSTextField!
@IBOutlet var convert: NSButton!
@IBOutlet var inPath: NSTextField!
var fileWrappers: [String : [String : FileWrapper]]!
var filesDone: Int = 0
var filesTotal: Int = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func convert(sender: NSButton) {
convert.isEnabled = false
(NSApp.delegate as! AppDelegate).isConverting = true
progress.stringValue = "File \(self.filesDone) of \(self.filesTotal)"
let opQueue: OperationQueue = OperationQueue()
let fileQueue: OperationQueue = OperationQueue()
fileQueue.maxConcurrentOperationCount = 4
let myActivity = ProcessInfo.processInfo.beginActivity(options: .userInitiated, reason: "Converting")
opQueue.addOperation {
defer {
fileQueue.waitUntilAllOperationsAreFinished()
ProcessInfo.processInfo.endActivity(myActivity)
OperationQueue.main.addOperation {
self.convert.isEnabled = true
(NSApp.delegate as! AppDelegate).isConverting = false
}
}
let inP: String = self.inPath.stringValue
for month in 1...12 {
for day in 1...31 {
let path: String = inP + String(format: "/%02d", month) + String(format: "/%02d", day)
do {
let directory = try FileWrapper(url: URL(fileURLWithPath: path), options: .immediate)
for file in directory.fileWrappers! {
if file.key == "KDLog.txt" {
let pathOut = path.appending("/" + file.key.replacingOccurrences(of: ".txt", with: ".hex")).replacingOccurrences(of: ".docsisplist2", with: "C.docsisplist2")
//print(path.appending(file.key) + " to " + pathOut)
self.makeSubDir(path: pathOut.replacingOccurrences(of: file.key.replacingOccurrences(of: ".txt", with: ".hex"), with: ""))
FileOperations.convertLoss(log: path.appending("/" + file.key), toFile: pathOut)
OperationQueue.main.addOperation {
self.filesDone += 1
self.progress.stringValue = "File \(self.filesDone) of \(self.filesTotal)"
}
} else if file.key.contains("Upstream") {
let pathOut = path.appending("/" + file.key.replacingOccurrences(of: ".csv", with: ".hex")).replacingOccurrences(of: ".docsisplist2", with: "C.docsisplist2")
//print(path.appending(file.key) + " to " + pathOut)
self.makeSubDir(path: pathOut.replacingOccurrences(of: file.key.replacingOccurrences(of: ".csv", with: ".hex"), with: ""))
FileOperations.convertUpstream(log: path.appending("/" + file.key), toFile: pathOut)
OperationQueue.main.addOperation {
self.filesDone += 1
self.progress.stringValue = "File \(self.filesDone) of \(self.filesTotal)"
}
} else if file.key.contains("Downstream") {
let pathOut = path.appending("/" + file.key.replacingOccurrences(of: ".csv", with: ".hex")).replacingOccurrences(of: ".docsisplist2", with: "C.docsisplist2")
//print(path.appending(file.key) + " to " + pathOut)
self.makeSubDir(path: pathOut.replacingOccurrences(of: file.key.replacingOccurrences(of: ".csv", with: ".hex"), with: ""))
FileOperations.convertDownstream(log: path.appending("/" + file.key), toFile: pathOut)
OperationQueue.main.addOperation {
self.filesDone += 1
self.progress.stringValue = "File \(self.filesDone) of \(self.filesTotal)"
}
}
}
} catch _ { continue }
}
}
}
}
func makeSubDir(path: String) {
// Check if directory exists, create or exit
let fileManager = FileManager.default
var directory: ObjCBool = ObjCBool(false)
let exists: Bool = fileManager.fileExists(atPath: (path as NSString).expandingTildeInPath, isDirectory: &directory)
if exists && directory.boolValue {
} else if exists {
NSLog("FILE WITH NAME KDLog EXISTS, REMOVE IT")
exit(1);
}
else {
do {
try fileManager.createDirectory(atPath: (path as NSString).expandingTildeInPath, withIntermediateDirectories: true, attributes: nil)
}
catch let error as NSError {
NSLog("ERROR ON DIRECTORY CREATION: \(error.localizedDescription)")
exit(1);
}
}
}
}