diff --git a/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift b/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift index 31fe0df115..bb511ddb3a 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift @@ -11,20 +11,35 @@ import LegacyComponents import ItemListUI import PresentationDataUtils +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 stringForCacheSize(strings: PresentationStrings, size: Int32) -> String { - if size > 50 { + if size > 100 { return strings.Cache_NoLimit } else { return dataSizeString(Int64(size) * 1024 * 1024 * 1024) } } -private let maximumCacheSizeValues: [Int32] = [ - 5, - 20, - 50, - Int32.max -] +private let maximumCacheSizeValues: [Int32] = { + let diskSpace = totalDiskSpace() + if diskSpace > 100 * 1024 * 1024 * 1024 { + return [5, 20, 50, Int32.max] + } else if diskSpace > 50 * 1024 * 1024 * 1024 { + return [5, 16, 32, Int32.max] + } else if diskSpace > 24 * 1024 * 1024 * 1024 { + return [2, 8, 16, Int32.max] + } else { + return [1, 4, 8, Int32.max] + } +}() final class MaximumCacheSizePickerItem: ListViewItem, ItemListItem { let theme: PresentationTheme diff --git a/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift b/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift index e76d3bea1b..9b9882a2b2 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift @@ -291,9 +291,9 @@ private func storageUsageControllerEntries(presentationData: PresentationData, c entries.append(.keepMedia(presentationData.theme, presentationData.strings, cacheSettings.defaultCacheStorageTimeout)) entries.append(.keepMediaInfo(presentationData.theme, presentationData.strings.Cache_KeepMediaHelp)) - /*entries.append(.maximumSizeHeader(presentationData.theme, presentationData.strings.Cache_MaximumCacheSize.uppercased())) + entries.append(.maximumSizeHeader(presentationData.theme, presentationData.strings.Cache_MaximumCacheSize.uppercased())) entries.append(.maximumSize(presentationData.theme, presentationData.strings, cacheSettings.defaultCacheStorageLimitGigabytes)) - entries.append(.maximumSizeInfo(presentationData.theme, presentationData.strings.Cache_MaximumCacheSizeHelp))*/ + entries.append(.maximumSizeInfo(presentationData.theme, presentationData.strings.Cache_MaximumCacheSizeHelp)) var addedHeader = false