KSP-CKAN / CKAN

The Comprehensive Kerbal Archive Network
https://forum.kerbalspaceprogram.com/index.php?/topic/197082-*
Other
1.99k stars 348 forks source link

Work around OpenFileDialog always showing all shortcuts despite filters #4168

Closed HebaruSan closed 3 months ago

HebaruSan commented 3 months ago

Problem

The popup to add a game instance is only supposed to let the user choose game executable files of known games, but it always shows all shortcuts:

image

If you choose one of these and try to use it to add a game instance, you get a (quite funny) "Catastrophic failure" message:

image

Reported by @PoofImAlex in KSP-CKAN/CKAN#4167.

Cause

This seems to be just how OpenFileDialog "works". I'm sure there's some obscure rationale for it in some Microsoft document somewhere, but it is truly inappropriate and in need of fixing in our case.

Changes

It seems to be impossible to hide shortcuts, so instead we hook into the FileOk event and reject any files that don't match the filter that we already gave to OpenFileDialog but which it decided to partially ignore:

image