Shorten the version display on the main screen

This commit is contained in:
Henrik Rydgård 2024-10-22 11:58:50 +02:00
parent 26de955c77
commit a859b2223a
3 changed files with 25 additions and 2 deletions

View File

@ -100,6 +100,16 @@ bool containsNoCase(std::string_view haystack, std::string_view needle) {
return found != haystack.end();
}
int countChar(std::string_view haystack, char needle) {
int count = 0;
for (int i = 0; i < haystack.size(); i++) {
if (haystack[i] == needle) {
count++;
}
}
return count;
}
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args)
{
int writtenCount = vsnprintf(out, outsize, format, args);

View File

@ -85,6 +85,8 @@ std::string_view StripQuotes(std::string_view s);
std::string_view StripPrefix(std::string_view prefix, std::string_view s);
int countChar(std::string_view haystack, char needle);
// NOTE: str must live at least as long as all uses of output.
void SplitString(std::string_view str, const char delim, std::vector<std::string_view> &output);
// Try to avoid this when possible, in favor of the string_view version.

View File

@ -1251,8 +1251,19 @@ void MainScreen::CreateViews() {
rightColumnItems->SetSpacing(0.0f);
rightColumn->Add(rightColumnItems);
char versionString[256];
snprintf(versionString, sizeof(versionString), "%s", PPSSPP_GIT_VERSION);
std::string versionString = PPSSPP_GIT_VERSION;
// Strip the 'v' from the displayed version, and shorten the commit hash.
if (versionString.size() > 2) {
if (versionString[0] == 'v' && isdigit(versionString[1])) {
versionString = versionString.substr(1);
}
if (countChar(versionString, '-') == 2) {
// Shorten the commit hash.
size_t cutPos = versionString.find_last_of('-') + 8;
versionString = versionString.substr(0, std::min(cutPos, versionString.size()));
}
}
rightColumnItems->SetSpacing(0.0f);
AnchorLayout *logos = new AnchorLayout(new AnchorLayoutParams(FILL_PARENT, 60.0f, false));
if (System_GetPropertyBool(SYSPROP_APP_GOLD)) {