From f6cdc035eef81cb1d6e402ccb1583c25ccb10407 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 10 Apr 2025 15:39:09 -0400 Subject: Use wx functions to get a temporary filename This is safer and more portable than the previous solution (tmpnam_s). --- src/updater.cpp | 31 +++++++++++++++++++------------ src/updater.h | 1 - 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, return; } - package_path_.clear(); - package_path_.resize(L_tmpnam + 1); - tmpnam_s(package_path_.data(), L_tmpnam); + bool download_issue = false; - { - wxFileOutputStream writeOut(package_path_); + wxFileName package_path; + package_path.AssignTempFileName(""); + + if (!package_path.IsOk()) { + download_issue = true; + } else { + wxFileOutputStream writeOut(package_path.GetPath()); wxString fileData = packageRequest.GetResponse().AsString(); writeOut.WriteAll(fileData.c_str(), fileData.length()); std::string downloadedChecksum = CalculateStringSha256(fileData); if (downloadedChecksum != checksum) { - if (wxMessageBox("There was an issue downloading the update. Would you " - "like to manually download it instead?", - "Error", wxYES_NO | wxICON_ERROR) == wxID_YES) { - wxLaunchDefaultBrowser(kChangelogUrl); - } - return; + download_issue = true; } } + if (download_issue) { + if (wxMessageBox("There was an issue downloading the update. Would you " + "like to manually download it instead?", + "Error", wxYES_NO | wxICON_ERROR) == wxID_YES) { + wxLaunchDefaultBrowser(kChangelogUrl); + } + return; + } + std::filesystem::path newArea = GetExecutableDirectory(); std::filesystem::path oldArea = newArea / "old"; std::set folders; @@ -241,7 +248,7 @@ void Updater::InstallUpdate(std::string url, std::string checksum, } } - wxFileInputStream fileInputStream(package_path_); + wxFileInputStream fileInputStream(package_path.GetPath()); wxZipInputStream zipStream(fileInputStream); std::unique_ptr zipEntry; while ((zipEntry = std::unique_ptr(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 { wxFrame* parent_; UpdateState update_state_ = UpdateState::GetVersionInvisible; - std::string package_path_; }; #endif /* end of include guard: UPDATER_H_809E7381 */ -- cgit 1.4.1