diff --git a/Converter/AppDelegate.swift b/Converter/AppDelegate.swift index b94ce1f..142e0b5 100644 --- a/Converter/AppDelegate.swift +++ b/Converter/AppDelegate.swift @@ -11,16 +11,19 @@ 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 + } } diff --git a/Converter/Assets.xcassets/AppIcon.appiconset/Contents.json b/Converter/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 2db2b1c..0000000 --- a/Converter/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "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" - } -} \ No newline at end of file diff --git a/Converter/Base.lproj/Main.storyboard b/Converter/Base.lproj/Main.storyboard index 0d6bd6a..dce55ba 100644 --- a/Converter/Base.lproj/Main.storyboard +++ b/Converter/Base.lproj/Main.storyboard @@ -1,7 +1,9 @@ - - + + - + + + @@ -21,13 +23,6 @@ - - - - - - - @@ -58,555 +53,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -635,25 +86,13 @@ - - - - - - - - - - - - - + @@ -661,33 +100,126 @@ - - - + + + - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + diff --git a/Converter/ViewController.swift b/Converter/ViewController.swift index 24221e5..778b599 100644 --- a/Converter/ViewController.swift +++ b/Converter/ViewController.swift @@ -2,26 +2,144 @@ // ViewController.swift // Converter // -// Created by Kilian Hofmann on 21.06.17. +// 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 + + 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 - override var representedObject: Any? { - didSet { - // Update the view, if already loaded. + var days: Int = 0 + do { + let directory = try FileWrapper(url: URL(fileURLWithPath: inP), options: .immediate) + for months in directory.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 } + self.filesTotal += (days.value.fileWrappers?.count)! + if (days.value.fileWrappers?.contains(where: {$0.0 == ".DS_Store" }))! { + self.filesTotal -= 1 + } + if (days.value.fileWrappers?.contains(where: {$0.0 == "Content.plist" }))! { + self.filesTotal -= 1 + } + } + } + OperationQueue.main.addOperation { + self.months.stringValue = "\(directory.fileWrappers!.count)" + self.days.stringValue = "\(days)" + self.files.stringValue = "\(self.filesTotal)" + self.progress.stringValue = "File \(self.filesDone) of \(self.filesTotal)" + } + } catch _ { + OperationQueue.main.addOperation { + self.convert.isEnabled = true + (NSApp.delegate as! AppDelegate).isConverting = false + } + } + + 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); + } } } - - } - diff --git a/Docsis Toolkit.xcodeproj/project.pbxproj b/Docsis Toolkit.xcodeproj/project.pbxproj index 9ae82ed..e1dc372 100644 --- a/Docsis Toolkit.xcodeproj/project.pbxproj +++ b/Docsis Toolkit.xcodeproj/project.pbxproj @@ -7,10 +7,10 @@ objects = { /* Begin PBXBuildFile section */ - E220BF9F1EFB22D400DF5A97 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E220BF9E1EFB22D400DF5A97 /* AppDelegate.swift */; }; E220BFA11EFB22D400DF5A97 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E220BFA01EFB22D400DF5A97 /* ViewController.swift */; }; - E220BFA31EFB22D400DF5A97 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E220BFA21EFB22D400DF5A97 /* Assets.xcassets */; }; E220BFA61EFB22D400DF5A97 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E220BFA41EFB22D400DF5A97 /* Main.storyboard */; }; + E220BFAC1EFB231200DF5A97 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E220BFAB1EFB231200DF5A97 /* AppDelegate.swift */; }; + E220BFAD1EFB250800DF5A97 /* FileOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = E23E2C611EF7FE530009D376 /* FileOperations.swift */; }; E2218C9B1EF2D345004298F6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2218C9A1EF2D345004298F6 /* AppDelegate.swift */; }; E2218CA91EF2D37B004298F6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E2218CA81EF2D37B004298F6 /* Assets.xcassets */; }; E2218CDE1EF2D461004298F6 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2218CDC1EF2D461004298F6 /* MainMenu.xib */; }; @@ -69,11 +69,10 @@ /* Begin PBXFileReference section */ E220BF9C1EFB22D400DF5A97 /* Converter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Converter.app; sourceTree = BUILT_PRODUCTS_DIR; }; - E220BF9E1EFB22D400DF5A97 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E220BFA01EFB22D400DF5A97 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - E220BFA21EFB22D400DF5A97 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E220BFA51EFB22D400DF5A97 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; E220BFA71EFB22D500DF5A97 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E220BFAB1EFB231200DF5A97 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E2218C981EF2D345004298F6 /* Logger4.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Logger4.app; sourceTree = BUILT_PRODUCTS_DIR; }; E2218C9A1EF2D345004298F6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E2218CA31EF2D345004298F6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -150,15 +149,71 @@ E220BF9D1EFB22D400DF5A97 /* Converter */ = { isa = PBXGroup; children = ( - E220BF9E1EFB22D400DF5A97 /* AppDelegate.swift */, - E220BFA01EFB22D400DF5A97 /* ViewController.swift */, - E220BFA21EFB22D400DF5A97 /* Assets.xcassets */, - E220BFA41EFB22D400DF5A97 /* Main.storyboard */, - E220BFA71EFB22D500DF5A97 /* Info.plist */, + E220BFB11EFB26F500DF5A97 /* Sources */, + E220BFB31EFB271300DF5A97 /* Support Files */, ); path = Converter; sourceTree = ""; }; + E220BFAE1EFB26C100DF5A97 /* Sources */ = { + isa = PBXGroup; + children = ( + E2218D041EF2D67B004298F6 /* Obj-C */, + E2218CEB1EF2D648004298F6 /* Swift */, + ); + name = Sources; + sourceTree = ""; + }; + E220BFAF1EFB26D800DF5A97 /* Sources */ = { + isa = PBXGroup; + children = ( + E2218D4D1EF329AE004298F6 /* Swift */, + ); + name = Sources; + sourceTree = ""; + }; + E220BFB01EFB26E800DF5A97 /* Sources */ = { + isa = PBXGroup; + children = ( + E23E2C5D1EF7E63A0009D376 /* Swift */, + ); + name = Sources; + sourceTree = ""; + }; + E220BFB11EFB26F500DF5A97 /* Sources */ = { + isa = PBXGroup; + children = ( + E220BFB21EFB26FB00DF5A97 /* Swift */, + ); + name = Sources; + sourceTree = ""; + }; + E220BFB21EFB26FB00DF5A97 /* Swift */ = { + isa = PBXGroup; + children = ( + E220BFAB1EFB231200DF5A97 /* AppDelegate.swift */, + E220BFA01EFB22D400DF5A97 /* ViewController.swift */, + ); + name = Swift; + sourceTree = ""; + }; + E220BFB31EFB271300DF5A97 /* Support Files */ = { + isa = PBXGroup; + children = ( + E220BFA71EFB22D500DF5A97 /* Info.plist */, + E220BFB41EFB271B00DF5A97 /* UI */, + ); + name = "Support Files"; + sourceTree = ""; + }; + E220BFB41EFB271B00DF5A97 /* UI */ = { + isa = PBXGroup; + children = ( + E220BFA41EFB22D400DF5A97 /* Main.storyboard */, + ); + name = UI; + sourceTree = ""; + }; E2218C791EF2D2B5004298F6 = { isa = PBXGroup; children = ( @@ -184,9 +239,8 @@ E2218C991EF2D345004298F6 /* Logger4 */ = { isa = PBXGroup; children = ( - E2218D041EF2D67B004298F6 /* Obj-C */, + E220BFAE1EFB26C100DF5A97 /* Sources */, E2218CDA1EF2D43A004298F6 /* Support Files */, - E2218CEB1EF2D648004298F6 /* Swift */, ); path = Logger4; sourceTree = ""; @@ -194,8 +248,8 @@ E2218CA71EF2D35B004298F6 /* Shared Resources */ = { isa = PBXGroup; children = ( - E23E2C5D1EF7E63A0009D376 /* Swift */, E2218CA81EF2D37B004298F6 /* Assets.xcassets */, + E220BFB01EFB26E800DF5A97 /* Sources */, ); name = "Shared Resources"; sourceTree = ""; @@ -277,8 +331,8 @@ E2218D2A1EF3271F004298F6 /* Graphic Analysis 2 */ = { isa = PBXGroup; children = ( + E220BFAF1EFB26D800DF5A97 /* Sources */, E2218D3C1EF327CA004298F6 /* Support Files */, - E2218D4D1EF329AE004298F6 /* Swift */, ); path = "Graphic Analysis 2"; sourceTree = ""; @@ -581,7 +635,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - E220BFA31EFB22D400DF5A97 /* Assets.xcassets in Resources */, E220BFA61EFB22D400DF5A97 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -621,8 +674,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + E220BFAD1EFB250800DF5A97 /* FileOperations.swift in Sources */, + E220BFAC1EFB231200DF5A97 /* AppDelegate.swift in Sources */, E220BFA11EFB22D400DF5A97 /* ViewController.swift in Sources */, - E220BF9F1EFB22D400DF5A97 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -692,7 +746,7 @@ E220BFA91EFB22D500DF5A97 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = 795KPDV76S; INFOPLIST_FILE = Converter/Info.plist; @@ -700,6 +754,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.12; PRODUCT_BUNDLE_IDENTIFIER = com.weebly.alikja.Converter; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 3.0; }; name = Debug; @@ -707,7 +762,7 @@ E220BFAA1EFB22D500DF5A97 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = 795KPDV76S; INFOPLIST_FILE = Converter/Info.plist; @@ -715,6 +770,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.12; PRODUCT_BUNDLE_IDENTIFIER = com.weebly.alikja.Converter; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 3.0; }; name = Release; diff --git a/Docsis Toolkit.xcodeproj/xcshareddata/xcschemes/All.xcscheme b/Docsis Toolkit.xcodeproj/xcshareddata/xcschemes/All.xcscheme index 8b8013b..c1f748e 100644 --- a/Docsis Toolkit.xcodeproj/xcshareddata/xcschemes/All.xcscheme +++ b/Docsis Toolkit.xcodeproj/xcshareddata/xcschemes/All.xcscheme @@ -34,6 +34,20 @@ ReferencedContainer = "container:Docsis Toolkit.xcodeproj"> + + + + + + + + + +