Codacy compatibility (#575)

Refactor and split iostunnel with cmake changes, code cleanup
This commit is contained in:
isamnezia 2024-02-11 01:55:54 +03:00 committed by GitHub
parent 158c11a0ec
commit f3a168fd43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 679 additions and 684 deletions

View file

@ -13,59 +13,59 @@ struct Log {
}
private static let appGroupID = "group.org.amnezia.AmneziaVPN"
static let neLogURL = {
let sharedContainerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupID)!
return sharedContainerURL.appendingPathComponent("ne.log", isDirectory: false)
}()
private static var sharedUserDefaults = {
UserDefaults(suiteName: appGroupID)!
}()
static let dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return dateFormatter
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return dateFormatter
}()
var records: [Record]
init() {
self.records = []
}
init(_ str: String) {
self.records = str.split(whereSeparator: \.isNewline)
.compactMap {
Record(String($0))!
}
}
init?(at url: URL) {
if !FileManager.default.fileExists(atPath: url.path) {
guard let _ = try? "".data(using: .utf8)?.write(to: url) else { return nil }
guard (try? "".data(using: .utf8)?.write(to: url)) != nil else { return nil }
}
guard let fileHandle = try? FileHandle(forUpdating: url) else { return nil }
defer { fileHandle.closeFile() }
guard
let data = try? fileHandle.readToEnd(),
let str = String(data: data, encoding: .utf8) else {
return nil
}
self.init(str)
}
static func clear(at url: URL) {
if FileManager.default.fileExists(atPath: url.path) {
guard let fileHandle = try? FileHandle(forUpdating: url) else { return }
defer { fileHandle.closeFile() }
try? fileHandle.truncate(atOffset: 0)
}
}