From 259cb0f128223d860696c17b0d11557ac3a698e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 10 Feb 2019 15:55:00 +0100 Subject: [PATCH] Fix issue where too long filenames could wreck the Install Zip dialog layout. Well, technically just shortens the path to avoid the issue. --- Common/StringUtils.cpp | 18 +++++++++++++++++- Common/StringUtils.h | 2 ++ UI/InstallZipScreen.cpp | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 1946d0df92..c1289720b0 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -95,4 +95,20 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _ *_pExtension = full_path.substr(fname_end); return true; -} \ No newline at end of file +} + +std::string GetFilenameFromPath(std::string full_path) { + size_t pos; +#ifdef _WIN32 + pos = full_path.rfind('\\'); + if (pos != std::string::npos) { + return full_path.substr(pos + 1); + } +#endif + pos = full_path.rfind('/'); + if (pos != std::string::npos) { + return full_path.substr(pos + 1); + } + // No directory components, just return the full path. + return full_path; +} diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 5b53423a03..58d433697c 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -45,3 +45,5 @@ inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...) // "C:/Windows/winhelp.exe" to "C:/Windows/", "winhelp", ".exe" bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension); + +std::string GetFilenameFromPath(std::string full_path); diff --git a/UI/InstallZipScreen.cpp b/UI/InstallZipScreen.cpp index 353a71878f..943d0c9908 100644 --- a/UI/InstallZipScreen.cpp +++ b/UI/InstallZipScreen.cpp @@ -23,6 +23,7 @@ #include "UI/ui_atlas.h" #include "file/file_util.h" +#include "Common/StringUtils.h" #include "Core/Util/GameManager.h" #include "UI/InstallZipScreen.h" #include "UI/MainScreen.h" @@ -43,8 +44,9 @@ void InstallZipScreen::CreateViews() { ViewGroup *leftColumn = new AnchorLayout(new LinearLayoutParams(1.0f)); root_->Add(leftColumn); + std::string shortFilename = GetFilenameFromPath(zipPath_); leftColumn->Add(new TextView(iz->T("Install game from ZIP file?"), ALIGN_LEFT, false, new AnchorLayoutParams(10, 10, NONE, NONE))); - leftColumn->Add(new TextView(zipPath_, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE))); + leftColumn->Add(new TextView(shortFilename, ALIGN_LEFT, false, new AnchorLayoutParams(10, 60, NONE, NONE))); doneView_ = leftColumn->Add(new TextView("", new AnchorLayoutParams(10, 120, NONE, NONE))); progressBar_ = leftColumn->Add(new ProgressBar(new AnchorLayoutParams(10, 200, 200, NONE)));