| 1195 | } |
| 1196 | |
| 1197 | void 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), |
no test coverage detected