@@ -53,7 +53,7 @@ cpp::result<void, std::string> DownloadService::VerifyDownloadTask(
5353 return {};
5454}
5555
56- cpp::result<void , std::string> DownloadService::AddDownloadTask (
56+ cpp::result<bool , std::string> DownloadService::AddDownloadTask (
5757 DownloadTask& task,
5858 std::optional<OnDownloadTaskSuccessfully> callback) noexcept {
5959 auto validating_result = VerifyDownloadTask (task);
@@ -65,12 +65,15 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
6565 // if any item from the task failed to download, the whole task will be
6666 // considered failed
6767 std::optional<std::string> dl_err_msg = std::nullopt ;
68+ bool has_task_done = false ;
6869 for (const auto & item : task.items ) {
6970 CLI_LOG (" Start downloading: " + item.localPath .filename ().string ());
7071 auto result = Download (task.id , item, true );
7172 if (result.has_error ()) {
7273 dl_err_msg = result.error ();
7374 break ;
75+ } else if (result) {
76+ has_task_done |= result.value ();
7477 }
7578 }
7679 if (dl_err_msg.has_value ()) {
@@ -81,7 +84,7 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
8184 if (callback.has_value ()) {
8285 callback.value ()(task);
8386 }
84- return {} ;
87+ return has_task_done ;
8588}
8689
8790cpp::result<uint64_t , std::string> DownloadService::GetFileSize (
@@ -109,7 +112,7 @@ cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
109112 return content_length;
110113}
111114
112- cpp::result<void , std::string> DownloadService::AddAsyncDownloadTask (
115+ cpp::result<bool , std::string> DownloadService::AddAsyncDownloadTask (
113116 DownloadTask& task,
114117 std::optional<OnDownloadTaskSuccessfully> callback) noexcept {
115118 auto verifying_result = VerifyDownloadTask (task);
@@ -142,10 +145,10 @@ cpp::result<void, std::string> DownloadService::AddAsyncDownloadTask(
142145 std::thread t (execute_download_async);
143146 t.detach ();
144147
145- return {} ;
148+ return true ;
146149}
147150
148- cpp::result<void , std::string> DownloadService::Download (
151+ cpp::result<bool , std::string> DownloadService::Download (
149152 const std::string& download_id, const DownloadItem& download_item,
150153 bool allow_resume) noexcept {
151154 CTL_INF (" Absolute file output: " << download_item.localPath .string ());
@@ -182,8 +185,7 @@ cpp::result<void, std::string> DownloadService::Download(
182185 mode = " ab" ;
183186 CLI_LOG (" Resuming download.." );
184187 } else {
185- CLI_LOG (" Start over.." );
186- return cpp::fail (" Cancelled Resume download!" );
188+ CLI_LOG (" Start over.." );
187189 }
188190 } else {
189191 CLI_LOG (download_item.localPath .filename ().string ()
@@ -195,7 +197,7 @@ cpp::result<void, std::string> DownloadService::Download(
195197 if (answer == " Y" || answer == " y" || answer.empty ()) {
196198 CLI_LOG (" Re-downloading.." );
197199 } else {
198- return cpp::fail ( " Cancelled Re-download! " ) ;
200+ return false ;
199201 }
200202 }
201203 }
@@ -232,7 +234,7 @@ cpp::result<void, std::string> DownloadService::Download(
232234
233235 fclose (file);
234236 curl_easy_cleanup (curl);
235- return {} ;
237+ return true ;
236238}
237239
238240curl_off_t DownloadService::GetLocalFileSize (
0 commit comments