calref / cboe

Classic Blades of Exile
http://spiderwebforums.ipbhost.com/index.php?/forum/12-blades-of-exile/
Other
173 stars 42 forks source link

Windows file dialog return empty on cancel/error #303

Closed NQNStudios closed 1 year ago

NQNStudios commented 1 year ago

If it compiles, this should fix #268.

According to this documentation:

https://learn.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-getopenfilenamea https://learn.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-getsavefilenamea https://learn.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-commdlgextendederror

When Get{Open/Save}FileNameA() finishes with the Cancel input, the function returns false and the error code is 0.

So the code had 2 problems before: 1) not checking for the cancel code 0, and 2) not returning an empty string on error.

Someone needs to test this on Windows

CelticMinstrel commented 1 year ago

Ugh, why is that function using manual memory management!? It looks like this change will leak the temporary buffer used for the path.

And that's just one of the problems. It should probably be migrated to Get{Open,Save}FileNameW() instead to properly handle Unicode paths… but that's out of scope for this now.

NQNStudios commented 1 year ago

Closing in favor of #305.