| 6 |
| * Copyright Nikolai Kudashov, 2015-2018. |
| 7 | */ |
| 8 |
| 9 | #ifndef FILELOADOPERATION_H |
| 10 | #define FILELOADOPERATION_H |
| 11 |
| 12 | #include <vector> |
| 13 | #include "Defines.h" |
| 14 |
| 15 | #ifdef ANDROID |
| 16 | #include <jni.h> |
| 17 | #endif |
| 18 |
| 19 | class TL_upload_file; |
| 20 | class InputFileLocation; |
| 21 | class ByteArray; |
| 22 | class FileLocation; |
| 23 |
| 24 | class FileLoadOperation { |
| 25 |
| 26 | public: |
| 27 | FileLoadOperation(int32_t dc_id, int64_t id, int64_t volume_id, int64_t access_hash, int32_t local_id, uint8_t *encKey, uint8_t *encIv, std::string extension, int32_t version, int32_t size, std::string dest, std::string temp); |
| 28 | ~FileLoadOperation(); |
| 29 |
| 30 | void start(); |
| 31 | void cancel(); |
| 32 | void setDelegate(onFinishedFunc onFinished, onFailedFunc onFailed, onProgressChangedFunc onProgressChanged); |
| 33 |
| 34 | #ifdef ANDROID |
| 35 | jobject ptr1 = nullptr; |
| 36 | #endif |
| 37 |
| 38 | private: |
| 39 |
| 40 | class RequestInfo { |
| 41 |
| 42 | public: |
| 43 | int32_t requestToken = 0; |
| 44 | int32_t offset = 0; |
| 45 | NativeByteBuffer *bytes = nullptr; |
| 46 |
| 47 | ~RequestInfo(); |
| 48 | }; |
| 49 |
| 50 | void cleanup(); |
| 51 | void onFinishLoadingFile(); |
| 52 | void startDownloadRequest(); |
| 53 | void processRequestResult(RequestInfo *requestInfo, TL_error *error, bool next); |
| 54 | void onFailedLoadingFile(int reason); |
| 55 |
| 56 | int32_t datacenter_id; |
| 57 | std::unique_ptr<InputFileLocation> location; |
| 58 | FileLoadState state = FileLoadStateIdle; |
| 59 | int32_t downloadedBytes = 0; |
| 60 | int32_t totalBytesCount = 0; |
| 61 | int32_t bytesCountPadding = 0; |
| 62 | std::unique_ptr<ByteArray> key; |
| 63 | std::unique_ptr<ByteArray> iv; |
| 64 | int32_t currentDownloadChunkSize = 0; |
| 65 | uint32_t currentMaxDownloadRequests = 0; |
| 66 | int32_t requestsCount = 0; |
| 67 |
| 68 | int32_t nextDownloadOffset = 0; |
| 69 | std::vector<std::unique_ptr<RequestInfo>> requestInfos; |
| 70 | std::vector<std::unique_ptr<RequestInfo>> delayedRequestInfos; |
| 71 |
| 72 | std::string ext; |
| 73 |
| 74 | std::string filePath; |
| 75 | std::string tempFilePath; |
| 76 | std::string tempFileIvPath; |
| 77 |
| 78 | FILE *tempFile = nullptr; |
| 79 | FILE *tempIvFile = nullptr; |
| 80 |
| 81 | std::string destPath; |
| 82 | std::string tempPath; |
| 83 |
| 84 | bool isForceRequest = false; |
| 85 |
| 86 | onFinishedFunc onFinishedCallback = nullptr; |
| 87 | onFailedFunc onFailedCallback = nullptr; |
| 88 | onProgressChangedFunc onProgressChangedCallback = nullptr; |
| 89 | }; |
| 90 |
| 91 | #endif |
| 92 |