Skip to content

Commit

Permalink
Allow Gui File Selector filter to check among more extensions
Browse files Browse the repository at this point in the history
For example now in Install menu we are seeing all files with .zip
extension, after this commit we can see also files with .ZIP extension.
Just add the extension between ";" separator.

Change-Id: I6ddd2a812a182570af3d76711b1e3e13740a466b
  • Loading branch information
mauronofrio authored and bigbiff committed Jun 10, 2020
1 parent 0cd6be9 commit 2702094
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions gui/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ endif

LOCAL_C_INCLUDES += \
bionic \
system/core/base/include \
system/core/include \
system/core/libpixelflinger/include

Expand Down
34 changes: 31 additions & 3 deletions gui/fileselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
#include <sys/stat.h>
#include <dirent.h>
#include <algorithm>

#ifdef __ANDROID_API_M__
#include <vector>
#ifdef __ANDROID_API_N__
#include <android-base/strings.h>
#else
#include <base/strings.h>
#endif
#else
#endif
extern "C" {
#include "../twcommon.h"
}
Expand Down Expand Up @@ -279,11 +287,31 @@ int GUIFileSelector::GetFileList(const std::string folder)
if (mShowNavFolders || (data.fileName != "." && data.fileName != ".."))
mFolderList.push_back(data);
} else if (data.fileType == DT_REG || data.fileType == DT_LNK || data.fileType == DT_BLK) {
if (mExtn.empty() || (data.fileName.length() > mExtn.length() && data.fileName.substr(data.fileName.length() - mExtn.length()) == mExtn)) {
if (mExtn == ".ab" && twadbbu::Check_ADB_Backup_File(path))
#ifdef __ANDROID_API_M__
std::vector<std::string> mExtnResults = android::base::Split(mExtn, ";");
for (const std::string& mExtnElement : mExtnResults)
{
std::string mExtnName = android::base::Trim(mExtnElement);
if (mExtnName.empty() || (data.fileName.length() > mExtnName.length() && data.fileName.substr(data.fileName.length() - mExtnName.length()) == mExtnName)) {
if (mExtnName == ".ab" && twadbbu::Check_ADB_Backup_File(path))
mFolderList.push_back(data);
else
mFileList.push_back(data);
}
#else //On android 5.1 we can't use android::base::Trim and Split so just use the first extension written in the list
std::size_t seppos = mExtn.find_first_of(";");
std::string mExtnf;
if (seppos!=std::string::npos){
mExtnf = mExtn.substr(0, seppos);
} else {
mExtnf = mExtn;
}
if (mExtnf.empty() || (data.fileName.length() > mExtnf.length() && data.fileName.substr(data.fileName.length() - mExtnf.length()) == mExtnf)) {
if (mExtnf == ".ab" && twadbbu::Check_ADB_Backup_File(path))
mFolderList.push_back(data);
else
mFileList.push_back(data);
#endif
}
}
}
Expand Down

0 comments on commit 2702094

Please sign in to comment.