* Find file information of a file by its name from the file list. * @param file The filename to return information about. Can be the actual name * or a numbered entry into the filename list. * @return The information on the file, or \c nullptr if the file is not available. */
| 101 | * @return The information on the file, or \c nullptr if the file is not available. |
| 102 | */ |
| 103 | const FiosItem *FileList::FindItem(std::string_view file) |
| 104 | { |
| 105 | for (const auto &it : *this) { |
| 106 | const FiosItem *item = ⁢ |
| 107 | if (file == item->name) return item; |
| 108 | if (file == item->title.GetDecodedString()) return item; |
| 109 | } |
| 110 | |
| 111 | /* If no name matches, try to parse it as number */ |
| 112 | StringConsumer consumer{file}; |
| 113 | auto number = consumer.TryReadIntegerBase<int>(10); |
| 114 | if (number.has_value() && !consumer.AnyBytesLeft() && IsInsideMM(*number, 0, this->size())) return &this->at(*number); |
| 115 | |
| 116 | /* As a last effort assume it is an OpenTTD savegame and |
| 117 | * that the ".sav" part was not given. */ |
| 118 | std::string long_file(file); |
| 119 | long_file += ".sav"; |
| 120 | for (const auto &it : *this) { |
| 121 | const FiosItem *item = ⁢ |
| 122 | if (long_file == item->name) return item; |
| 123 | if (long_file == item->title.GetDecodedString()) return item; |
| 124 | } |
| 125 | |
| 126 | return nullptr; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get the current path/working directory. |
no test coverage detected