diff options
Diffstat (limited to 'src/updater.cpp')
-rw-r--r-- | src/updater.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/updater.cpp b/src/updater.cpp index 67d5f31..2b05daf 100644 --- a/src/updater.cpp +++ b/src/updater.cpp | |||
@@ -36,7 +36,7 @@ std::string CalculateStringSha256(const wxString& data) { | |||
36 | 36 | ||
37 | char output[65] = {0}; | 37 | char output[65] = {0}; |
38 | for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { | 38 | for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { |
39 | sprintf(output + (i * 2), "%02x", hash[i]); | 39 | snprintf(output + (i * 2), 3, "%02x", hash[i]); |
40 | } | 40 | } |
41 | 41 | ||
42 | return std::string(output); | 42 | return std::string(output); |
@@ -172,26 +172,33 @@ void Updater::InstallUpdate(std::string url, std::string checksum, | |||
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | 174 | ||
175 | package_path_.clear(); | 175 | bool download_issue = false; |
176 | package_path_.resize(L_tmpnam + 1); | ||
177 | tmpnam_s(package_path_.data(), L_tmpnam); | ||
178 | 176 | ||
179 | { | 177 | wxFileName package_path; |
180 | wxFileOutputStream writeOut(package_path_); | 178 | package_path.AssignTempFileName(""); |
179 | |||
180 | if (!package_path.IsOk()) { | ||
181 | download_issue = true; | ||
182 | } else { | ||
183 | wxFileOutputStream writeOut(package_path.GetFullPath()); | ||
181 | wxString fileData = packageRequest.GetResponse().AsString(); | 184 | wxString fileData = packageRequest.GetResponse().AsString(); |
182 | writeOut.WriteAll(fileData.c_str(), fileData.length()); | 185 | writeOut.WriteAll(fileData.c_str(), fileData.length()); |
183 | 186 | ||
184 | std::string downloadedChecksum = CalculateStringSha256(fileData); | 187 | std::string downloadedChecksum = CalculateStringSha256(fileData); |
185 | if (downloadedChecksum != checksum) { | 188 | if (downloadedChecksum != checksum) { |
186 | if (wxMessageBox("There was an issue downloading the update. Would you " | 189 | download_issue = true; |
187 | "like to manually download it instead?", | ||
188 | "Error", wxYES_NO | wxICON_ERROR) == wxID_YES) { | ||
189 | wxLaunchDefaultBrowser(kChangelogUrl); | ||
190 | } | ||
191 | return; | ||
192 | } | 190 | } |
193 | } | 191 | } |
194 | 192 | ||
193 | if (download_issue) { | ||
194 | if (wxMessageBox("There was an issue downloading the update. Would you " | ||
195 | "like to manually download it instead?", | ||
196 | "Error", wxYES_NO | wxICON_ERROR) == wxID_YES) { | ||
197 | wxLaunchDefaultBrowser(kChangelogUrl); | ||
198 | } | ||
199 | return; | ||
200 | } | ||
201 | |||
195 | std::filesystem::path newArea = GetExecutableDirectory(); | 202 | std::filesystem::path newArea = GetExecutableDirectory(); |
196 | std::filesystem::path oldArea = newArea / "old"; | 203 | std::filesystem::path oldArea = newArea / "old"; |
197 | std::set<std::filesystem::path> folders; | 204 | std::set<std::filesystem::path> folders; |
@@ -241,7 +248,7 @@ void Updater::InstallUpdate(std::string url, std::string checksum, | |||
241 | } | 248 | } |
242 | } | 249 | } |
243 | 250 | ||
244 | wxFileInputStream fileInputStream(package_path_); | 251 | wxFileInputStream fileInputStream(package_path.GetFullPath()); |
245 | wxZipInputStream zipStream(fileInputStream); | 252 | wxZipInputStream zipStream(fileInputStream); |
246 | std::unique_ptr<wxZipEntry> zipEntry; | 253 | std::unique_ptr<wxZipEntry> zipEntry; |
247 | while ((zipEntry = std::unique_ptr<wxZipEntry>(zipStream.GetNextEntry())) != | 254 | while ((zipEntry = std::unique_ptr<wxZipEntry>(zipStream.GetNextEntry())) != |