MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / FindItem

Method FindItem

src/fios.cpp:103–127  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

101 * @return The information on the file, or \c nullptr if the file is not available.
102 */
103const 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 = &it;
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.

Callers 5

ConLoadFunction · 0.80
ConLoadScenarioFunction · 0.80
ConLoadHeightmapFunction · 0.80
ConRemoveFunction · 0.80
ConChangeDirectoryFunction · 0.80

Calls 5

IsInsideMMFunction · 0.85
GetDecodedStringMethod · 0.80
AnyBytesLeftMethod · 0.80
atMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected