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

Function FiosBrowseTo

src/fios.cpp:142–185  ·  view source on GitHub ↗

* Browse to a new path based on the passed \a item, starting at #_fios_path. * @param *item Item telling us what to do. * @return \c true when the path got changed. */

Source from the content-addressed store, hash-verified

140 * @return \c true when the path got changed.
141 */
142bool FiosBrowseTo(const FiosItem *item)
143{
144 switch (item->type.detailed) {
145 case DFT_FIOS_DRIVE:
146#if defined(_WIN32)
147 assert(_fios_path != nullptr);
148 *_fios_path = std::string{ item->name, 0, 1 } + ":" PATHSEP;
149#endif
150 break;
151
152 case DFT_INVALID:
153 break;
154
155 case DFT_FIOS_PARENT: {
156 assert(_fios_path != nullptr);
157 auto s = _fios_path->find_last_of(PATHSEPCHAR);
158 if (s != std::string::npos && s != 0) {
159 _fios_path->erase(s); // Remove last path separator character, so we can go up one level.
160 }
161
162 s = _fios_path->find_last_of(PATHSEPCHAR);
163 if (s != std::string::npos) {
164 _fios_path->erase(s + 1); // go up a directory
165 }
166 break;
167 }
168
169 case DFT_FIOS_DIR:
170 assert(_fios_path != nullptr);
171 *_fios_path += item->name;
172 *_fios_path += PATHSEP;
173 break;
174
175 case DFT_FIOS_DIRECT:
176 assert(_fios_path != nullptr);
177 *_fios_path = item->name;
178 break;
179
180 default:
181 return false;
182 }
183
184 return true;
185}
186
187/**
188 * Construct a filename from its components in destination buffer \a buf.

Callers 2

OnClickMethod · 0.85
ConChangeDirectoryFunction · 0.85

Calls 1

eraseMethod · 0.45

Tested by

no test coverage detected