Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2012 bigbiff/Dees_Troy TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 19 | #include <string.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 20 | #include <sys/stat.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 21 | #include <dirent.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 22 | #include <algorithm> |
| 23 | |
| 24 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 25 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 26 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | #include "rapidxml.hpp" |
| 30 | #include "objects.hpp" |
| 31 | #include "../data.hpp" |
Dees_Troy | 3ee47bc | 2013-01-25 21:47:37 +0000 | [diff] [blame] | 32 | #include "../twrp-functions.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 33 | |
| 34 | #define TW_FILESELECTOR_UP_A_LEVEL "(Up A Level)" |
| 35 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | int GUIFileSelector::mSortOrder = 0; |
| 37 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 38 | GUIFileSelector::GUIFileSelector(xml_node<>* node) : GUIScrollList(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 39 | { |
| 40 | xml_attribute<>* attr; |
| 41 | xml_node<>* child; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 43 | mFolderIcon = mFileIcon = NULL; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 44 | mShowFolders = mShowFiles = mShowNavFolders = 1; |
| 45 | mUpdate = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | mPathVar = "cwd"; |
Dees_Troy | c0583f5 | 2013-02-28 11:19:57 -0600 | [diff] [blame] | 47 | updateFileList = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 49 | // Load filter for filtering files (e.g. *.zip for only zips) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 50 | child = node->first_node("filter"); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 51 | if (child) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 52 | attr = child->first_attribute("extn"); |
| 53 | if (attr) |
| 54 | mExtn = attr->value(); |
| 55 | attr = child->first_attribute("folders"); |
| 56 | if (attr) |
| 57 | mShowFolders = atoi(attr->value()); |
| 58 | attr = child->first_attribute("files"); |
| 59 | if (attr) |
| 60 | mShowFiles = atoi(attr->value()); |
| 61 | attr = child->first_attribute("nav"); |
| 62 | if (attr) |
| 63 | mShowNavFolders = atoi(attr->value()); |
| 64 | } |
| 65 | |
| 66 | // Handle the path variable |
| 67 | child = node->first_node("path"); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 68 | if (child) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 69 | attr = child->first_attribute("name"); |
| 70 | if (attr) |
| 71 | mPathVar = attr->value(); |
| 72 | attr = child->first_attribute("default"); |
| 73 | if (attr) |
| 74 | DataManager::SetValue(mPathVar, attr->value()); |
| 75 | } |
| 76 | |
| 77 | // Handle the result variable |
| 78 | child = node->first_node("data"); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 79 | if (child) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 80 | attr = child->first_attribute("name"); |
| 81 | if (attr) |
| 82 | mVariable = attr->value(); |
| 83 | attr = child->first_attribute("default"); |
| 84 | if (attr) |
| 85 | DataManager::SetValue(mVariable, attr->value()); |
| 86 | } |
| 87 | |
| 88 | // Handle the sort variable |
| 89 | child = node->first_node("sort"); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 90 | if (child) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 91 | attr = child->first_attribute("name"); |
| 92 | if (attr) |
| 93 | mSortVariable = attr->value(); |
| 94 | attr = child->first_attribute("default"); |
| 95 | if (attr) |
| 96 | DataManager::SetValue(mSortVariable, attr->value()); |
| 97 | |
| 98 | DataManager::GetValue(mSortVariable, mSortOrder); |
| 99 | } |
| 100 | |
| 101 | // Handle the selection variable |
| 102 | child = node->first_node("selection"); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 103 | if (child && (attr = child->first_attribute("name"))) |
| 104 | mSelection = attr->value(); |
| 105 | else |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 106 | mSelection = "0"; |
| 107 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 108 | // Get folder and file icons if present |
| 109 | child = node->first_node("icon"); |
| 110 | if (child) { |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame^] | 111 | mFolderIcon = LoadAttrImage(child, "folder"); |
| 112 | mFileIcon = LoadAttrImage(child, "file"); |
Vojtech Bocek | 7cc278b | 2013-02-24 01:40:19 +0100 | [diff] [blame] | 113 | } |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame^] | 114 | int iconWidth = std::max(mFolderIcon->GetWidth(), mFileIcon->GetWidth()); |
| 115 | int iconHeight = std::max(mFolderIcon->GetHeight(), mFileIcon->GetHeight()); |
| 116 | SetMaxIconSize(iconWidth, iconHeight); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 117 | |
| 118 | // Fetch the file/folder list |
| 119 | std::string value; |
| 120 | DataManager::GetValue(mPathVar, value); |
Dees_Troy | 80a11d9 | 2013-01-25 16:36:07 +0000 | [diff] [blame] | 121 | GetFileList(value); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | GUIFileSelector::~GUIFileSelector() |
| 125 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | int GUIFileSelector::Update(void) |
| 129 | { |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 130 | if(!isConditionTrue()) |
| 131 | return 0; |
| 132 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 133 | GUIScrollList::Update(); |
| 134 | |
| 135 | // Update the file list if needed |
| 136 | if (updateFileList) { |
| 137 | string value; |
| 138 | DataManager::GetValue(mPathVar, value); |
| 139 | if (GetFileList(value) == 0) { |
| 140 | updateFileList = false; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 141 | mUpdate = 1; |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 142 | } else |
| 143 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 144 | } |
| 145 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 146 | if (mUpdate) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 147 | mUpdate = 0; |
| 148 | if (Render() == 0) |
| 149 | return 2; |
| 150 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 154 | int GUIFileSelector::NotifyVarChange(const std::string& varName, const std::string& value) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 155 | { |
that | fa30aca | 2015-02-13 01:22:22 +0100 | [diff] [blame] | 156 | GUIScrollList::NotifyVarChange(varName, value); |
| 157 | |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 158 | if(!isConditionTrue()) |
| 159 | return 0; |
| 160 | |
Dees_Troy | 146d72a | 2013-03-11 17:46:19 +0000 | [diff] [blame] | 161 | if (varName.empty()) { |
| 162 | // Always clear the data variable so we know to use it |
| 163 | DataManager::SetValue(mVariable, ""); |
| 164 | } |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 165 | if (varName == mPathVar || varName == mSortVariable) { |
Dees_Troy | 4622cf9 | 2013-03-01 15:29:36 -0600 | [diff] [blame] | 166 | if (varName == mSortVariable) { |
| 167 | DataManager::GetValue(mSortVariable, mSortOrder); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 168 | } else { |
| 169 | // Reset the list to the top |
| 170 | SetVisibleListLocation(0); |
Dees_Troy | c0583f5 | 2013-02-28 11:19:57 -0600 | [diff] [blame] | 171 | } |
| 172 | updateFileList = true; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 173 | mUpdate = 1; |
| 174 | return 0; |
| 175 | } |
| 176 | return 0; |
| 177 | } |
| 178 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 179 | bool GUIFileSelector::fileSort(FileData d1, FileData d2) |
| 180 | { |
| 181 | if (d1.fileName == ".") |
| 182 | return -1; |
| 183 | if (d2.fileName == ".") |
| 184 | return 0; |
| 185 | if (d1.fileName == TW_FILESELECTOR_UP_A_LEVEL) |
| 186 | return -1; |
| 187 | if (d2.fileName == TW_FILESELECTOR_UP_A_LEVEL) |
| 188 | return 0; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 189 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 190 | switch (mSortOrder) { |
| 191 | case 3: // by size largest first |
| 192 | if (d1.fileSize == d2.fileSize || d1.fileType == DT_DIR) // some directories report a different size than others - but this is not the size of the files inside the directory, so we just sort by name on directories |
| 193 | return (strcasecmp(d1.fileName.c_str(), d2.fileName.c_str()) < 0); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 194 | return d1.fileSize < d2.fileSize; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 195 | case -3: // by size smallest first |
| 196 | if (d1.fileSize == d2.fileSize || d1.fileType == DT_DIR) // some directories report a different size than others - but this is not the size of the files inside the directory, so we just sort by name on directories |
| 197 | return (strcasecmp(d1.fileName.c_str(), d2.fileName.c_str()) > 0); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 198 | return d1.fileSize > d2.fileSize; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 199 | case 2: // by last modified date newest first |
| 200 | if (d1.lastModified == d2.lastModified) |
| 201 | return (strcasecmp(d1.fileName.c_str(), d2.fileName.c_str()) < 0); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 202 | return d1.lastModified < d2.lastModified; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 203 | case -2: // by date oldest first |
| 204 | if (d1.lastModified == d2.lastModified) |
| 205 | return (strcasecmp(d1.fileName.c_str(), d2.fileName.c_str()) > 0); |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 206 | return d1.lastModified > d2.lastModified; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 207 | case -1: // by name descending |
| 208 | return (strcasecmp(d1.fileName.c_str(), d2.fileName.c_str()) > 0); |
| 209 | default: // should be a 1 - sort by name ascending |
| 210 | return (strcasecmp(d1.fileName.c_str(), d2.fileName.c_str()) < 0); |
| 211 | } |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 212 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | int GUIFileSelector::GetFileList(const std::string folder) |
| 216 | { |
| 217 | DIR* d; |
| 218 | struct dirent* de; |
| 219 | struct stat st; |
| 220 | |
| 221 | // Clear all data |
| 222 | mFolderList.clear(); |
| 223 | mFileList.clear(); |
| 224 | |
| 225 | d = opendir(folder.c_str()); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 226 | if (d == NULL) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 227 | LOGINFO("Unable to open '%s'\n", folder.c_str()); |
Dees_Troy | 80a11d9 | 2013-01-25 16:36:07 +0000 | [diff] [blame] | 228 | if (folder != "/" && (mShowNavFolders != 0 || mShowFiles != 0)) { |
| 229 | size_t found; |
| 230 | found = folder.find_last_of('/'); |
| 231 | if (found != string::npos) { |
| 232 | string new_folder = folder.substr(0, found); |
| 233 | |
| 234 | if (new_folder.length() < 2) |
| 235 | new_folder = "/"; |
| 236 | DataManager::SetValue(mPathVar, new_folder); |
| 237 | } |
| 238 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 239 | return -1; |
| 240 | } |
| 241 | |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 242 | while ((de = readdir(d)) != NULL) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 243 | FileData data; |
| 244 | |
| 245 | data.fileName = de->d_name; |
| 246 | if (data.fileName == ".") |
| 247 | continue; |
| 248 | if (data.fileName == ".." && folder == "/") |
| 249 | continue; |
Dees_Troy | 3ee47bc | 2013-01-25 21:47:37 +0000 | [diff] [blame] | 250 | if (data.fileName == "..") { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | data.fileName = TW_FILESELECTOR_UP_A_LEVEL; |
Dees_Troy | 3ee47bc | 2013-01-25 21:47:37 +0000 | [diff] [blame] | 252 | data.fileType = DT_DIR; |
| 253 | } else { |
| 254 | data.fileType = de->d_type; |
| 255 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 256 | |
| 257 | std::string path = folder + "/" + data.fileName; |
| 258 | stat(path.c_str(), &st); |
| 259 | data.protection = st.st_mode; |
| 260 | data.userId = st.st_uid; |
| 261 | data.groupId = st.st_gid; |
| 262 | data.fileSize = st.st_size; |
| 263 | data.lastAccess = st.st_atime; |
| 264 | data.lastModified = st.st_mtime; |
| 265 | data.lastStatChange = st.st_ctime; |
| 266 | |
Dees_Troy | 3ee47bc | 2013-01-25 21:47:37 +0000 | [diff] [blame] | 267 | if (data.fileType == DT_UNKNOWN) { |
| 268 | data.fileType = TWFunc::Get_D_Type_From_Stat(path); |
| 269 | } |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 270 | if (data.fileType == DT_DIR) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 271 | if (mShowNavFolders || (data.fileName != "." && data.fileName != TW_FILESELECTOR_UP_A_LEVEL)) |
| 272 | mFolderList.push_back(data); |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 273 | } else if (data.fileType == DT_REG || data.fileType == DT_LNK || data.fileType == DT_BLK) { |
| 274 | if (mExtn.empty() || (data.fileName.length() > mExtn.length() && data.fileName.substr(data.fileName.length() - mExtn.length()) == mExtn)) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 275 | mFileList.push_back(data); |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | closedir(d); |
| 280 | |
| 281 | std::sort(mFolderList.begin(), mFolderList.end(), fileSort); |
| 282 | std::sort(mFileList.begin(), mFileList.end(), fileSort); |
Dees_Troy | c0583f5 | 2013-02-28 11:19:57 -0600 | [diff] [blame] | 283 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | void GUIFileSelector::SetPageFocus(int inFocus) |
| 288 | { |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 289 | GUIScrollList::SetPageFocus(inFocus); |
| 290 | if (inFocus) { |
Dees_Troy | c0583f5 | 2013-02-28 11:19:57 -0600 | [diff] [blame] | 291 | updateFileList = true; |
Dees_Troy | c0583f5 | 2013-02-28 11:19:57 -0600 | [diff] [blame] | 292 | mUpdate = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 293 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 294 | } |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 295 | |
| 296 | size_t GUIFileSelector::GetItemCount() |
| 297 | { |
| 298 | size_t folderSize = mShowFolders ? mFolderList.size() : 0; |
| 299 | size_t fileSize = mShowFiles ? mFileList.size() : 0; |
| 300 | return folderSize + fileSize; |
| 301 | } |
| 302 | |
that | f6ed8fc | 2015-02-14 20:23:16 +0100 | [diff] [blame^] | 303 | int GUIFileSelector::GetListItem(size_t item_index, ImageResource*& icon, std::string &text) |
Ethan Yonker | 0a3a98f | 2015-02-05 00:48:28 +0100 | [diff] [blame] | 304 | { |
| 305 | size_t folderSize = mShowFolders ? mFolderList.size() : 0; |
| 306 | size_t fileSize = mShowFiles ? mFileList.size() : 0; |
| 307 | |
| 308 | if (item_index < folderSize) { |
| 309 | text = mFolderList.at(item_index).fileName; |
| 310 | icon = mFolderIcon; |
| 311 | } else { |
| 312 | text = mFileList.at(item_index - folderSize).fileName; |
| 313 | icon = mFileIcon; |
| 314 | } |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | void GUIFileSelector::NotifySelect(size_t item_selected) |
| 319 | { |
| 320 | size_t folderSize = mShowFolders ? mFolderList.size() : 0; |
| 321 | size_t fileSize = mShowFiles ? mFileList.size() : 0; |
| 322 | |
| 323 | if (item_selected < folderSize + fileSize) { |
| 324 | // We've selected an item! |
| 325 | std::string str; |
| 326 | if (item_selected < folderSize) { |
| 327 | std::string cwd; |
| 328 | |
| 329 | str = mFolderList.at(item_selected).fileName; |
| 330 | if (mSelection != "0") |
| 331 | DataManager::SetValue(mSelection, str); |
| 332 | DataManager::GetValue(mPathVar, cwd); |
| 333 | |
| 334 | // Ignore requests to do nothing |
| 335 | if (str == ".") return; |
| 336 | if (str == TW_FILESELECTOR_UP_A_LEVEL) { |
| 337 | if (cwd != "/") { |
| 338 | size_t found; |
| 339 | found = cwd.find_last_of('/'); |
| 340 | cwd = cwd.substr(0,found); |
| 341 | |
| 342 | if (cwd.length() < 2) cwd = "/"; |
| 343 | } |
| 344 | } else { |
| 345 | // Add a slash if we're not the root folder |
| 346 | if (cwd != "/") cwd += "/"; |
| 347 | cwd += str; |
| 348 | } |
| 349 | |
| 350 | if (mShowNavFolders == 0 && mShowFiles == 0) { |
| 351 | // nav folders and files are disabled, this is probably the restore list and we need to save chosen location to mVariable instead of mPathVar |
| 352 | DataManager::SetValue(mVariable, cwd); |
| 353 | } else { |
| 354 | // We are changing paths, so we need to set mPathVar |
| 355 | DataManager::SetValue(mPathVar, cwd); |
| 356 | } |
| 357 | } else if (!mVariable.empty()) { |
| 358 | str = mFileList.at(item_selected - folderSize).fileName; |
| 359 | if (mSelection != "0") |
| 360 | DataManager::SetValue(mSelection, str); |
| 361 | |
| 362 | std::string cwd; |
| 363 | DataManager::GetValue(mPathVar, cwd); |
| 364 | if (cwd != "/") |
| 365 | cwd += "/"; |
| 366 | DataManager::SetValue(mVariable, cwd + str); |
| 367 | } |
| 368 | } |
| 369 | mUpdate = 1; |
| 370 | } |