17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 18:50:34 +01:00

fix(launcher): the scans of the sceneries and the vehicles go past folders they can't read, a vehicle dropped without its skin set isn't added

A folder without the permission to read it or a name that can't be converted ended the scan with an exception. Ctrl+Delete with no trainset selected, a dropped skin whose vehicle is gone, and a description with a % in it no longer crash the launcher.
This commit is contained in:
maj00r
2026-11-03 21:45:58 +01:00
parent e75d849679
commit 0d69059448
3 changed files with 33 additions and 20 deletions

View File

@@ -10,13 +10,21 @@ scenery_scanner::scenery_scanner(ui::vehicles_bank &bank)
void scenery_scanner::scan()
{
for (auto &f : std::filesystem::directory_iterator("scenery")) {
std::filesystem::path path(std::filesystem::relative(f.path(), "scenery/"));
std::error_code error;
for (std::filesystem::directory_iterator f{"scenery", std::filesystem::directory_options::skip_permission_denied, error}, end; f != end; f.increment(error)) {
std::filesystem::path path(std::filesystem::relative(f->path(), "scenery/", error));
std::string name;
try {
name = path.string();
}
catch (std::exception const &) {
continue;
}
if (*path.filename().string().begin() == '$')
if (name.empty() || path.filename().string().front() == '$')
continue;
if (path.string().ends_with(".scn"))
if (name.ends_with(".scn"))
scan_scn(path);
}