Initial downloads list implementation

This commit is contained in:
Ali
2022-02-11 23:49:38 +04:00
parent e87cf3710f
commit c8bc4b7f12
39 changed files with 816 additions and 139 deletions

View File

@@ -13,7 +13,7 @@ import PresentationDataUtils
import OverlayStatusController
import AccountContext
import AppBundle
import GZip
import ZipArchive
@objc private final class DebugControllerMailComposeDelegate: NSObject, MFMailComposeViewControllerDelegate {
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
@@ -252,7 +252,19 @@ private enum DebugControllerEntry: ItemListNodeEntry {
}
}
let gzippedData = TGGZipData(rawLogData, 1.0)
let tempSource = TempBox.shared.tempFile(fileName: "Log.txt")
let tempZip = TempBox.shared.tempFile(fileName: "destination.zip")
let _ = try? rawLogData.write(to: URL(fileURLWithPath: tempSource.path))
SSZipArchive.createZipFile(atPath: tempZip.path, withFilesAtPaths: [tempSource.path])
guard let gzippedData = try? Data(contentsOf: URL(fileURLWithPath: tempZip.path)) else {
return
}
TempBox.shared.dispose(tempSource)
TempBox.shared.dispose(tempZip)
let id = Int64.random(in: Int64.min ... Int64.max)
let fileResource = LocalFileMediaResource(fileId: id, size: gzippedData.count, isSecretRelated: false)
@@ -406,7 +418,19 @@ private enum DebugControllerEntry: ItemListNodeEntry {
}
}
let gzippedData = TGGZipData(rawLogData, 1.0)
let tempSource = TempBox.shared.tempFile(fileName: "Log.txt")
let tempZip = TempBox.shared.tempFile(fileName: "destination.zip")
let _ = try? rawLogData.write(to: URL(fileURLWithPath: tempSource.path))
SSZipArchive.createZipFile(atPath: tempZip.path, withFilesAtPaths: [tempSource.path])
guard let gzippedData = try? Data(contentsOf: URL(fileURLWithPath: tempZip.path)) else {
return
}
TempBox.shared.dispose(tempSource)
TempBox.shared.dispose(tempZip)
let id = Int64.random(in: Int64.min ... Int64.max)
let fileResource = LocalFileMediaResource(fileId: id, size: gzippedData.count, isSecretRelated: false)
@@ -478,7 +502,19 @@ private enum DebugControllerEntry: ItemListNodeEntry {
}
}
let gzippedData = TGGZipData(rawLogData, 1.0)
let tempSource = TempBox.shared.tempFile(fileName: "Log.txt")
let tempZip = TempBox.shared.tempFile(fileName: "destination.zip")
let _ = try? rawLogData.write(to: URL(fileURLWithPath: tempSource.path))
SSZipArchive.createZipFile(atPath: tempZip.path, withFilesAtPaths: [tempSource.path])
guard let gzippedData = try? Data(contentsOf: URL(fileURLWithPath: tempZip.path)) else {
return
}
TempBox.shared.dispose(tempSource)
TempBox.shared.dispose(tempZip)
let id = Int64.random(in: Int64.min ... Int64.max)
let fileResource = LocalFileMediaResource(fileId: id, size: gzippedData.count, isSecretRelated: false)
@@ -1055,3 +1091,61 @@ public func debugController(sharedContext: SharedAccountContext, context: Accoun
}
return controller
}
public func triggerDebugSendLogsUI(context: AccountContext, additionalInfo: String = "", pushController: @escaping (ViewController) -> Void) {
let _ = (Logger.shared.collectLogs()
|> deliverOnMainQueue).start(next: { logs in
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.onlyWriteable, .excludeDisabled]))
controller.peerSelected = { [weak controller] peer in
let peerId = peer.id
if let strongController = controller {
strongController.dismiss()
let lineFeed = "\n".data(using: .utf8)!
var rawLogData: Data = Data()
for (name, path) in logs {
if !rawLogData.isEmpty {
rawLogData.append(lineFeed)
rawLogData.append(lineFeed)
}
rawLogData.append("------ File: \(name) ------\n".data(using: .utf8)!)
if let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
rawLogData.append(data)
}
}
if !additionalInfo.isEmpty {
rawLogData.append("------ Additional Info ------\n".data(using: .utf8)!)
rawLogData.append("\(additionalInfo)".data(using: .utf8)!)
}
let tempSource = TempBox.shared.tempFile(fileName: "Log.txt")
let tempZip = TempBox.shared.tempFile(fileName: "destination.zip")
let _ = try? rawLogData.write(to: URL(fileURLWithPath: tempSource.path))
SSZipArchive.createZipFile(atPath: tempZip.path, withFilesAtPaths: [tempSource.path])
guard let gzippedData = try? Data(contentsOf: URL(fileURLWithPath: tempZip.path)) else {
return
}
TempBox.shared.dispose(tempSource)
TempBox.shared.dispose(tempZip)
let id = Int64.random(in: Int64.min ... Int64.max)
let fileResource = LocalFileMediaResource(fileId: id, size: gzippedData.count, isSecretRelated: false)
context.account.postbox.mediaBox.storeResourceData(fileResource.id, data: gzippedData)
let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: fileResource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: gzippedData.count, attributes: [.FileName(fileName: "Log-iOS-Full.txt.zip")])
let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)
let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start()
}
}
pushController(controller)
})
}