mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
41 lines
1.5 KiB
Swift
41 lines
1.5 KiB
Swift
import Foundation
|
|
import Display
|
|
import TelegramCore
|
|
import SyncCore
|
|
import AccountContext
|
|
import AlertUI
|
|
import PresentationDataUtils
|
|
import SettingsUI
|
|
|
|
private func totalDiskSpace() -> Int64 {
|
|
do {
|
|
let systemAttributes = try FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory() as String)
|
|
return (systemAttributes[FileAttributeKey.systemSize] as? NSNumber)?.int64Value ?? 0
|
|
} catch {
|
|
return 0
|
|
}
|
|
}
|
|
|
|
private func freeDiskSpace() -> Int64 {
|
|
do {
|
|
let systemAttributes = try FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory() as String)
|
|
return (systemAttributes[FileAttributeKey.systemFreeSize] as? NSNumber)?.int64Value ?? 0
|
|
} catch {
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func checkAvailableDiskSpace(context: AccountContext, threshold: Int64 = 100 * 1024 * 1024, push: @escaping (ViewController) -> Void) -> Bool {
|
|
guard freeDiskSpace() < threshold else {
|
|
return true
|
|
}
|
|
|
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
|
let controller = textAlertController(context: context, title: nil, text: presentationData.strings.Cache_LowDiskSpaceText, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.AccessDenied_Settings, action: {
|
|
push(storageUsageController(context: context, isModal: true))
|
|
}), TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})])
|
|
push(controller)
|
|
|
|
return false
|
|
}
|