• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "multi_download_progress_core.h"
17 
18 #include <memory>
19 
20 #include "cloud_sync_common.h"
21 #include "dfs_error.h"
22 #include "utils_log.h"
23 
24 namespace OHOS::FileManagement::CloudSync {
25 using namespace ModuleFileIO;
26 using namespace std;
Constructor()27 FsResult<MultiDlProgressCore *> MultiDlProgressCore::Constructor()
28 {
29     std::unique_ptr<MultiDlProgressCore> dlProgress = std::make_unique<MultiDlProgressCore>();
30     return FsResult<MultiDlProgressCore *>::Success(dlProgress.release());
31 }
32 
GetStatus()33 int32_t MultiDlProgressCore::GetStatus()
34 {
35     int32_t state = static_cast<int32_t>(DownloadProgressObj::Status::FAILED);
36     if (downloadProgress_ == nullptr) {
37         LOGE("Failed to get multiDlProgress.");
38     } else {
39         state = downloadProgress_->GetState();
40     }
41 
42     return state;
43 }
44 
GetTaskId()45 int64_t MultiDlProgressCore::GetTaskId()
46 {
47     int64_t taskId = 0;
48     if (downloadProgress_ == nullptr) {
49         LOGE("Failed to get MultiDlProgressEntity.");
50     } else {
51         taskId = downloadProgress_->GetTaskId();
52     }
53 
54     return taskId;
55 }
56 
GetDownloadedNum()57 int64_t MultiDlProgressCore::GetDownloadedNum()
58 {
59     int64_t succNum = -1;
60     if (downloadProgress_ == nullptr) {
61         LOGE("Failed to get MultiDlProgressEntity.");
62     } else {
63         succNum = static_cast<int64_t>(downloadProgress_->GetSuccNum());
64     }
65 
66     return succNum;
67 }
68 
GetFailedNum()69 int64_t MultiDlProgressCore::GetFailedNum()
70 {
71     int64_t failedNum = -1;
72     if (downloadProgress_ == nullptr) {
73         LOGE("Failed to get MultiDlProgressEntity.");
74     } else {
75         failedNum = static_cast<int64_t>(downloadProgress_->GetFailedNum());
76     }
77 
78     return failedNum;
79 }
80 
GetTotalNum()81 int64_t MultiDlProgressCore::GetTotalNum()
82 {
83     int64_t totalNum = -1;
84     if (downloadProgress_ == nullptr) {
85         LOGE("Failed to get MultiDlProgressEntity.");
86     } else {
87         totalNum = downloadProgress_->GetTotalNum();
88     }
89 
90     return totalNum;
91 }
92 
GetDownloadedSize()93 int64_t MultiDlProgressCore::GetDownloadedSize()
94 {
95     int64_t downloadSize = INT64_MAX;
96     if (downloadProgress_ == nullptr) {
97         LOGE("Failed to get MultiDlProgressEntity.");
98     } else {
99         downloadSize = downloadProgress_->GetDownloadedSize();
100     }
101 
102     return downloadSize;
103 }
104 
GetTotalSize()105 int64_t MultiDlProgressCore::GetTotalSize()
106 {
107     int64_t totalSize = INT64_MAX;
108     if (downloadProgress_ == nullptr) {
109         LOGE("Failed to get MultiDlProgressEntity.");
110     } else {
111         totalSize = downloadProgress_->GetTotalSize();
112     }
113 
114     return totalSize;
115 }
116 
GetErrorType()117 int32_t MultiDlProgressCore::GetErrorType()
118 {
119     int32_t errorType = static_cast<int32_t>(DownloadProgressObj::DownloadErrorType::UNKNOWN_ERROR);
120     if (downloadProgress_ == nullptr) {
121         LOGE("Failed to get MultiDlProgressEntity.");
122     } else {
123         errorType = downloadProgress_->GetErrorType();
124     }
125 
126     return errorType;
127 }
128 
GetFailedFileList()129 FsResult<std::vector<FailedFileInfo>> MultiDlProgressCore::GetFailedFileList()
130 {
131     if (downloadProgress_ == nullptr) {
132         LOGE("Failed to get MultiDlProgressEntity.");
133         return FsResult<std::vector<FailedFileInfo>>::Error(Convert2ErrNum(E_SERVICE_INNER_ERROR));
134     }
135     auto failedFiles = downloadProgress_->GetFailedFiles();
136     std::vector<FailedFileInfo> res;
137     for (auto &iter : failedFiles) {
138         res.emplace_back(iter.first, iter.second);
139     }
140 
141     return FsResult<std::vector<FailedFileInfo>>::Success(res);
142 }
143 
GetDownloadedFileList()144 FsResult<std::vector<std::string>> MultiDlProgressCore::GetDownloadedFileList()
145 {
146     if (downloadProgress_ == nullptr) {
147         LOGE("Failed to get MultiDlProgressEntity.");
148         return FsResult<std::vector<std::string>>::Error(Convert2ErrNum(E_SERVICE_INNER_ERROR));
149     }
150 
151     auto downloadedFiles = downloadProgress_->GetDownloadedFiles();
152     std::vector<string> res(downloadedFiles.begin(), downloadedFiles.end());
153     return FsResult<std::vector<std::string>>::Success(res);
154 }
155 } // namespace OHOS::FileManagement::CloudSync