17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 02:58:37 +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

@@ -23,7 +23,7 @@ bool ui::scenerylist_panel::on_key(int key, int action)
if (it == keyboard.keytonamemap.end())
return false;
if (Global.ctrlState && it->second == "delete")
if (Global.ctrlState && it->second == "delete" && selected_trainset != nullptr)
purge_selected_trainset();
return true;
@@ -117,7 +117,7 @@ void ui::scenerylist_panel::draw_launch_box()
{
ImGui::NextColumn();
ImGui::TextWrapped(selected_trainset->description.c_str());
ImGui::TextWrapped("%s", selected_trainset->description.c_str());
ImGui::Checkbox(STR_C("Trainset turned around"), &selected_trainset->reversed);
if (ImGui::IsItemHovered())
@@ -283,7 +283,8 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
draw_droptarget(trainset, position++);
ImGui::SameLine(15.0f);
for (auto &dyn_desc : trainset.vehicles) {
for (std::size_t index = 0; index < trainset.vehicles.size(); ++index) {
auto &dyn_desc = trainset.vehicles[index];
deferred_image *mini = nullptr;
if (dyn_desc.skin && dyn_desc.skin->mini.get() != deferred_image::invalid_id)
@@ -345,16 +346,19 @@ void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int positio
if (payload) {
skin_set *ptr = *reinterpret_cast<skin_set **>(payload->Data);
std::shared_ptr<skin_set> skin;
for (auto &s : ptr->vehicle.lock()->matching_skinsets)
if (s.get() == ptr)
skin = s;
if (auto const vehicle = ptr->vehicle.lock())
for (auto &s : vehicle->matching_skinsets)
if (s.get() == ptr)
skin = s;
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
dynamic_desc &desc = trainset.vehicles[position];
if (skin) {
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
dynamic_desc &desc = trainset.vehicles[position];
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
desc.vehicle = skin->vehicle.lock();
desc.skin = skin;
desc.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
desc.vehicle = skin->vehicle.lock();
desc.skin = skin;
}
}
payload = ImGui::AcceptDragDropPayload("vehicle_set");
@@ -368,7 +372,7 @@ void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int positio
if (moved->position < position)
offset = -1;
} else {
desc_copy.name = desc_copy.skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
desc_copy.name = (desc_copy.skin ? desc_copy.skin->skin : desc_copy.name) + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
}
trainset.vehicles.insert(trainset.vehicles.begin() + position + offset, desc_copy);

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);
}

View File

@@ -4,12 +4,13 @@
void ui::vehicles_bank::scan_textures()
{
for (auto &f : std::filesystem::recursive_directory_iterator("dynamic")) {
if (f.path().filename() != "textures.txt")
std::error_code error;
for (std::filesystem::recursive_directory_iterator f{"dynamic", std::filesystem::directory_options::skip_permission_denied, error}, end; f != end; f.increment(error)) {
if (f->path().filename() != "textures.txt")
continue;
std::fstream stream(f.path(), std::ios_base::binary | std::ios_base::in);
ctx_path = std::filesystem::relative(f.path().parent_path(), "dynamic/");
std::fstream stream(f->path(), std::ios_base::binary | std::ios_base::in);
ctx_path = std::filesystem::relative(f->path().parent_path(), "dynamic/", error);
std::string line;
while (std::getline(stream, line))