Skip to content

Commit

Permalink
Merge pull request #20009 from hrydgard/copy-build-version
Browse files Browse the repository at this point in the history
Add easy way to copy build number, add way to copy system information to clipboard
  • Loading branch information
hrydgard authored Feb 20, 2025
2 parents b4ca098 + a78ce8d commit d557971
Show file tree
Hide file tree
Showing 51 changed files with 236 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Common/Data/Text/Parsers.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstdarg>
#include <climits>
#include <cstdio>
#include <string>
Expand Down Expand Up @@ -157,3 +158,11 @@ bool TryParse(const std::string &str, bool *const output) {

return true;
}

StringWriter &StringWriter::F(const char *format, ...) {
va_list args;
va_start(args, format);
p_ += vsprintf(p_, format, args);
va_end(args);
return *this;
}
39 changes: 39 additions & 0 deletions Common/Data/Text/Parsers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include <cstring>
#include <sstream>
#include <cstdint>

Expand Down Expand Up @@ -78,3 +79,41 @@ std::string NiceSizeFormat(uint64_t size);
// seconds, or minutes, or hours.
// Uses I18N strings.
std::string NiceTimeFormat(int seconds);

// Not a parser, needs a better location.
// Simplified version of ShaderWriter. Would like to have that inherit from this but can't figure out how
// due to the return value chaining.
class StringWriter {
public:
explicit StringWriter(char *buffer) : p_(buffer) {
buffer[0] = '\0';
}
StringWriter(const StringWriter &) = delete;

// Assumes the input is zero-terminated.
// C: Copies a string literal (which always are zero-terminated, the count includes the zero) directly to the stream.
template<size_t T>
StringWriter &C(const char(&text)[T]) {
memcpy(p_, text, T);
p_ += T - 1;
return *this;
}
// W: Writes a string_view to the stream.
StringWriter &W(std::string_view text) {
memcpy(p_, text.data(), text.length());
p_ += text.length();
*p_ = '\0';
return *this;
}

// F: Formats into the buffer.
StringWriter &F(const char *format, ...);
StringWriter &endl() { return C("\n"); }

void Rewind(size_t offset) {
p_ -= offset;
}

private:
char *p_;
};
34 changes: 34 additions & 0 deletions Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,40 @@ void TextView::Draw(UIContext &dc) {
}
}

bool ClickableTextView::Touch(const TouchInput &input) {
bool contains = bounds_.Contains(input.x, input.y);

// Ignore buttons other than the left one.
if ((input.flags & TOUCH_MOUSE) && (input.buttons & 1) == 0) {
return contains;
}

if (input.flags & TOUCH_DOWN) {
if (bounds_.Contains(input.x, input.y)) {
if (IsFocusMovementEnabled())
SetFocusedView(this);
dragging_ = true;
down_ = true;
} else {
down_ = false;
dragging_ = false;
}
} else if (input.flags & TOUCH_MOVE) {
if (dragging_)
down_ = bounds_.Contains(input.x, input.y);
}
if (input.flags & TOUCH_UP) {
if ((input.flags & TOUCH_CANCEL) == 0 && dragging_ && bounds_.Contains(input.x, input.y)) {
EventParams e{};
e.v = this;
OnClick.Trigger(e);
}
down_ = false;
dragging_ = false;
}
return contains;
}

TextEdit::TextEdit(std::string_view text, std::string_view title, std::string_view placeholderText, LayoutParams *layoutParams)
: View(layoutParams), text_(text), title_(title), undo_(text), placeholderText_(placeholderText),
textColor_(0xFFFFFFFF), maxLen_(255) {
Expand Down
13 changes: 13 additions & 0 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,19 @@ class TextView : public InertView {
float pad_ = 0.0f;
};

// Quick hack for clickable version number
class ClickableTextView : public TextView {
public:
ClickableTextView(std::string_view text, LayoutParams *layoutParams = 0)
: TextView(text, layoutParams) {}
bool Touch(const TouchInput &input);
Event OnClick;

private:
bool down_;
bool dragging_;
};

class TextEdit : public View {
public:
TextEdit(std::string_view text, std::string_view title, std::string_view placeholderText, LayoutParams *layoutParams = nullptr);
Expand Down
46 changes: 43 additions & 3 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "Common/File/AndroidStorage.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Data/Text/Parsers.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/Net/HTTPClient.h"
#include "Common/UI/Context.h"
Expand All @@ -49,6 +50,7 @@
#include "Common/Log/LogManager.h"
#include "Common/CPUDetect.h"
#include "Common/StringUtils.h"
#include "Common/GPU/ShaderWriter.h"

#include "Core/MemMap.h"
#include "Core/Config.h"
Expand Down Expand Up @@ -471,6 +473,45 @@ void SystemInfoScreen::update() {
g_OSD.NudgeSidebar();
}

// TODO: How can we de-duplicate this and SystemInfoScreen::CreateTabs?
UI::EventReturn SystemInfoScreen::CopySummaryToClipboard(UI::EventParams &e) {
auto di = GetI18NCategory(I18NCat::DIALOG);
auto si = GetI18NCategory(I18NCat::DIALOG);

char *summary = new char[100000];
StringWriter w(summary);

std::string_view build = "Release";
#ifdef _DEBUG
build = "Debug";
#endif
w.W(PPSSPP_GIT_VERSION).C(" ").W(build).endl();
w.C("CPU: ").W(cpu_info.cpu_string).endl();
w.C("ABI: ").W(GetCompilerABI()).endl();
w.C("OS: ").W(System_GetProperty(SYSPROP_NAME)).C(" ").W(System_GetProperty(SYSPROP_SYSTEMBUILD)).endl();
w.C("Page Size: ").W(StringFromFormat(si->T_cstr("%d bytes"), GetMemoryProtectPageSize())).endl();
w.C("RW/RX exclusive: ").W(PlatformIsWXExclusive() ? "Yes" : "No").endl();

std::string board = System_GetProperty(SYSPROP_BOARDNAME);
if (!board.empty())
w.C("Board: ").W(board).endl();
Draw::DrawContext *draw = screenManager()->getDrawContext();
w.C("3D API: ").W(draw->GetInfoString(Draw::InfoField::APINAME)).endl();
w.C("API version: ").W(draw->GetInfoString(Draw::InfoField::APIVERSION)).endl();
w.C("Device API version: ").W(draw->GetInfoString(Draw::InfoField::DEVICE_API_VERSION)).endl();
w.C("Vendor: ").W(draw->GetInfoString(Draw::InfoField::VENDOR)).endl();
w.C("VendorString: ").W(draw->GetInfoString(Draw::InfoField::VENDORSTRING)).endl();
w.C("Driver: ").W(draw->GetInfoString(Draw::InfoField::DRIVER)).endl();
w.C("Depth buffer format: ").W(DataFormatToString(draw->GetDeviceCaps().preferredDepthBufferFormat)).endl();
w.C("Refresh rate: ").W(StringFromFormat(si->T_cstr("%0.2f Hz"), (float)System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE))).endl();

System_CopyStringToClipboard(summary);
delete[] summary;

g_OSD.Show(OSDType::MESSAGE_INFO, ApplySafeSubstitutions(di->T("Copied to clipboard: %1"), si->T("System Information")));
return UI::EVENT_DONE;
}

void SystemInfoScreen::CreateTabs() {
using namespace Draw;
using namespace UI;
Expand All @@ -483,6 +524,8 @@ void SystemInfoScreen::CreateTabs() {
LinearLayout *deviceSpecs = AddTab("Device Info", si->T("Device Info"));

CollapsibleSection *systemInfo = deviceSpecs->Add(new CollapsibleSection(si->T("System Information")));

systemInfo->Add(new Choice(si->T("Copy summary to clipboard")))->OnClick.Handle(this, &SystemInfoScreen::CopySummaryToClipboard);
systemInfo->Add(new InfoItem(si->T("System Name", "Name"), System_GetProperty(SYSPROP_NAME)));
#if PPSSPP_PLATFORM(ANDROID)
systemInfo->Add(new InfoItem(si->T("System Version"), StringFromInt(System_GetPropertyInt(SYSPROP_SYSTEMVERSION))));
Expand Down Expand Up @@ -699,9 +742,6 @@ void SystemInfoScreen::CreateTabs() {
LinearLayout *buildConfig = AddTab("DevSystemInfoBuildConfig", si->T("Build Config"));

buildConfig->Add(new ItemHeader(si->T("Build Configuration")));
#ifdef JENKINS
buildConfig->Add(new InfoItem(si->T("Built by"), "Jenkins"));
#endif
#ifdef ANDROID_LEGACY
buildConfig->Add(new InfoItem("ANDROID_LEGACY", ""));
#endif
Expand Down
1 change: 1 addition & 0 deletions UI/DevScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class SystemInfoScreen : public TabbedUIDialogScreenWithGameBackground {
void update() override;

protected:
UI::EventReturn CopySummaryToClipboard(UI::EventParams &e);
bool ShowSearchControls() const override { return false; }
void CreateInternalsTab(UI::ViewGroup *internals);
};
Expand Down
10 changes: 9 additions & 1 deletion UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "Common/File/FileUtil.h"
#include "Common/TimeUtil.h"
#include "Common/StringUtils.h"
#include "Common/System/System.h"
#include "Common/System/OSD.h"
#include "Core/System.h"
#include "Core/Reporting.h"
#include "Core/HLE/sceCtrl.h"
Expand Down Expand Up @@ -1286,9 +1288,15 @@ void MainScreen::CreateViews() {
#endif

rightColumnItems->Add(logos);
TextView *ver = rightColumnItems->Add(new TextView(versionString, new LinearLayoutParams(Margins(70, -10, 0, 4))));
ClickableTextView *ver = rightColumnItems->Add(new ClickableTextView(versionString, new LinearLayoutParams(Margins(70, -10, 0, 4))));
ver->SetSmall(true);
ver->SetClip(false);
ver->OnClick.Add([](UI::EventParams &e) {
auto di = GetI18NCategory(I18NCat::DIALOG);
System_CopyStringToClipboard(PPSSPP_GIT_VERSION);
g_OSD.Show(OSDType::MESSAGE_INFO, ApplySafeSubstitutions(di->T("Copied to clipboard: %1"), PPSSPP_GIT_VERSION));
return UI::EVENT_DONE;
});

LinearLayout *rightColumnChoices = rightColumnItems;
if (vertical) {
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ ConfirmLoad = ‎تحميل هذه البيانات?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = ‎مسح
Expand Down Expand Up @@ -1236,6 +1237,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Load this data?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Sil
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Зареди тези данни?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Изтрий
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/ca_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Vols carregar les dades?
ConnectingAP = Connectant al punt d'accés.\nPer favor espera...
ConnectingPleaseWait = Connectant.\nPer favor espera...
ConnectionName = Nom de la connexió
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Dades corruptes
Delete = Eliminar
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/cz_CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Načíst tyto data?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Smazat
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/da_DK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Hent dette data?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Slet
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/de_DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Wollen Sie diese Daten laden?
ConnectingAP = Verbinde zu dem Access Point.\nBitte warten...
ConnectingPleaseWait = Verbinde.\nBitte warten...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Löschen
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Erstellungskonfig.
Build Configuration = Erstellungskonfiguration
Built by = Erstellt von
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Kerne
CPU Extensions = CPU Erweiterungen
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/dr_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ ConfirmLoad = Bukka'mi te' data?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Hapusi
Expand Down Expand Up @@ -1228,6 +1229,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
2 changes: 2 additions & 0 deletions assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ ConfirmLoad = Load this data?
ConnectingAP = Connecting to the access point.\nPlease wait...
ConnectingPleaseWait = Connecting.\nPlease wait...
ConnectionName = Connection name
Copied to clipboard: %1 = Copied to clipboard: %1
Copy to clipboard = Copy to clipboard
Corrupted Data = Corrupted data
Delete = Delete
Expand Down Expand Up @@ -1244,6 +1245,7 @@ Build Config = Build config
Build Configuration = Build Configuration
Built by = Built by
Compressed texture formats = Compressed texture formats
Copy summary to clipboard = Copy summary to clipboard
Core Context = Core context
Cores = Cores
CPU Extensions = CPU extensions
Expand Down
Loading

0 comments on commit d557971

Please sign in to comment.