SafeData.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2018-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import Foundation
  21. @objc public class SafeData: NSObject, NSCoding {
  22. public var key: [UInt8]?
  23. public var customServer: String?
  24. public var server: String?
  25. public var maxBackupBytes: Int?
  26. public var retentionDays: Int?
  27. public var backupSize: Int64?
  28. public var backupStartedAt: Date?
  29. public var lastBackup: Date?
  30. public var lastResult: String?
  31. public var lastChecksum: [UInt8]?
  32. public var lastAlertBackupFailed: Date?
  33. public var isTriggered: Int? = 0
  34. public init(key: [UInt8]?, customServer: String?, server: String?, maxBackupBytes: Int?, retentionDays: Int?, backupSize: Int64?, backupStartedAt: Date?, lastBackup: Date?, lastResult: String?, lastChecksum: [UInt8]?, lastAlertBackupFailed: Date?, isTriggered: Int?) {
  35. self.key = key
  36. self.customServer = customServer
  37. self.server = server
  38. self.maxBackupBytes = maxBackupBytes
  39. self.retentionDays = retentionDays
  40. self.backupSize = backupSize
  41. self.backupStartedAt = backupStartedAt
  42. self.lastBackup = lastBackup
  43. self.lastResult = lastResult
  44. self.lastChecksum = lastChecksum
  45. self.lastAlertBackupFailed = lastAlertBackupFailed
  46. self.isTriggered = isTriggered
  47. }
  48. public required convenience init?(coder aDecoder: NSCoder) {
  49. let key = aDecoder.decodeObject(forKey: "key") as? [UInt8]
  50. let customServer = aDecoder.decodeObject(forKey: "customServer") as? String
  51. let server = aDecoder.decodeObject(forKey: "server") as? String
  52. let maxBackupBytes = aDecoder.decodeObject(forKey: "maxBackupBytes") as? Int
  53. let retentionDays = aDecoder.decodeObject(forKey: "retentionDays") as? Int
  54. let backupSize = aDecoder.decodeObject(forKey: "backupSize") as? Int64
  55. let backupStartedAt = aDecoder.decodeObject(forKey: "backupStartedAt") as? Date
  56. let lastBackup = aDecoder.decodeObject(forKey: "lastBackup") as? Date
  57. let lastResult = aDecoder.decodeObject(forKey: "lastResult") as? String
  58. let lastChecksum = aDecoder.decodeObject(forKey: "lastChecksum") as? [UInt8]
  59. let lastAlertBackupFailed = aDecoder.decodeObject(forKey: "lastAlertBackupFailed") as? Date
  60. let isTriggered = aDecoder.decodeObject(forKey: "isTriggered") as? Int
  61. self.init(key: key, customServer: customServer, server: server, maxBackupBytes: maxBackupBytes, retentionDays: retentionDays, backupSize: backupSize, backupStartedAt: backupStartedAt, lastBackup: lastBackup, lastResult: lastResult, lastChecksum: lastChecksum, lastAlertBackupFailed: lastAlertBackupFailed, isTriggered: isTriggered ?? 0)
  62. }
  63. public func encode(with aCoder: NSCoder) {
  64. aCoder.encode(self.key, forKey: "key")
  65. aCoder.encode(self.customServer, forKey: "customServer")
  66. aCoder.encode(self.server, forKey: "server")
  67. aCoder.encode(self.maxBackupBytes, forKey: "maxBackupBytes")
  68. aCoder.encode(self.retentionDays, forKey: "retentionDays")
  69. aCoder.encode(self.backupSize, forKey: "backupSize")
  70. aCoder.encode(self.backupStartedAt, forKey: "backupStartedAt")
  71. aCoder.encode(self.lastBackup, forKey: "lastBackup")
  72. aCoder.encode(self.lastResult, forKey: "lastResult")
  73. aCoder.encode(self.lastChecksum, forKey: "lastChecksum")
  74. aCoder.encode(self.lastAlertBackupFailed, forKey: "lastAlertBackupFailed")
  75. aCoder.encode(self.isTriggered, forKey: "isTriggered")
  76. }
  77. }