| 131 | } |
| 132 | |
| 133 | std::optional<std::string> GitHubFileListProvider::download_dictionary_impl(const Concurrency::cancellation_token &token, const std::wstring &aff_filepath, |
| 134 | const std::wstring &target_path, |
| 135 | std::shared_ptr<ProgressData> progress_data, |
| 136 | std::vector<std::wstring> &downloaded_file_names, const Settings::Data & |
| 137 | settings_data, bool &cancelled) { |
| 138 | auto do_download = [&](const std::wstring &path, bool &cancelled) -> std::optional<std::string> { |
| 139 | |
| 140 | auto inet = create_global_handle(settings_data); |
| 141 | auto url_handle = create_url_handle(settings_data, inet, path.c_str()); |
| 142 | auto filename = path.substr(path.rfind(L'/'), std::wstring::npos); |
| 143 | auto local_file_path = target_path + filename; |
| 144 | downloaded_file_names.push_back(local_file_path); |
| 145 | std::ofstream fs(local_file_path, std::ios_base::out | std::ios_base::binary); |
| 146 | if (!fs.is_open()) |
| 147 | return "Failed to save a file locally"; |
| 148 | if (!WinInet::download_file(url_handle, fs, [&](int bytes_read, int total_bytes) { |
| 149 | if (token.is_canceled()) |
| 150 | return false; |
| 151 | |
| 152 | auto percent = bytes_read * 100 / total_bytes; |
| 153 | progress_data->set(percent, wstring_printf(rc_str(IDS_PD_OF_PD_BYTES_DOWNLOADED_PD).c_str(), bytes_read, total_bytes, percent)); |
| 154 | return true; |
| 155 | })) { |
| 156 | cancelled = true; |
| 157 | return "Cancelled"; |
| 158 | } |
| 159 | |
| 160 | return {}; |
| 161 | }; |
| 162 | if (auto ret = do_download(aff_filepath, cancelled)) |
| 163 | return ret; |
| 164 | |
| 165 | if (auto ret = do_download(aff_filepath.substr(0, aff_filepath.length() - aff_ext.length()) + dic_ext_w.data(), cancelled)) |
| 166 | return ret; |
| 167 | |
| 168 | return {}; |
| 169 | } |
| 170 | |
| 171 | namespace { |
| 172 | class DownloadResult { |
nothing calls this directly
no test coverage detected