MCPcopy Create free account
hub / github.com/Predelnik/DSpellCheck / download_dictionary_impl

Method download_dictionary_impl

src/network/GithubFileListProvider.cpp:133–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133std::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
171namespace {
172class DownloadResult {

Callers

nothing calls this directly

Calls 7

download_fileFunction · 0.85
wstring_printfFunction · 0.85
rc_strFunction · 0.85
c_strMethod · 0.80
substrMethod · 0.80
dataMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected