mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-29 06:26:10 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
60 lines
2.5 KiB
Swift
60 lines
2.5 KiB
Swift
import Foundation
|
|
import SGLogging
|
|
import SwiftSignalKit
|
|
|
|
|
|
extension SGLogger {
|
|
public func collectLogs(prefix: String? = nil) -> Signal<[(String, String)], NoError> {
|
|
return Signal { subscriber in
|
|
self.queue.async {
|
|
let logsPath: String
|
|
if let prefix = prefix {
|
|
logsPath = self.rootPath + prefix
|
|
} else {
|
|
logsPath = self.basePath
|
|
}
|
|
|
|
var result: [(Date, String, String)] = []
|
|
if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) {
|
|
for url in files {
|
|
if url.lastPathComponent.hasPrefix("log-") {
|
|
if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate {
|
|
result.append((creationDate, url.lastPathComponent, url.path))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
result.sort(by: { $0.0 < $1.0 })
|
|
subscriber.putNext(result.map { ($0.1, $0.2) })
|
|
subscriber.putCompletion()
|
|
}
|
|
|
|
return EmptyDisposable
|
|
}
|
|
}
|
|
|
|
public func collectLogs(basePath: String) -> Signal<[(String, String)], NoError> {
|
|
return Signal { subscriber in
|
|
self.queue.async {
|
|
let logsPath: String = basePath
|
|
|
|
var result: [(Date, String, String)] = []
|
|
if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) {
|
|
for url in files {
|
|
if url.lastPathComponent.hasPrefix("log-") {
|
|
if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate {
|
|
result.append((creationDate, url.lastPathComponent, url.path))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
result.sort(by: { $0.0 < $1.0 })
|
|
subscriber.putNext(result.map { ($0.1, $0.2) })
|
|
subscriber.putCompletion()
|
|
}
|
|
|
|
return EmptyDisposable
|
|
}
|
|
}
|
|
}
|