ReactOS 0.4.15-dev-8116-gf69e256
dialog.c
Go to the documentation of this file.
1/*
2 * SetupAPI dialog functions
3 *
4 * Copyright 2009 Ricardo Filipe
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "setupapi_private.h"
22
33};
34
35/* initiates the fields of the SetupPromptForDisk dialog according to the parameters
36*/
38{
40
41 if(params->DialogTitle)
42 SetWindowTextW(hwnd, params->DialogTitle);
43 if(params->PathToSource)
44 SetDlgItemTextW(hwnd, IDC_PATH, params->PathToSource);
45
46 if(!(params->DiskPromptStyle & IDF_OEMDISK))
47 {
48 WCHAR message[256+2*MAX_PATH];
49 WCHAR format[256];
50 WCHAR unknown[256];
51 DWORD_PTR args[2];
53 sizeof(format)/sizeof(format[0]));
54
55 args[0] = (DWORD_PTR)params->FileSought;
56 if(params->DiskName)
57 args[1] = (DWORD_PTR)params->DiskName;
58 else
59 {
61 sizeof(unknown)/sizeof(unknown[0]));
63 }
65 format, 0, 0, message, sizeof(message)/sizeof(*message),
68
70 sizeof(message)/sizeof(message[0]));
73 sizeof(message)/sizeof(message[0]));
75 }
76 if(params->DiskPromptStyle & IDF_NOBROWSE)
78}
79
80/* When the user clicks in the Ok button in SetupPromptForDisk dialog
81 * if the parameters are good it copies the path from the dialog to the output buffer
82 * saves the required size for the buffer if PathRequiredSize is given
83 * returns NO_ERROR if there is no PathBuffer to copy too
84 * returns DPROMPT_BUFFERTOOSMALL if the path is too big to fit in PathBuffer
85 */
87{
88 int requiredSize;
91 requiredSize = strlenW(aux)+1;
92
93 if(params->PathRequiredSize)
94 {
95 *params->PathRequiredSize = requiredSize;
96 TRACE("returning PathRequiredSize=%d\n",*params->PathRequiredSize);
97 }
98 if(!params->PathBuffer)
99 {
101 return;
102 }
103 if(requiredSize > params->PathBufferSize)
104 {
106 return;
107 }
108 strcpyW(params->PathBuffer, aux);
109 TRACE("returning PathBuffer=%s\n", debugstr_w(params->PathBuffer));
111}
112
113/* When the user clicks the browse button in SetupPromptForDisk dialog
114 * it copies the path of the selected file to the dialog path field
115 */
117{
119 ZeroMemory(&ofn, sizeof(ofn));
120
121 ofn.lStructSize = sizeof(ofn);
126 strcpyW(ofn.lpstrFile, params->FileSought);
127
129 {
130 WCHAR* last_slash = strrchrW(ofn.lpstrFile, '\\');
131 if (last_slash) *last_slash = 0;
133 }
135}
136
137/* Handles the messages sent to the SetupPromptForDisk dialog
138*/
140{
141 switch(msg)
142 {
143 case WM_INITDIALOG:
145 return TRUE;
146 case WM_COMMAND:
147 switch(wParam)
148 {
149 case IDOK:
150 {
151 struct promptdisk_params *params =
154 return TRUE;
155 }
156 case IDCANCEL:
158 return TRUE;
160 {
161 struct promptdisk_params *params =
164 return TRUE;
165 }
166 }
167 }
168 return FALSE;
169}
170
171/***********************************************************************
172 * SetupPromptForDiskA (SETUPAPI.@)
173 */
177{
178 WCHAR *DialogTitleW, *DiskNameW, *PathToSourceW;
179 WCHAR *FileSoughtW, *TagFileW, PathBufferW[MAX_PATH];
180 UINT ret, length;
181
182 TRACE("%p, %s, %s, %s, %s, %s, 0x%08x, %p, %d, %p\n", hwndParent, debugstr_a(DialogTitle),
186
187 DialogTitleW = strdupAtoW(DialogTitle);
188 DiskNameW = strdupAtoW(DiskName);
189 PathToSourceW = strdupAtoW(PathToSource);
190 FileSoughtW = strdupAtoW(FileSought);
191 TagFileW = strdupAtoW(TagFile);
192
193 ret = SetupPromptForDiskW(hwndParent, DialogTitleW, DiskNameW, PathToSourceW,
194 FileSoughtW, TagFileW, DiskPromptStyle, PathBufferW, MAX_PATH, PathRequiredSize);
195
196 HeapFree(GetProcessHeap(), 0, DialogTitleW);
197 HeapFree(GetProcessHeap(), 0, DiskNameW);
198 HeapFree(GetProcessHeap(), 0, PathToSourceW);
199 HeapFree(GetProcessHeap(), 0, FileSoughtW);
200 HeapFree(GetProcessHeap(), 0, TagFileW);
201
202 if(ret == DPROMPT_SUCCESS)
203 {
204 length = WideCharToMultiByte(CP_ACP, 0, PathBufferW, -1, NULL, 0, NULL, NULL);
206 if(PathBuffer)
207 {
210 WideCharToMultiByte(CP_ACP, 0, PathBufferW, -1, PathBuffer, length, NULL, NULL);
211 }
212 }
213 return ret;
214}
215
216/***********************************************************************
217 * SetupPromptForDiskW (SETUPAPI.@)
218 */
222{
224 UINT ret;
225
226 TRACE("%p, %s, %s, %s, %s, %s, 0x%08x, %p, %d, %p\n", hwndParent, debugstr_w(DialogTitle),
230
231 if(!FileSought)
232 {
234 return DPROMPT_CANCEL;
235 }
236
238 {
239 static const WCHAR format[] = {'%', 's', '\\', '%', 's', '\0'};
240 WCHAR filepath[MAX_PATH];
241
242 if (strlenW(PathToSource) + 1 + strlenW(FileSought) < sizeof(filepath))
243 {
245
247 {
250
251 if (!PathBuffer)
252 return DPROMPT_SUCCESS;
253
255 {
257 return DPROMPT_SUCCESS;
258 }
259 else
261 }
262 }
263 }
264
265 params.DialogTitle = DialogTitle;
266 params.DiskName = DiskName;
267 params.PathToSource = PathToSource;
268 params.FileSought = FileSought;
269 params.TagFile = TagFile;
270 params.DiskPromptStyle = DiskPromptStyle;
271 params.PathBuffer = PathBuffer;
272 params.PathBufferSize = PathBufferSize;
273 params.PathRequiredSize = PathRequiredSize;
274
277
278 if(ret == DPROMPT_CANCEL)
280 return ret;
281}
#define msg(x)
Definition: auth_time.c:54
#define IDS_UNKNOWN
Definition: resource.h:7
#define IDC_PATH
Definition: resource.h:65
#define IDS_INFO
Definition: resource.h:53
HINSTANCE hInstance
Definition: charmap.c:19
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define OFN_EXPLORER
Definition: commdlg.h:104
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
static HWND hwndParent
Definition: cryptui.c:300
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4736
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1605
static WCHAR * strdupAtoW(const char *str)
Definition: main.c:65
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:109
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define WideCharToMultiByte
Definition: compat.h:111
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
static void promptdisk_browse(HWND hwnd, struct promptdisk_params *params)
Definition: dialog.c:116
UINT WINAPI SetupPromptForDiskW(HWND hwndParent, PCWSTR DialogTitle, PCWSTR DiskName, PCWSTR PathToSource, PCWSTR FileSought, PCWSTR TagFile, DWORD DiskPromptStyle, PWSTR PathBuffer, DWORD PathBufferSize, PDWORD PathRequiredSize)
Definition: dialog.c:219
static void promptdisk_ok(HWND hwnd, struct promptdisk_params *params)
Definition: dialog.c:86
static void promptdisk_init(HWND hwnd, struct promptdisk_params *params)
Definition: dialog.c:37
static INT_PTR CALLBACK promptdisk_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:139
UINT WINAPI SetupPromptForDiskA(HWND hwndParent, PCSTR DialogTitle, PCSTR DiskName, PCSTR PathToSource, PCSTR FileSought, PCSTR TagFile, DWORD DiskPromptStyle, PSTR PathBuffer, DWORD PathBufferSize, PDWORD PathRequiredSize)
Definition: dialog.c:174
#define IDS_COPYFROM
Definition: resource.h:11
#define IDPROMPTFORDISK
Definition: resource.h:23
#define IDS_PROMPTDISK
Definition: resource.h:9
#define IDC_COPYFROM
Definition: resource.h:5
#define IDC_RUNDLG_BROWSE
Definition: resource.h:7
#define IDC_INFO
Definition: resource.h:4
#define IDC_FILENEEDED
Definition: resource.h:3
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLenum const GLfloat * params
Definition: glext.h:5645
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
static const WCHAR aux[]
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
DWORD * PDWORD
Definition: pedump.c:68
#define strlenW(s)
Definition: unicode.h:34
#define strrchrW(s, c)
Definition: unicode.h:41
#define snprintfW
Definition: unicode.h:66
#define strcpyW(d, s)
Definition: unicode.h:35
#define IDF_OEMDISK
Definition: setupapi.h:431
#define DPROMPT_BUFFERTOOSMALL
Definition: setupapi.h:272
#define DPROMPT_SUCCESS
Definition: setupapi.h:269
#define IDF_CHECKFIRST
Definition: setupapi.h:427
#define IDF_NOBROWSE
Definition: setupapi.h:423
#define DPROMPT_CANCEL
Definition: setupapi.h:270
OPENFILENAME ofn
Definition: sndrec32.cpp:56
#define TRACE(s)
Definition: solgame.cpp:4
Definition: match.c:390
Definition: tftpd.h:60
DWORD DiskPromptStyle
Definition: dialog.c:29
DWORD PathBufferSize
Definition: dialog.c:31
PCWSTR TagFile
Definition: dialog.c:28
PDWORD PathRequiredSize
Definition: dialog.c:32
PCWSTR DialogTitle
Definition: dialog.c:24
PCWSTR FileSought
Definition: dialog.c:27
PCWSTR DiskName
Definition: dialog.c:25
PWSTR PathBuffer
Definition: dialog.c:30
PCWSTR PathToSource
Definition: dialog.c:26
HWND hwndOwner
Definition: commdlg.h:330
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD Flags
Definition: commdlg.h:342
DWORD lStructSize
Definition: commdlg.h:329
DWORD nMaxFile
Definition: commdlg.h:337
#define DWORD_PTR
Definition: treelist.c:76
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT_PTR
Definition: typedefs.h:64
char * PSTR
Definition: typedefs.h:51
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t DWORD_PTR
Definition: typedefs.h:65
const char * PCSTR
Definition: typedefs.h:52
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
int ret
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
#define ZeroMemory
Definition: winbase.h:1712
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:424
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define __ms_va_list
Definition: windef.h:456
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define ERROR_CANCELLED
Definition: winerror.h:726
#define SW_HIDE
Definition: winuser.h:768
#define DWLP_USER
Definition: winuser.h:872
#define GetWindowLongPtrW
Definition: winuser.h:4829
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define IDCANCEL
Definition: winuser.h:831
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define WM_COMMAND
Definition: winuser.h:1740
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:830
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define SetWindowLongPtrW
Definition: winuser.h:5346
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180