@@ -93,11 +93,50 @@ void _al_shutdown_native_dialog_addon(void)
93
93
wm_size_cond = NULL ;
94
94
}
95
95
96
+ static INT CALLBACK _browse_callback_proc (HWND hwnd , UINT uMsg , LPARAM unused , LPARAM pData )
97
+ {
98
+ (void )unused ;
99
+ if (uMsg == BFFM_INITIALIZED ) SendMessage (hwnd , BFFM_SETSELECTION , TRUE, pData );
100
+ return 0 ;
101
+ }
102
+
103
+ static TCHAR * _extract_dirname (ALLEGRO_PATH * fullpath )
104
+ {
105
+ TCHAR * wpath = NULL ;
106
+ bool is_dir ;
107
+ const ALLEGRO_USTR * path = al_path_ustr (fullpath , ALLEGRO_NATIVE_PATH_SEP );
108
+
109
+ if (al_filename_exists (al_cstr (path ))) {
110
+ ALLEGRO_FS_ENTRY * fs = al_create_fs_entry (al_cstr (path ));
111
+ is_dir = al_get_fs_entry_mode (fs ) & ALLEGRO_FILEMODE_ISDIR ;
112
+ al_destroy_fs_entry (fs );
113
+ }
114
+ else {
115
+ is_dir = false;
116
+ }
117
+
118
+ if (is_dir ) {
119
+ wpath = _twin_ustr_to_tchar (path );
120
+ }
121
+ else {
122
+ /* Extract the directory from the path. */
123
+
124
+ ALLEGRO_PATH * initial_dir_path = NULL ;
125
+ initial_dir_path = al_clone_path (fullpath );
126
+ if (initial_dir_path ) {
127
+ al_set_path_filename (initial_dir_path , NULL );
128
+ wpath = _twin_utf8_to_tchar (al_path_cstr (initial_dir_path , ALLEGRO_NATIVE_PATH_SEP ));
129
+ al_destroy_path (initial_dir_path );
130
+ }
131
+ }
132
+ return wpath ;
133
+ }
96
134
97
135
static bool select_folder (ALLEGRO_DISPLAY_WIN * win_display ,
98
136
ALLEGRO_NATIVE_DIALOG * fd )
99
137
{
100
138
BROWSEINFO folderinfo ;
139
+ TCHAR * wpath = NULL ;
101
140
LPCITEMIDLIST pidl ;
102
141
/* Selected path */
103
142
TCHAR buf [MAX_PATH ] = TEXT ("" );
@@ -110,10 +149,17 @@ static bool select_folder(ALLEGRO_DISPLAY_WIN *win_display,
110
149
folderinfo .lpszTitle = _twin_ustr_to_tchar (fd -> title );
111
150
folderinfo .ulFlags = 0 ;
112
151
folderinfo .lpfn = NULL ;
152
+
153
+ if (fd -> fc_initial_path ) {
154
+ wpath = _extract_dirname (fd -> fc_initial_path );
155
+ folderinfo .lpfn = _browse_callback_proc ;
156
+ folderinfo .lParam = (LPARAM ) wpath ;
157
+ }
113
158
114
159
pidl = SHBrowseForFolder (& folderinfo );
115
160
116
161
al_free ((void * ) folderinfo .lpszTitle );
162
+ al_free (wpath );
117
163
118
164
if (pidl ) {
119
165
SHGetPathFromIDList (pidl , buf );
@@ -197,7 +243,6 @@ bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display,
197
243
TCHAR * wfilter = NULL ;
198
244
TCHAR * wpath = NULL ;
199
245
ALLEGRO_USTR * filter_string = NULL ;
200
- ALLEGRO_PATH * initial_dir_path = NULL ;
201
246
202
247
buf [0 ] = '\0' ;
203
248
@@ -229,29 +274,8 @@ bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display,
229
274
230
275
/* Initialize file name buffer and starting directory. */
231
276
if (fd -> fc_initial_path ) {
232
- bool is_dir ;
233
- const ALLEGRO_USTR * path = al_path_ustr (fd -> fc_initial_path , ALLEGRO_NATIVE_PATH_SEP );
234
277
235
- if (al_filename_exists (al_cstr (path ))) {
236
- ALLEGRO_FS_ENTRY * fs = al_create_fs_entry (al_cstr (path ));
237
- is_dir = al_get_fs_entry_mode (fs ) & ALLEGRO_FILEMODE_ISDIR ;
238
- al_destroy_fs_entry (fs );
239
- }
240
- else {
241
- is_dir = false;
242
- }
243
-
244
- if (is_dir ) {
245
- wpath = _twin_ustr_to_tchar (path );
246
- }
247
- else {
248
- /* Extract the directory from the path. */
249
- initial_dir_path = al_clone_path (fd -> fc_initial_path );
250
- if (initial_dir_path ) {
251
- al_set_path_filename (initial_dir_path , NULL );
252
- wpath = _twin_utf8_to_tchar (al_path_cstr (initial_dir_path , ALLEGRO_NATIVE_PATH_SEP ));
253
- }
254
- }
278
+ wpath = _extract_dirname (fd -> fc_initial_path );
255
279
ofn .lpstrInitialDir = wpath ;
256
280
}
257
281
@@ -276,9 +300,6 @@ bool _al_show_native_file_dialog(ALLEGRO_DISPLAY *display,
276
300
ret = GetOpenFileName (& ofn );
277
301
}
278
302
279
- if (initial_dir_path ) {
280
- al_destroy_path (initial_dir_path );
281
- }
282
303
al_free ((void * ) ofn .lpstrTitle );
283
304
al_free (wfilter );
284
305
al_free (wpath );
0 commit comments