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
24 #include "wine/port.h"
26 #define WIN32_LEAN_AND_MEAN
29 #include <wine/library.h>
30 #include <wine/debug.h>
35 #ifdef HAVE_SYS_STAT_H
45 WINE_DEFAULT_DEBUG_CHANNEL(winecfg
);
47 /* dlls that shouldn't be configured anything other than builtin; list must be sorted*/
48 static const char * const builtin_only
[] =
87 UNKNOWN
/* Special value indicating an erroneous DLL override mode */
96 static const WCHAR emptyW
[1];
98 /* Convert a registry string to a dllmode */
99 static enum dllmode
string_to_mode(char *in
)
106 out
= HeapAlloc(GetProcessHeap(), 0, len
+ 1);
108 /* remove the spaces */
109 for (i
= j
= 0; i
<= len
; ++i
) {
115 /* parse the string */
117 if (strcmp(out
, "builtin,native") == 0) res
= BUILTIN_NATIVE
;
118 if (strcmp(out
, "native,builtin") == 0) res
= NATIVE_BUILTIN
;
119 if (strcmp(out
, "builtin") == 0) res
= BUILTIN
;
120 if (strcmp(out
, "native") == 0) res
= NATIVE
;
121 if (strcmp(out
, "") == 0) res
= DISABLE
;
123 HeapFree(GetProcessHeap(), 0, out
);
127 /* Convert a dllmode to a registry string. */
128 static const char* mode_to_string(enum dllmode mode
)
132 case NATIVE
: return "native";
133 case BUILTIN
: return "builtin";
134 case NATIVE_BUILTIN
: return "native,builtin";
135 case BUILTIN_NATIVE
: return "builtin,native";
136 case DISABLE
: return "";
141 /* Convert a dllmode to a pretty string for display. TODO: use translations. */
142 static const char* mode_to_label(enum dllmode mode
)
144 static char buffer
[256];
149 case NATIVE
: id
= IDS_DLL_NATIVE
; break;
150 case BUILTIN
: id
= IDS_DLL_BUILTIN
; break;
151 case NATIVE_BUILTIN
: id
= IDS_DLL_NATIVE_BUILTIN
; break;
152 case BUILTIN_NATIVE
: id
= IDS_DLL_BUILTIN_NATIVE
; break;
153 case DISABLE
: id
= IDS_DLL_DISABLED
; break;
154 default: return "??";
156 if (!LoadStringA( GetModuleHandleA(NULL
), id
, buffer
, sizeof(buffer
) )) buffer
[0] = 0;
160 /* Convert a control id (IDC_ constant) to a dllmode */
161 static enum dllmode
id_to_mode(DWORD id
)
165 case IDC_RAD_BUILTIN
: return BUILTIN
;
166 case IDC_RAD_NATIVE
: return NATIVE
;
167 case IDC_RAD_NATIVE_BUILTIN
: return NATIVE_BUILTIN
;
168 case IDC_RAD_BUILTIN_NATIVE
: return BUILTIN_NATIVE
;
169 case IDC_RAD_DISABLE
: return DISABLE
;
170 default: assert( FALSE
); return 0; /* should not be reached */
174 /* Convert a dllmode to a control id (IDC_ constant) */
175 static DWORD
mode_to_id(enum dllmode mode
)
179 case BUILTIN
: return IDC_RAD_BUILTIN
;
180 case NATIVE
: return IDC_RAD_NATIVE
;
181 case NATIVE_BUILTIN
: return IDC_RAD_NATIVE_BUILTIN
;
182 case BUILTIN_NATIVE
: return IDC_RAD_BUILTIN_NATIVE
;
183 case DISABLE
: return IDC_RAD_DISABLE
;
184 default: return IDC_RAD_BUILTIN_NATIVE
;
188 /* helper for is_builtin_only */
189 static int compare_dll( const void *ptr1
, const void *ptr2
)
191 const char * const *name1
= ptr1
;
192 const char * const *name2
= ptr2
;
193 return strcmp( *name1
, *name2
);
196 /* check if dll is recommended as builtin only */
197 static inline BOOL
is_builtin_only( const char *name
)
199 const char *ext
= strrchr( name
, '.' );
203 if (!strcmp( ext
, ".vxd" ) ||
204 !strcmp( ext
, ".drv" ) ||
205 !strcmp( ext
, ".tlb" ))
208 if (!strncmp( name
, "wine", 4 )) return TRUE
;
209 return bsearch( &name
, builtin_only
, ARRAY_SIZE(builtin_only
),
210 sizeof(builtin_only
[0]), compare_dll
) != NULL
;
213 /* check if dll should be offered in the drop-down list */
214 static BOOL
show_dll_in_list( const char *name
)
216 const char *ext
= strrchr( name
, '.' );
220 /* skip 16-bit dlls */
221 if (strlen(ext
) > 2 && !strcmp( ext
+ strlen(ext
) - 2, "16" )) return FALSE
;
223 if (!strcmp( ext
, ".exe" )) return FALSE
;
225 /* skip api set placeholders */
226 if (!strncmp( name
, "api-ms-", 7 ) || !strncmp( name
, "ext-ms-", 7 )) return FALSE
;
227 /* skip dlls that should always be builtin */
228 return !is_builtin_only( name
);
231 static void set_controls_from_selection(HWND dialog
)
233 /* FIXME: display/update some information about the selected dll (purpose, recommended load order) maybe? */
236 static void clear_settings(HWND dialog
)
238 int count
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCOUNT
, 0, 0);
241 WINE_TRACE("count=%d\n", count
);
243 for (i
= 0; i
< count
; i
++)
245 struct dll
*dll
= (struct dll
*) SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETITEMDATA
, 0, 0);
247 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_DELETESTRING
, 0, 0);
248 HeapFree(GetProcessHeap(), 0, dll
->name
);
249 HeapFree(GetProcessHeap(), 0, dll
);
253 /* load the list of available libraries from a given dir */
254 static void load_library_list_from_dir( HWND dialog
, const char *dir_path
, int check_subdirs
)
256 static const char * const ext
[] = { ".dll", ".dll.so", ".so", "" };
257 char *buffer
= NULL
, name
[256];
260 DIR *dir
= opendir( dir_path
);
265 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(dir_path
) + 2 * sizeof(name
) + 10 );
267 while ((de
= readdir( dir
)))
269 size_t len
= strlen(de
->d_name
);
270 if (len
> sizeof(name
)) continue;
275 if (!strcmp( de
->d_name
, "." )) continue;
276 if (!strcmp( de
->d_name
, ".." )) continue;
277 if (!show_dll_in_list( de
->d_name
)) continue;
278 for (i
= 0; i
< ARRAY_SIZE( ext
); i
++)
280 sprintf( buffer
, "%s/%s/%s%s", dir_path
, de
->d_name
, de
->d_name
, ext
[i
] );
281 if (!stat( buffer
, &st
))
283 SendDlgItemMessageA( dialog
, IDC_DLLCOMBO
, CB_ADDSTRING
, 0, (LPARAM
)de
->d_name
);
290 for (i
= 0; i
< ARRAY_SIZE( ext
); i
++)
292 if (!ext
[i
][0]) continue;
293 if (len
> strlen(ext
[i
]) && !strcmp( de
->d_name
+ len
- strlen(ext
[i
]), ext
[i
]))
295 len
-= strlen( ext
[i
] );
296 memcpy( name
, de
->d_name
, len
);
298 if (!show_dll_in_list( name
)) continue;
299 SendDlgItemMessageA( dialog
, IDC_DLLCOMBO
, CB_ADDSTRING
, 0, (LPARAM
)name
);
305 HeapFree( GetProcessHeap(), 0, buffer
);
308 /* load the list of available libraries */
309 static void load_library_list( HWND dialog
)
312 const char *path
, *build_dir
= wine_get_build_dir();
313 char item1
[256], item2
[256];
314 HCURSOR old_cursor
= SetCursor( LoadCursorW(0, (LPWSTR
)IDC_WAIT
) );
318 char *dir
= HeapAlloc( GetProcessHeap(), 0, strlen(build_dir
) + sizeof("/dlls") );
319 strcpy( dir
, build_dir
);
320 strcat( dir
, "/dlls" );
321 load_library_list_from_dir( dialog
, dir
, TRUE
);
322 HeapFree( GetProcessHeap(), 0, dir
);
325 while ((path
= wine_dll_enum_load_path( i
++ )))
326 load_library_list_from_dir( dialog
, path
, FALSE
);
328 /* get rid of duplicate entries */
330 SendDlgItemMessageA( dialog
, IDC_DLLCOMBO
, CB_GETLBTEXT
, 0, (LPARAM
)item1
);
332 while (SendDlgItemMessageA( dialog
, IDC_DLLCOMBO
, CB_GETLBTEXT
, i
, (LPARAM
)item2
) >= 0)
334 if (!strcmp( item1
, item2
))
336 SendDlgItemMessageA( dialog
, IDC_DLLCOMBO
, CB_DELETESTRING
, i
, 0 );
340 strcpy( item1
, item2
);
344 SetCursor( old_cursor
);
347 static void load_library_settings(HWND dialog
)
349 char **overrides
= enumerate_values(config_key
, keypath("DllOverrides"));
353 sel
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
355 WINE_TRACE("sel=%d\n", sel
);
357 clear_settings(dialog
);
359 if (!overrides
|| *overrides
== NULL
)
361 set_controls_from_selection(dialog
);
362 disable(IDC_DLLS_EDITDLL
);
363 disable(IDC_DLLS_REMOVEDLL
);
364 HeapFree(GetProcessHeap(), 0, overrides
);
368 enable(IDC_DLLS_EDITDLL
);
369 enable(IDC_DLLS_REMOVEDLL
);
371 for (p
= overrides
; *p
!= NULL
; p
++)
378 value
= get_reg_key(config_key
, keypath("DllOverrides"), *p
, NULL
);
380 label
= mode_to_label(string_to_mode(value
));
382 str
= HeapAlloc(GetProcessHeap(), 0, strlen(*p
) + 2 + strlen(label
) + 2);
388 dll
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct dll
));
390 dll
->mode
= string_to_mode(value
);
392 index
= SendDlgItemMessageA(dialog
, IDC_DLLS_LIST
, LB_ADDSTRING
, (WPARAM
) -1, (LPARAM
) str
);
393 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SETITEMDATA
, index
, (LPARAM
) dll
);
395 HeapFree(GetProcessHeap(), 0, str
);
400 HeapFree(GetProcessHeap(), 0, overrides
);
402 /* restore the previous selection, if possible */
403 if (sel
>= count
- 1) sel
= count
- 1;
404 else if (sel
== -1) sel
= 0;
406 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SETCURSEL
, sel
, 0);
408 set_controls_from_selection(dialog
);
411 /* Called when the application is initialized (cannot reinit!) */
412 static void init_libsheet(HWND dialog
)
414 /* clear the add dll controls */
415 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_SETTEXT
, 1, (LPARAM
)emptyW
);
416 load_library_list( dialog
);
417 disable(IDC_DLLS_ADDDLL
);
420 static void on_add_combo_change(HWND dialog
)
425 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_GETTEXT
, ARRAY_SIZE(buffer
), (LPARAM
)buffer
);
426 /* if lib was chosen from combobox, we receive an empty buffer, check manually */
427 sel
=SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, CB_GETCURSEL
, 0, 0);
428 len
=SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, CB_GETLBTEXTLEN
, sel
, 0);
430 if (buffer
[0] || len
>0)
432 enable(IDC_DLLS_ADDDLL
)
433 SendMessageW(GetParent(dialog
), DM_SETDEFID
, IDC_DLLS_ADDDLL
, 0);
437 disable(IDC_DLLS_ADDDLL
);
438 SendMessageW(GetParent(dialog
), DM_SETDEFID
, IDOK
, 0);
442 static void set_dllmode(HWND dialog
, DWORD id
)
449 mode
= id_to_mode(id
);
451 sel
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
452 if (sel
== -1) return;
454 dll
= (struct dll
*) SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETITEMDATA
, sel
, 0);
456 str
= mode_to_string(mode
);
457 WINE_TRACE("Setting %s to %s\n", dll
->name
, str
);
459 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
460 set_reg_key(config_key
, keypath("DllOverrides"), dll
->name
, str
);
462 load_library_settings(dialog
); /* ... and refresh */
465 static void on_add_click(HWND dialog
)
467 static const char dotDll
[] = ".dll";
468 char buffer
[1024], *ptr
;
470 ZeroMemory(buffer
, sizeof(buffer
));
472 SendDlgItemMessageA(dialog
, IDC_DLLCOMBO
, WM_GETTEXT
, sizeof(buffer
), (LPARAM
) buffer
);
473 if (lstrlenA(buffer
) >= sizeof(dotDll
))
475 ptr
= buffer
+ lstrlenA(buffer
) - sizeof(dotDll
) + 1;
476 if (!lstrcmpiA(ptr
, dotDll
))
478 WINE_TRACE("Stripping dll extension\n");
483 /* check if dll is in the builtin-only list */
484 if (!(ptr
= strrchr( buffer
, '\\' )))
487 if (*ptr
== '*') ptr
++;
490 if (is_builtin_only( ptr
))
492 MSGBOXPARAMSA params
;
493 params
.cbSize
= sizeof(params
);
494 params
.hwndOwner
= dialog
;
495 params
.hInstance
= GetModuleHandleA( NULL
);
496 params
.lpszText
= MAKEINTRESOURCEA( IDS_DLL_WARNING
);
497 params
.lpszCaption
= MAKEINTRESOURCEA( IDS_DLL_WARNING_CAPTION
);
498 params
.dwStyle
= MB_ICONWARNING
| MB_YESNO
;
499 params
.lpszIcon
= NULL
;
500 params
.dwContextHelpId
= 0;
501 params
.lpfnMsgBoxCallback
= NULL
;
502 params
.dwLanguageId
= 0;
503 if (MessageBoxIndirectA( ¶ms
) != IDYES
) return;
506 SendDlgItemMessageW(dialog
, IDC_DLLCOMBO
, WM_SETTEXT
, 0, (LPARAM
)emptyW
);
507 disable(IDC_DLLS_ADDDLL
);
508 SendMessageW(GetParent(dialog
), DM_SETDEFID
, IDOK
, 0);
510 WINE_TRACE("Adding %s as native, builtin\n", buffer
);
512 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
513 set_reg_key(config_key
, keypath("DllOverrides"), buffer
, "native,builtin");
515 load_library_settings(dialog
);
517 SendDlgItemMessageA(dialog
, IDC_DLLS_LIST
, LB_SELECTSTRING
, 0, (LPARAM
) buffer
);
519 set_controls_from_selection(dialog
);
522 static INT_PTR CALLBACK
loadorder_dlgproc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
529 CheckRadioButton(hwndDlg
, IDC_RAD_BUILTIN
, IDC_RAD_DISABLE
, lParam
);
534 if(HIWORD(wParam
) != BN_CLICKED
) break;
535 switch (LOWORD(wParam
))
537 case IDC_RAD_BUILTIN
:
539 case IDC_RAD_BUILTIN_NATIVE
:
540 case IDC_RAD_NATIVE_BUILTIN
:
541 case IDC_RAD_DISABLE
:
542 sel
= LOWORD(wParam
);
545 EndDialog(hwndDlg
, sel
);
548 EndDialog(hwndDlg
, wParam
);
555 static void on_edit_click(HWND hwnd
)
558 int index
= SendDlgItemMessageW(hwnd
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
562 /* if no override is selected the edit button should be disabled... */
565 dll
= (struct dll
*) SendDlgItemMessageW(hwnd
, IDC_DLLS_LIST
, LB_GETITEMDATA
, index
, 0);
566 id
= mode_to_id(dll
->mode
);
568 ret
= DialogBoxParamW(0, MAKEINTRESOURCEW(IDD_LOADORDER
), hwnd
, loadorder_dlgproc
, id
);
571 set_dllmode(hwnd
, ret
);
574 static void on_remove_click(HWND dialog
)
576 int sel
= SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCURSEL
, 0, 0);
579 if (sel
== LB_ERR
) return;
581 dll
= (struct dll
*) SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETITEMDATA
, sel
, 0);
583 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_DELETESTRING
, sel
, 0);
585 SendMessageW(GetParent(dialog
), PSM_CHANGED
, 0, 0);
586 set_reg_key(config_key
, keypath("DllOverrides"), dll
->name
, NULL
);
588 HeapFree(GetProcessHeap(), 0, dll
->name
);
589 HeapFree(GetProcessHeap(), 0, dll
);
591 if (SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_GETCOUNT
, 0, 0) > 0)
592 SendDlgItemMessageW(dialog
, IDC_DLLS_LIST
, LB_SETCURSEL
, max(sel
- 1, 0), 0);
595 disable(IDC_DLLS_EDITDLL
);
596 disable(IDC_DLLS_REMOVEDLL
);
599 set_controls_from_selection(dialog
);
603 LibrariesDlgProc (HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
611 set_window_title(hDlg
);
614 switch (((LPNMHDR
)lParam
)->code
) {
616 load_library_settings(hDlg
);
621 switch(HIWORD(wParam
)) {
623 if (LOWORD(wParam
) == IDC_DLLCOMBO
)
624 on_add_combo_change(hDlg
);
627 if (LOWORD(wParam
) == IDC_DLLCOMBO
)
628 on_add_combo_change(hDlg
);
631 if (LOWORD(wParam
) == IDC_DLLCOMBO
)
632 SendMessageW(GetParent(hDlg
), DM_SETDEFID
, IDOK
, 0);
635 switch(LOWORD(wParam
)) {
636 case IDC_DLLS_ADDDLL
:
639 case IDC_DLLS_EDITDLL
:
642 case IDC_DLLS_REMOVEDLL
:
643 on_remove_click(hDlg
);
648 if(LOWORD(wParam
) == IDC_DLLCOMBO
)
649 on_add_combo_change(hDlg
);
651 set_controls_from_selection(hDlg
);