Hello !. I have a problem opening directories with special cards. The only thing that works for me is directories with no special characters. Thank you.
.......................
dialogo1 = al_create_native_file_dialog("", "", "", ALLEGRO_FILECHOOSER_FOLDER);
al_show_native_file_dialog(ventana, dialogo1);
DIRECTORIO = al_create_fs_entry(al_get_native_file_dialog_path(dialogo1, 0));
if (!(al_open_directory(DIRECTORIO))) {
al_show_native_message_box(ventana, "Mensaje", "Error", "IMPOSIBLE LEER DIRECTORIO ORIGEN", NULL, ALLEGRO_MESSAGEBOX_ERROR); }
You can use <code>code goes here...</code> tags for code please.
Can you produce a simple example program that does this? What do you mean by special characters? Where? In the source code? Or on your OS? Or?
Please be as specific as possible and help us reproduce this. What compiler and what version of allegro are you using?
EDIT
Do you mean specifically unicode characters? Non ascii? What is your OS and what language are you using?
I use the Spanish language. Windows 10 system. Visual studio.
The version of allegro is 5.
With the names of folders with special characters
( canción , フォルダの例 ... )
the previous program fails.
It only reads folders with ascii characters from 0 to 127.
dialogo1 = al_create_native_file_dialog("", "", "", ALLEGRO_FILECHOOSER_FOLDER); al_show_native_file_dialog(ventana, dialogo1); DIRECTORIO = al_create_fs_entry(al_get_native_file_dialog_path(dialogo1, 0)); if (!(al_open_directory(DIRECTORIO))) { al_show_native_message_box(ventana, "Mensaje", "Error", "IMPOSIBLE LEER DIRECTORIO ORIGEN", NULL, ALLEGRO_MESSAGEBOX_ERROR); }
I'm new to this end of the API, but from the looks of it calling al_get_native_file_dialog_path when the user hasn't selected a file will just return NULL. Unfortunately, you're not checking return values. To help you understand where your program goes wrong you should be checking return values and printing error messages when something unexpected happens (like if al_get_native_file_dialog_path returns NULL, since your program is currently assuming that won't happen). Don't pass the result of functions that can possibly fail to other functions. Store the result, check it, and then pass it on. It will save you a lot of trouble.
I don't know who created this API, but it seems pretty insane. Apparently you need to query al_get_native_file_dialog_count until it returns a value > 0 and that indicates that you can then get the path(s) from the dialog. This seems very racy and insane. You'd think with Allegro's event system that the dialog would signal selected paths with an event, but I digress... I guess that means to get the path that you need to do something like:
It's bizarre that there isn't an event when the user actually clicks "OK" or something in the dialog. Assuming that is a thing. I don't know if I've ever seen the dialog that Allegro produces.
A timeout probably doesn't make sense for a file selection dialog... I cannot imagine how you're supposed to make a user-friendly program from this. Am I missing something crucial to this API, or is it just not really meant to be used?
al_show_native_file_dialog blocks until it returns. The underlying dialog probably doesn't support Unicode.
Odd. Tried it on Linux (debian/gnome) and it seemed to be OK with unicode filenames but there was no way to choose a folder - if I selected one and pressed Open it would always just open the folder and show its contents.
Edit: Actually it's been fixed - Debian installs 5.2.2 but when I built Allegro myself (5.2.5) it worked.
Peter, it's still broken on Windows.
I had to fix a null pointer crash for your code to work (in allegro) and then it ran okay. But I tried making a directory called 'ù' and you can't select it with the dialog.
This is with Allegro 5.2.X from GIT.
The null pointer crash is in win_dialog.c on line
al_show_native_file_dialog specifically says you can pass null for the display, but select_folder doesn't handle it. Assigning hwndOwner to NULL works fine to fix it though.
I interpret then that you can not open folders in this way that contain characters that are not ascii (from 0 to 127)?
With directory names (ascii from 0 to 127) it works perfect ..
OK,
when I said "it's been fixed" I meant not being able to select directories on Linux.
The problem with Windows seems to be that it was written specifically to use the ANSI API. (As I'm sure you know) a lot of Windows functions have two variants, one ending in A for ANSI the other ending in W for wide characters, i.e. unicode. (example)
Edgar, your null pointer crash is also a bug, well spotted - the docs say it's OK to pass NULL for the display.
Pete
I understand, thanks to everyone for the help. My knowledge is very limited, anyway I have 95% completed the program (some retouching is missing) and although I would like to solve the problem, it is not vital for its correct functioning. Maybe for later ...
So guys how are we going to fix it?
please tell me technicalities, I want to work on it.
There are several problems. One, as Peter mentioned, the ascii version of windows dialog functions are being used, instead of the wide character version. This means no unicode support.
Second, the old dialogs have been superseded by the Common Item dialog starting with Windows Vista, so there are new Open and Save dialogs that should be used instead.
1. Fork https://github.com/liballeg/allegro5
2. Fix
3. Test
4. Make a pull request
and you're done!