2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
class FileLoader;
|
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
namespace Storage {
|
|
|
|
namespace Cache {
|
|
|
|
struct Key;
|
|
|
|
} // namespace Cache
|
|
|
|
} // namespace Storage
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
struct UpdatedFileReferences;
|
|
|
|
} // namespace Data
|
|
|
|
|
2017-03-04 19:36:59 +00:00
|
|
|
enum LoadFromCloudSetting {
|
|
|
|
LoadFromCloudOrLocal,
|
|
|
|
LoadFromLocalOnly,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum LoadToCacheSetting {
|
|
|
|
LoadToFileOnly,
|
|
|
|
LoadToCacheAsWell,
|
|
|
|
};
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
using InMemoryKey = std::pair<uint64, uint64>;
|
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct hash<InMemoryKey> {
|
|
|
|
size_t operator()(InMemoryKey value) const {
|
|
|
|
auto seed = hash<uint64>()(value.first);
|
|
|
|
seed ^= hash<uint64>()(value.second)
|
|
|
|
+ std::size_t(0x9e3779b9)
|
|
|
|
+ (seed << 6) + (seed >> 2);
|
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
class StorageFileLocation {
|
|
|
|
public:
|
|
|
|
// Those are used in serialization, don't change.
|
2019-03-22 14:19:43 +00:00
|
|
|
enum class Type : uint8 {
|
|
|
|
Legacy = 0x00,
|
2019-03-22 13:43:34 +00:00
|
|
|
Encrypted = 0x01,
|
|
|
|
Document = 0x02,
|
|
|
|
Secure = 0x03,
|
|
|
|
Takeout = 0x04,
|
|
|
|
Photo = 0x05,
|
|
|
|
PeerPhoto = 0x06,
|
|
|
|
StickerSetThumb = 0x07,
|
|
|
|
};
|
|
|
|
|
|
|
|
StorageFileLocation() = default;
|
2019-03-22 14:19:43 +00:00
|
|
|
StorageFileLocation(
|
|
|
|
int32 dcId,
|
|
|
|
int32 self,
|
|
|
|
const MTPInputFileLocation &tl);
|
2019-03-22 13:43:34 +00:00
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] StorageFileLocation convertToModern(
|
|
|
|
Type type,
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash) const;
|
|
|
|
|
|
|
|
[[nodiscard]] int32 dcId() const;
|
2019-03-25 11:50:42 +00:00
|
|
|
[[nodiscard]] uint64 objectId() const;
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] MTPInputFileLocation tl(int32 self) const;
|
2019-03-22 13:43:34 +00:00
|
|
|
|
|
|
|
[[nodiscard]] QByteArray serialize() const;
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] int serializeSize() const;
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] static std::optional<StorageFileLocation> FromSerialized(
|
|
|
|
const QByteArray &serialized);
|
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] Type type() const;
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] bool valid() const;
|
2020-05-28 10:00:51 +00:00
|
|
|
[[nodiscard]] bool isLegacy() const;
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] Storage::Cache::Key cacheKey() const;
|
2019-03-25 09:17:47 +00:00
|
|
|
[[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const;
|
2019-03-22 13:43:34 +00:00
|
|
|
|
2019-04-03 20:05:29 +00:00
|
|
|
// We have to allow checking this because of a serialization bug.
|
|
|
|
[[nodiscard]] bool isDocumentThumbnail() const;
|
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] QByteArray fileReference() const;
|
2019-03-22 14:19:43 +00:00
|
|
|
bool refreshFileReference(const Data::UpdatedFileReferences &updates);
|
|
|
|
bool refreshFileReference(const QByteArray &data);
|
|
|
|
|
|
|
|
[[nodiscard]] static const StorageFileLocation &Invalid();
|
2019-03-22 13:43:34 +00:00
|
|
|
|
|
|
|
friend bool operator==(
|
|
|
|
const StorageFileLocation &a,
|
|
|
|
const StorageFileLocation &b);
|
2019-04-12 12:33:21 +00:00
|
|
|
friend bool operator<(
|
|
|
|
const StorageFileLocation &a,
|
|
|
|
const StorageFileLocation &b);
|
2019-03-22 13:43:34 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
private:
|
2019-03-22 13:43:34 +00:00
|
|
|
uint16 _dcId = 0;
|
2019-03-22 14:19:43 +00:00
|
|
|
Type _type = Type::Legacy;
|
2019-03-22 13:43:34 +00:00
|
|
|
uint8 _sizeLetter = 0;
|
|
|
|
int32 _localId = 0;
|
|
|
|
uint64 _id = 0;
|
|
|
|
uint64 _accessHash = 0;
|
|
|
|
uint64 _volumeId = 0;
|
2019-05-20 14:57:25 +00:00
|
|
|
uint32 _inMessagePeerId = 0; // > 0 'userId', < 0 '-channelId'.
|
|
|
|
uint32 _inMessageId = 0;
|
2019-03-22 13:43:34 +00:00
|
|
|
QByteArray _fileReference;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator!=(
|
|
|
|
const StorageFileLocation &a,
|
|
|
|
const StorageFileLocation &b) {
|
|
|
|
return !(a == b);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 12:33:21 +00:00
|
|
|
inline bool operator>(
|
|
|
|
const StorageFileLocation &a,
|
|
|
|
const StorageFileLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const StorageFileLocation &a,
|
|
|
|
const StorageFileLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const StorageFileLocation &a,
|
|
|
|
const StorageFileLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2015-12-24 19:26:28 +00:00
|
|
|
class StorageImageLocation {
|
|
|
|
public:
|
2017-03-05 17:33:32 +00:00
|
|
|
StorageImageLocation() = default;
|
2018-07-13 16:49:46 +00:00
|
|
|
StorageImageLocation(
|
2019-03-22 13:43:34 +00:00
|
|
|
const StorageFileLocation &file,
|
|
|
|
int width,
|
|
|
|
int height);
|
2018-07-13 16:49:46 +00:00
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] QByteArray serialize() const;
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] int serializeSize() const;
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] static std::optional<StorageImageLocation> FromSerialized(
|
|
|
|
const QByteArray &serialized);
|
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] StorageImageLocation convertToModern(
|
|
|
|
StorageFileLocation::Type type,
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash) const {
|
|
|
|
return StorageImageLocation(
|
|
|
|
_file.convertToModern(type, id, accessHash),
|
|
|
|
_width,
|
|
|
|
_height);
|
|
|
|
}
|
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] const StorageFileLocation &file() const {
|
|
|
|
return _file;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] int width() const {
|
|
|
|
return _width;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] int height() const {
|
|
|
|
return _height;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
|
|
|
|
void setSize(int width, int height) {
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
[[nodiscard]] StorageFileLocation::Type type() const {
|
|
|
|
return _file.type();
|
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] bool valid() const {
|
|
|
|
return _file.valid();
|
2018-07-13 16:49:46 +00:00
|
|
|
}
|
2020-05-28 10:00:51 +00:00
|
|
|
[[nodiscard]] bool isLegacy() const {
|
|
|
|
return _file.isLegacy();
|
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
[[nodiscard]] QByteArray fileReference() const {
|
|
|
|
return _file.fileReference();
|
2017-12-05 06:41:43 +00:00
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
bool refreshFileReference(const QByteArray &data) {
|
|
|
|
return _file.refreshFileReference(data);
|
2017-12-05 06:41:43 +00:00
|
|
|
}
|
2019-03-22 14:19:43 +00:00
|
|
|
bool refreshFileReference(const Data::UpdatedFileReferences &updates) {
|
|
|
|
return _file.refreshFileReference(updates);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] static const StorageImageLocation &Invalid() {
|
|
|
|
static auto result = StorageImageLocation();
|
|
|
|
return result;
|
|
|
|
}
|
2017-12-05 06:41:43 +00:00
|
|
|
|
2018-07-13 16:49:46 +00:00
|
|
|
friend inline bool operator==(
|
|
|
|
const StorageImageLocation &a,
|
|
|
|
const StorageImageLocation &b) {
|
2019-03-22 13:43:34 +00:00
|
|
|
return (a._file == b._file);
|
2015-12-24 19:26:28 +00:00
|
|
|
}
|
2019-04-12 12:33:21 +00:00
|
|
|
friend inline bool operator<(
|
|
|
|
const StorageImageLocation &a,
|
|
|
|
const StorageImageLocation &b) {
|
|
|
|
return (a._file < b._file);
|
|
|
|
}
|
2015-12-24 19:26:28 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
private:
|
2019-03-22 13:43:34 +00:00
|
|
|
StorageFileLocation _file;
|
|
|
|
int _width = 0;
|
|
|
|
int _height = 0;
|
|
|
|
|
2015-05-19 15:46:45 +00:00
|
|
|
};
|
|
|
|
|
2019-03-22 13:43:34 +00:00
|
|
|
inline bool operator!=(
|
|
|
|
const StorageImageLocation &a,
|
|
|
|
const StorageImageLocation &b) {
|
2015-08-07 12:11:50 +00:00
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:33:21 +00:00
|
|
|
inline bool operator>(
|
|
|
|
const StorageImageLocation &a,
|
|
|
|
const StorageImageLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const StorageImageLocation &a,
|
|
|
|
const StorageImageLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const StorageImageLocation &a,
|
|
|
|
const StorageImageLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
class WebFileLocation {
|
2017-03-05 17:33:32 +00:00
|
|
|
public:
|
2018-03-04 20:04:13 +00:00
|
|
|
WebFileLocation() = default;
|
2019-03-25 11:50:42 +00:00
|
|
|
WebFileLocation(const QByteArray &url, uint64 accessHash)
|
2018-03-04 20:04:13 +00:00
|
|
|
: _accessHash(accessHash)
|
2019-03-25 11:50:42 +00:00
|
|
|
, _url(url) {
|
2017-03-05 17:33:32 +00:00
|
|
|
}
|
|
|
|
bool isNull() const {
|
2019-03-25 11:50:42 +00:00
|
|
|
return _url.isEmpty();
|
2017-03-05 17:33:32 +00:00
|
|
|
}
|
|
|
|
uint64 accessHash() const {
|
|
|
|
return _accessHash;
|
|
|
|
}
|
|
|
|
const QByteArray &url() const {
|
|
|
|
return _url;
|
|
|
|
}
|
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
static WebFileLocation Null;
|
2017-03-05 17:33:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint64 _accessHash = 0;
|
|
|
|
QByteArray _url;
|
|
|
|
|
2018-07-13 16:49:46 +00:00
|
|
|
friend inline bool operator==(
|
|
|
|
const WebFileLocation &a,
|
|
|
|
const WebFileLocation &b) {
|
2019-03-25 11:50:42 +00:00
|
|
|
return (a._accessHash == b._accessHash)
|
2018-07-13 16:49:46 +00:00
|
|
|
&& (a._url == b._url);
|
2017-03-05 17:33:32 +00:00
|
|
|
}
|
2019-04-12 12:33:21 +00:00
|
|
|
friend inline bool operator<(
|
|
|
|
const WebFileLocation &a,
|
|
|
|
const WebFileLocation &b) {
|
|
|
|
return std::tie(a._accessHash, a._url)
|
|
|
|
< std::tie(b._accessHash, b._url);
|
|
|
|
}
|
2017-03-05 17:33:32 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-03-04 20:04:13 +00:00
|
|
|
inline bool operator!=(const WebFileLocation &a, const WebFileLocation &b) {
|
2017-03-05 17:33:32 +00:00
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:33:21 +00:00
|
|
|
inline bool operator>(const WebFileLocation &a, const WebFileLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(const WebFileLocation &a, const WebFileLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(const WebFileLocation &a, const WebFileLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2018-10-08 18:14:05 +00:00
|
|
|
struct GeoPointLocation {
|
|
|
|
float64 lat = 0.;
|
|
|
|
float64 lon = 0.;
|
|
|
|
uint64 access = 0;
|
|
|
|
int32 width = 0;
|
|
|
|
int32 height = 0;
|
|
|
|
int32 zoom = 0;
|
|
|
|
int32 scale = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(
|
|
|
|
const GeoPointLocation &a,
|
|
|
|
const GeoPointLocation &b) {
|
|
|
|
return (a.lat == b.lat)
|
|
|
|
&& (a.lon == b.lon)
|
|
|
|
&& (a.access == b.access)
|
|
|
|
&& (a.width == b.width)
|
|
|
|
&& (a.height == b.height)
|
|
|
|
&& (a.zoom == b.zoom)
|
|
|
|
&& (a.scale == b.scale);
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:33:21 +00:00
|
|
|
inline bool operator<(
|
|
|
|
const GeoPointLocation &a,
|
|
|
|
const GeoPointLocation &b) {
|
|
|
|
return std::tie(
|
|
|
|
a.access,
|
|
|
|
a.lat,
|
|
|
|
a.lon,
|
|
|
|
a.width,
|
|
|
|
a.height,
|
|
|
|
a.zoom,
|
|
|
|
a.scale)
|
|
|
|
< std::tie(
|
|
|
|
b.access,
|
|
|
|
b.lat,
|
|
|
|
b.lon,
|
|
|
|
b.width,
|
|
|
|
b.height,
|
|
|
|
b.zoom,
|
|
|
|
b.scale);
|
|
|
|
}
|
|
|
|
|
2018-10-08 18:14:05 +00:00
|
|
|
inline bool operator!=(
|
|
|
|
const GeoPointLocation &a,
|
|
|
|
const GeoPointLocation &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2019-04-12 12:33:21 +00:00
|
|
|
inline bool operator>(
|
|
|
|
const GeoPointLocation &a,
|
|
|
|
const GeoPointLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const GeoPointLocation &a,
|
|
|
|
const GeoPointLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const GeoPointLocation &a,
|
|
|
|
const GeoPointLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2020-04-16 09:06:46 +00:00
|
|
|
struct PlainUrlLocation {
|
|
|
|
QString url;
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const PlainUrlLocation &a,
|
|
|
|
const PlainUrlLocation &b) {
|
|
|
|
return (a.url == b.url);
|
|
|
|
}
|
|
|
|
friend inline bool operator<(
|
|
|
|
const PlainUrlLocation &a,
|
|
|
|
const PlainUrlLocation &b) {
|
|
|
|
return (a.url < b.url);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
inline bool operator!=(
|
|
|
|
const PlainUrlLocation &a,
|
|
|
|
const PlainUrlLocation &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>(
|
|
|
|
const PlainUrlLocation &a,
|
|
|
|
const PlainUrlLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const PlainUrlLocation &a,
|
|
|
|
const PlainUrlLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const PlainUrlLocation &a,
|
|
|
|
const PlainUrlLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2020-04-16 09:06:46 +00:00
|
|
|
struct InMemoryLocation {
|
|
|
|
QByteArray bytes;
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const InMemoryLocation &a,
|
|
|
|
const InMemoryLocation &b) {
|
|
|
|
return (a.bytes == b.bytes);
|
|
|
|
}
|
|
|
|
friend inline bool operator<(
|
|
|
|
const InMemoryLocation &a,
|
|
|
|
const InMemoryLocation &b) {
|
|
|
|
return (a.bytes < b.bytes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
inline bool operator!=(
|
|
|
|
const InMemoryLocation &a,
|
|
|
|
const InMemoryLocation &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>(
|
|
|
|
const InMemoryLocation &a,
|
|
|
|
const InMemoryLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const InMemoryLocation &a,
|
|
|
|
const InMemoryLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const InMemoryLocation &a,
|
|
|
|
const InMemoryLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2020-04-16 09:06:46 +00:00
|
|
|
class DownloadLocation {
|
|
|
|
public:
|
2020-08-31 08:14:53 +00:00
|
|
|
std::variant<
|
2020-04-16 09:06:46 +00:00
|
|
|
StorageFileLocation,
|
|
|
|
WebFileLocation,
|
|
|
|
GeoPointLocation,
|
|
|
|
PlainUrlLocation,
|
|
|
|
InMemoryLocation> data;
|
|
|
|
|
|
|
|
[[nodiscard]] QByteArray serialize() const;
|
|
|
|
[[nodiscard]] int serializeSize() const;
|
|
|
|
[[nodiscard]] static std::optional<DownloadLocation> FromSerialized(
|
|
|
|
const QByteArray &serialized);
|
|
|
|
|
|
|
|
[[nodiscard]] DownloadLocation convertToModern(
|
|
|
|
StorageFileLocation::Type type,
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash) const;
|
|
|
|
|
2020-05-20 12:28:18 +00:00
|
|
|
[[nodiscard]] Storage::Cache::Key cacheKey() const;
|
2020-05-28 11:58:50 +00:00
|
|
|
[[nodiscard]] Storage::Cache::Key bigFileBaseCacheKey() const;
|
2020-04-16 09:06:46 +00:00
|
|
|
[[nodiscard]] bool valid() const;
|
2020-05-28 10:00:51 +00:00
|
|
|
[[nodiscard]] bool isLegacy() const;
|
2020-04-16 09:06:46 +00:00
|
|
|
[[nodiscard]] QByteArray fileReference() const;
|
|
|
|
bool refreshFileReference(const QByteArray &data);
|
|
|
|
bool refreshFileReference(const Data::UpdatedFileReferences &updates);
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const DownloadLocation &a,
|
|
|
|
const DownloadLocation &b) {
|
|
|
|
return (a.data == b.data);
|
|
|
|
}
|
|
|
|
friend inline bool operator<(
|
|
|
|
const DownloadLocation &a,
|
|
|
|
const DownloadLocation &b) {
|
|
|
|
return (a.data < b.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
inline bool operator!=(
|
|
|
|
const DownloadLocation &a,
|
|
|
|
const DownloadLocation &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>(
|
|
|
|
const DownloadLocation &a,
|
|
|
|
const DownloadLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const DownloadLocation &a,
|
|
|
|
const DownloadLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const DownloadLocation &a,
|
|
|
|
const DownloadLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2020-04-16 09:06:46 +00:00
|
|
|
class ImageLocation {
|
|
|
|
public:
|
|
|
|
ImageLocation() = default;
|
|
|
|
ImageLocation(
|
|
|
|
const DownloadLocation &file,
|
|
|
|
int width,
|
|
|
|
int height);
|
|
|
|
|
|
|
|
[[nodiscard]] QByteArray serialize() const;
|
|
|
|
[[nodiscard]] int serializeSize() const;
|
|
|
|
[[nodiscard]] static std::optional<ImageLocation> FromSerialized(
|
|
|
|
const QByteArray &serialized);
|
|
|
|
|
|
|
|
[[nodiscard]] ImageLocation convertToModern(
|
|
|
|
StorageFileLocation::Type type,
|
|
|
|
uint64 id,
|
|
|
|
uint64 accessHash) const {
|
|
|
|
return ImageLocation(
|
|
|
|
_file.convertToModern(type, id, accessHash),
|
|
|
|
_width,
|
|
|
|
_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] const DownloadLocation &file() const {
|
|
|
|
return _file;
|
|
|
|
}
|
|
|
|
[[nodiscard]] int width() const {
|
|
|
|
return _width;
|
|
|
|
}
|
|
|
|
[[nodiscard]] int height() const {
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSize(int width, int height) {
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool valid() const {
|
|
|
|
return _file.valid();
|
|
|
|
}
|
2020-05-28 10:00:51 +00:00
|
|
|
[[nodiscard]] bool isLegacy() const {
|
|
|
|
return _file.isLegacy();
|
|
|
|
}
|
2020-04-16 09:06:46 +00:00
|
|
|
[[nodiscard]] QByteArray fileReference() const {
|
|
|
|
return _file.fileReference();
|
|
|
|
}
|
|
|
|
bool refreshFileReference(const QByteArray &data) {
|
|
|
|
return _file.refreshFileReference(data);
|
|
|
|
}
|
|
|
|
bool refreshFileReference(const Data::UpdatedFileReferences &updates) {
|
|
|
|
return _file.refreshFileReference(updates);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] static const ImageLocation &Invalid() {
|
|
|
|
static auto result = ImageLocation();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline bool operator==(
|
|
|
|
const ImageLocation &a,
|
|
|
|
const ImageLocation &b) {
|
|
|
|
return (a._file == b._file);
|
|
|
|
}
|
|
|
|
friend inline bool operator<(
|
|
|
|
const ImageLocation &a,
|
|
|
|
const ImageLocation &b) {
|
|
|
|
return (a._file < b._file);
|
|
|
|
}
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
private:
|
2020-04-16 09:06:46 +00:00
|
|
|
DownloadLocation _file;
|
|
|
|
int _width = 0;
|
|
|
|
int _height = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
inline bool operator!=(
|
|
|
|
const ImageLocation &a,
|
|
|
|
const ImageLocation &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>(
|
|
|
|
const ImageLocation &a,
|
|
|
|
const ImageLocation &b) {
|
|
|
|
return (b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<=(
|
|
|
|
const ImageLocation &a,
|
|
|
|
const ImageLocation &b) {
|
|
|
|
return !(b < a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>=(
|
|
|
|
const ImageLocation &a,
|
|
|
|
const ImageLocation &b) {
|
|
|
|
return !(a < b);
|
|
|
|
}
|
|
|
|
|
2020-04-16 12:37:26 +00:00
|
|
|
struct ImageWithLocation {
|
|
|
|
ImageLocation location;
|
|
|
|
QByteArray bytes;
|
|
|
|
QImage preloaded;
|
2020-07-03 10:48:55 +00:00
|
|
|
int bytesCount = 0;
|
2020-08-25 18:03:41 +00:00
|
|
|
int progressivePartSize = 0;
|
2020-04-16 12:37:26 +00:00
|
|
|
};
|
|
|
|
|
2019-03-22 14:19:43 +00:00
|
|
|
InMemoryKey inMemoryKey(const StorageFileLocation &location);
|
2019-03-22 13:43:34 +00:00
|
|
|
|
|
|
|
inline InMemoryKey inMemoryKey(const StorageImageLocation &location) {
|
2019-03-22 14:19:43 +00:00
|
|
|
return inMemoryKey(location.file());
|
2015-08-11 19:50:48 +00:00
|
|
|
}
|
2019-03-22 13:43:34 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
InMemoryKey inMemoryKey(const WebFileLocation &location);
|
|
|
|
InMemoryKey inMemoryKey(const GeoPointLocation &location);
|
|
|
|
InMemoryKey inMemoryKey(const PlainUrlLocation &location);
|
|
|
|
InMemoryKey inMemoryKey(const InMemoryLocation &location);
|
|
|
|
InMemoryKey inMemoryKey(const DownloadLocation &location);
|
2019-03-22 13:43:34 +00:00
|
|
|
|
2020-05-28 14:32:10 +00:00
|
|
|
inline InMemoryKey inMemoryKey(const ImageLocation &location) {
|
|
|
|
return inMemoryKey(location.file());
|
2018-10-08 18:14:05 +00:00
|
|
|
}
|
2015-08-11 19:50:48 +00:00
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
inline QSize shrinkToKeepAspect(int32 width, int32 height, int32 towidth, int32 toheight) {
|
2015-12-31 15:27:21 +00:00
|
|
|
int32 w = qMax(width, 1), h = qMax(height, 1);
|
|
|
|
if (w * toheight > h * towidth) {
|
|
|
|
h = qRound(h * towidth / float64(w));
|
|
|
|
w = towidth;
|
|
|
|
} else {
|
|
|
|
w = qRound(w * toheight / float64(h));
|
|
|
|
h = toheight;
|
|
|
|
}
|
|
|
|
return QSize(qMax(w, 1), qMax(h, 1));
|
|
|
|
}
|
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
class PsFileBookmark;
|
|
|
|
class ReadAccessEnabler {
|
|
|
|
public:
|
|
|
|
ReadAccessEnabler(const PsFileBookmark *bookmark);
|
2017-12-18 09:07:18 +00:00
|
|
|
ReadAccessEnabler(const std::shared_ptr<PsFileBookmark> &bookmark);
|
2015-11-26 17:34:52 +00:00
|
|
|
bool failed() const {
|
|
|
|
return _failed;
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
2015-11-26 17:34:52 +00:00
|
|
|
~ReadAccessEnabler();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const PsFileBookmark *_bookmark;
|
|
|
|
bool _failed;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileLocation {
|
|
|
|
public:
|
2017-03-04 11:28:21 +00:00
|
|
|
FileLocation() = default;
|
|
|
|
explicit FileLocation(const QString &name);
|
2014-12-05 13:44:27 +00:00
|
|
|
|
2019-05-31 16:45:03 +00:00
|
|
|
static FileLocation InMediaCacheLocation();
|
|
|
|
|
|
|
|
[[nodiscard]] bool check() const;
|
|
|
|
[[nodiscard]] const QString &name() const;
|
2015-11-26 17:34:52 +00:00
|
|
|
void setBookmark(const QByteArray &bookmark);
|
|
|
|
QByteArray bookmark() const;
|
2019-05-31 16:45:03 +00:00
|
|
|
[[nodiscard]] bool isEmpty() const {
|
2015-11-26 17:34:52 +00:00
|
|
|
return name().isEmpty();
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
2019-05-31 16:45:03 +00:00
|
|
|
[[nodiscard]] bool inMediaCache() const;
|
2015-11-26 17:34:52 +00:00
|
|
|
|
|
|
|
bool accessEnable() const;
|
|
|
|
void accessDisable() const;
|
|
|
|
|
|
|
|
QString fname;
|
2014-12-05 13:44:27 +00:00
|
|
|
QDateTime modified;
|
|
|
|
qint32 size;
|
2015-11-26 17:34:52 +00:00
|
|
|
|
|
|
|
private:
|
2017-12-18 09:07:18 +00:00
|
|
|
std::shared_ptr<PsFileBookmark> _bookmark;
|
2015-11-26 17:34:52 +00:00
|
|
|
|
2014-12-05 13:44:27 +00:00
|
|
|
};
|
|
|
|
inline bool operator==(const FileLocation &a, const FileLocation &b) {
|
2020-04-16 12:37:26 +00:00
|
|
|
return (a.name() == b.name())
|
|
|
|
&& (a.modified == b.modified)
|
|
|
|
&& (a.size == b.size);
|
2014-12-05 13:44:27 +00:00
|
|
|
}
|
|
|
|
inline bool operator!=(const FileLocation &a, const FileLocation &b) {
|
|
|
|
return !(a == b);
|
|
|
|
}
|