Loss Log now uses binary file, 2/3 size reduction
This commit is contained in:
parent
1e56a6247b
commit
16ea155d0d
@ -33,6 +33,8 @@
|
|||||||
E2218D691EF478C0004298F6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E2218CA81EF2D37B004298F6 /* Assets.xcassets */; };
|
E2218D691EF478C0004298F6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E2218CA81EF2D37B004298F6 /* Assets.xcassets */; };
|
||||||
E2268DF81EF7095100C97726 /* PDFTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2268DF61EF7095100C97726 /* PDFTitle.swift */; };
|
E2268DF81EF7095100C97726 /* PDFTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2268DF61EF7095100C97726 /* PDFTitle.swift */; };
|
||||||
E2268DF91EF7095100C97726 /* PDFTitle.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2268DF71EF7095100C97726 /* PDFTitle.xib */; };
|
E2268DF91EF7095100C97726 /* PDFTitle.xib in Resources */ = {isa = PBXBuildFile; fileRef = E2268DF71EF7095100C97726 /* PDFTitle.xib */; };
|
||||||
|
E23E2C621EF7FE530009D376 /* FileOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = E23E2C611EF7FE530009D376 /* FileOperations.swift */; };
|
||||||
|
E23E2C631EF7FE530009D376 /* FileOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = E23E2C611EF7FE530009D376 /* FileOperations.swift */; };
|
||||||
E262463E1EF55BCE00EAA4A6 /* GraphWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = E262463C1EF55BCE00EAA4A6 /* GraphWindow.swift */; };
|
E262463E1EF55BCE00EAA4A6 /* GraphWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = E262463C1EF55BCE00EAA4A6 /* GraphWindow.swift */; };
|
||||||
E262463F1EF55BCE00EAA4A6 /* GraphWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = E262463D1EF55BCE00EAA4A6 /* GraphWindow.xib */; };
|
E262463F1EF55BCE00EAA4A6 /* GraphWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = E262463D1EF55BCE00EAA4A6 /* GraphWindow.xib */; };
|
||||||
E26246441EF5E64900EAA4A6 /* PDFDraw.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26246421EF5E64900EAA4A6 /* PDFDraw.swift */; };
|
E26246441EF5E64900EAA4A6 /* PDFDraw.swift in Sources */ = {isa = PBXBuildFile; fileRef = E26246421EF5E64900EAA4A6 /* PDFDraw.swift */; };
|
||||||
@ -94,6 +96,7 @@
|
|||||||
E2218D661EF463B4004298F6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
|
E2218D661EF463B4004298F6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
|
||||||
E2268DF61EF7095100C97726 /* PDFTitle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFTitle.swift; sourceTree = "<group>"; };
|
E2268DF61EF7095100C97726 /* PDFTitle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFTitle.swift; sourceTree = "<group>"; };
|
||||||
E2268DF71EF7095100C97726 /* PDFTitle.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PDFTitle.xib; sourceTree = "<group>"; };
|
E2268DF71EF7095100C97726 /* PDFTitle.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PDFTitle.xib; sourceTree = "<group>"; };
|
||||||
|
E23E2C611EF7FE530009D376 /* FileOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileOperations.swift; sourceTree = "<group>"; };
|
||||||
E262463C1EF55BCE00EAA4A6 /* GraphWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphWindow.swift; sourceTree = "<group>"; };
|
E262463C1EF55BCE00EAA4A6 /* GraphWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphWindow.swift; sourceTree = "<group>"; };
|
||||||
E262463D1EF55BCE00EAA4A6 /* GraphWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GraphWindow.xib; sourceTree = "<group>"; };
|
E262463D1EF55BCE00EAA4A6 /* GraphWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GraphWindow.xib; sourceTree = "<group>"; };
|
||||||
E26246421EF5E64900EAA4A6 /* PDFDraw.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFDraw.swift; sourceTree = "<group>"; };
|
E26246421EF5E64900EAA4A6 /* PDFDraw.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFDraw.swift; sourceTree = "<group>"; };
|
||||||
@ -154,6 +157,7 @@
|
|||||||
E2218CA71EF2D35B004298F6 /* Shared Resources */ = {
|
E2218CA71EF2D35B004298F6 /* Shared Resources */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E23E2C5D1EF7E63A0009D376 /* Swift */,
|
||||||
E2218CA81EF2D37B004298F6 /* Assets.xcassets */,
|
E2218CA81EF2D37B004298F6 /* Assets.xcassets */,
|
||||||
);
|
);
|
||||||
name = "Shared Resources";
|
name = "Shared Resources";
|
||||||
@ -236,8 +240,8 @@
|
|||||||
E2218D2A1EF3271F004298F6 /* Graphic Analysis 2 */ = {
|
E2218D2A1EF3271F004298F6 /* Graphic Analysis 2 */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
E2218D4D1EF329AE004298F6 /* Swift */,
|
|
||||||
E2218D3C1EF327CA004298F6 /* Support Files */,
|
E2218D3C1EF327CA004298F6 /* Support Files */,
|
||||||
|
E2218D4D1EF329AE004298F6 /* Swift */,
|
||||||
);
|
);
|
||||||
path = "Graphic Analysis 2";
|
path = "Graphic Analysis 2";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -377,6 +381,14 @@
|
|||||||
name = "Collection View";
|
name = "Collection View";
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
E23E2C5D1EF7E63A0009D376 /* Swift */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
E23E2C611EF7FE530009D376 /* FileOperations.swift */,
|
||||||
|
);
|
||||||
|
name = Swift;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXLegacyTarget section */
|
/* Begin PBXLegacyTarget section */
|
||||||
@ -537,6 +549,7 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
E23E2C621EF7FE530009D376 /* FileOperations.swift in Sources */,
|
||||||
E2218D241EF3267F004298F6 /* XMLDictionary.m in Sources */,
|
E2218D241EF3267F004298F6 /* XMLDictionary.m in Sources */,
|
||||||
E2218D111EF2D6F1004298F6 /* SettingsWindowController.swift in Sources */,
|
E2218D111EF2D6F1004298F6 /* SettingsWindowController.swift in Sources */,
|
||||||
E2218D151EF2E470004298F6 /* ConnectionLossOperation.swift in Sources */,
|
E2218D151EF2E470004298F6 /* ConnectionLossOperation.swift in Sources */,
|
||||||
@ -553,6 +566,7 @@
|
|||||||
E2268DF81EF7095100C97726 /* PDFTitle.swift in Sources */,
|
E2268DF81EF7095100C97726 /* PDFTitle.swift in Sources */,
|
||||||
E2218D2C1EF3271F004298F6 /* AppDelegate.swift in Sources */,
|
E2218D2C1EF3271F004298F6 /* AppDelegate.swift in Sources */,
|
||||||
E2218D621EF41415004298F6 /* CollectionViewMonth.swift in Sources */,
|
E2218D621EF41415004298F6 /* CollectionViewMonth.swift in Sources */,
|
||||||
|
E23E2C631EF7FE530009D376 /* FileOperations.swift in Sources */,
|
||||||
E2218D601EF40E23004298F6 /* CollectionViewYear.swift in Sources */,
|
E2218D601EF40E23004298F6 /* CollectionViewYear.swift in Sources */,
|
||||||
E262463E1EF55BCE00EAA4A6 /* GraphWindow.swift in Sources */,
|
E262463E1EF55BCE00EAA4A6 /* GraphWindow.swift in Sources */,
|
||||||
E26246491EF6688400EAA4A6 /* PDFItemViewController.swift in Sources */,
|
E26246491EF6688400EAA4A6 /* PDFItemViewController.swift in Sources */,
|
||||||
|
|||||||
51
FileOperations.swift
Normal file
51
FileOperations.swift
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
//
|
||||||
|
// FileOperations.swift
|
||||||
|
// Docsis Toolkit
|
||||||
|
//
|
||||||
|
// Created by Kilian Hofmann on 19.06.17.
|
||||||
|
// Copyright © 2017 Kilian Hofmann. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
class FileOperations: NSObject {
|
||||||
|
|
||||||
|
static func log(data: String, toLog path: String) {
|
||||||
|
let seperated: Array<String> = data.components(separatedBy: ":")
|
||||||
|
let hours: UInt32 = UInt32(seperated[0])!
|
||||||
|
let minutes: UInt32 = UInt32(seperated[1])!
|
||||||
|
let seconds: UInt32 = UInt32(seperated[2])!
|
||||||
|
var dataToWrite: UInt32 = 0
|
||||||
|
dataToWrite = ((((dataToWrite | hours) << 6) | minutes) << 8) | seconds
|
||||||
|
let file: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1)
|
||||||
|
file.storeBytes(of: dataToWrite, as: UInt32.self)
|
||||||
|
do {
|
||||||
|
let fileData: NSMutableData = try NSMutableData(contentsOf: URL(fileURLWithPath: path))
|
||||||
|
fileData.append(file, length: 3)
|
||||||
|
fileData.write(to: URL(fileURLWithPath: path), atomically: true)
|
||||||
|
} catch _ {
|
||||||
|
let fileData: NSMutableData = NSMutableData()
|
||||||
|
fileData.append(file, length: 3)
|
||||||
|
fileData.write(to: URL(fileURLWithPath: path), atomically: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static func load(log Data: NSData) -> String? {
|
||||||
|
var returnString: String? = ""
|
||||||
|
var i: Int = 0
|
||||||
|
while i < Data.length - 3 {
|
||||||
|
let data: UnsafeMutableRawPointer = UnsafeMutableRawPointer.allocate(bytes: 3, alignedTo: 1)
|
||||||
|
Data.getBytes(data, range: NSRange(location: i, length: 3))
|
||||||
|
let compound: UInt32 = data.load(as: UInt32.self)
|
||||||
|
let seconds: UInt32 = (compound) & 0b111111
|
||||||
|
let minutes: UInt32 = (compound >> 8) & 0b111111
|
||||||
|
let hours: UInt32 = (compound >> 14) & 0b11111
|
||||||
|
returnString?.append("\(hours):\(minutes):\(seconds)\n")
|
||||||
|
i += 3
|
||||||
|
}
|
||||||
|
if returnString != "" {
|
||||||
|
return returnString
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -75,7 +75,7 @@ extension CollectionViewMonth: NSCollectionViewDataSource {
|
|||||||
}
|
}
|
||||||
item2.day.textColor = NSColor.black
|
item2.day.textColor = NSColor.black
|
||||||
operationQueue.addOperation {
|
operationQueue.addOperation {
|
||||||
guard let log = day.fileWrappers?["KDLog.txt"] else {
|
guard let log = day.fileWrappers?["KDLog.hex"] else {
|
||||||
OperationQueue.main.addOperation {
|
OperationQueue.main.addOperation {
|
||||||
self.doc.progress.increment(by: 100/31)
|
self.doc.progress.increment(by: 100/31)
|
||||||
if self.doc.progress.doubleValue > 98 {
|
if self.doc.progress.doubleValue > 98 {
|
||||||
@ -84,7 +84,10 @@ extension CollectionViewMonth: NSCollectionViewDataSource {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
guard var logA = String(data: log.regularFileContents!, encoding: .utf8)?.components(separatedBy: "\n") else { return }
|
guard var logA = String(data: log.regularFileContents!, encoding: .utf8)?.components(separatedBy: "\n") else { return }
|
||||||
|
*/
|
||||||
|
guard var logA = FileOperations.load(log: log.regularFileContents! as NSData)?.components(separatedBy: "\n") else { return }
|
||||||
logA.removeLast()
|
logA.removeLast()
|
||||||
item2.distribution = logA
|
item2.distribution = logA
|
||||||
OperationQueue.main.addOperation {
|
OperationQueue.main.addOperation {
|
||||||
|
|||||||
@ -44,7 +44,7 @@
|
|||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>2.0</string>
|
<string>2.0</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>414</string>
|
<string>417</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
version 2.0
|
version 2.0
|
||||||
build 414
|
build 417
|
||||||
|
|||||||
@ -21,11 +21,11 @@ class ConnectionLossOperation: Operation {
|
|||||||
let time : Date = Date()
|
let time : Date = Date()
|
||||||
let start: Array<String> = (NSApp.delegate as! AppDelegate).justDate.string(from: time).components(separatedBy: ".")
|
let start: Array<String> = (NSApp.delegate as! AppDelegate).justDate.string(from: time).components(separatedBy: ".")
|
||||||
// Line to write
|
// Line to write
|
||||||
let entry: String = String(format: "%@\n", (NSApp.delegate as! AppDelegate).justTime.string(from: time))
|
let entry: String = String(format: "%@", (NSApp.delegate as! AppDelegate).justTime.string(from: time))
|
||||||
// File manager
|
// File manager
|
||||||
let fileManager: FileManager = FileManager.default
|
let fileManager: FileManager = FileManager.default
|
||||||
// Path to file
|
// Path to file
|
||||||
let file: String = NSString(format: "~/KDLog/%@.docsisplist2/%@/%@/KDLog.txt", start[2], start[1], start[0]).expandingTildeInPath
|
let file: String = NSString(format: "~/KDLog/%@.docsisplist2/%@/%@/KDLog.hex", start[2], start[1], start[0]).expandingTildeInPath
|
||||||
// Make all relevant directories if not present
|
// Make all relevant directories if not present
|
||||||
pthread_mutex_lock(&((NSApp.delegate as! AppDelegate).lock))
|
pthread_mutex_lock(&((NSApp.delegate as! AppDelegate).lock))
|
||||||
let dir: NSString = NSString(format: "~/KDLog/%@.docsisplist2/%@/%@", start[2], start[1], start[0])
|
let dir: NSString = NSString(format: "~/KDLog/%@.docsisplist2/%@/%@", start[2], start[1], start[0])
|
||||||
@ -44,6 +44,7 @@ class ConnectionLossOperation: Operation {
|
|||||||
data, response, error in
|
data, response, error in
|
||||||
|
|
||||||
if error != nil && data == nil && self.result2 {
|
if error != nil && data == nil && self.result2 {
|
||||||
|
/*
|
||||||
let fileH: FileHandle? = FileHandle(forUpdatingAtPath: file)
|
let fileH: FileHandle? = FileHandle(forUpdatingAtPath: file)
|
||||||
if fileH == nil {
|
if fileH == nil {
|
||||||
do{
|
do{
|
||||||
@ -58,7 +59,11 @@ class ConnectionLossOperation: Operation {
|
|||||||
fileH?.write(data!)
|
fileH?.write(data!)
|
||||||
fileH?.closeFile()
|
fileH?.closeFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sep = entry.components(separatedBy: ":")
|
||||||
|
FileOperations.logHours(UInt8(sep[0])!, minutes: UInt8(sep[1])!, seconds: UInt8(sep[2])!, toLog: file)
|
||||||
|
*/
|
||||||
|
FileOperations.log(data: entry, toLog: file)
|
||||||
self.result2 = false;
|
self.result2 = false;
|
||||||
NSLog("Internet loss logged!")
|
NSLog("Internet loss logged!")
|
||||||
}
|
}
|
||||||
@ -70,6 +75,7 @@ class ConnectionLossOperation: Operation {
|
|||||||
data, response, error in
|
data, response, error in
|
||||||
|
|
||||||
if error != nil && data == nil && self.result1 {
|
if error != nil && data == nil && self.result1 {
|
||||||
|
/*
|
||||||
let fileH: FileHandle? = FileHandle(forUpdatingAtPath: file)
|
let fileH: FileHandle? = FileHandle(forUpdatingAtPath: file)
|
||||||
if fileH == nil {
|
if fileH == nil {
|
||||||
do{
|
do{
|
||||||
@ -84,7 +90,11 @@ class ConnectionLossOperation: Operation {
|
|||||||
fileH?.write(data!)
|
fileH?.write(data!)
|
||||||
fileH?.closeFile()
|
fileH?.closeFile()
|
||||||
}
|
}
|
||||||
self.result1 = false;
|
let sep = entry.components(separatedBy: ":")
|
||||||
|
FileOperations.logHours(UInt8(sep[0])!, minutes: UInt8(sep[1])!, seconds: UInt8(sep[2])!, toLog: file)
|
||||||
|
*/
|
||||||
|
FileOperations.log(data: entry, toLog: file)
|
||||||
|
self.result2 = false;
|
||||||
NSLog("Internet loss logged!")
|
NSLog("Internet loss logged!")
|
||||||
}
|
}
|
||||||
else if error != nil && response == nil && data == nil {
|
else if error != nil && response == nil && data == nil {
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>4.0</string>
|
<string>4.0</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>27</string>
|
<string>39</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.utilities</string>
|
<string>public.app-category.utilities</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@ -4,3 +4,4 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "XMLDictionary.h"
|
#import "XMLDictionary.h"
|
||||||
|
//#import "FileOperations.h"
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
version 4.0
|
version 4.0
|
||||||
build 27
|
build 39
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user