mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Check tmp dir size
This commit is contained in:
parent
524e8f1e81
commit
b92a46ee58
@ -25,6 +25,7 @@ swift_library(
|
|||||||
"//submodules/GZip:GZip",
|
"//submodules/GZip:GZip",
|
||||||
"//third-party/ZipArchive:ZipArchive",
|
"//third-party/ZipArchive:ZipArchive",
|
||||||
"//submodules/InAppPurchaseManager:InAppPurchaseManager",
|
"//submodules/InAppPurchaseManager:InAppPurchaseManager",
|
||||||
|
"//submodules/Utils/DarwinDirStat",
|
||||||
],
|
],
|
||||||
visibility = [
|
visibility = [
|
||||||
"//visibility:public",
|
"//visibility:public",
|
||||||
|
@ -16,6 +16,7 @@ import AppBundle
|
|||||||
import ZipArchive
|
import ZipArchive
|
||||||
import WebKit
|
import WebKit
|
||||||
import InAppPurchaseManager
|
import InAppPurchaseManager
|
||||||
|
import DarwinDirStat
|
||||||
|
|
||||||
@objc private final class DebugControllerMailComposeDelegate: NSObject, MFMailComposeViewControllerDelegate {
|
@objc private final class DebugControllerMailComposeDelegate: NSObject, MFMailComposeViewControllerDelegate {
|
||||||
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
|
||||||
@ -947,10 +948,15 @@ private enum DebugControllerEntry: ItemListNodeEntry {
|
|||||||
case .resetTranslationStates:
|
case .resetTranslationStates:
|
||||||
return ItemListActionItem(presentationData: presentationData, title: "Reset Translation States", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
|
return ItemListActionItem(presentationData: presentationData, title: "Reset Translation States", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
|
||||||
if let context = arguments.context {
|
if let context = arguments.context {
|
||||||
let _ = context.engine.itemCache.clear(collectionIds: [
|
let size = statForDirectory(path: NSTemporaryDirectory())
|
||||||
ApplicationSpecificItemCacheCollectionId.translationState
|
let controller = textAlertController(context: context, title: nil, text: "temp dir size \(size)", actions: [TextAlertAction(type: .genericAction, title: "OK", action: {})])
|
||||||
]).start()
|
arguments.presentController(controller, nil)
|
||||||
}
|
}
|
||||||
|
// if let context = arguments.context {
|
||||||
|
// let _ = context.engine.itemCache.clear(collectionIds: [
|
||||||
|
// ApplicationSpecificItemCacheCollectionId.translationState
|
||||||
|
// ]).start()
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
case .crash:
|
case .crash:
|
||||||
return ItemListActionItem(presentationData: presentationData, title: "Crash", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
|
return ItemListActionItem(presentationData: presentationData, title: "Crash", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
|
||||||
@ -1539,3 +1545,30 @@ public func triggerDebugSendLogsUI(context: AccountContext, additionalInfo: Stri
|
|||||||
pushController(controller)
|
pushController(controller)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func statForDirectory(path: String) -> Int64 {
|
||||||
|
if #available(macOS 10.13, *) {
|
||||||
|
var s = darwin_dirstat()
|
||||||
|
var result = dirstat_np(path, 1, &s, MemoryLayout<darwin_dirstat>.size)
|
||||||
|
if result != -1 {
|
||||||
|
return Int64(s.total_size)
|
||||||
|
} else {
|
||||||
|
result = dirstat_np(path, 0, &s, MemoryLayout<darwin_dirstat>.size)
|
||||||
|
if result != -1 {
|
||||||
|
return Int64(s.total_size)
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
let folderURL = URL(fileURLWithPath: path)
|
||||||
|
var folderSize: Int64 = 0
|
||||||
|
if let files = try? fileManager.contentsOfDirectory(at: folderURL, includingPropertiesForKeys: nil, options: []) {
|
||||||
|
for file in files {
|
||||||
|
folderSize += (fileSize(file.path) ?? 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return folderSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user