diff --git a/pcsx2-qt/AutoUpdaterDialog.cpp b/pcsx2-qt/AutoUpdaterDialog.cpp index caece04b7b..d08225350c 100644 --- a/pcsx2-qt/AutoUpdaterDialog.cpp +++ b/pcsx2-qt/AutoUpdaterDialog.cpp @@ -7,8 +7,8 @@ #include "QtProgressCallback.h" #include "QtUtils.h" +#include "pcsx2/BuildVersion.h" #include "pcsx2/Host.h" -#include "svnrev.h" #include "updater/UpdaterExtractor.h" @@ -47,12 +47,6 @@ // Interval at which HTTP requests are polled. static constexpr u32 HTTP_POLL_INTERVAL = 10; -// Logic to detect whether we can use the auto updater. -// We use tagged commit, because this gets set on nightly builds. -#if (defined(_WIN32) || defined(__linux__) || defined(__APPLE__)) && GIT_TAGGED_COMMIT - -#define AUTO_UPDATER_SUPPORTED 1 - #if defined(_WIN32) #define UPDATE_PLATFORM_STR "Windows" #elif defined(__linux__) @@ -69,10 +63,6 @@ static constexpr u32 HTTP_POLL_INTERVAL = 10; #define UPDATE_ADDITIONAL_TAGS "SSE4" #endif -#endif - -#ifdef AUTO_UPDATER_SUPPORTED - #define LATEST_RELEASE_URL "https://api.pcsx2.net/v1/%1Releases?pageSize=1" #define CHANGES_URL "https://api.github.com/repos/PCSX2/pcsx2/compare/%1...%2" @@ -87,8 +77,6 @@ static const char* UPDATE_TAGS[] = {"stable", "nightly"}; #define DEFAULT_UPDATER_CHANNEL "nightly" #endif -#endif - AutoUpdaterDialog::AutoUpdaterDialog(QWidget* parent /* = nullptr */) : QDialog(parent) { @@ -109,7 +97,11 @@ AutoUpdaterDialog::~AutoUpdaterDialog() = default; bool AutoUpdaterDialog::isSupported() { -#ifdef AUTO_UPDATER_SUPPORTED + // Logic to detect whether we can use the auto updater. + // We use tagged commit, because this gets set on nightly builds. + if (!BuildVersion::GitTaggedCommit) + return false; + #ifdef __linux__ // For Linux, we need to check whether we're running from the appimage. if (!std::getenv("APPIMAGE")) @@ -119,10 +111,9 @@ bool AutoUpdaterDialog::isSupported() } return true; -#else +#elif defined(_WIN32) || defined(__APPLE__) // Windows, MacOS - always supported. return true; -#endif #else return false; #endif @@ -130,39 +121,36 @@ bool AutoUpdaterDialog::isSupported() QStringList AutoUpdaterDialog::getTagList() { -#ifdef AUTO_UPDATER_SUPPORTED + if (!isSupported()) + return QStringList(); + return QStringList(std::begin(UPDATE_TAGS), std::end(UPDATE_TAGS)); -#else - return QStringList(); -#endif } std::string AutoUpdaterDialog::getDefaultTag() { -#ifdef AUTO_UPDATER_SUPPORTED + if (!isSupported()) + return {}; + return DEFAULT_UPDATER_CHANNEL; -#else - return {}; -#endif } QString AutoUpdaterDialog::getCurrentVersion() { - return QStringLiteral(GIT_TAG); + return QString(BuildVersion::GitTag); } QString AutoUpdaterDialog::getCurrentVersionDate() { - return QStringLiteral(GIT_DATE); + return QString(BuildVersion::GitDate); } QString AutoUpdaterDialog::getCurrentUpdateTag() const { -#ifdef AUTO_UPDATER_SUPPORTED + if (!isSupported()) + return QString(); + return QString::fromStdString(Host::GetBaseStringSettingValue("AutoUpdater", "UpdateTag", DEFAULT_UPDATER_CHANNEL)); -#else - return QString(); -#endif } void AutoUpdaterDialog::reportError(const char* msg, ...) @@ -215,18 +203,21 @@ void AutoUpdaterDialog::queueUpdateCheck(bool display_message) { m_display_messages = display_message; -#ifdef AUTO_UPDATER_SUPPORTED - if (!ensureHttpReady()) + if (isSupported()) + { + if (!ensureHttpReady()) + { + emit updateCheckCompleted(); + return; + } + + m_http->CreateRequest(QStringLiteral(LATEST_RELEASE_URL).arg(getCurrentUpdateTag()).toStdString(), + std::bind(&AutoUpdaterDialog::getLatestReleaseComplete, this, std::placeholders::_1, std::placeholders::_3)); + } + else { emit updateCheckCompleted(); - return; } - - m_http->CreateRequest(QStringLiteral(LATEST_RELEASE_URL).arg(getCurrentUpdateTag()).toStdString(), - std::bind(&AutoUpdaterDialog::getLatestReleaseComplete, this, std::placeholders::_1, std::placeholders::_3)); -#else - emit updateCheckCompleted(); -#endif } void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, std::vector data) @@ -236,7 +227,9 @@ void AutoUpdaterDialog::getLatestReleaseComplete(s32 status_code, std::vectorCreateRequest(QStringLiteral(CHANGES_URL).arg(GIT_HASH).arg(m_latest_version).toStdString(), + m_http->CreateRequest(QStringLiteral(CHANGES_URL).arg(BuildVersion::GitHash).arg(m_latest_version).toStdString(), std::bind(&AutoUpdaterDialog::getChangesComplete, this, std::placeholders::_1, std::placeholders::_3)); -#endif } void AutoUpdaterDialog::getChangesComplete(s32 status_code, std::vector data) { -#ifdef AUTO_UPDATER_SUPPORTED + if (!isSupported()) + { + m_ui.downloadAndInstall->setEnabled(true); + return; + } + if (status_code == HTTPDownloader::HTTP_STATUS_OK) { QJsonParseError parse_error; @@ -456,7 +451,6 @@ void AutoUpdaterDialog::getChangesComplete(s32 status_code, std::vector data { reportError("Failed to download change list: %d", status_code); } -#endif m_ui.downloadAndInstall->setEnabled(true); } @@ -542,10 +536,10 @@ void AutoUpdaterDialog::checkIfUpdateNeeded() const QString last_checked_version( QString::fromStdString(Host::GetBaseStringSettingValue("AutoUpdater", "LastVersion"))); - Console.WriteLn(Color_StrongGreen, "Current version: %s", GIT_TAG); + Console.WriteLn(Color_StrongGreen, "Current version: %s", BuildVersion::GitTag); Console.WriteLn(Color_StrongYellow, "Latest version: %s", m_latest_version.toUtf8().constData()); Console.WriteLn(Color_StrongOrange, "Last checked version: %s", last_checked_version.toUtf8().constData()); - if (m_latest_version == GIT_TAG || m_latest_version == last_checked_version) + if (m_latest_version == BuildVersion::GitTag || m_latest_version == last_checked_version) { Console.WriteLn(Color_StrongGreen, "No update needed."); @@ -787,7 +781,7 @@ void AutoUpdaterDialog::cleanupAfterUpdate() static QString UpdateVersionNumberInName(QString name, QStringView new_version) { - QString current_version_string = QStringLiteral(GIT_TAG); + QString current_version_string(BuildVersion::GitTag); QStringView current_version = current_version_string; if (!current_version.empty() && !new_version.empty() && current_version[0] == 'v' && new_version[0] == 'v') { diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index 8ff7b1507a..78eb8f82a1 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -19,7 +19,6 @@ #include "Settings/MemoryCardCreateDialog.h" #include "Tools/InputRecording/InputRecordingViewer.h" #include "Tools/InputRecording/NewInputRecordingDlg.h" -#include "svnrev.h" #include "pcsx2/Achievements.h" #include "pcsx2/CDVD/CDVDcommon.h" diff --git a/pcsx2-qt/QtHost.cpp b/pcsx2-qt/QtHost.cpp index fc751f740d..eb0a40b3f2 100644 --- a/pcsx2-qt/QtHost.cpp +++ b/pcsx2-qt/QtHost.cpp @@ -10,10 +10,10 @@ #include "QtProgressCallback.h" #include "QtUtils.h" #include "SetupWizardDialog.h" -#include "svnrev.h" #include "pcsx2/CDVD/CDVDcommon.h" #include "pcsx2/Achievements.h" +#include "pcsx2/BuildVersion.h" #include "pcsx2/CDVD/CDVD.h" #include "pcsx2/Counters.h" #include "pcsx2/DebugTools/Debug.h" @@ -1468,7 +1468,7 @@ bool Host::RequestResetSettings(bool folders, bool core, bool controllers, bool QString QtHost::GetAppNameAndVersion() { - return QStringLiteral("PCSX2 " GIT_REV); + return QString("PCSX2 %1").arg(BuildVersion::GitRev); } QString QtHost::GetAppConfigSuffix() diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index 7860846307..677fcc95bf 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -4,6 +4,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include "Achievements.h" +#include "BuildVersion.h" #include "CDVD/CDVD.h" #include "Elfheader.h" #include "Host.h" @@ -16,7 +17,6 @@ #include "Memory.h" #include "SaveState.h" #include "VMManager.h" -#include "svnrev.h" #include "vtlb.h" #include "common/Assertions.h" @@ -3039,7 +3039,7 @@ void Achievements::SwitchToRAIntegration() void Achievements::RAIntegration::InitializeRAIntegration(void* main_window_handle) { - RA_InitClient((HWND)main_window_handle, "PCSX2", GIT_TAG); + RA_InitClient((HWND)main_window_handle, "PCSX2", BuildVersion::GitTag); RA_SetUserAgentDetail(Host::GetHTTPUserAgent().c_str()); RA_InstallSharedFunctions(RACallbackIsActive, RACallbackCauseUnpause, RACallbackCausePause, RACallbackRebuildMenu, diff --git a/pcsx2/BuildVersion.cpp b/pcsx2/BuildVersion.cpp new file mode 100644 index 0000000000..0fe5a265ae --- /dev/null +++ b/pcsx2/BuildVersion.cpp @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team +// SPDX-License-Identifier: GPL-3.0+ + +#include "svnrev.h" + +namespace BuildVersion +{ + const char* GitTag = GIT_TAG; + bool GitTaggedCommit = GIT_TAGGED_COMMIT; + int GitTagHi = GIT_TAG_HI; + int GitTagMid = GIT_TAG_MID; + int GitTagLo = GIT_TAG_LO; + const char* GitRev = GIT_REV; + const char* GitHash = GIT_HASH; + const char* GitDate = GIT_DATE; +} // namespace BuildVersion diff --git a/pcsx2/BuildVersion.h b/pcsx2/BuildVersion.h new file mode 100644 index 0000000000..6b399404ea --- /dev/null +++ b/pcsx2/BuildVersion.h @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team +// SPDX-License-Identifier: GPL-3.0+ + +#pragma once + +// This file provides the same information as svnrev.h except you don't need to +// recompile each object file using it when said information is updated. +namespace BuildVersion +{ + extern const char* GitTag; + extern bool GitTaggedCommit; + extern int GitTagHi; + extern int GitTagMid; + extern int GitTagLo; + extern const char* GitRev; + extern const char* GitHash; + extern const char* GitDate; +} // namespace BuildVersion diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 804ab2e406..5430675614 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -54,6 +54,7 @@ endif(WIN32) # Main pcsx2 source set(pcsx2Sources Achievements.cpp + BuildVersion.cpp Cache.cpp COP0.cpp COP2.cpp @@ -140,6 +141,7 @@ set(pcsx2Sources # Main pcsx2 header set(pcsx2Headers Achievements.h + BuildVersion.h Cache.h Common.h Config.h diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index c16af54cde..a58f82d924 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -10,6 +10,7 @@ #include "GS/Renderers/Vulkan/VKShaderCache.h" #include "GS/Renderers/Vulkan/VKSwapChain.h" +#include "BuildVersion.h" #include "Host.h" #include "common/Console.h" @@ -103,16 +104,15 @@ VkInstance GSDeviceVK::CreateVulkanInstance(const WindowInfo& wi, OptionalExtens if (!SelectInstanceExtensions(&enabled_extensions, wi, oe, enable_debug_utils)) return VK_NULL_HANDLE; - // Remember to manually update this every release. We don't pull in svnrev.h here, because - // it's only the major/minor version, and rebuilding the file every time something else changes - // is unnecessary. VkApplicationInfo app_info = {}; app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; app_info.pNext = nullptr; app_info.pApplicationName = "PCSX2"; - app_info.applicationVersion = VK_MAKE_VERSION(1, 7, 0); + app_info.applicationVersion = VK_MAKE_VERSION( + BuildVersion::GitTagHi, BuildVersion::GitTagMid, BuildVersion::GitTagLo); app_info.pEngineName = "PCSX2"; - app_info.engineVersion = VK_MAKE_VERSION(1, 7, 0); + app_info.engineVersion = VK_MAKE_VERSION( + BuildVersion::GitTagHi, BuildVersion::GitTagMid, BuildVersion::GitTagLo); app_info.apiVersion = VK_API_VERSION_1_1; VkInstanceCreateInfo instance_create_info = {}; diff --git a/pcsx2/Host.cpp b/pcsx2/Host.cpp index 6b18c685d9..bd64ad0770 100644 --- a/pcsx2/Host.cpp +++ b/pcsx2/Host.cpp @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team // SPDX-License-Identifier: GPL-3.0+ +#include "BuildVersion.h" #include "GS.h" #include "GS/Renderers/HW/GSTextureReplacements.h" #include "Host.h" #include "LayeredSettingsInterface.h" #include "VMManager.h" -#include "svnrev.h" #include "common/Assertions.h" #include "common/CrashHandler.h" @@ -159,7 +159,7 @@ bool Host::ConfirmFormattedMessage(const std::string_view title, const char* for std::string Host::GetHTTPUserAgent() { - return fmt::format("PCSX2 " GIT_REV " ({})", GetOSVersionString()); + return fmt::format("PCSX2 {} ({})", BuildVersion::GitRev, GetOSVersionString()); } std::unique_lock Host::GetSettingsLock() diff --git a/pcsx2/ImGui/FullscreenUI.cpp b/pcsx2/ImGui/FullscreenUI.cpp index a26d494419..44afb555a5 100644 --- a/pcsx2/ImGui/FullscreenUI.cpp +++ b/pcsx2/ImGui/FullscreenUI.cpp @@ -3,6 +3,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS +#include "BuildVersion.h" #include "CDVD/CDVDcommon.h" #include "GS/Renderers/Common/GSDevice.h" #include "GS/Renderers/Common/GSTexture.h" @@ -23,7 +24,6 @@ #include "USB/USB.h" #include "VMManager.h" #include "ps2/BiosTools.h" -#include "svnrev.h" #include "common/Console.h" #include "common/Error.h" @@ -6633,7 +6633,7 @@ void FullscreenUI::DrawAboutWindow() "This allows you to play PS2 games on your PC, with many additional features and benefits.")); ImGui::NewLine(); - ImGui::TextWrapped(FSUI_CSTR("Version: %s"), GIT_REV); + ImGui::TextWrapped(FSUI_CSTR("Version: %s"), BuildVersion::GitRev); ImGui::NewLine(); ImGui::TextWrapped("%s", diff --git a/pcsx2/ImGui/ImGuiOverlays.cpp b/pcsx2/ImGui/ImGuiOverlays.cpp index 319f3d5a8f..b17459fbef 100644 --- a/pcsx2/ImGui/ImGuiOverlays.cpp +++ b/pcsx2/ImGui/ImGuiOverlays.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team // SPDX-License-Identifier: GPL-3.0+ +#include "BuildVersion.h" #include "Config.h" #include "Counters.h" #include "GS.h" @@ -24,7 +25,6 @@ #include "SIO/Pad/PadBase.h" #include "USB/USB.h" #include "VMManager.h" -#include "svnrev.h" #include "cpuinfo.h" #include "common/BitUtils.h" @@ -170,7 +170,7 @@ __ri void ImGuiManager::DrawPerformanceOverlay(float& position_y, float scale, f if (GSConfig.OsdShowVersion) { - text.append_format("{}PCSX2 {}", first ? "" : " | ", GIT_REV); + text.append_format("{}PCSX2 {}", first ? "" : " | ", BuildVersion::GitRev); } if (!text.empty()) diff --git a/pcsx2/PINE.cpp b/pcsx2/PINE.cpp index 0bd6ec87cc..6103c0a64e 100644 --- a/pcsx2/PINE.cpp +++ b/pcsx2/PINE.cpp @@ -1,13 +1,13 @@ // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team // SPDX-License-Identifier: GPL-3.0+ +#include "BuildVersion.h" #include "Common.h" #include "Host.h" #include "Memory.h" #include "Elfheader.h" #include "PINE.h" #include "VMManager.h" -#include "svnrev.h" #include #include @@ -607,14 +607,12 @@ PINEServer::IPCBuffer PINEServer::ParseCommand(std::span buf, std::vector(&ret_buffer[ret_cnt]), size, "PCSX2 %s", BuildVersion::GitRev); ret_cnt += size; break; } diff --git a/pcsx2/Recording/InputRecordingFile.cpp b/pcsx2/Recording/InputRecordingFile.cpp index 9adb43f42d..b3c5fbd1c5 100644 --- a/pcsx2/Recording/InputRecordingFile.cpp +++ b/pcsx2/Recording/InputRecordingFile.cpp @@ -3,13 +3,10 @@ #include "InputRecordingFile.h" +#include "BuildVersion.h" #include "Utilities/InputRecordingLogger.h" #include "common/FileSystem.h" -#include "common/StringUtil.h" -#include "DebugTools/Debug.h" -#include "MemoryTypes.h" -#include "svnrev.h" #include @@ -23,7 +20,7 @@ void InputRecordingFile::InputRecordingFileHeader::init() noexcept void InputRecordingFile::setEmulatorVersion() { - StringUtil::Strlcpy(m_header.m_emulatorVersion, "PCSX2-" GIT_REV, sizeof(m_header.m_emulatorVersion)); + snprintf(m_header.m_emulatorVersion, sizeof(m_header.m_emulatorVersion), "PCSX2-%s", BuildVersion::GitRev); } void InputRecordingFile::setAuthor(const std::string& _author) diff --git a/pcsx2/SIO/Memcard/MemoryCardFile.cpp b/pcsx2/SIO/Memcard/MemoryCardFile.cpp index 796ea9510e..e48a0eacb7 100644 --- a/pcsx2/SIO/Memcard/MemoryCardFile.cpp +++ b/pcsx2/SIO/Memcard/MemoryCardFile.cpp @@ -20,8 +20,6 @@ #include "Host.h" #include "IconsPromptFont.h" -#include "svnrev.h" - #include "fmt/core.h" #include @@ -1075,4 +1073,4 @@ bool FileMcd_DeleteCard(const std::string_view name) } return true; -} \ No newline at end of file +} diff --git a/pcsx2/SIO/Memcard/MemoryCardFolder.cpp b/pcsx2/SIO/Memcard/MemoryCardFolder.cpp index cd49357d85..bcdb121b25 100644 --- a/pcsx2/SIO/Memcard/MemoryCardFolder.cpp +++ b/pcsx2/SIO/Memcard/MemoryCardFolder.cpp @@ -21,8 +21,6 @@ #include "ryml_std.hpp" #include "ryml.hpp" -#include "svnrev.h" - #include #include #include @@ -2380,4 +2378,4 @@ bool FolderMemoryCardAggregator::ReIndex(uint slot, const bool enableFiltering, SetFiltering(enableFiltering); m_lastKnownFilter = filter; return false; -} \ No newline at end of file +} diff --git a/pcsx2/SaveState.cpp b/pcsx2/SaveState.cpp index ac90e60481..36bb2eec5c 100644 --- a/pcsx2/SaveState.cpp +++ b/pcsx2/SaveState.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0+ #include "Achievements.h" +#include "BuildVersion.h" #include "CDVD/CDVD.h" #include "COP0.h" #include "Cache.h" @@ -27,7 +28,6 @@ #include "VMManager.h" #include "VUmicro.h" #include "ps2/BiosTools.h" -#include "svnrev.h" #include "common/Error.h" #include "common/FileSystem.h" @@ -972,11 +972,14 @@ static bool SaveState_AddToZip(zip_t* zf, ArchiveEntryList* srclist, SaveStateSc VersionIndicator* vi = static_cast(std::malloc(sizeof(VersionIndicator))); vi->save_version = g_SaveVersion; -#if GIT_TAGGED_COMMIT - StringUtil::Strlcpy(vi->version, GIT_TAG, std::size(vi->version)); -#else - StringUtil::Strlcpy(vi->version, "Unknown", std::size(vi->version)); -#endif + if (BuildVersion::GitTaggedCommit) + { + StringUtil::Strlcpy(vi->version, BuildVersion::GitTag, std::size(vi->version)); + } + else + { + StringUtil::Strlcpy(vi->version, "Unknown", std::size(vi->version)); + } zip_source_t* const zs = zip_source_buffer(zf, vi, sizeof(*vi), 1); if (!zs) diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 43f98b101b..55fb77d761 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0+ #include "Achievements.h" +#include "BuildVersion.h" #include "CDVD/CDVD.h" #include "CDVD/IsoReader.h" #include "Counters.h" @@ -40,7 +41,6 @@ #include "Vif_Dynarec.h" #include "VMManager.h" #include "ps2/BiosTools.h" -#include "svnrev.h" #include "common/Console.h" #include "common/Error.h" @@ -2490,7 +2490,7 @@ void LogGPUCapabilities() void VMManager::LogCPUCapabilities() { - Console.WriteLn(Color_StrongGreen, "PCSX2 " GIT_REV); + Console.WriteLn(Color_StrongGreen, "PCSX2 %s", BuildVersion::GitRev); Console.WriteLnFmt("Savestate version: 0x{:x}\n", g_SaveVersion); Console.WriteLn(); diff --git a/pcsx2/pcsx2.vcxproj b/pcsx2/pcsx2.vcxproj index 41ff04385a..c7f68793cf 100644 --- a/pcsx2/pcsx2.vcxproj +++ b/pcsx2/pcsx2.vcxproj @@ -419,6 +419,7 @@ true + @@ -865,6 +866,7 @@ + diff --git a/pcsx2/pcsx2.vcxproj.filters b/pcsx2/pcsx2.vcxproj.filters index fd225c4d16..51782a5fcf 100644 --- a/pcsx2/pcsx2.vcxproj.filters +++ b/pcsx2/pcsx2.vcxproj.filters @@ -1292,6 +1292,9 @@ Misc + + Misc + System\Ps2\EmotionEngine\Hardware @@ -2244,6 +2247,9 @@ System\Ps2\Iop + + Misc + System\Ps2\EmotionEngine\Hardware