Navigation Menu

Skip to content

Commit

Permalink
Fix issue where too long filenames could wreck the Install Zip dialog…
Browse files Browse the repository at this point in the history
… layout.

Well, technically just shortens the path to avoid the issue.
  • Loading branch information
hrydgard committed Feb 10, 2019
1 parent ccfcbc7 commit 259cb0f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Common/StringUtils.cpp
Expand Up @@ -95,4 +95,20 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
*_pExtension = full_path.substr(fname_end);

return true;
}
}

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;
}
2 changes: 2 additions & 0 deletions Common/StringUtils.h
Expand Up @@ -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);
4 changes: 3 additions & 1 deletion UI/InstallZipScreen.cpp
Expand Up @@ -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"
Expand All @@ -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)));
Expand Down

0 comments on commit 259cb0f

Please sign in to comment.