| 166 | } |
| 167 | |
| 168 | void PopulateList(const u8string& directory, std::string_view extensionPattern) |
| 169 | { |
| 170 | const auto absoluteDirectory = Path::GetAbsolute(directory); |
| 171 | String::safeUtf8Copy(_directory, absoluteDirectory.c_str(), std::size(_directory)); |
| 172 | // Note: This compares the pointers, not values |
| 173 | _extensionPattern = extensionPattern; |
| 174 | |
| 175 | _listItems.clear(); |
| 176 | |
| 177 | int32_t drives = Platform::GetDrives(); |
| 178 | if (directory.empty() && drives) |
| 179 | { |
| 180 | // List Windows drives |
| 181 | setWidgetDisabled(WIDX_NEW_FOLDER, true); |
| 182 | setWidgetDisabled(WIDX_PARENT_FOLDER, true); |
| 183 | static constexpr auto NumDriveLetters = 26; |
| 184 | for (int32_t x = 0; x < NumDriveLetters; x++) |
| 185 | { |
| 186 | if (drives & (1 << x)) |
| 187 | { |
| 188 | // If the drive exists, list it |
| 189 | LoadSaveListItem newListItem; |
| 190 | newListItem.path = std::string(1, 'A' + x) + ":" PATH_SEPARATOR; |
| 191 | newListItem.name = newListItem.path; |
| 192 | newListItem.type = FileType::directory; |
| 193 | |
| 194 | _listItems.push_back(std::move(newListItem)); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | // Remove the separator at the end of the path, if present |
| 201 | String::safeUtf8Copy(_parentDirectory, absoluteDirectory.c_str(), std::size(_parentDirectory)); |
| 202 | if (_parentDirectory[strlen(_parentDirectory) - 1] == *PATH_SEPARATOR |
| 203 | || _parentDirectory[strlen(_parentDirectory) - 1] == '/') |
| 204 | _parentDirectory[strlen(_parentDirectory) - 1] = '\0'; |
| 205 | |
| 206 | // Remove everything past the now last separator |
| 207 | char* ch = strrchr(_parentDirectory, *PATH_SEPARATOR); |
| 208 | char* posix_ch = strrchr(_parentDirectory, '/'); |
| 209 | ch = ch < posix_ch ? posix_ch : ch; |
| 210 | if (ch != nullptr) |
| 211 | { |
| 212 | *(ch + 1) = '\0'; |
| 213 | } |
| 214 | else if (drives) |
| 215 | { |
| 216 | // If on Windows, clear the entire path to show the drives |
| 217 | _parentDirectory[0] = '\0'; |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | // Else, go to the root directory |
| 222 | snprintf(_parentDirectory, MAX_PATH, "%c", *PATH_SEPARATOR); |
| 223 | } |
| 224 | |
| 225 | // Disable the Up button if the current directory is the root directory |
nothing calls this directly
no test coverage detected