mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-08 10:31:01 +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:
@@ -23,7 +23,7 @@ bool ui::scenerylist_panel::on_key(int key, int action)
|
|||||||
if (it == keyboard.keytonamemap.end())
|
if (it == keyboard.keytonamemap.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Global.ctrlState && it->second == "delete")
|
if (Global.ctrlState && it->second == "delete" && selected_trainset != nullptr)
|
||||||
purge_selected_trainset();
|
purge_selected_trainset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -117,7 +117,7 @@ void ui::scenerylist_panel::draw_launch_box()
|
|||||||
{
|
{
|
||||||
ImGui::NextColumn();
|
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);
|
ImGui::Checkbox(STR_C("Trainset turned around"), &selected_trainset->reversed);
|
||||||
if (ImGui::IsItemHovered())
|
if (ImGui::IsItemHovered())
|
||||||
@@ -283,7 +283,8 @@ void ui::scenerylist_panel::draw_trainset(trainset_desc &trainset)
|
|||||||
draw_droptarget(trainset, position++);
|
draw_droptarget(trainset, position++);
|
||||||
ImGui::SameLine(15.0f);
|
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;
|
deferred_image *mini = nullptr;
|
||||||
|
|
||||||
if (dyn_desc.skin && dyn_desc.skin->mini.get() != deferred_image::invalid_id)
|
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) {
|
if (payload) {
|
||||||
skin_set *ptr = *reinterpret_cast<skin_set **>(payload->Data);
|
skin_set *ptr = *reinterpret_cast<skin_set **>(payload->Data);
|
||||||
std::shared_ptr<skin_set> skin;
|
std::shared_ptr<skin_set> skin;
|
||||||
for (auto &s : ptr->vehicle.lock()->matching_skinsets)
|
if (auto const vehicle = ptr->vehicle.lock())
|
||||||
if (s.get() == ptr)
|
for (auto &s : vehicle->matching_skinsets)
|
||||||
skin = s;
|
if (s.get() == ptr)
|
||||||
|
skin = s;
|
||||||
|
|
||||||
trainset.vehicles.emplace(trainset.vehicles.begin() + position);
|
if (skin) {
|
||||||
dynamic_desc &desc = trainset.vehicles[position];
|
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.name = skin->skin + "_" + std::to_string((int)LocalRandom(0.0, 10000000.0));
|
||||||
desc.vehicle = skin->vehicle.lock();
|
desc.vehicle = skin->vehicle.lock();
|
||||||
desc.skin = skin;
|
desc.skin = skin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = ImGui::AcceptDragDropPayload("vehicle_set");
|
payload = ImGui::AcceptDragDropPayload("vehicle_set");
|
||||||
@@ -368,7 +372,7 @@ void ui::scenerylist_panel::draw_droptarget(trainset_desc &trainset, int positio
|
|||||||
if (moved->position < position)
|
if (moved->position < position)
|
||||||
offset = -1;
|
offset = -1;
|
||||||
} else {
|
} 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);
|
trainset.vehicles.insert(trainset.vehicles.begin() + position + offset, desc_copy);
|
||||||
|
|||||||
@@ -10,13 +10,21 @@ scenery_scanner::scenery_scanner(ui::vehicles_bank &bank)
|
|||||||
|
|
||||||
void scenery_scanner::scan()
|
void scenery_scanner::scan()
|
||||||
{
|
{
|
||||||
for (auto &f : std::filesystem::directory_iterator("scenery")) {
|
std::error_code error;
|
||||||
std::filesystem::path path(std::filesystem::relative(f.path(), "scenery/"));
|
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;
|
continue;
|
||||||
|
|
||||||
if (path.string().ends_with(".scn"))
|
if (name.ends_with(".scn"))
|
||||||
scan_scn(path);
|
scan_scn(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,13 @@
|
|||||||
|
|
||||||
void ui::vehicles_bank::scan_textures()
|
void ui::vehicles_bank::scan_textures()
|
||||||
{
|
{
|
||||||
for (auto &f : std::filesystem::recursive_directory_iterator("dynamic")) {
|
std::error_code error;
|
||||||
if (f.path().filename() != "textures.txt")
|
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;
|
continue;
|
||||||
|
|
||||||
std::fstream stream(f.path(), std::ios_base::binary | std::ios_base::in);
|
std::fstream stream(f->path(), std::ios_base::binary | std::ios_base::in);
|
||||||
ctx_path = std::filesystem::relative(f.path().parent_path(), "dynamic/");
|
ctx_path = std::filesystem::relative(f->path().parent_path(), "dynamic/", error);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(stream, line))
|
while (std::getline(stream, line))
|
||||||
|
|||||||
Reference in New Issue
Block a user