From 1930a2132c8c5b61eb72b0646f6712716c900b3f Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Mon, 2 Jun 2025 18:02:37 +0200 Subject: [PATCH] Fix SSH remote links (#3025) --- src/common/scm_rev.cpp.in | 23 +++++++++++++++++++++++ src/common/scm_rev.h | 4 ++++ src/emulator.cpp | 10 +--------- src/qt_gui/main_window.cpp | 10 +--------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/common/scm_rev.cpp.in b/src/common/scm_rev.cpp.in index 71c4c2d0a..0b113eb31 100644 --- a/src/common/scm_rev.cpp.in +++ b/src/common/scm_rev.cpp.in @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include + #include "common/scm_rev.h" namespace Common { @@ -15,5 +17,26 @@ constexpr char g_scm_remote_name[] = "@GIT_REMOTE_NAME@"; constexpr char g_scm_remote_url[] = "@GIT_REMOTE_URL@"; constexpr char g_scm_date[] = "@BUILD_DATE@"; +const std::string GetRemoteNameFromLink() { + std::string remote_url(Common::g_scm_remote_url); + std::string remote_host; + try { + if (remote_url.starts_with("http")) { + if (*remote_url.rbegin() == '/') { + remote_url.pop_back(); + } + remote_host = remote_url.substr(19, remote_url.rfind('/') - 19); + } else if (remote_url.starts_with("git@")) { + auto after_comma_pos = remote_url.find(':') + 1, slash_pos = remote_url.find('/'); + remote_host = remote_url.substr(after_comma_pos, slash_pos - after_comma_pos); + } else { + remote_host = "unknown"; + } + } catch (...) { + remote_host = "unknown"; + } + return remote_host; +} + } // namespace diff --git a/src/common/scm_rev.h b/src/common/scm_rev.h index 36b844e94..2f6d770bb 100644 --- a/src/common/scm_rev.h +++ b/src/common/scm_rev.h @@ -3,6 +3,8 @@ #pragma once +#include + namespace Common { extern const char g_version[]; @@ -15,4 +17,6 @@ extern const char g_scm_remote_name[]; extern const char g_scm_remote_url[]; extern const char g_scm_date[]; +const std::string GetRemoteNameFromLink(); + } // namespace Common diff --git a/src/emulator.cpp b/src/emulator.cpp index 2ad8446ab..4fcb0cfc2 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -194,15 +194,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector", id, title, app_version); std::string window_title = ""; std::string remote_url(Common::g_scm_remote_url); - std::string remote_host; - try { - if (*remote_url.rbegin() == '/') { - remote_url.pop_back(); - } - remote_host = remote_url.substr(19, remote_url.rfind('/') - 19); - } catch (...) { - remote_host = "unknown"; - } + std::string remote_host = Common::GetRemoteNameFromLink(); if (Common::g_is_release) { if (remote_host == "shadps4-emu" || remote_url.length() == 0) { window_title = fmt::format("shadPS4 v{} | {}", Common::g_version, game_title); diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 77b088b78..0f6773751 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -56,15 +56,7 @@ bool MainWindow::Init() { setMinimumSize(720, 405); std::string window_title = ""; std::string remote_url(Common::g_scm_remote_url); - std::string remote_host; - try { - if (*remote_url.rbegin() == '/') { - remote_url.pop_back(); - } - remote_host = remote_url.substr(19, remote_url.rfind('/') - 19); - } catch (...) { - remote_host = "unknown"; - } + std::string remote_host = Common::GetRemoteNameFromLink(); if (Common::g_is_release) { if (remote_host == "shadps4-emu" || remote_url.length() == 0) { window_title = fmt::format("shadPS4 v{}", Common::g_version);