2 * WineCfg libraries tabsheet
4 * Copyright 2004 Robert van Herk
5 * Copyright 2004 Mike Hearn
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define WIN32_LEAN_AND_MEAN
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
37 static const WCHAR pe_dir
[] = L
"\\i386-windows";
38 #elif defined __x86_64__
39 static const WCHAR pe_dir
[] = L
"\\x86_64-windows";
41 static const WCHAR pe_dir
[] = L
"\\arm-windows";
42 #elif defined __aarch64__
43 static const WCHAR pe_dir
[] = L
"\\aarch64-windows";
45 static const WCHAR pe_dir
[] = L
"";
48 /* dlls that shouldn't be configured anything other than builtin; list must be sorted*/
49 static const WCHAR
* const builtin_only
[] =
88 UNKNOWN
/* Special value indicating an erroneous DLL override mode */
97 static const WCHAR emptyW
[1];
99 /* Convert a registry string to a dllmode */
100 static enum dllmode
string_to_mode(const WCHAR
*in
)
107 out
= malloc((len
+ 1) * sizeof(WCHAR
));
109 /* remove the spaces */
110 for (i
= j
= 0; i
<= len
; ++i
) {
116 /* parse the string */
118 if (wcscmp(out
, L
"builtin,native") == 0) res
= BUILTIN_NATIVE
;
119 if (wcscmp(out
, L
"native,builtin") == 0) res
= NATIVE_BUILTIN
;
120 if (wcscmp(out
, L
"builtin") == 0) res
= BUILTIN
;
121 if (wcscmp(out
, L
"native") == 0) res
= NATIVE
;
122 if (wcscmp(out
, L
"") == 0) res
= DISABLE
;
128 /* Convert a dllmode to a registry string. */
129 static const WCHAR
* mode_to_string(enum dllmode mode
)
133 case NATIVE
: return L
"native";
134 case BUILTIN
: return L
"builtin";
135 case NATIVE_BUILTIN
: return L
"native,builtin";
136 case BUILTIN_NATIVE
: return L
"builtin,native";
137 case DISABLE
: return L
"";
142 /* Convert a dllmode to a pretty string for display. TODO: use translations. */
143 static const WCHAR
* mode_to_label(enum dllmode mode
)
145 static WCHAR buffer
[256];
150 case NATIVE
: id
= IDS_DLL_NATIVE
; break;
151 case BUILTIN
: id
= IDS_DLL_BUILTIN
; break;
152 case NATIVE_BUILTIN
: id
= IDS_DLL_NATIVE_BUILTIN
; break;
153 case BUILTIN_NATIVE
: id
= IDS_DLL_BUILTIN_NATIVE
; break;
154 case DISABLE
: id
= IDS_DLL_DISABLED
; break;
155 default: return L
"??";
157 if (!LoadStringW( GetModuleHandleW(NULL
), id
, buffer
, ARRAY_SIZE(buffer
) )) buffer
[0] = 0;
161 /* Convert a control id (IDC_ constant) to a dllmode */
162 static enum dllmode
id_to_mode(DWORD id
)
166 case IDC_RAD_BUILTIN
: return BUILTIN
;
167 case IDC_RAD_NATIVE
: return NATIVE
;
168 case IDC_RAD_NATIVE_BUILTIN
: return NATIVE_BUILTIN
;
169 case IDC_RAD_BUILTIN_NATIVE
: return BUILTIN_NATIVE
;
170 case IDC_RAD_DISABLE
: return DISABLE
;
171 default: assert( FALSE
); return 0; /* should not be reached */
175 /* Convert a dllmode to a control id (IDC_ constant) */
176 static DWORD
mode_to_id(enum dllmode mode
)
180 case BUILTIN
: return IDC_RAD_BUILTIN
;
181 case NATIVE
: return IDC_RAD_NATIVE
;
182 case NATIVE_BUILTIN
: return IDC_RAD_NATIVE_BUILTIN
;
183 case BUILTIN_NATIVE
: return IDC_RAD_BUILTIN_NATIVE
;
184 case DISABLE
: return IDC_RAD_DISABLE
;
185 default: return IDC_RAD_BUILTIN_NATIVE
;
189 /* helper for is_builtin_only */
190 static int __cdecl
compare_dll( const void *ptr1
, const void *ptr2
)
192 const WCHAR
* const *name1
= ptr1
;
193 const WCHAR
* const *name2
= ptr2
;
194 return wcscmp( *name1
, *name2
);
197 /* check if dll is recommended as builtin only */
198 static inline BOOL
is_builtin_only( const WCHAR
*name
)
200 const WCHAR
*ext
= wcsrchr( name
, '.' );
204 if (!wcscmp( ext
, L
".vxd" ) ||
205 !wcscmp( ext
, L
".drv" ) ||
206 !wcscmp( ext
, L
".tlb" ))
209 if (!wcsncmp( name
, L
"wine", 4 )) return TRUE
;
210 return bsearch( &name
, builtin_only
, ARRAY_SIZE(builtin_only
),
211 sizeof(builtin_only
[0]), compare_dll
) != NULL
;
214 /* check if dll should be offered in the drop-down list */
215 static BOOL
show_dll_in_list( const WCHAR
*name
)
217 const WCHAR
*ext
= wcsrchr( name
, '.' );
221 /* skip 16-bit dlls */
222 if (wcslen(ext
) > 2 && !wcscmp( ext
+ wcslen(ext
) - 2, L
"16" )) return FALSE
;
224 if (!wcscmp( ext
, L
".exe" )) return FALSE
;
226 /* skip dlls that should always be builtin */
227 return !is_builtin_only( name
);
230 static void set_controls_from_selection(HWND dialog
)
232 /* FIXME: display/update some information about the selected dll (purpose, recommended load order) maybe? */
235 static void clear_settings(HWND dialog
)
237 int count
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCOUNT
, 0, 0);
240 WINE_TRACE("count=%d\n", count
);
242 for (i
= 0; i
< count
; i
++)
244 struct dll
*dll
= (struct dll
*) SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETITEMDATA
, 0, 0);
246 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_DELETESTRING
, 0, 0);
252 /* load the list of available libraries from a given dir */
253 static void load_library_list_from_dir( HWND dialog
, const WCHAR
*dir_path
, int check_subdirs
)
255 static const WCHAR
* const ext
[] = { L
".dll", L
"", L
".dll.so", L
".so" };
256 WCHAR
*buffer
, *p
, name
[256];
259 WIN32_FIND_DATAW data
;
260 ULONG maxlen
= wcslen(dir_path
) + wcslen(pe_dir
) + 10 + 2 * ARRAY_SIZE(name
);
262 buffer
= malloc( maxlen
* sizeof(WCHAR
) );
263 wcscpy( buffer
, dir_path
);
264 wcscat( buffer
, L
"\\*" );
265 buffer
[1] = '\\'; /* change \??\ to \\?\ */
266 p
= buffer
+ wcslen(buffer
) - 1;
268 if ((handle
= FindFirstFileW( buffer
, &data
)) == INVALID_HANDLE_VALUE
)
276 size_t len
= wcslen(data
.cFileName
);
277 if (len
> ARRAY_SIZE(name
)) continue;
280 if (!wcscmp( data
.cFileName
, L
"." )) continue;
281 if (!wcscmp( data
.cFileName
, L
".." )) continue;
282 if (!show_dll_in_list( data
.cFileName
)) continue;
283 for (i
= 0; i
< ARRAY_SIZE( ext
); i
++)
285 if (!ext
[i
][0] && !wcschr( data
.cFileName
, '.' )) continue;
286 swprintf( p
, buffer
+ maxlen
- p
, L
"%s%s\\%s%s", data
.cFileName
,
287 i
> 1 ? L
"" : pe_dir
, data
.cFileName
, ext
[i
] );
288 if (GetFileAttributesW( buffer
) != INVALID_FILE_ATTRIBUTES
)
290 SendDlgItemMessageW( dialog
, IDC_DLLCOMBO
, CB_ADDSTRING
, 0, (LPARAM
)data
.cFileName
);
297 for (i
= 0; i
< ARRAY_SIZE( ext
); i
++)
299 if (!ext
[i
][0]) continue;
300 if (len
> wcslen(ext
[i
]) && !wcscmp( data
.cFileName
+ len
- wcslen(ext
[i
]), ext
[i
]))
302 len
-= wcslen( ext
[i
] );
303 memcpy( name
, data
.cFileName
, len
* sizeof(WCHAR
) );
305 if (!show_dll_in_list( name
)) continue;
306 SendDlgItemMessageW( dialog
, IDC_DLLCOMBO
, CB_ADDSTRING
, 0, (LPARAM
)name
);
310 } while (FindNextFileW( handle
, &data
));
316 /* load the list of available libraries */
317 static void load_library_list( HWND dialog
)
320 WCHAR item1
[256], item2
[256], var
[32], path
[MAX_PATH
];
321 HCURSOR old_cursor
= SetCursor( LoadCursorW(0, (LPWSTR
)IDC_WAIT
) );
323 if (GetEnvironmentVariableW( L
"WINEBUILDDIR", path
, MAX_PATH
))
325 WCHAR
*dir
= malloc( wcslen(path
) * sizeof(WCHAR
) + sizeof(L
"\\dlls") );
327 wcscat( dir
, L
"\\dlls" );
328 load_library_list_from_dir( dialog
, dir
, TRUE
);
334 swprintf( var
, ARRAY_SIZE(var
), L
"WINEDLLDIR%u", i
++ );
335 if (!GetEnvironmentVariableW( var
, path
, MAX_PATH
)) break;
336 load_library_list_from_dir( dialog
, path
, FALSE
);
337 wcscat( path
, pe_dir
);
338 load_library_list_from_dir( dialog
, path
, FALSE
);
341 /* get rid of duplicate entries */
343 SendDlgItemMessageW( dialog
, IDC_DLLCOMBO
, CB_GETLBTEXT
, 0, (LPARAM
)item1
);
345 while (SendDlgItemMessageW( dialog
, IDC_DLLCOMBO
, CB_GETLBTEXT
, i
, (LPARAM
)item2
) >= 0)
347 if (!wcscmp( item1
, item2
))
349 SendDlgItemMessageW( dialog
, IDC_DLLCOMBO
, CB_DELETESTRING
, i
, 0 );
353 wcscpy( item1
, item2
);
357 SetCursor( old_cursor
);
360 static void load_library_settings(HWND dialog
)
362 WCHAR
**overrides
= enumerate_values(config_key
, keypath(L
"DllOverrides"));
366 sel
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
368 WINE_TRACE("sel=%d\n", sel
);
370 clear_settings(dialog
);
372 if (!overrides
|| *overrides
== NULL
)
374 set_controls_from_selection(dialog
);
375 disable(IDC_DLLS_EDITDLL
);
376 disable(IDC_DLLS_REMOVEDLL
);
381 enable(IDC_DLLS_EDITDLL
);
382 enable(IDC_DLLS_REMOVEDLL
);
384 for (p
= overrides
; *p
!= NULL
; p
++)
391 value
= get_reg_key(config_key
, keypath(L
"DllOverrides"), *p
, NULL
);
393 label
= mode_to_label(string_to_mode(value
));
395 len
= wcslen(*p
) + 2 + wcslen(label
) + 2;
396 str
= malloc(len
* sizeof(WCHAR
));
397 swprintf( str
, len
, L
"%s (%s)", *p
, label
);
399 dll
= malloc(sizeof(struct dll
));
401 dll
->mode
= string_to_mode(value
);
403 index
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_ADDSTRING
, (WPARAM
) -1, (LPARAM
) str
);
404 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SETITEMDATA
, index
, (LPARAM
) dll
);
413 /* restore the previous selection, if possible */
414 if (sel
>= count
- 1) sel
= count
- 1;
415 else if (sel
== -1) sel
= 0;
417 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SETCURSEL
, sel
, 0);
419 set_controls_from_selection(dialog
);
422 /* Called when the application is initialized (cannot reinit!) */
423 static void init_libsheet(HWND dialog
)
425 /* clear the add dll controls */
426 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_SETTEXT
, 1, (LPARAM
)emptyW
);
427 load_library_list( dialog
);
428 disable(IDC_DLLS_ADDDLL
);
431 static void on_add_combo_change(HWND dialog
)
436 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_GETTEXT
, ARRAY_SIZE(buffer
), (LPARAM
)buffer
);
437 /* if lib was chosen from combobox, we receive an empty buffer, check manually */
438 sel
=SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, CB_GETCURSEL
, 0, 0);
439 len
=SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, CB_GETLBTEXTLEN
, sel
, 0);
441 if (buffer
[0] || len
>0)
443 enable(IDC_DLLS_ADDDLL
)
444 SendMessageW(GetParent(dialog
), DM_SETDEFID
, IDC_DLLS_ADDDLL
, 0);
448 disable(IDC_DLLS_ADDDLL
);
449 SendMessageW(GetParent(dialog
), DM_SETDEFID
, IDOK
, 0);
453 static void set_dllmode(HWND dialog
, DWORD id
)
460 mode
= id_to_mode(id
);
462 sel
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
463 if (sel
== -1) return;
465 dll
= (struct dll
*) SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETITEMDATA
, sel
, 0);
467 str
= mode_to_string(mode
);
468 WINE_TRACE("Setting %s to %s\n", debugstr_w(dll
->name
), debugstr_w(str
));
470 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
471 set_reg_key(config_key
, keypath(L
"DllOverrides"), dll
->name
, str
);
473 load_library_settings(dialog
); /* ... and refresh */
476 static void on_add_click(HWND dialog
)
478 WCHAR buffer
[1024], *ptr
;
481 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_GETTEXT
, ARRAY_SIZE(buffer
), (LPARAM
) buffer
);
482 if (wcslen(buffer
) > 4)
484 ptr
= buffer
+ wcslen(buffer
) - 4;
485 if (!wcsicmp(ptr
, L
".dll"))
487 WINE_TRACE("Stripping dll extension\n");
492 /* check if dll is in the builtin-only list */
493 if (!(ptr
= wcsrchr( buffer
, '\\' )))
496 if (*ptr
== '*') ptr
++;
499 if (is_builtin_only( ptr
))
501 MSGBOXPARAMSW params
;
502 params
.cbSize
= sizeof(params
);
503 params
.hwndOwner
= dialog
;
504 params
.hInstance
= GetModuleHandleW( NULL
);
505 params
.lpszText
= MAKEINTRESOURCEW( IDS_DLL_WARNING
);
506 params
.lpszCaption
= MAKEINTRESOURCEW( IDS_DLL_WARNING_CAPTION
);
507 params
.dwStyle
= MB_ICONWARNING
| MB_YESNO
;
508 params
.lpszIcon
= NULL
;
509 params
.dwContextHelpId
= 0;
510 params
.lpfnMsgBoxCallback
= NULL
;
511 params
.dwLanguageId
= 0;
512 if (MessageBoxIndirectW( ¶ms
) != IDYES
) return;
515 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_SETTEXT
, 0, (LPARAM
)emptyW
);
516 disable(IDC_DLLS_ADDDLL
);
517 SendMessageW(GetParent(dialog
), DM_SETDEFID
, IDOK
, 0);
519 WINE_TRACE("Adding %s as native, builtin\n", debugstr_w(buffer
));
521 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
522 set_reg_key(config_key
, keypath(L
"DllOverrides"), buffer
, L
"native,builtin");
524 load_library_settings(dialog
);
526 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SELECTSTRING
, 0, (LPARAM
) buffer
);
528 set_controls_from_selection(dialog
);
531 static INT_PTR CALLBACK
loadorder_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
538 CheckRadioButton(hwndDlg
, IDC_RAD_BUILTIN
, IDC_RAD_DISABLE
, lParam
);
543 if(HIWORD(wParam
) != BN_CLICKED
) break;
544 switch (LOWORD(wParam
))
546 case IDC_RAD_BUILTIN
:
548 case IDC_RAD_BUILTIN_NATIVE
:
549 case IDC_RAD_NATIVE_BUILTIN
:
550 case IDC_RAD_DISABLE
:
551 sel
= LOWORD(wParam
);
554 EndDialog(hwndDlg
, sel
);
557 EndDialog(hwndDlg
, wParam
);
564 static void on_edit_click(HWND hwnd
)
567 int index
= SendDlgItemMessageW(hwnd
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
571 /* if no override is selected the edit button should be disabled... */
574 dll
= (struct dll
*) SendDlgItemMessageW(hwnd
, IDC_DLLS_LIST
, LB_GETITEMDATA
, index
, 0);
575 id
= mode_to_id(dll
->mode
);
577 ret
= DialogBoxParamW(0, MAKEINTRESOURCEW(IDD_LOADORDER
), hwnd
, loadorder_dlgproc
, id
);
580 set_dllmode(hwnd
, ret
);
583 static void on_remove_click(HWND dialog
)
585 int sel
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
588 if (sel
== LB_ERR
) return;
590 dll
= (struct dll
*) SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETITEMDATA
, sel
, 0);
592 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_DELETESTRING
, sel
, 0);
594 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
595 set_reg_key(config_key
, keypath(L
"DllOverrides"), dll
->name
, NULL
);
600 if (SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCOUNT
, 0, 0) > 0)
601 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SETCURSEL
, max(sel
- 1, 0), 0);
604 disable(IDC_DLLS_EDITDLL
);
605 disable(IDC_DLLS_REMOVEDLL
);
608 set_controls_from_selection(dialog
);
612 LibrariesDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
620 set_window_title(hDlg
);
623 switch (((LPNMHDR
)lParam
)->code
) {
625 load_library_settings(hDlg
);
630 switch(HIWORD(wParam
)) {
632 if (LOWORD(wParam
) == IDC_DLLCOMBO
)
633 on_add_combo_change(hDlg
);
636 if (LOWORD(wParam
) == IDC_DLLCOMBO
)
637 on_add_combo_change(hDlg
);
640 if (LOWORD(wParam
) == IDC_DLLCOMBO
)
641 SendMessageW(GetParent(hDlg
), DM_SETDEFID
, IDOK
, 0);
644 switch(LOWORD(wParam
)) {
645 case IDC_DLLS_ADDDLL
:
648 case IDC_DLLS_EDITDLL
:
651 case IDC_DLLS_REMOVEDLL
:
652 on_remove_click(hDlg
);
657 if(LOWORD(wParam
) == IDC_DLLCOMBO
)
658 on_add_combo_change(hDlg
);
660 set_controls_from_selection(hDlg
);