2 * SetupAPI dialog functions
4 * Copyright 2009 Ricardo Filipe
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/debug.h"
32 #include "setupapi_private.h"
34 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
38 struct promptdisk_params {
44 DWORD DiskPromptStyle;
47 PDWORD PathRequiredSize;
50 /* initiates the fields of the SetupPromptForDisk dialog according to the parameters
52 static void promptdisk_init(HWND hwnd, struct promptdisk_params *params)
57 SetWindowLongPtrW(hwnd, DWLP_USER, (LONG_PTR)params);
59 if(params->DialogTitle)
60 SetWindowTextW(hwnd, params->DialogTitle);
61 if(params->PathToSource)
62 SetDlgItemTextW(hwnd, IDC_PATH, params->PathToSource);
64 if(!(params->DiskPromptStyle & IDF_OEMDISK))
66 LoadStringW(SETUPAPI_hInstance, IDS_PROMPTDISK, format,
67 sizeof(format)/sizeof(format[0]));
70 snprintfW(message, sizeof(message)/sizeof(message[0]), format,
71 params->FileSought, params->DiskName);
75 LoadStringW(SETUPAPI_hInstance, IDS_UNKNOWN, unknown,
76 sizeof(unknown)/sizeof(unknown[0]));
77 snprintfW(message, sizeof(message)/sizeof(message[0]), format,
78 params->FileSought, unknown);
80 SetDlgItemTextW(hwnd, IDC_FILENEEDED, message);
82 LoadStringW(SETUPAPI_hInstance, IDS_INFO, message,
83 sizeof(message)/sizeof(message[0]));
84 SetDlgItemTextW(hwnd, IDC_INFO, message);
85 LoadStringW(SETUPAPI_hInstance, IDS_COPYFROM, message,
86 sizeof(message)/sizeof(message[0]));
87 SetDlgItemTextW(hwnd, IDC_COPYFROM, message);
89 if(params->DiskPromptStyle & IDF_NOBROWSE)
90 ShowWindow(GetDlgItem(hwnd, IDC_RUNDLG_BROWSE), SW_HIDE);
93 /* When the user clicks the browse button in SetupPromptForDisk dialog
94 * it copies the path of the selected file to the dialog path field
96 static void promptdisk_browse(HWND hwnd, struct promptdisk_params *params)
99 ZeroMemory(&ofn, sizeof(ofn));
101 ofn.lStructSize = sizeof(ofn);
102 ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
103 ofn.hwndOwner = hwnd;
104 ofn.nMaxFile = MAX_PATH;
105 ofn.lpstrFile = HeapAlloc(GetProcessHeap(), 0, MAX_PATH*sizeof(WCHAR));
106 strcpyW(ofn.lpstrFile, params->FileSought);
108 if(GetOpenFileNameW(&ofn))
110 WCHAR* last_slash = strrchrW(ofn.lpstrFile, '\\');
111 if (last_slash) *last_slash = 0;
112 SetDlgItemTextW(hwnd, IDC_PATH, ofn.lpstrFile);
114 HeapFree(GetProcessHeap(), 0, ofn.lpstrFile);
117 /* Handles the messages sent to the SetupPromptForDisk dialog
119 static INT_PTR CALLBACK promptdisk_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
124 promptdisk_init(hwnd, (struct promptdisk_params *)lParam);
130 EndDialog(hwnd, DPROMPT_CANCEL);
132 case IDC_RUNDLG_BROWSE:
134 struct promptdisk_params *params =
135 (struct promptdisk_params *)GetWindowLongPtrW(hwnd, DWLP_USER);
136 promptdisk_browse(hwnd, params);
144 /***********************************************************************
145 * SetupPromptForDiskW (SETUPAPI.@)
147 UINT WINAPI SetupPromptForDiskW(HWND hwndParent, PCWSTR DialogTitle, PCWSTR DiskName,
148 PCWSTR PathToSource, PCWSTR FileSought, PCWSTR TagFile, DWORD DiskPromptStyle,
149 PWSTR PathBuffer, DWORD PathBufferSize, PDWORD PathRequiredSize)
151 struct promptdisk_params params;
154 TRACE("%p, %s, %s, %s, %s, %s, 0x%08x, %p, %d, %p\n", hwndParent, debugstr_w(DialogTitle),
155 debugstr_w(DiskName), debugstr_w(PathToSource), debugstr_w(FileSought),
156 debugstr_w(TagFile), DiskPromptStyle, PathBuffer, PathBufferSize,
161 SetLastError(ERROR_INVALID_PARAMETER);
162 return DPROMPT_CANCEL;
164 params.DialogTitle = DialogTitle;
165 params.DiskName = DiskName;
166 params.PathToSource = PathToSource;
167 params.FileSought = FileSought;
168 params.TagFile = TagFile;
169 params.DiskPromptStyle = DiskPromptStyle;
170 params.PathBuffer = PathBuffer;
171 params.PathBufferSize = PathBufferSize;
172 params.PathRequiredSize = PathRequiredSize;
174 ret = DialogBoxParamW(SETUPAPI_hInstance, MAKEINTRESOURCEW(IDPROMPTFORDISK),
175 hwndParent, promptdisk_proc, (LPARAM)¶ms);
177 if(ret == DPROMPT_CANCEL)
178 SetLastError(ERROR_CANCELLED);