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