| 277 | |
| 278 | public: |
| 279 | FileHttpRequest(std::vector<std::string> const & urls, std::string const & filePath, int64_t fileSize, |
| 280 | Callback && onFinish, Callback && onProgress, int64_t chunkSize, bool doCleanProgressFiles) |
| 281 | : HttpRequest(std::move(onFinish), std::move(onProgress)) |
| 282 | , m_strategy(urls) |
| 283 | , m_filePath(filePath) |
| 284 | , m_doCleanProgressFiles(doCleanProgressFiles) |
| 285 | { |
| 286 | ASSERT(!urls.empty(), ()); |
| 287 | |
| 288 | // Load resume downloading information. |
| 289 | m_progress.m_bytesDownloaded = m_strategy.LoadOrInitChunks(m_filePath + RESUME_FILE_EXTENSION, fileSize, chunkSize); |
| 290 | m_progress.m_bytesTotal = fileSize; |
| 291 | |
| 292 | FileWriter::Op openMode = FileWriter::OP_WRITE_TRUNCATE; |
| 293 | if (m_progress.m_bytesDownloaded != 0) |
| 294 | { |
| 295 | // Check that resume information is correct with existing file. |
| 296 | uint64_t size; |
| 297 | if (base::GetFileSize(filePath + DOWNLOADING_FILE_EXTENSION, size) && size <= static_cast<uint64_t>(fileSize)) |
| 298 | openMode = FileWriter::OP_WRITE_EXISTING; |
| 299 | else |
| 300 | { |
| 301 | LOG(LWARNING, ("Incomplete file size is bigger than expected, re-downloading.")); |
| 302 | m_strategy.InitChunks(fileSize, chunkSize); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // Create file and reserve needed size. |
| 307 | std::unique_ptr<FileWriter> writer(new FileWriter(filePath + DOWNLOADING_FILE_EXTENSION, openMode)); |
| 308 | |
| 309 | // Assign here, because previous functions can throw an exception. |
| 310 | m_writer.swap(writer); |
| 311 | Platform::DisableBackupForFile(filePath + DOWNLOADING_FILE_EXTENSION); |
| 312 | StartThreads(); |
| 313 | } |
| 314 | |
| 315 | virtual ~FileHttpRequest() |
| 316 | { |
nothing calls this directly
no test coverage detected