Fix for tmpdir when loading multiple mission files #360
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes sure that each mission file, when loaded, it extracts resources to unique temp dir rather than a shared one, which would lead to resource overwriting when working with multiple loaded missions.
I worked with two missions, and each had "briefing.png" attached. When I saved them I noticed that one was overwriting the other.
I guess accessing map_resource.files["DEFAULT"].values() directly might not be desired and if you want, I can remove it. I think if m.tmpdir is good, then a validation that m1.tmpdir != m2.tmpdir should be enough.
NOTE that get_file_path works only when .miz is loaded. It does not work properly (even before this patch) for missions generated by pydcs, where resources are added, e.g:
m = dcs.Mission(terrain=dcs.terrain.Caucasus())
res_key = m.add_picture_blue("tests/images/blue")
calling m.map_resource.get_file_path(res_key) would returns "'cs/dcs/tests/images/blue.png'". But that's a separate problem to solve.
With this patch the get_file_path() throws an exception, which is IMHO better than silently working wrong.
tmpdir is optional since I didn't see the need of creating a new tmp folder every time a new Mission() object is created.
Let me know your thoughts.