bool mtpFileLoader::loadPart() { if (complete || lastComplete || (!requests.isEmpty() && !size)) return false; if (size && nextRequestOffset >= size) return false; int32 limit = DocumentDownloadPartSize; MTPInputFileLocation loc; switch (_locationType) { case UnknownFileLocation: loc = MTP_inputFileLocation(MTP_long(volume), MTP_int(local), MTP_long(secret)); limit = DownloadPartSize; break; case VideoFileLocation: loc = MTP_inputVideoFileLocation(MTP_long(id), MTP_long(access)); break; case AudioFileLocation: loc = MTP_inputAudioFileLocation(MTP_long(id), MTP_long(access)); break; case DocumentFileLocation: loc = MTP_inputDocumentFileLocation(MTP_long(id), MTP_long(access)); break; default: finishFail(); return false; break; } int32 offset = nextRequestOffset, dcIndex = 0; DataRequested &dr(_dataRequested[dc]); if (size) { for (int32 i = 1; i < MTPDownloadSessionsCount; ++i) { if (dr.v[i] < dr.v[dcIndex]) { dcIndex = i; } } } App::app()->killDownloadSessionsStop(dc); mtpRequestId reqId = MTP::send(MTPupload_GetFile(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))), rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld[dcIndex] + dc, 50); ++queue->queries; dr.v[dcIndex] += limit; requests.insert(reqId, dcIndex); nextRequestOffset += limit; return true; }
bool mtpFileLoader::loadPart() { if (complete || requestId) return false; int32 limit = DocumentDownloadPartSize; MTPInputFileLocation loc; switch (locationType) { case 0: loc = MTP_inputFileLocation(MTP_long(volume), MTP_int(local), MTP_long(secret)); limit = DownloadPartSize; break; case mtpc_inputVideoFileLocation: loc = MTP_inputVideoFileLocation(MTP_long(id), MTP_long(access)); break; case mtpc_inputAudioFileLocation: loc = MTP_inputAudioFileLocation(MTP_long(id), MTP_long(access)); break; case mtpc_inputDocumentFileLocation: loc = MTP_inputDocumentFileLocation(MTP_long(id), MTP_long(access)); break; default: finishFail(); return false; break; } ++queue->queries; int32 offset = currentOffset(); MTPupload_GetFile request(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))); requestId = MTP::send(request, rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld + dc, 50); return true; }