diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 2c90f615c8..5bb12deea6 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -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); diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 0543466a8e..7f5ffaff31 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -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 &output); // Try to avoid this when possible, in favor of the string_view version. diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 0ad6eb28ed..d5e9c30c6f 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -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)) {