NiteHackr brought up a bug in the native file dialog on Windows in this thread :
https://www.allegro.cc/forums/thread/614568
I said I would work on it and I finally got time to do it.
The problem was that lpstrFile wasn't being initialized (which prevented you from specifying the open/save file), and lpstrInitialDir was being initialized with a file path and not a folder.
This is a very hacky fix, but it works, and it gives you the idea. I'm not aware of the conventions for handling strings in allegro internals so this is the way I did it. Here's the diff for win_dialog.c :
And here's the full al_show_native_file_dialog with the changes made to it so you can see more easily what is different. Whatever changes you wanna make are fine. I'm sure it will need to be edited before being accepted.
Could you change this to use al_remove_path_component?
EDIT: nvm, only removes directories...
EDIT2: Try al_set_path_filename with NULL.
Try al_set_path_filename with NULL.
Okay, it works. Just have to keep in mind the file name has been erased from fc_initial_path for future reference.
Here's the new diff :
And the function :
Not sure this is going to work. Shouldn't it check if it's an OPEN dialog before trimming the filename? After all if it's a SAVE dialog you want the filename right?
Well you don't need it. Unless someone tried to re-use a file dialog. We could clone a path, discard the filename, set the directory and then discard the clone after calling GetOpenFileName. Because you don't want the filename in the string for the directory in open or save dialogs.
New patch using a clone of the directory and checking for an empty filename to respect the documentation that states when the path ends with a directory separator then the filename is not specified, but the starting directory is :
Cloning the string wasn't the problem I had in mind. When you go to save a file sometimes you want a default filename, for examples when you do Save As. How is this specified if not through fc_initial_path?
EDIT: Ok I think you last patch looks good (upon further inspection )... let me look closer and I'll let you know.
EDIT2: Here's what I came up with. Your patch fails in some cases. For example if you set the initial path to C:\Users\trent then it assumes trent is a filename. I check if it exists, if it does I check if it's a directory, if it doesn't exist I assume it's a file.
EDIT2: Here's what I came up with. Your patch fails in some cases. For example if you set the initial path to C:\Users\trent then it assumes trent is a filename. I check if it exists, if it does I check if it's a directory, if it doesn't exist I assume it's a file.
Okay, yeah, your patch looks fine and it passes my simple test program.
Thanks for the patch, it's committed.
This needs a small fix to compile on Windows:
diff --git a/addons/native_dialog/win_dialog.c b/addons/native_dialog/win_dialog.c index 04bd873..a47b9a6 100644 --- a/addons/native_dialog/win_dialog.c +++ b/addons/native_dialog/win_dialog.c @@ -144,8 +144,8 @@ bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display, ALLEGRO_DISPLAY_WIN *win_display; int flags = 0; bool ret; - const int BUFSIZE = 4096; - char buf[BUFSIZE]; + char buf[4096]; + const int BUFSIZE = sizeof(buf); ALLEGRO_USTR *filter_string = NULL; ALLEGRO_PATH* initial_dir_path = NULL;
or see the attached patch for git HEAD.
Applied, thanks (and thanks for using git am, makes hunting down people's emails easier ).
This needs a small fix to compile on Windows
It works with MinGW 4.8.1. Are you using MSVC?
Yes, I'm using MSVC 2013 right now.