ReactOS  0.4.13-dev-551-gf37fb1f
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]));
62  args[1] = (DWORD_PTR)unknown;
63  }
65  format, 0, 0, message, sizeof(message)/sizeof(*message),
66  (__ms_va_list*)args);
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);
123  ofn.hwndOwner = hwnd;
126  strcpyW(ofn.lpstrFile, params->FileSought);
127 
128  if(GetOpenFileNameW(&ofn))
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;
159  case IDC_RUNDLG_BROWSE:
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  {
208  if(length > PathBufferSize)
209  return DPROMPT_BUFFERTOOSMALL;
210  WideCharToMultiByte(CP_ACP, 0, PathBufferW, -1, PathBuffer, length, NULL, NULL);
211  }
212  }
213  return ret;
214 }
215 
216 /***********************************************************************
217  * SetupPromptForDiskW (SETUPAPI.@)
218  */
222 {
223  struct promptdisk_params params;
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  {
248  if (PathRequiredSize)
250 
251  if (!PathBuffer)
252  return DPROMPT_SUCCESS;
253 
254  if (PathBufferSize >= strlenW(PathToSource) + 1)
255  {
257  return DPROMPT_SUCCESS;
258  }
259  else
260  return DPROMPT_BUFFERTOOSMALL;
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 OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define IDPROMPTFORDISK
Definition: resource.h:23
PCWSTR DialogTitle
Definition: dialog.c:24
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
const uint16_t * PCWSTR
Definition: typedefs.h:55
Definition: tftpd.h:59
static const char __ms_va_list
Definition: printf.c:70
#define TRUE
Definition: types.h:120
#define IDF_NOBROWSE
Definition: setupapi.h:418
#define IDOK
Definition: winuser.h:824
#define snprintfW
Definition: unicode.h:60
#define IDC_INFO
Definition: resource.h:4
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define IDF_OEMDISK
Definition: setupapi.h:426
#define DWORD_PTR
Definition: treelist.c:76
#define IDF_CHECKFIRST
Definition: setupapi.h:422
#define WideCharToMultiByte
Definition: compat.h:101
HWND hwndOwner
Definition: commdlg.h:330
#define SW_HIDE
Definition: winuser.h:762
uint16_t * PWSTR
Definition: typedefs.h:54
#define CP_ACP
Definition: compat.h:99
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
#define CALLBACK
Definition: compat.h:27
OPENFILENAME ofn
Definition: main.cpp:37
#define ZeroMemory
Definition: winbase.h:1635
#define IDC_PATH
Definition: resource.h:65
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowLongPtrW
Definition: winuser.h:4698
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
int32_t INT_PTR
Definition: typedefs.h:62
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define NO_ERROR
Definition: dderror.h:5
Definition: match.c:390
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
WPARAM wParam
Definition: combotst.c:138
#define IDS_PROMPTDISK
Definition: resource.h:9
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
DWORD nMaxFile
Definition: commdlg.h:337
HINSTANCE hInstance
Definition: charmap.c:20
GLenum const GLfloat * params
Definition: glext.h:5645
#define IDC_COPYFROM
Definition: resource.h:5
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define debugstr_w
Definition: kernel32.h:32
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4564
smooth NULL
Definition: ftsmooth.c:416
static HWND hwndParent
Definition: cryptui.c:300
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI SetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPCWSTR lpString)
Definition: dialog.c:2756
#define IDS_UNKNOWN
Definition: resource.h:7
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
static void promptdisk_ok(HWND hwnd, struct promptdisk_params *params)
Definition: dialog.c:86
#define DPROMPT_SUCCESS
Definition: setupapi.h:269
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static INT_PTR CALLBACK promptdisk_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: dialog.c:139
PCWSTR DiskName
Definition: dialog.c:25
#define MAX_PATH
Definition: compat.h:26
DWORD lStructSize
Definition: commdlg.h:329
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
PCWSTR FileSought
Definition: dialog.c:27
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
DWORD DiskPromptStyle
Definition: dialog.c:29
#define SetLastError(x)
Definition: compat.h:409
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
Definition: id3.c:18
PCWSTR TagFile
Definition: dialog.c:28
int ret
static void promptdisk_browse(HWND hwnd, struct promptdisk_params *params)
Definition: dialog.c:116
#define IDS_COPYFROM
Definition: resource.h:11
#define DWLP_USER
Definition: winuser.h:866
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define WM_COMMAND
Definition: winuser.h:1716
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define IDC_FILENEEDED
Definition: resource.h:3
WINE_UNICODE_INLINE WCHAR * strrchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:254
PWSTR PathBuffer
Definition: dialog.c:30
static HWND hwnd[MAXHWNDS]
Definition: dialog.c:47
static void promptdisk_init(HWND hwnd, struct promptdisk_params *params)
Definition: dialog.c:37
WINE_UNICODE_INLINE WCHAR * strcpyW(WCHAR *dst, const WCHAR *src)
Definition: unicode.h:219
BOOL WINAPI EndDialog(HWND hwnd, INT_PTR retval)
Definition: dialog.c:2015
#define ERROR_CANCELLED
Definition: winerror.h:726
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
LPSTR lpstrFile
Definition: commdlg.h:336
#define DPROMPT_BUFFERTOOSMALL
Definition: setupapi.h:272
signed char * PSTR
Definition: retypes.h:7
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
PDWORD PathRequiredSize
Definition: dialog.c:32
PCWSTR PathToSource
Definition: dialog.c:26
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
DWORD * PDWORD
Definition: pedump.c:68
#define msg(x)
Definition: auth_time.c:54
static const WCHAR aux[]
#define IDS_INFO
Definition: resource.h:53
#define IDC_RUNDLG_BROWSE
Definition: resource.h:7
HWND WINAPI GetDlgItem(HWND hDlg, int nIDDlgItem)
Definition: dialog.c:2113
#define SetWindowLongPtrW
Definition: winuser.h:5215
DWORD PathBufferSize
Definition: dialog.c:31
const char * PCSTR
Definition: typedefs.h:51
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDCANCEL
Definition: winuser.h:825
#define DPROMPT_CANCEL
Definition: setupapi.h:270
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define HeapFree(x, y, z)
Definition: compat.h:394
INT_PTR WINAPI DialogBoxParamW(HINSTANCE hInstance, LPCWSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
Definition: dialog.c:1858
static WCHAR * strdupAtoW(const char *str)
Definition: main.c:67
DWORD Flags
Definition: commdlg.h:342