mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Support large files in Downloads.
This commit is contained in:
parent
87662de2a6
commit
308f106dc1
Telegram/SourceFiles
@ -16,6 +16,7 @@ namespace Core {
|
||||
namespace {
|
||||
|
||||
const auto kInMediaCacheLocation = u"*media_cache*"_q;
|
||||
constexpr auto kMaxFileSize = 4000 * int64(1024 * 1024);
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -55,13 +56,13 @@ FileLocation::FileLocation(const QFileInfo &info) : fname(info.filePath()) {
|
||||
void FileLocation::resolveFromInfo(const QFileInfo &info) {
|
||||
if (info.exists()) {
|
||||
const auto s = info.size();
|
||||
if (s > INT_MAX) {
|
||||
if (s > kMaxFileSize) {
|
||||
fname = QString();
|
||||
_bookmark = nullptr;
|
||||
size = 0;
|
||||
} else {
|
||||
modified = info.lastModified();
|
||||
size = qint32(s);
|
||||
size = s;
|
||||
}
|
||||
} else {
|
||||
fname = QString();
|
||||
@ -88,12 +89,12 @@ bool FileLocation::check() const {
|
||||
if (!f.isReadable()) return false;
|
||||
|
||||
quint64 s = f.size();
|
||||
if (s > INT_MAX) {
|
||||
if (s > kMaxFileSize) {
|
||||
DEBUG_LOG(("File location check: Wrong size %1").arg(s));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (qint32(s) != size) {
|
||||
if (s != size) {
|
||||
DEBUG_LOG(("File location check: Wrong size %1 when should be %2").arg(s).arg(size));
|
||||
return false;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
|
||||
QString fname;
|
||||
QDateTime modified;
|
||||
qint32 size;
|
||||
qint64 size = 0;
|
||||
|
||||
private:
|
||||
void resolveFromInfo(const QFileInfo &info);
|
||||
|
@ -39,7 +39,7 @@ namespace Data {
|
||||
namespace {
|
||||
|
||||
constexpr auto kClearLoadingTimeout = 5 * crl::time(1000);
|
||||
constexpr auto kMaxFileSize = 2000 * 1024 * 1024;
|
||||
constexpr auto kMaxFileSize = 4000 * int64(1024 * 1024);
|
||||
constexpr auto kMaxResolvePerAttempt = 100;
|
||||
|
||||
constexpr auto ByItem = [](const auto &entry) {
|
||||
@ -944,7 +944,7 @@ Fn<std::optional<QByteArray>()> DownloadManager::serializator(
|
||||
const auto constant = sizeof(quint64) // download.objectId
|
||||
+ sizeof(qint32) // download.type
|
||||
+ sizeof(qint64) // started
|
||||
+ sizeof(qint32) // size
|
||||
+ sizeof(quint32) // size
|
||||
+ sizeof(quint64) // itemId.peer
|
||||
+ sizeof(qint64) // itemId.msg
|
||||
+ sizeof(quint64); // peerAccessHash
|
||||
@ -963,7 +963,8 @@ Fn<std::optional<QByteArray>()> DownloadManager::serializator(
|
||||
<< quint64(id.download.objectId)
|
||||
<< qint32(id.download.type)
|
||||
<< qint64(id.started)
|
||||
<< qint32(id.size)
|
||||
// FileSize: Right now any file size fits 32 bit.
|
||||
<< quint32(id.size)
|
||||
<< quint64(id.itemId.peer.value)
|
||||
<< qint64(id.itemId.msg.bare)
|
||||
<< quint64(id.peerAccessHash)
|
||||
@ -996,7 +997,8 @@ std::vector<DownloadedId> DownloadManager::deserialize(
|
||||
auto downloadObjectId = quint64();
|
||||
auto uncheckedDownloadType = qint32();
|
||||
auto started = qint64();
|
||||
auto size = qint32();
|
||||
// FileSize: Right now any file size fits 32 bit.
|
||||
auto size = quint32();
|
||||
auto itemIdPeer = quint64();
|
||||
auto itemIdMsg = qint64();
|
||||
auto peerAccessHash = quint64();
|
||||
@ -1026,7 +1028,7 @@ std::vector<DownloadedId> DownloadManager::deserialize(
|
||||
},
|
||||
.started = started,
|
||||
.path = path,
|
||||
.size = size,
|
||||
.size = int64(size),
|
||||
.itemId = { PeerId(itemIdPeer), MsgId(itemIdMsg) },
|
||||
.peerAccessHash = peerAccessHash,
|
||||
});
|
||||
|
@ -730,12 +730,14 @@ void Account::readLocations() {
|
||||
QByteArray bookmark;
|
||||
Core::FileLocation loc;
|
||||
quint32 legacyTypeField = 0;
|
||||
quint32 size = 0;
|
||||
locations.stream >> first >> second >> legacyTypeField >> loc.fname;
|
||||
if (locations.version > 9013) {
|
||||
locations.stream >> bookmark;
|
||||
}
|
||||
locations.stream >> loc.modified >> loc.size;
|
||||
locations.stream >> loc.modified >> size;
|
||||
loc.setBookmark(bookmark);
|
||||
loc.size = int64(size);
|
||||
|
||||
if (!first && !second && !legacyTypeField && loc.fname.isEmpty() && !loc.size) { // end mark
|
||||
endMarkFound = true;
|
||||
|
Loading…
Reference in New Issue
Block a user