about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-04-10 15:39:09 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2025-04-10 15:39:09 -0400
commitf6cdc035eef81cb1d6e402ccb1583c25ccb10407 (patch)
treeffd7758d78890f7f69b79d8766a04ecb3f616a1e
parentfca53646c03b904dfaddccaf1124eab65d0d5079 (diff)
downloadlingo-ap-tracker-f6cdc035eef81cb1d6e402ccb1583c25ccb10407.tar.gz
lingo-ap-tracker-f6cdc035eef81cb1d6e402ccb1583c25ccb10407.tar.bz2
lingo-ap-tracker-f6cdc035eef81cb1d6e402ccb1583c25ccb10407.zip
Use wx functions to get a temporary filename
This is safer and more portable than the previous solution (tmpnam_s).
-rw-r--r--src/updater.cpp31
-rw-r--r--src/updater.h1
2 files changed, 19 insertions, 13 deletions
diff --git a/src/updater.cpp b/src/updater.cpp index 67d5f31..2d87124 100644 --- a/src/updater.cpp +++ b/src/updater.cpp
@@ -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.GetPath());
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.GetPath());
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())) !=
diff --git a/src/updater.h b/src/updater.h index 2d2f746..c604a49 100644 --- a/src/updater.h +++ b/src/updater.h
@@ -41,7 +41,6 @@ class Updater : public wxEvtHandler {
41 41
42 wxFrame* parent_; 42 wxFrame* parent_;
43 UpdateState update_state_ = UpdateState::GetVersionInvisible; 43 UpdateState update_state_ = UpdateState::GetVersionInvisible;
44 std::string package_path_;
45}; 44};
46 45
47#endif /* end of include guard: UPDATER_H_809E7381 */ 46#endif /* end of include guard: UPDATER_H_809E7381 */