MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / save

Method save

Telegram/SourceFiles/data/data_document.cpp:1197–1303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1195}
1196
1197void DocumentData::save(
1198 Data::FileOrigin origin,
1199 const QString &toFile,
1200 LoadFromCloudSetting fromCloud,
1201 bool autoLoading) {
1202 if (const auto media = activeMediaView(); media && media->loaded(true)) {
1203 auto &l = location(true);
1204 if (!toFile.isEmpty()) {
1205 if (!media->bytes().isEmpty()) {
1206 QFile f(toFile);
1207 if (f.open(QIODevice::WriteOnly)) {
1208 f.write(media->bytes());
1209 f.close();
1210 }
1211
1212 setLocation(Core::FileLocation(toFile));
1213 session().local().writeFileLocation(
1214 mediaKey(),
1215 Core::FileLocation(toFile));
1216 } else if (l.accessEnable()) {
1217 const auto &alreadyName = l.name();
1218 if (alreadyName != toFile) {
1219 QFile(toFile).remove();
1220 QFile(alreadyName).copy(toFile);
1221 }
1222 l.accessDisable();
1223 }
1224 }
1225 return;
1226 }
1227
1228 if (_loader) {
1229 if (!_loader->setFileName(toFile)) {
1230 cancel();
1231 }
1232 }
1233 resetCancelled();
1234
1235 if (_loader) {
1236 if (fromCloud == LoadFromCloudOrLocal) {
1237 _loader->permitLoadFromCloud();
1238 }
1239 } else {
1240 status = FileReady;
1241 auto reader = owner().streaming().sharedReader(this, origin, true);
1242 if (reader) {
1243 _loader = std::make_unique<Storage::StreamedFileDownloader>(
1244 &session(),
1245 id,
1246 _dc,
1247 origin,
1248 Data::DocumentCacheKey(_dc, id),
1249 mediaKey(),
1250 std::move(reader),
1251 toFile,
1252 size,
1253 locationType(),
1254 (saveToCache() ? LoadToCacheAsWell : LoadToFileOnly),

Callers 8

saveToFileMethod · 0.45
paintUserpicMethod · 0.45
loadDocumentMethod · 0.45
automaticLoadMethod · 0.45
GenerateGoodThumbnailMethod · 0.45
SaveMethod · 0.45
loadDocumentAndInvokeMethod · 0.45
PaintCornerBadgeFrameMethod · 0.45

Calls 15

mediaKeyFunction · 0.85
DocumentCacheKeyFunction · 0.85
StorageFileLocationClass · 0.85
MTP_longFunction · 0.85
MTP_bytesFunction · 0.85
MTP_stringFunction · 0.85
bytesMethod · 0.80
writeFileLocationMethod · 0.80
accessEnableMethod · 0.80
accessDisableMethod · 0.80
permitLoadFromCloudMethod · 0.80
sharedReaderMethod · 0.80

Tested by

no test coverage detected