Removed obsolete storage_file_type fields.

This commit is contained in:
John Preston 2017-03-04 14:28:21 +03:00
parent 83720d8789
commit 31009b19c6
9 changed files with 75 additions and 145 deletions

View File

@ -1657,7 +1657,7 @@ private:
}; };
MTPDocumentAttribute audioReadSongAttributes(const QString &fname, const QByteArray &data, QImage &cover, QByteArray &coverBytes, QByteArray &coverFormat) { MTPDocumentAttribute audioReadSongAttributes(const QString &fname, const QByteArray &data, QImage &cover, QByteArray &coverBytes, QByteArray &coverFormat) {
FFMpegAttributesReader reader(FileLocation(StorageFilePartial, fname), data); FFMpegAttributesReader reader(FileLocation(fname), data);
qint64 position = 0; qint64 position = 0;
if (reader.open(position)) { if (reader.open(position)) {
int32 duration = reader.duration() / reader.frequency(); int32 duration = reader.duration() / reader.frequency();

View File

@ -833,7 +833,7 @@ Manager::~Manager() {
} }
MTPDocumentAttribute readAttributes(const QString &fname, const QByteArray &data, QImage &cover) { MTPDocumentAttribute readAttributes(const QString &fname, const QByteArray &data, QImage &cover) {
FileLocation localloc(StorageFilePartial, fname); FileLocation localloc(fname);
QByteArray localdata(data); QByteArray localdata(data);
auto playId = 0ULL; auto playId = 0ULL;

View File

@ -70,7 +70,6 @@ FileLoader::FileLoader(const QString &toFile, int32 size, LocationType locationT
, _toCache(toCache) , _toCache(toCache)
, _fromCloud(fromCloud) , _fromCloud(fromCloud)
, _size(size) , _size(size)
, _type(mtpc_storage_fileUnknown)
, _locationType(locationType) { , _locationType(locationType) {
} }
@ -89,14 +88,8 @@ QPixmap FileLoader::imagePixmap(const QSize &shrinkBox) const {
} }
void FileLoader::readImage(const QSize &shrinkBox) const { void FileLoader::readImage(const QSize &shrinkBox) const {
QByteArray format; auto format = QByteArray();
switch (_type) { auto image = App::readImage(_data, &format, false);
case mtpc_storage_fileGif: format = "GIF"; break;
case mtpc_storage_fileJpeg: format = "JPG"; break;
case mtpc_storage_filePng: format = "PNG"; break;
default: format = QByteArray(); break;
}
QImage image = App::readImage(_data, &format, false);
if (!image.isNull()) { if (!image.isNull()) {
if (!shrinkBox.isEmpty() && (image.width() > shrinkBox.width() || image.height() > shrinkBox.height())) { if (!shrinkBox.isEmpty() && (image.width() > shrinkBox.width() || image.height() > shrinkBox.height())) {
_imagePixmap = App::pixmapFromImageInPlace(image.scaled(shrinkBox, Qt::KeepAspectRatio, Qt::SmoothTransformation)); _imagePixmap = App::pixmapFromImageInPlace(image.scaled(shrinkBox, Qt::KeepAspectRatio, Qt::SmoothTransformation));
@ -108,7 +101,7 @@ void FileLoader::readImage(const QSize &shrinkBox) const {
} }
float64 FileLoader::currentProgress() const { float64 FileLoader::currentProgress() const {
if (_complete) return 1.; if (_finished) return 1.;
if (!fullSize()) return 0.; if (!fullSize()) return 0.;
return snap(float64(currentOffset()) / fullSize(), 0., 1.); return snap(float64(currentOffset()) / fullSize(), 0., 1.);
} }
@ -175,13 +168,12 @@ FileLoader::~FileLoader() {
void FileLoader::localLoaded(const StorageImageSaved &result, const QByteArray &imageFormat, const QPixmap &imagePixmap) { void FileLoader::localLoaded(const StorageImageSaved &result, const QByteArray &imageFormat, const QPixmap &imagePixmap) {
_localTaskId = 0; _localTaskId = 0;
if (result.type == StorageFileUnknown) { if (result.data.isEmpty()) {
_localStatus = LocalFailed; _localStatus = LocalFailed;
start(true); start(true);
return; return;
} }
_data = result.data; _data = result.data;
_type = mtpFromStorageType(result.type);
if (!imagePixmap.isNull()) { if (!imagePixmap.isNull()) {
_imageFormat = imageFormat; _imageFormat = imageFormat;
_imagePixmap = imagePixmap; _imagePixmap = imagePixmap;
@ -199,7 +191,7 @@ void FileLoader::localLoaded(const StorageImageSaved &result, const QByteArray &
} }
} }
_complete = true; _finished = true;
if (_fileIsOpen) { if (_fileIsOpen) {
_file.close(); _file.close();
_fileIsOpen = false; _fileIsOpen = false;
@ -218,7 +210,7 @@ void FileLoader::start(bool loadFirst, bool prior) {
if (_paused) { if (_paused) {
_paused = false; _paused = false;
} }
if (_complete || tryLoadLocal()) return; if (_finished || tryLoadLocal()) return;
if (_fromCloud == LoadFromLocalOnly) { if (_fromCloud == LoadFromLocalOnly) {
cancel(); cancel();
@ -327,8 +319,8 @@ void FileLoader::cancel() {
void FileLoader::cancel(bool fail) { void FileLoader::cancel(bool fail) {
bool started = currentOffset(true) > 0; bool started = currentOffset(true) > 0;
cancelRequests(); cancelRequests();
_type = mtpc_storage_fileUnknown; _cancelled = true;
_complete = true; _finished = true;
if (_fileIsOpen) { if (_fileIsOpen) {
_file.close(); _file.close();
_fileIsOpen = false; _fileIsOpen = false;
@ -350,7 +342,7 @@ void FileLoader::cancel(bool fail) {
} }
void FileLoader::startLoading(bool loadFirst, bool prior) { void FileLoader::startLoading(bool loadFirst, bool prior) {
if ((_queue->queries >= _queue->limit && (!loadFirst || !prior)) || _complete) return; if ((_queue->queries >= _queue->limit && (!loadFirst || !prior)) || _finished) return;
loadPart(); loadPart();
} }
@ -403,9 +395,9 @@ namespace {
} }
bool mtpFileLoader::loadPart() { bool mtpFileLoader::loadPart() {
if (_complete || _lastComplete || (!_requests.isEmpty() && !_size)) { if (_finished || _lastComplete || (!_requests.isEmpty() && !_size)) {
if (DebugLogging::FileLoader() && _id) { if (DebugLogging::FileLoader() && _id) {
DEBUG_LOG(("FileLoader(%1): loadPart() returned, _complete=%2, _lastComplete=%3, _requests.size()=%4, _size=%5").arg(_id).arg(Logs::b(_complete)).arg(Logs::b(_lastComplete)).arg(_requests.size()).arg(_size)); DEBUG_LOG(("FileLoader(%1): loadPart() returned, _finished=%2, _lastComplete=%3, _requests.size()=%4, _size=%5").arg(_id).arg(Logs::b(_finished)).arg(Logs::b(_lastComplete)).arg(_requests.size()).arg(_size));
} }
return false; return false;
} }
@ -526,8 +518,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
return cancel(true); return cancel(true);
} }
} }
_type = d.vtype.type(); _finished = true;
_complete = true;
if (_fileIsOpen) { if (_fileIsOpen) {
_file.close(); _file.close();
_fileIsOpen = false; _fileIsOpen = false;
@ -543,7 +534,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
if (_locationType != UnknownFileLocation) { // audio, video, document if (_locationType != UnknownFileLocation) { // audio, video, document
MediaKey mkey = mediaKey(_locationType, _dc, _id, _version); MediaKey mkey = mediaKey(_locationType, _dc, _id, _version);
if (!_fname.isEmpty()) { if (!_fname.isEmpty()) {
Local::writeFileLocation(mkey, FileLocation(mtpToStorageType(_type), _fname)); Local::writeFileLocation(mkey, FileLocation(_fname));
} }
if (_toCache == LoadToCacheAsWell) { if (_toCache == LoadToCacheAsWell) {
if (_locationType == DocumentFileLocation) { if (_locationType == DocumentFileLocation) {
@ -553,7 +544,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
} }
} }
} else { } else {
Local::writeImage(storageKey(*_location), StorageImageSaved(mtpToStorageType(_type), _data)); Local::writeImage(storageKey(*_location), StorageImageSaved(_data));
} }
} }
} else { } else {
@ -561,7 +552,7 @@ void mtpFileLoader::partLoaded(int32 offset, const MTPupload_File &result, mtpRe
DEBUG_LOG(("FileLoader(%1): not done yet, _lastComplete=%2, _size=%3, _nextRequestOffset=%4, _requests=%5").arg(_id).arg(Logs::b(_lastComplete)).arg(_size).arg(_nextRequestOffset).arg(serializereqs(_requests))); DEBUG_LOG(("FileLoader(%1): not done yet, _lastComplete=%2, _size=%3, _nextRequestOffset=%4, _requests=%5").arg(_id).arg(Logs::b(_lastComplete)).arg(_size).arg(_nextRequestOffset).arg(serializereqs(_requests)));
} }
} }
if (_complete) { if (_finished) {
FileDownload::ImageLoaded().notify(); FileDownload::ImageLoaded().notify();
} }
@ -623,7 +614,7 @@ bool mtpFileLoader::tryLoadLocal() {
MustNotDestroy.erase(this); MustNotDestroy.erase(this);
if (_localStatus != LocalNotTried) { if (_localStatus != LocalNotTried) {
return _complete; return _finished;
} else if (_localTaskId) { } else if (_localTaskId) {
_localStatus = LocalLoading; _localStatus = LocalLoading;
return true; return true;
@ -645,7 +636,7 @@ webFileLoader::webFileLoader(const QString &url, const QString &to, LoadFromClou
} }
bool webFileLoader::loadPart() { bool webFileLoader::loadPart() {
if (_complete || _requestSent || _webLoadManager == FinishedWebLoadManager) return false; if (_finished || _requestSent || _webLoadManager == FinishedWebLoadManager) return false;
if (!_webLoadManager) { if (!_webLoadManager) {
_webLoadMainManager = new WebLoadMainManager(); _webLoadMainManager = new WebLoadMainManager();
@ -688,8 +679,7 @@ void webFileLoader::onFinished(const QByteArray &data) {
return cancel(true); return cancel(true);
} }
} }
_type = mtpc_storage_filePartial; _finished = true;
_complete = true;
if (_fileIsOpen) { if (_fileIsOpen) {
_file.close(); _file.close();
_fileIsOpen = false; _fileIsOpen = false;
@ -723,7 +713,7 @@ bool webFileLoader::tryLoadLocal() {
_localTaskId = Local::startWebFileLoad(_url, this); _localTaskId = Local::startWebFileLoad(_url, this);
if (_localStatus != LocalNotTried) { if (_localStatus != LocalNotTried) {
return _complete; return _finished;
} else if (_localTaskId) { } else if (_localTaskId) {
_localStatus = LocalLoading; _localStatus = LocalLoading;
return true; return true;

View File

@ -35,55 +35,13 @@ enum LocationType {
VideoFileLocation = 0x3d0364ec, // mtpc_inputVideoFileLocation VideoFileLocation = 0x3d0364ec, // mtpc_inputVideoFileLocation
}; };
enum StorageFileType {
StorageFileUnknown = 0xaa963b05, // mtpc_storage_fileUnknown
StorageFileJpeg = 0x7efe0e, // mtpc_storage_fileJpeg
StorageFileGif = 0xcae1aadf, // mtpc_storage_fileGif
StorageFilePng = 0xa4f63c0, // mtpc_storage_filePng
StorageFilePdf = 0xae1e508d, // mtpc_storage_filePdf
StorageFileMp3 = 0x528a0677, // mtpc_storage_fileMp3
StorageFileMov = 0x4b09ebbc, // mtpc_storage_fileMov
StorageFilePartial = 0x40bc6f52, // mtpc_storage_filePartial
StorageFileMp4 = 0xb3cea0e4, // mtpc_storage_fileMp4
StorageFileWebp = 0x1081464c, // mtpc_storage_fileWebp
};
inline StorageFileType mtpToStorageType(mtpTypeId type) {
switch (type) {
case mtpc_storage_fileJpeg: return StorageFileJpeg;
case mtpc_storage_fileGif: return StorageFileGif;
case mtpc_storage_filePng: return StorageFilePng;
case mtpc_storage_filePdf: return StorageFilePdf;
case mtpc_storage_fileMp3: return StorageFileMp3;
case mtpc_storage_fileMov: return StorageFileMov;
case mtpc_storage_filePartial: return StorageFilePartial;
case mtpc_storage_fileMp4: return StorageFileMp4;
case mtpc_storage_fileWebp: return StorageFileWebp;
case mtpc_storage_fileUnknown:
default: return StorageFileUnknown;
}
}
inline mtpTypeId mtpFromStorageType(StorageFileType type) {
switch (type) {
case StorageFileJpeg: return mtpc_storage_fileJpeg;
case StorageFileGif: return mtpc_storage_fileGif;
case StorageFilePng: return mtpc_storage_filePng;
case StorageFilePdf: return mtpc_storage_filePdf;
case StorageFileMp3: return mtpc_storage_fileMp3;
case StorageFileMov: return mtpc_storage_fileMov;
case StorageFilePartial: return mtpc_storage_filePartial;
case StorageFileMp4: return mtpc_storage_fileMp4;
case StorageFileWebp: return mtpc_storage_fileWebp;
case StorageFileUnknown:
default: return mtpc_storage_fileUnknown;
}
}
struct StorageImageSaved { struct StorageImageSaved {
StorageImageSaved() : type(StorageFileUnknown) { StorageImageSaved() = default;
explicit StorageImageSaved(const QByteArray &data) : data(data) {
} }
StorageImageSaved(StorageFileType type, const QByteArray &data) : type(type), data(data) {
}
StorageFileType type;
QByteArray data; QByteArray data;
}; };
enum LocalLoadStatus { enum LocalLoadStatus {
@ -114,11 +72,11 @@ class FileLoader : public QObject {
public: public:
FileLoader(const QString &toFile, int32 size, LocationType locationType, LoadToCacheSetting, LoadFromCloudSetting fromCloud, bool autoLoading); FileLoader(const QString &toFile, int32 size, LocationType locationType, LoadToCacheSetting, LoadFromCloudSetting fromCloud, bool autoLoading);
bool done() const { bool finished() const {
return _complete; return _finished;
} }
mtpTypeId fileType() const { bool cancelled() const {
return _type; return _cancelled;
} }
const QByteArray &bytes() const { const QByteArray &bytes() const {
return _data; return _data;
@ -179,7 +137,8 @@ protected:
bool _paused = false; bool _paused = false;
bool _autoLoading = false; bool _autoLoading = false;
bool _inQueue = false; bool _inQueue = false;
bool _complete = false; bool _finished = false;
bool _cancelled = false;
mutable LocalLoadStatus _localStatus = LocalNotTried; mutable LocalLoadStatus _localStatus = LocalNotTried;
virtual bool tryLoadLocal() = 0; virtual bool tryLoadLocal() = 0;
@ -202,7 +161,6 @@ protected:
QByteArray _data; QByteArray _data;
int32 _size; int32 _size;
mtpTypeId _type;
LocationType _locationType; LocationType _locationType;
TaskId _localTaskId = 0; TaskId _localTaskId = 0;

View File

@ -43,7 +43,7 @@ void FileUploader::uploadMedia(const FullMsgId &msgId, const SendMediaReady &med
document->setData(media.data); document->setData(media.data);
} }
if (!media.file.isEmpty()) { if (!media.file.isEmpty()) {
document->setLocation(FileLocation(StorageFilePartial, media.file)); document->setLocation(FileLocation(media.file));
} }
} }
queue.insert(msgId, File(media)); queue.insert(msgId, File(media));
@ -66,7 +66,7 @@ void FileUploader::upload(const FullMsgId &msgId, const FileLoadResultPtr &file)
document->setData(file->content); document->setData(file->content);
} }
if (!file->filepath.isEmpty()) { if (!file->filepath.isEmpty()) {
document->setLocation(FileLocation(StorageFilePartial, file->filepath)); document->setLocation(FileLocation(file->filepath));
} }
} }
queue.insert(msgId, File(file)); queue.insert(msgId, File(file));

View File

@ -691,8 +691,9 @@ void _writeLocations(WriteMapWhen when = WriteMapSoon) {
} }
EncryptedDescriptor data(size); EncryptedDescriptor data(size);
auto legacyTypeField = 0;
for (FileLocations::const_iterator i = _fileLocations.cbegin(); i != _fileLocations.cend(); ++i) { for (FileLocations::const_iterator i = _fileLocations.cbegin(); i != _fileLocations.cend(); ++i) {
data.stream << quint64(i.key().first) << quint64(i.key().second) << quint32(i.value().type) << i.value().name(); data.stream << quint64(i.key().first) << quint64(i.key().second) << quint32(legacyTypeField) << i.value().name();
if (AppVersion > 9013) { if (AppVersion > 9013) {
data.stream << i.value().bookmark(); data.stream << i.value().bookmark();
} }
@ -734,21 +735,20 @@ void _readLocations() {
quint64 first, second; quint64 first, second;
QByteArray bookmark; QByteArray bookmark;
FileLocation loc; FileLocation loc;
quint32 type; quint32 legacyTypeField = 0;
locations.stream >> first >> second >> type >> 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 >> loc.size;
loc.setBookmark(bookmark); loc.setBookmark(bookmark);
if (!first && !second && !type && loc.fname.isEmpty() && !loc.size) { // end mark if (!first && !second && !legacyTypeField && loc.fname.isEmpty() && !loc.size) { // end mark
endMarkFound = true; endMarkFound = true;
break; break;
} }
MediaKey key(first, second); MediaKey key(first, second);
loc.type = StorageFileType(type);
_fileLocations.insert(key, loc); _fileLocations.insert(key, loc);
_fileLocationPairs.insert(loc.fname, FileLocationPair(key, loc)); _fileLocationPairs.insert(loc.fname, FileLocationPair(key, loc));
@ -2628,19 +2628,8 @@ void writeImage(const StorageKey &location, const ImagePtr &image) {
if (image->isNull() || !image->loaded()) return; if (image->isNull() || !image->loaded()) return;
if (_imagesMap.constFind(location) != _imagesMap.cend()) return; if (_imagesMap.constFind(location) != _imagesMap.cend()) return;
QByteArray fmt = image->savedFormat(); image->forget();
StorageFileType format = StorageFileUnknown; writeImage(location, StorageImageSaved(image->savedData()), false);
if (fmt == "JPG") {
format = StorageFileJpeg;
} else if (fmt == "PNG") {
format = StorageFilePng;
} else if (fmt == "GIF") {
format = StorageFileGif;
}
if (format) {
image->forget();
writeImage(location, StorageImageSaved(format, image->savedData()), false);
}
} }
void writeImage(const StorageKey &location, const StorageImageSaved &image, bool overwrite) { void writeImage(const StorageKey &location, const StorageImageSaved &image, bool overwrite) {
@ -2656,8 +2645,12 @@ void writeImage(const StorageKey &location, const StorageImageSaved &image, bool
} else if (!overwrite) { } else if (!overwrite) {
return; return;
} }
auto legacyTypeField = 0;
EncryptedDescriptor data(sizeof(quint64) * 2 + sizeof(quint32) + sizeof(quint32) + image.data.size()); EncryptedDescriptor data(sizeof(quint64) * 2 + sizeof(quint32) + sizeof(quint32) + image.data.size());
data.stream << quint64(location.first) << quint64(location.second) << quint32(image.type) << image.data; data.stream << quint64(location.first) << quint64(location.second) << quint32(legacyTypeField) << image.data;
FileWriteDescriptor file(i.value().first, FileOption::User); FileWriteDescriptor file(i.value().first, FileOption::User);
file.writeEncrypted(data); file.writeEncrypted(data);
if (i.value().second != size) { if (i.value().second != size) {
@ -2681,15 +2674,15 @@ public:
QByteArray imageData; QByteArray imageData;
quint64 locFirst, locSecond; quint64 locFirst, locSecond;
quint32 imageType; quint32 legacyTypeField = 0;
readFromStream(image.stream, locFirst, locSecond, imageType, imageData); readFromStream(image.stream, locFirst, locSecond, imageData);
// we're saving files now before we have actual location // we're saving files now before we have actual location
//if (locFirst != _location.first || locSecond != _location.second) { //if (locFirst != _location.first || locSecond != _location.second) {
// return; // return;
//} //}
_result = new Result(StorageFileType(imageType), imageData, _readImageFlag); _result = new Result(imageData, _readImageFlag);
} }
void finish() { void finish() {
if (_result) { if (_result) {
@ -2699,7 +2692,7 @@ public:
_loader->localLoaded(StorageImageSaved()); _loader->localLoaded(StorageImageSaved());
} }
} }
virtual void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) = 0; virtual void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, QByteArray &data) = 0;
virtual void clearInMap() = 0; virtual void clearInMap() = 0;
virtual ~AbstractCachedLoadTask() { virtual ~AbstractCachedLoadTask() {
delete base::take(_result); delete base::take(_result);
@ -2710,25 +2703,19 @@ protected:
StorageKey _location; StorageKey _location;
bool _readImageFlag; bool _readImageFlag;
struct Result { struct Result {
Result(StorageFileType type, const QByteArray &data, bool readImageFlag) : image(type, data) { Result(const QByteArray &data, bool readImageFlag) : image(data) {
if (readImageFlag) { if (readImageFlag) {
QByteArray guessFormat; auto realFormat = QByteArray();
switch (type) { pixmap = App::pixmapFromImageInPlace(App::readImage(data, &realFormat, false));
case StorageFileGif: guessFormat = "GIF"; break;
case StorageFileJpeg: guessFormat = "JPG"; break;
case StorageFilePng: guessFormat = "PNG"; break;
case StorageFileWebp: guessFormat = "WEBP"; break;
default: guessFormat = QByteArray(); break;
}
pixmap = App::pixmapFromImageInPlace(App::readImage(data, &guessFormat, false));
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
format = guessFormat; format = realFormat;
} }
} }
} }
StorageImageSaved image; StorageImageSaved image;
QByteArray format; QByteArray format;
QPixmap pixmap; QPixmap pixmap;
}; };
mtpFileLoader *_loader; mtpFileLoader *_loader;
Result *_result; Result *_result;
@ -2740,8 +2727,9 @@ public:
ImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) : ImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
AbstractCachedLoadTask(key, location, true, loader) { AbstractCachedLoadTask(key, location, true, loader) {
} }
void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) { void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, QByteArray &data) override {
stream >> first >> second >> type >> data; qint32 legacyTypeField = 0;
stream >> first >> second >> legacyTypeField >> data;
} }
void clearInMap() { void clearInMap() {
StorageMap::iterator j = _imagesMap.find(_location); StorageMap::iterator j = _imagesMap.find(_location);
@ -2798,9 +2786,8 @@ public:
StickerImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) : StickerImageLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
AbstractCachedLoadTask(key, location, true, loader) { AbstractCachedLoadTask(key, location, true, loader) {
} }
void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) { void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, QByteArray &data) {
stream >> first >> second >> data; stream >> first >> second >> data;
type = StorageFilePartial;
} }
void clearInMap() { void clearInMap() {
auto j = _stickerImagesMap.find(_location); auto j = _stickerImagesMap.find(_location);
@ -2872,9 +2859,8 @@ public:
AudioLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) : AudioLoadTask(const FileKey &key, const StorageKey &location, mtpFileLoader *loader) :
AbstractCachedLoadTask(key, location, false, loader) { AbstractCachedLoadTask(key, location, false, loader) {
} }
void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, quint32 &type, QByteArray &data) { void readFromStream(QDataStream &stream, quint64 &first, quint64 &second, QByteArray &data) {
stream >> first >> second >> data; stream >> first >> second >> data;
type = StorageFilePartial;
} }
void clearInMap() { void clearInMap() {
auto j = _audiosMap.find(_location); auto j = _audiosMap.find(_location);
@ -2962,7 +2948,7 @@ public:
QString url; QString url;
image.stream >> url >> imageData; image.stream >> url >> imageData;
_result = new Result(StorageFilePartial, imageData); _result = new Result(imageData);
} }
void finish() { void finish() {
if (_result) { if (_result) {
@ -2985,7 +2971,7 @@ protected:
FileKey _key; FileKey _key;
QString _url; QString _url;
struct Result { struct Result {
Result(StorageFileType type, const QByteArray &data) : image(type, data) { explicit Result(const QByteArray &data) : image(data) {
QByteArray guessFormat; QByteArray guessFormat;
pixmap = App::pixmapFromImageInPlace(App::readImage(data, &guessFormat, false)); pixmap = App::pixmapFromImageInPlace(App::readImage(data, &guessFormat, false));
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
@ -2995,6 +2981,7 @@ protected:
StorageImageSaved image; StorageImageSaved image;
QByteArray format; QByteArray format;
QPixmap pixmap; QPixmap pixmap;
}; };
webFileLoader *_loader; webFileLoader *_loader;
Result *_result; Result *_result;

View File

@ -1520,12 +1520,12 @@ void DocumentData::performActionOnLoad() {
} }
bool DocumentData::loaded(FilePathResolveType type) const { bool DocumentData::loaded(FilePathResolveType type) const {
if (loading() && _loader->done()) { if (loading() && _loader->finished()) {
if (_loader->fileType() == mtpc_storage_fileUnknown) { if (_loader->cancelled()) {
destroyLoaderDelayed(CancelledMtpFileLoader); destroyLoaderDelayed(CancelledMtpFileLoader);
} else { } else {
auto that = const_cast<DocumentData*>(this); auto that = const_cast<DocumentData*>(this);
that->_location = FileLocation(mtpToStorageType(_loader->fileType()), _loader->fileName()); that->_location = FileLocation(_loader->fileName());
that->_data = _loader->bytes(); that->_data = _loader->bytes();
if (that->sticker() && !_loader->imagePixmap().isNull()) { if (that->sticker() && !_loader->imagePixmap().isNull()) {
that->sticker()->img = ImagePtr(_data, _loader->imageFormat(), _loader->imagePixmap()); that->sticker()->img = ImagePtr(_data, _loader->imageFormat(), _loader->imagePixmap());
@ -1580,8 +1580,8 @@ void DocumentData::save(const QString &toFile, ActionOnLoad action, const FullMs
f.write(_data); f.write(_data);
f.close(); f.close();
setLocation(FileLocation(StorageFilePartial, toFile)); setLocation(FileLocation(toFile));
Local::writeFileLocation(mediaKey(), FileLocation(mtpToStorageType(mtpc_storage_filePartial), toFile)); Local::writeFileLocation(mediaKey(), FileLocation(toFile));
} else if (l.accessEnable()) { } else if (l.accessEnable()) {
auto alreadyName = l.name(); auto alreadyName = l.name();
if (alreadyName != toFile) { if (alreadyName != toFile) {
@ -1738,7 +1738,7 @@ QString DocumentData::filepath(FilePathResolveType type, bool forceSavingAs) con
if (f.open(QIODevice::WriteOnly)) { if (f.open(QIODevice::WriteOnly)) {
if (f.write(data()) == data().size()) { if (f.write(data()) == data().size()) {
f.close(); f.close();
const_cast<DocumentData*>(this)->_location = FileLocation(StorageFilePartial, filename); const_cast<DocumentData*>(this)->_location = FileLocation(filename);
Local::writeFileLocation(mediaKey(), _location); Local::writeFileLocation(mediaKey(), _location);
result = filename; result = filename;
} }

View File

@ -823,7 +823,7 @@ int64 imageCacheSize() {
} }
void RemoteImage::doCheckload() const { void RemoteImage::doCheckload() const {
if (!amLoading() || !_loader->done()) return; if (!amLoading() || !_loader->finished()) return;
QPixmap data = _loader->imagePixmap(shrinkBox()); QPixmap data = _loader->imagePixmap(shrinkBox());
if (data.isNull()) { if (data.isNull()) {
@ -969,7 +969,7 @@ StorageImage::StorageImage(const StorageImageLocation &location, QByteArray &byt
, _size(bytes.size()) { , _size(bytes.size()) {
setData(bytes); setData(bytes);
if (!_location.isNull()) { if (!_location.isNull()) {
Local::writeImage(storageKey(_location), StorageImageSaved(mtpToStorageType(mtpc_storage_filePartial), bytes)); Local::writeImage(storageKey(_location), StorageImageSaved(bytes));
} }
} }
@ -1178,7 +1178,7 @@ StorageImage *getImage(const StorageImageLocation &location, const QByteArray &b
QByteArray bytesArr(bytes); QByteArray bytesArr(bytes);
i.value()->setData(bytesArr); i.value()->setData(bytesArr);
if (!location.isNull()) { if (!location.isNull()) {
Local::writeImage(key, StorageImageSaved(mtpToStorageType(mtpc_storage_filePartial), bytes)); Local::writeImage(key, StorageImageSaved(bytes));
} }
} }
return i.value(); return i.value();
@ -1196,10 +1196,9 @@ ReadAccessEnabler::~ReadAccessEnabler() {
if (_bookmark && !_failed) _bookmark->disable(); if (_bookmark && !_failed) _bookmark->disable();
} }
FileLocation::FileLocation(StorageFileType type, const QString &name) : type(type), fname(name) { FileLocation::FileLocation(const QString &name) : fname(name) {
if (fname.isEmpty()) { if (fname.isEmpty()) {
size = 0; size = 0;
type = StorageFileUnknown;
} else { } else {
setBookmark(psPathBookmark(name)); setBookmark(psPathBookmark(name));
@ -1210,7 +1209,6 @@ FileLocation::FileLocation(StorageFileType type, const QString &name) : type(typ
fname = QString(); fname = QString();
_bookmark.clear(); _bookmark.clear();
size = 0; size = 0;
type = StorageFileUnknown;
} else { } else {
modified = f.lastModified(); modified = f.lastModified();
size = qint32(s); size = qint32(s);
@ -1219,7 +1217,6 @@ FileLocation::FileLocation(StorageFileType type, const QString &name) : type(typ
fname = QString(); fname = QString();
_bookmark.clear(); _bookmark.clear();
size = 0; size = 0;
type = StorageFileUnknown;
} }
} }
} }

View File

@ -483,9 +483,8 @@ private:
class FileLocation { class FileLocation {
public: public:
FileLocation(StorageFileType type, const QString &name); FileLocation() = default;
FileLocation() : size(0) { explicit FileLocation(const QString &name);
}
bool check() const; bool check() const;
const QString &name() const; const QString &name() const;
@ -498,7 +497,6 @@ public:
bool accessEnable() const; bool accessEnable() const;
void accessDisable() const; void accessDisable() const;
StorageFileType type;
QString fname; QString fname;
QDateTime modified; QDateTime modified;
qint32 size; qint32 size;
@ -508,7 +506,7 @@ private:
}; };
inline bool operator==(const FileLocation &a, const FileLocation &b) { inline bool operator==(const FileLocation &a, const FileLocation &b) {
return a.type == b.type && a.name() == b.name() && a.modified == b.modified && a.size == b.size; return (a.name() == b.name()) && (a.modified == b.modified) && (a.size == b.size);
} }
inline bool operator!=(const FileLocation &a, const FileLocation &b) { inline bool operator!=(const FileLocation &a, const FileLocation &b) {
return !(a == b); return !(a == b);