diff --git a/Core/Util/PathUtil.cpp b/Core/Util/PathUtil.cpp index ad7f847235..a82bc95fe6 100644 --- a/Core/Util/PathUtil.cpp +++ b/Core/Util/PathUtil.cpp @@ -189,21 +189,21 @@ std::string GetFriendlyPath(Path path, const Path &rootMatch, std::string_view r const Path &root = rootMatch.empty() ? g_Config.memStickDirectory : rootMatch; // Show relative to memstick root if there. - if (path.StartsWith(rootMatch)) { + if (path.StartsWith(root)) { std::string p; - if (rootMatch.ComputePathTo(path, p)) { + if (root.ComputePathTo(path, p)) { return join(rootDisplay, p); } std::string str = path.ToString(); - if (rootMatch.size() < str.length()) { - return join(rootDisplay, str.substr(rootMatch.size())); + if (root.size() < str.length()) { + return join(rootDisplay, str.substr(root.size())); } else { return std::string(rootDisplay); } } - std::string str = path.ToString(); #if !PPSSPP_PLATFORM(ANDROID) && (PPSSPP_PLATFORM(LINUX) || PPSSPP_PLATFORM(MAC)) + std::string str = path.ToString(); char *home = getenv("HOME"); if (home != nullptr && !strncmp(str.c_str(), home, strlen(home))) { return "~" + str.substr(strlen(home)); diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 02fac91889..1fd6ed16ac 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -38,9 +38,10 @@ #include "Core/Reporting.h" #include "Core/System.h" #include "Core/Loaders.h" -#include "Core/Util/GameDB.h" #include "Core/HLE/Plugins.h" +#include "Core/Util/GameDB.h" #include "Core/Util/RecentFiles.h" +#include "Core/Util/PathUtil.h" #include "UI/OnScreenDisplay.h" #include "UI/Background.h" #include "UI/CwCheatScreen.h" @@ -250,7 +251,7 @@ void GameScreen::CreateContentViews(UI::ViewGroup *parent) { } } - infoLayout->Add(new TextView(gamePath_.ToVisualString(), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetShadow(true); + infoLayout->Add(new TextView(GetFriendlyPath(gamePath_), ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)))->SetShadow(true); std::string timeStr; if (g_Config.TimeTracker().GetPlayedTimeString(info_->id, &timeStr)) { diff --git a/UI/InstallZipScreen.cpp b/UI/InstallZipScreen.cpp index e9fc3b0682..c5ac40e31c 100644 --- a/UI/InstallZipScreen.cpp +++ b/UI/InstallZipScreen.cpp @@ -249,11 +249,11 @@ void InstallZipScreen::CreateContentViews(UI::ViewGroup *parent) { if (destFolders_.size() > 1) { leftColumn->Add(new TextView(iz->T("Install into folder"))); for (int i = 0; i < (int)destFolders_.size(); i++) { - leftColumn->Add(new RadioButton(&destFolderChoice_, i, destFolders_[i].ToVisualString())); + leftColumn->Add(new RadioButton(&destFolderChoice_, i, GetFriendlyPath(destFolders_[i]))); } } else if (destFolders_.size() == 1 && zipFileInfo_.contents != ZipFileContents::SAVE_DATA) { leftColumn->Add(new TextView(iz->T("Install into folder"))); - leftColumn->Add(new TextView(destFolders_[0].ToVisualString()))->SetAlign(FLAG_WRAP_TEXT); + leftColumn->Add(new TextView(GetFriendlyPath(destFolders_[0])))->SetAlign(FLAG_WRAP_TEXT); } if (overwrite) { diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 204667c5e4..3b9617789a 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -115,14 +115,11 @@ static bool IsTempPath(const Path &str) { } static void DrawIconWithText(UIContext &dc, ImageID image, std::string_view text, const Bounds &bounds, bool gridStyle, const UI::Style &style) { - // This function is not used in the current code. - float tw, th; dc.MeasureText(dc.GetFontStyle(), gridStyle ? g_Config.fGameGridScale : 1.0, gridStyle ? g_Config.fGameGridScale : 1.0, text, &tw, &th, 0); - bool compact = bounds.w < 180 * (gridStyle ? g_Config.fGameGridScale : 1.0); + const bool compact = bounds.w < 180 * (gridStyle ? g_Config.fGameGridScale : 1.0); if (compact) { - // No folder icon, except "up" dc.PushScissor(bounds); const FontStyle *fontStyle = GetTextStyle(dc, UI::TextSize::Small); dc.SetFontStyle(*GetTextStyle(dc, UI::TextSize::Small)); @@ -134,7 +131,7 @@ static void DrawIconWithText(UIContext &dc, ImageID image, std::string_view text int totalHeight = iconSize + (int)textHeight; - float y = bounds.h / 2.0f - totalHeight / 2.0f; + const float y = std::max(0.0f, bounds.h / 2.0f - totalHeight / 2.0f); if (image.isValid()) { const AtlasImage *img = dc.Draw()->GetAtlas()->getImage(image); @@ -186,7 +183,7 @@ public: holdEnabled_ = hold; } bool Touch(const TouchInput &input) override { - bool retval = UI::Clickable::Touch(input); + const bool retval = UI::Clickable::Touch(input); hovering_ = bounds_.Contains(input.x, input.y); if (hovering_ && (input.flags & TouchInputFlags::DOWN)) { holdStart_ = time_now_d(); diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 35b6e4aa73..e182d3fcfa 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -84,6 +84,7 @@ #include "Core/FileSystems/ISOFileSystem.h" #include "Core/MemMap.h" #include "Core/KeyMap.h" +#include "Core/Util/PathUtil.h" #include "Core/MIPS/MIPSVFPUUtils.h" #include "GPU/Common/TextureDecoder.h" #include "GPU/Common/GPUStateUtils.h" @@ -1249,6 +1250,14 @@ bool TestSplitSearch() { return true; } +bool TestFriendlyPath() { + Path path("/home/user/PPSSPP/games/My Game (USA)/EBOOT.PBP"); + Path baseDir("/home/user/PPSSPP/games/"); + std::string friendlyPath = GetFriendlyPath(path, baseDir, "ms:/"); + EXPECT_EQ_STR(friendlyPath, std::string("ms:/My Game (USA)/EBOOT.PBP")); + return true; +} + typedef bool (*TestFunc)(); struct TestItem { const char *name; @@ -1319,6 +1328,7 @@ TestItem availableTests[] = { TEST_ITEM(CrossSIMD), TEST_ITEM(VolumeFunc), TEST_ITEM(SplitSearch), + TEST_ITEM(FriendlyPath), }; int main(int argc, const char *argv[]) {