Bugfix GetFriendlyPath, use in more places

This commit is contained in:
Henrik Rydgård
2026-01-29 23:15:32 +01:00
parent 1ed2f53385
commit cbcec3e27f
5 changed files with 23 additions and 15 deletions
+5 -5
View File
@@ -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));
+3 -2
View File
@@ -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)) {
+2 -2
View File
@@ -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) {
+3 -6
View File
@@ -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();
+10
View File
@@ -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[]) {