diff --git a/main/Extensions/URL.swift b/main/Extensions/URL.swift index 1c0951a..c69a627 100644 --- a/main/Extensions/URL.swift +++ b/main/Extensions/URL.swift @@ -12,6 +12,18 @@ fileprivate extension FileManager { } } +extension FileManager { + func sizeOf(path: String) -> Int64? { + try? attributesOfItem(atPath: path)[.size] as? Int64 + } + func readableSizeOf(path: String) -> String? { + guard let fSize = sizeOf(path: path) else { return nil } + let bcf = ByteCountFormatter() + bcf.countStyle = .file + return bcf.string(fromByteCount: fSize) + } +} + extension URL { // static func exportDir() -> URL { FileManager.default.exportDir() } static func appGroupDir() -> URL { FileManager.default.appGroupDir() } diff --git a/main/Settings/TVCSettings.swift b/main/Settings/TVCSettings.swift index a97d4fb..ba3c25f 100644 --- a/main/Settings/TVCSettings.swift +++ b/main/Settings/TVCSettings.swift @@ -121,6 +121,14 @@ class TVCSettings: UITableViewController { let sheet = UIActivityViewController(activityItems: [URL.internalDB()], applicationActivities: nil) self.present(sheet, animated: true) } + + override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { + if section == tableView.numberOfSections - 1 { + let fs = FileManager.default.readableSizeOf(path: URL.internalDB().relativePath) + return "Database size: \(fs ?? "0 MB")" + } + return nil + } }