Skip to content

Commit 51f7027

Browse files
committed
Qt/Updater: Log version transitions to update_log.txt on update
1 parent 7f59be2 commit 51f7027

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

pcsx2-qt/AutoUpdaterDialog.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cpuinfo.h"
2525

2626
#include <functional>
27+
#include <ctime>
2728
#include <QtCore/QCoreApplication>
2829
#include <QtCore/QDir>
2930
#include <QtCore/QFile>
@@ -640,8 +641,8 @@ bool AutoUpdaterDialog::doUpdate(const std::string& application_dir, const std::
640641

641642
const std::wstring wupdater_path = StringUtil::UTF8StringToWideString(updater_path);
642643
const std::wstring wapplication_dir = StringUtil::UTF8StringToWideString(application_dir);
643-
const std::wstring arguments = StringUtil::UTF8StringToWideString(fmt::format("{} \"{}\" \"{}\" \"{}\"",
644-
QCoreApplication::applicationPid(), application_dir, zip_path, program_path));
644+
const std::wstring arguments = StringUtil::UTF8StringToWideString(fmt::format("{} \"{}\" \"{}\" \"{}\" \"{}\" \"{}\"",
645+
QCoreApplication::applicationPid(), application_dir, zip_path, program_path, BuildVersion::GitRev, m_latest_version.toStdString()));
645646

646647
const bool needs_elevation = doesUpdaterNeedElevation(application_dir);
647648

@@ -756,6 +757,18 @@ bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& data, QProgressDial
756757
return false;
757758
}
758759

760+
// Log the version transition for regression bisecting
761+
if (auto fp = FileSystem::OpenManagedCFile(
762+
Path::Combine(EmuFolders::DataRoot, "update_log.txt").c_str(), "ab"))
763+
{
764+
const std::time_t t = std::time(nullptr);
765+
char timestamp[32];
766+
std::strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
767+
const std::string entry = fmt::format("[{}] Updated PCSX2 from {} to {}\n",
768+
timestamp, BuildVersion::GitRev, m_latest_version.toStdString());
769+
std::fwrite(entry.c_str(), 1, entry.size(), fp.get());
770+
}
771+
759772
// We exit once we return.
760773
return true;
761774
}
@@ -894,6 +907,19 @@ bool AutoUpdaterDialog::processUpdate(const std::vector<u8>& data, QProgressDial
894907
reportError("Failed to start new application");
895908
return false;
896909
}
910+
911+
// Log the version transition for regression bisecting
912+
if (auto fp = FileSystem::OpenManagedCFile(
913+
Path::Combine(EmuFolders::DataRoot, "update_log.txt").c_str(), "ab"))
914+
{
915+
const std::time_t t = std::time(nullptr);
916+
char timestamp[32];
917+
std::strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
918+
const std::string entry = fmt::format("[{}] Updated PCSX2 from {} to {}\n",
919+
timestamp, BuildVersion::GitRev, m_latest_version.toStdString());
920+
std::fwrite(entry.c_str(), 1, entry.size(), fp.get());
921+
}
922+
897923
return true;
898924
}
899925

updater/Windows/WindowsUpdater.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "common/StringUtil.h"
1111
#include "common/ProgressCallback.h"
1212
#include "common/RedtapeWilCom.h"
13+
#include "common/Path.h"
14+
#include <fmt/format.h>
15+
#include <ctime>
1316

1417
#include <CommCtrl.h>
1518
#include <shellapi.h>
@@ -433,10 +436,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
433436
progress.ModalError("Failed to parse command line.");
434437
return 1;
435438
}
436-
if (argc != 5)
439+
if (argc != 7)
437440
{
438-
progress.ModalError("Expected 4 arguments: parent process id, output directory, update zip, program to "
439-
"launch.\n\nThis program is not intended to be run manually, please use the main PCSX2 application and "
441+
progress.ModalError("Expected 6 arguments: parent process id, output directory, update zip, program to "
442+
"launch, old version, new version.\n\nThis program is not intended to be run manually, please use the main PCSX2 application and "
440443
"click Help->Check for Updates.");
441444
return 1;
442445
}
@@ -445,6 +448,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
445448
const std::string destination_directory = StringUtil::WideStringToUTF8String(argv[2]);
446449
const std::string zip_path = StringUtil::WideStringToUTF8String(argv[3]);
447450
const std::wstring program_to_launch(argv[4]);
451+
const std::string old_version = StringUtil::WideStringToUTF8String(argv[5]);
452+
const std::string new_version = StringUtil::WideStringToUTF8String(argv[6]);
448453
argv.reset();
449454

450455
if (parent_process_id <= 0 || destination_directory.empty() || zip_path.empty() || program_to_launch.empty())
@@ -494,6 +499,18 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
494499
updater.CleanupStagingDirectory();
495500
updater.RemoveUpdateZip();
496501

502+
// Log the version transition for regression bisecting
503+
if (!old_version.empty() && !new_version.empty())
504+
{
505+
const std::string log_path = Path::Combine(destination_directory, "update_log.txt");
506+
const std::time_t t = std::time(nullptr);
507+
char timestamp[32];
508+
std::strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", std::localtime(&t));
509+
const std::string entry = fmt::format("[{}] Updated PCSX2 from {} to {}\n", timestamp, old_version, new_version);
510+
if (auto fp = FileSystem::OpenManagedCFile(log_path.c_str(), "ab"))
511+
std::fwrite(entry.c_str(), 1, entry.size(), fp.get());
512+
}
513+
497514
// Rename the new executable to match the existing one
498515
if (std::string actual_exe = updater.FindPCSX2Exe(); !actual_exe.empty())
499516
{

0 commit comments

Comments
 (0)