-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple file selection in ui_choose_file #559
base: master
Are you sure you want to change the base?
Conversation
Hi, |
Fixes: - Revert buffer size increase for fileStr - Revert memcpy change; the old behavior was fine. - Revert increase of op.nMaxFile. The old value is correct NOW, but was a crash under the old buffer sizing!
Pushed an update to both PRs. That line was originally just a safety valve during testing, but removing and testing revealed a rather exciting bug: I fixed this and reverted some other unnecessary changes I made in the process. Buffer sizing is now accounting for wchar size, and appears to behave correctly when fed too many files (returns null) |
The final hl_copy_bytes value seems incorrect. maybe should be sizeof(outputFile) ? |
Yep, that's clearly a bug. Fixed. |
I wonder if this helps the |
This is one of two PRs (The other in haxe for ui.hx) to add support for multiple selection in hl.UI.chooseFile. The haxe side PR can be found here: HaxeFoundation/haxe#10788
Both do weird things for dumb windows API reasons, so I'll explain my sins in advance. Documentation for this API can be found here: https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamea (We use the widechar version, but otherwise the call pattern is identical).
To enable multi select, we really only need to set a flag. Since we just pass a simple
Dynamic
across the fence for this, I just key off a new field and set the related flag. Note we also have to setOFN_EXPLORER
else you get the win 3.x era version of this dialogue... which is magical in its own right.The elephant in the room though is the larger buffer, and the fact that we return the entire thing. The buffer size increase is because this API doesn't really have any mechanism for letting you ask for how many bytes you need; hence we should always oversize. And the size chosen is simply due to that being the largest buffer you can even send this API. We'll need to use a newer API if we want anything more sophisticated.
The reason we pass the whole buffer, instead of the old behavior of just copying the length, is because the return format is null terminated. So
wcslen
will only ever return the path. The haxe commit has the untangling code for converting this data into haxe strings. This code isn't performance critical, so the extra copy shouldn't be a huge deal, andString.fromUCS2
doesn't rely on buffer size.