Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/gui/gui.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/gui/gui.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Lines of Code in a Single File

The lines of code decreases from 2464 to 2463, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
* Copyright (C) 2019 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -63,7 +63,6 @@
#include "core/sstate.h"
#include "core/web-server.h"
#include "flags.h"
#include "fmt/chrono.h"
#include "gui/gui.h"
#include "gui/luaimguiextra.h"
#include "gui/luanvg.h"
Expand Down Expand Up @@ -2413,16 +2412,17 @@
ImGui::EndDisabled();
ImGui::TextUnformatted(_("No version information.\n\nProbably built from source."));
} else {
auto timestamp = version.formatTimestamp("{:%Y-%m-%d %H:%M:%S}");
if (ImGui::Button(_("Copy to clipboard"))) {
if (version.buildId.has_value()) {
clip::set_text(
fmt::format("Version: {}\nBuild: {}\nChangeset: {}\nDate & time: {:%Y-%m-%d %H:%M:%S}",
fmt::format("Version: {}\nBuild: {}\nChangeset: {}\nDate & time: {}",
version.version, version.buildId.value(), version.changeset,
fmt::localtime(version.timestamp)));
timestamp));
} else {
clip::set_text(fmt::format("Version: {}\nChangeset: {}\nDate & time: {:%Y-%m-%d %H:%M:%S}",
clip::set_text(fmt::format("Version: {}\nChangeset: {}\nDate & time: {}",
version.version, version.changeset,
fmt::localtime(version.timestamp)));
timestamp));
}
}
ImGui::Text(_("Version: %s"), version.version.c_str());
Expand All @@ -2434,8 +2434,6 @@
if (ImGui::SmallButton(version.changeset.c_str())) {
openUrl(fmt::format("https://github.com/grumpycoders/pcsx-redux/commit/{}", version.changeset));
}
std::tm tm = fmt::localtime(version.timestamp);
std::string timestamp = fmt::format("{:%Y-%m-%d %H:%M:%S}", tm);
ImGui::Text(_("Date & time: %s"), timestamp.c_str());
}
ImGui::EndTabItem();
Expand Down
5 changes: 2 additions & 3 deletions src/main/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "core/sstate.h"
#include "core/ui.h"
#include "flags.h"
#include "fmt/chrono.h"
#include "gui/gui.h"
#include "lua/extra.h"
#include "lua/luawrapper.h"
Expand Down Expand Up @@ -217,8 +216,8 @@ int pcsxMain(int argc, char **argv) {
}
fmt::print(
"{{\n \"version\": \"{}\",\n \"changeset\": \"{}\",\n \"timestamp\": \"{}\",\n \"timestampDecoded\": "
"\"{:%Y-%m-%d %H:%M:%S}\"\n}}\n",
version.version, version.changeset, version.timestamp, fmt::localtime(version.timestamp));
"\"{}\"\n}}\n",
version.version, version.changeset, version.timestamp, version.formatTimestamp("{:%Y-%m-%d %H:%M:%S}"));
return 0;
}

Expand Down
9 changes: 9 additions & 0 deletions src/support/version.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ SOFTWARE.
#include "support/version.h"

#include <algorithm>
#include <chrono>
#include <fmt/chrono.h>
#include <fmt/format.h>

#include "json.hpp"
#include "support/container-file.h"
Expand Down Expand Up @@ -65,6 +68,12 @@ void PCSX::VersionInfo::loadFromFile(IO<File> file) {
updateStorageUrl = getString("updateStorageUrl");
}

std::string PCSX::VersionInfo::formatTimestamp(const std::string& format) const {
auto timepoint = std::chrono::system_clock::from_time_t(timestamp);
auto local = std::chrono::current_zone()->to_local(timepoint);
return fmt::format(fmt::runtime(format), floor<std::chrono::seconds>(local));
}

bool PCSX::Update::downloadUpdateInfo(const VersionInfo& versionInfo, std::function<void(bool)> callback,
uv_loop_t* loop) {
if (versionInfo.failed() || !versionInfo.hasUpdateInfo()) return false;
Expand Down
1 change: 1 addition & 0 deletions src/support/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct VersionInfo {
}
return (updateMethod == "appcenter");
}
std::string formatTimestamp(const std::string& format) const;
void clear() {
version.clear();
buildId = std::nullopt;
Expand Down
65 changes: 65 additions & 0 deletions tests/support/version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/***************************************************************************
* Copyright (C) 2025 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
***************************************************************************/

#include <ctime>
#include <fmt/chrono.h>
#include "support/version.h"
#include "gtest/gtest.h"

using namespace PCSX;

class VersionInfoTest: public ::testing::Test {
protected:
VersionInfo vi{
"06fdac53",
159,
"06fdac536d1d8301fdc626fe89d1084a3ad241ad",
1737185273,
};
static std::string formatWithStdLocal(std::time_t ts, const char* fmt_str) {
auto tm_ptr = std::localtime(&ts);
if (!tm_ptr) {
return {};
}
return fmt::format(fmt::runtime(fmt_str), *tm_ptr);
}
};

TEST_F(VersionInfoTest, TimestampFormatsDateAndTime) {
auto format = "{:%Y-%m-%d %H:%M:%S}";
EXPECT_EQ(vi.formatTimestamp(format), formatWithStdLocal(vi.timestamp, format));
}

TEST_F(VersionInfoTest, TimestampNullFormatReturnsNullString) {
EXPECT_EQ(vi.formatTimestamp(""), "");
}

TEST_F(VersionInfoTest, TimestampFormatNoPlaceholderReturnsCopy) {
EXPECT_EQ(vi.formatTimestamp("abc"), "abc");
}

TEST_F(VersionInfoTest, TimestampFormatReturnsNonPlaceholderText) {
auto format = "123 {}";
EXPECT_EQ(vi.formatTimestamp(format), formatWithStdLocal(vi.timestamp, format));
}

TEST_F(VersionInfoTest, TimestampFormatHandlesNegativeNumber) {
vi.timestamp = -1;
EXPECT_EQ(vi.formatTimestamp("{}"), formatWithStdLocal(vi.timestamp, "{}"));
}
2 changes: 1 addition & 1 deletion third_party/fmt
Submodule fmt updated 187 files
Loading