ReactOS 0.4.16-dev-597-gdbf7844
vfdguisave.c File Reference
#include <windows.h>
#include <commdlg.h>
#include "vfdtypes.h"
#include "vfdapi.h"
#include "vfdlib.h"
#include "vfdmsg.h"
#include "vfdguirc.h"
Include dependency graph for vfdguisave.c:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 

Functions

static INT CALLBACK SaveDialogProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static void OnInit (HWND hDlg, PCSAVE_PARAM pParam)
 
static void OnTarget (HWND hDlg, HWND hEdit)
 
static void OnBrowse (HWND hDlg)
 
static void OnOverwrite (HWND hDlg, HWND hCheck)
 
static void OnTruncate (HWND hDlg, HWND hCheck)
 
static DWORD OnOK (HWND hDlg)
 
DWORD WINAPI VfdGuiSave (HWND hParent, ULONG nDevice)
 
DWORD GuiSaveParam (HWND hParent, PCSAVE_PARAM pParam)
 

Macro Definition Documentation

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 15 of file vfdguisave.c.

Function Documentation

◆ GuiSaveParam()

DWORD GuiSaveParam ( HWND  hParent,
PCSAVE_PARAM  pParam 
)

Definition at line 101 of file vfdguisave.c.

104{
105 switch (DialogBoxParam(
108 hParent,
110 (LPARAM)pParam))
111 {
112 case IDOK:
113 return ERROR_SUCCESS;
114
115 case IDCANCEL:
116 return ERROR_CANCELLED;
117
118 default:
119 return GetLastError();
120 }
121}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDD_SAVEDIALOG
Definition: vfdguirc.h:7
static INT CALLBACK SaveDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: vfdguisave.c:127
HINSTANCE g_hDllModule
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
LONG_PTR LPARAM
Definition: windef.h:208
#define ERROR_CANCELLED
Definition: winerror.h:726
#define IDCANCEL
Definition: winuser.h:834
#define DialogBoxParam
Definition: winuser.h:5776
#define IDOK
Definition: winuser.h:833
#define MAKEINTRESOURCE
Definition: winuser.h:591

Referenced by VfdGuiClose(), and VfdGuiSave().

◆ OnBrowse()

void OnBrowse ( HWND  hDlg)
static

Definition at line 401 of file vfdguisave.c.

403{
405 PSTR title;
408 DWORD len;
409
410 title = ModuleMessage(MSG_SAVE_TITLE);
411
412 ZeroMemory(&ofn, sizeof(ofn));
413 ZeroMemory(file, sizeof(file));
414 ZeroMemory(dir, sizeof(dir));
415
416 len = GetDlgItemText(hDlg, IDC_TARGETFILE, file, sizeof(file));
417
418 if (len && file[len - 1] == '\\') {
419 strcpy(dir, file);
420 ZeroMemory(file, sizeof(file));
421 }
422
423 // Different structure sizes must be used for NT and 2K/XP
426
427 ofn.hwndOwner = hDlg;
429 ofn.nMaxFile = sizeof(file);
431 ofn.lpstrTitle = title ? title : "Save Image";
432 ofn.lpstrFilter = "*.*\0*.*\0";
433#ifndef __REACTOS__
435#else
437#endif
438
439 if (GetSaveFileName(&ofn)) {
442 }
443
444 if (title) {
446 }
447}
unsigned int dir
Definition: maze.c:112
#define GetSaveFileName
Definition: commdlg.h:666
#define OFN_EXPLORER
Definition: commdlg.h:104
#define OPENFILENAME_SIZE_VERSION_400
Definition: commdlg.h:402
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_ENABLESIZING
Definition: commdlg.h:101
#define OFN_PATHMUSTEXIST
Definition: commdlg.h:117
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
static char title[]
Definition: ps.c:92
strcpy
Definition: string.h:131
OPENFILENAME ofn
Definition: sndrec32.cpp:56
Definition: fci.c:127
HWND hwndOwner
Definition: commdlg.h:330
LPCSTR lpstrTitle
Definition: commdlg.h:341
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD Flags
Definition: commdlg.h:342
LPCSTR lpstrInitialDir
Definition: commdlg.h:340
DWORD lStructSize
Definition: commdlg.h:329
LPCSTR lpstrFilter
Definition: commdlg.h:332
DWORD nMaxFile
Definition: commdlg.h:337
char * PSTR
Definition: typedefs.h:51
#define IS_WINDOWS_NT()
Definition: vfdcmd.c:159
#define IDC_TARGETFILE
Definition: vfdguirc.h:19
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
#define ZeroMemory
Definition: winbase.h:1737
#define GetDlgItemText
Definition: winuser.h:5797
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HWND WINAPI SetFocus(_In_opt_ HWND)
#define SetDlgItemText
Definition: winuser.h:5861
char CHAR
Definition: xmlstorage.h:175

Referenced by SaveDialogProc().

◆ OnInit()

void OnInit ( HWND  hDlg,
PCSAVE_PARAM  pParam 
)
static

Definition at line 192 of file vfdguisave.c.

195{
196 // Store parameters
197
198#ifndef __REACTOS__
199 SetWindowLong(hDlg, GWL_USERDATA, (ULONG)pParam);
200#else
202#endif
203
204 // clear the target existence flag
205
206 SetWindowLong(hDlg, DWL_USER, 0);
207
208 // Set dialog window title
209
210 SetControlText(hDlg, 0, MSG_SAVE_TITLE);
211
212 // Set control captions
213
214 SetControlText(hDlg, IDC_IMAGEFILE_LABEL, MSG_IMAGEFILE_LABEL);
215 SetControlText(hDlg, IDC_DISKTYPE_LABEL, MSG_DISKTYPE_LABEL);
216 SetControlText(hDlg, IDC_MEDIATYPE_LABEL, MSG_MEDIATYPE_LABEL);
217 SetControlText(hDlg, IDC_TARGETFILE_LABEL, MSG_TARGETFILE_LABEL);
218 SetControlText(hDlg, IDC_IMAGEDESC_LABEL, MSG_DESCRIPTION_LABEL);
219 SetControlText(hDlg, IDC_BROWSE, MSG_BROWSE_BUTTON);
220 SetControlText(hDlg, IDC_OVERWRITE, MSG_OVERWRITE_CHECK);
221 SetControlText(hDlg, IDC_TRUNCATE, MSG_TRUNCATE_CHECK);
222 SetControlText(hDlg, IDOK, MSG_SAVE_BUTTON);
223 SetControlText(hDlg, IDCANCEL, MSG_CANCEL_BUTTON);
224
225 // set disk type
226
227 if (pParam->DiskType == VFD_DISKTYPE_FILE) {
228 SetDlgItemText(hDlg, IDC_DISKTYPE, "FILE");
229 }
230 else {
231 SetDlgItemText(hDlg, IDC_DISKTYPE, "RAM");
232 }
233
234 // display media type
235
237 VfdMediaTypeName(pParam->MediaType));
238
239 // set current image and initial target
240
241 if (pParam->ImageName[0]) {
242 SetDlgItemText(hDlg, IDC_IMAGEFILE, pParam->ImageName);
244 }
245 else if (pParam->DiskType != VFD_DISKTYPE_FILE) {
246 SetDlgItemText(hDlg, IDC_IMAGEFILE, "<RAM>");
247 OnTarget(hDlg, GetDlgItem(hDlg, IDC_TARGETFILE));
248 }
249}
#define IDC_BROWSE
Definition: resource.h:21
PSTR ImageName
Definition: vfdlib.h:98
VFD_DISKTYPE DiskType
Definition: vfdlib.h:93
VFD_MEDIA MediaType
Definition: vfdlib.h:94
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
PCSTR WINAPI VfdMediaTypeName(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3280
#define IDC_TRUNCATE
Definition: vfdguirc.h:35
#define IDC_MEDIATYPE_LABEL
Definition: vfdguirc.h:24
#define IDC_DISKTYPE_LABEL
Definition: vfdguirc.h:20
#define IDC_OVERWRITE
Definition: vfdguirc.h:34
#define IDC_IMAGEFILE_LABEL
Definition: vfdguirc.h:13
#define IDC_DISKTYPE
Definition: vfdguirc.h:21
#define IDC_TARGETFILE_LABEL
Definition: vfdguirc.h:18
#define IDC_IMAGEDESC_LABEL
Definition: vfdguirc.h:15
#define IDC_MEDIATYPE
Definition: vfdguirc.h:25
#define IDC_IMAGEFILE
Definition: vfdguirc.h:14
static void OnTarget(HWND hDlg, HWND hEdit)
Definition: vfdguisave.c:254
void SetControlText(HWND hWnd, UINT nCtrl, DWORD nMsg)
Definition: vfdguiut.c:350
@ VFD_DISKTYPE_FILE
Definition: vfdtypes.h:18
#define SetWindowLong
Definition: winuser.h:5865
#define GWL_USERDATA
Definition: winuser.h:864
#define DWL_USER
Definition: winuser.h:870

Referenced by SaveDialogProc().

◆ OnOK()

DWORD OnOK ( HWND  hDlg)
static

Definition at line 475 of file vfdguisave.c.

477{
480 BOOL overwrite;
481 BOOL truncate;
482 DWORD ret;
483
484#ifndef __REACTOS__
486#else
488#endif
489
490 if (!param) {
492 }
493
494 // get the target image name
495
496 if (GetDlgItemText(hDlg, IDC_TARGETFILE, path, sizeof(path)) == 0) {
498 }
499
500 if (GetWindowLong(hDlg, DWL_USER)) {
501 // the target file exists and overwritable
502 overwrite = (IsDlgButtonChecked(hDlg, IDC_OVERWRITE) == BST_CHECKED);
503 truncate = (IsDlgButtonChecked(hDlg, IDC_TRUNCATE) == BST_CHECKED);
504 }
505 else {
506 overwrite = FALSE;
507 truncate = TRUE;
508 }
509
510retry:
511 ret = VfdDismountVolume(param->hDevice, FALSE);
512
513 if (ret == ERROR_ACCESS_DENIED) {
514 PSTR msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
515
516 int reply = MessageBox(
517 hDlg, msg ? msg : "retry", VFD_MSGBOX_TITLE,
519
520 if (msg) {
521 LocalFree(msg);
522 }
523
524 if (reply == IDRETRY) {
525 goto retry;
526 }
527 else if (reply == IDCANCEL) {
528 return ERROR_CANCELLED;
529 }
530 else {
531 VfdDismountVolume(param->hDevice, TRUE);
532 }
533 }
534 else if (ret != ERROR_SUCCESS) {
535
538
539 return ret;
540 }
541
542 ret = VfdSaveImage(param->hDevice, path, overwrite, truncate);
543
544 if (ret != ERROR_SUCCESS) {
545
546 // show error message
547
550 }
551
552 return ret;
553}
#define msg(x)
Definition: auth_time.c:54
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned int BOOL
Definition: ntddk_ex.h:94
GLfloat param
Definition: glext.h:5796
#define GetWindowLongPtr
Definition: treelist.c:73
DWORD WINAPI VfdSaveImage(HANDLE hDevice, PCSTR sFileName, BOOL bOverWrite, BOOL bTruncate)
Definition: vfdctl.c:2685
DWORD WINAPI VfdDismountVolume(HANDLE hDevice, BOOL bForce)
Definition: vfdctl.c:2629
#define MB_CANCELTRYCONTINUE
Definition: vfdguiut.c:34
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
const SAVE_PARAM * PCSAVE_PARAM
Definition: vfdlib.h:101
#define VFD_MSGBOX_TITLE
Definition: vfdlib.h:53
int ret
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define GetWindowLong
Definition: winuser.h:5808
#define MB_ICONEXCLAMATION
Definition: winuser.h:788
#define MessageBox
Definition: winuser.h:5834
#define MB_ICONSTOP
Definition: winuser.h:806
#define IDRETRY
Definition: winuser.h:836
#define BST_CHECKED
Definition: winuser.h:197

Referenced by SaveDialogProc().

◆ OnOverwrite()

void OnOverwrite ( HWND  hDlg,
HWND  hCheck 
)
static

Definition at line 449 of file vfdguisave.c.

452{
453 if (GetWindowLong(hDlg, DWL_USER)) {
454 // the target file exists and overwritable
455 if (SendMessage(hCheck, BM_GETCHECK, 0, 0) != BST_CHECKED) {
457 }
458 else {
460 }
461 }
462}
#define SendMessage
Definition: winuser.h:5855
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define BM_GETCHECK
Definition: winuser.h:1921

Referenced by SaveDialogProc().

◆ OnTarget()

void OnTarget ( HWND  hDlg,
HWND  hEdit 
)
static

Definition at line 254 of file vfdguisave.c.

257{
262 DWORD file_attr;
263 DWORD ret;
264
265 // clear the target existence flag
266
267 SetWindowLong(hDlg, DWL_USER, 0);
268
269 // clear the description and hint text
270
273
274 // get the target file name
275
276 if (GetWindowText(hEdit, buf, sizeof(buf)) == 0) {
277
278 // target file is blank
279
283
284 return;
285 }
286 else {
287 CHAR full[MAX_PATH];
288 PSTR file;
289
290 // convert into a full path
291
292 if (GetFullPathName(buf, sizeof(full), full, &file)) {
293 strcpy(buf, full);
294 }
295 }
296
297 //
298 // get the current image info
299 //
300#ifndef __REACTOS__
302#else
304#endif
305
306 if (_stricmp(param->ImageName, buf) == 0) {
307
308 // target is the current file
309
310 char desc[MAX_PATH];
311
312 VfdMakeFileDesc(desc, sizeof(desc),
313 param->FileType, param->ImageSize,
314 GetFileAttributes(param->ImageName));
315
317 SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_CURRENT_FILE);
318
319 if (param->DiskType == VFD_DISKTYPE_FILE) {
320
321 // cannot overwrite the current FILE disk image
322
326 return;
327 }
328 }
329
330 //
331 // check target image file
332 //
334 buf, &file_attr, &file_type, &file_size);
335
336 if (ret == ERROR_FILE_NOT_FOUND) {
337 // file does not exist
338 SetControlText(hDlg, IDC_IMAGEFILE_DESC, MSG_DESC_NEW_FILE);
342 return;
343 }
344 else if (ret != ERROR_SUCCESS) {
349 return;
350 }
351
352 // set target file description
353
354 VfdMakeFileDesc(buf, sizeof(buf),
355 file_type, file_size, file_attr);
356
358
359 // check target file type
360
362 SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_TARGET_IS_ZIP);
366 return;
367 }
368
369 // the target is an existing raw file
370
372
373 // set truncate box
374
375 if (file_size > VfdGetMediaSize(param->MediaType)) {
377 SetControlText(hDlg, IDC_IMAGEFILE_HINT, MSG_SIZE_MISMATCH);
378 }
379 else {
381 }
382
383 // check overwrite setting
384
387 }
388 else {
390 }
391
392 // target file exists and overwritable
393
394 SetWindowLong(hDlg, DWL_USER, 1);
395}
#define _stricmp
Definition: cat.c:22
#define NULL
Definition: types.h:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static const WCHAR desc[]
Definition: protectdata.c:36
static unsigned int file_size
Definition: regtests2xml.c:47
FD_TYPE file_type(FDSC **curr, char *fixed)
Definition: file.c:221
static HWND hEdit
Definition: autocomplete.c:34
ULONG WINAPI VfdGetMediaSize(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3272
void WINAPI VfdMakeFileDesc(PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
Definition: vfdguiut.c:376
DWORD WINAPI VfdCheckImageFile(PCSTR sFileName, PDWORD pAttributes, PVFD_FILETYPE pFileType, PULONG pImageSize)
Definition: vfdctl.c:3035
#define IDC_IMAGEFILE_HINT
Definition: vfdguirc.h:17
#define IDC_IMAGEFILE_DESC
Definition: vfdguirc.h:16
UCHAR VFD_FILETYPE
Definition: vfdtypes.h:62
@ VFD_FILETYPE_ZIP
Definition: vfdtypes.h:53
#define GetFileAttributes
Definition: winbase.h:3840
#define GetFullPathName
Definition: winbase.h:3846
#define GetWindowText
Definition: winuser.h:5810

Referenced by OnInit(), and SaveDialogProc().

◆ OnTruncate()

void OnTruncate ( HWND  hDlg,
HWND  hCheck 
)
static

Definition at line 464 of file vfdguisave.c.

467{
470}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325

Referenced by SaveDialogProc().

◆ SaveDialogProc()

INT CALLBACK SaveDialogProc ( HWND  hDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 127 of file vfdguisave.c.

135{
136 switch (uMsg) {
137 case WM_INITDIALOG:
138 OnInit(hDlg, (PCSAVE_PARAM)lParam);
139 return TRUE;
140
141 case WM_COMMAND:
142 switch (wParam) {
144 OnTarget(hDlg, (HWND)lParam);
145 return TRUE;
146
147 case IDC_BROWSE:
148 OnBrowse(hDlg);
149 return TRUE;
150
151 case IDC_OVERWRITE:
152 OnOverwrite(hDlg, (HWND)lParam);
153 return TRUE;
154
155 case IDC_TRUNCATE:
156 OnTruncate(hDlg, (HWND)lParam);
157 return TRUE;
158
159 case IDOK:
160 if (OnOK(hDlg) == ERROR_SUCCESS) {
161 EndDialog(hDlg, IDOK);
162 }
163 return TRUE;
164
165 case IDCANCEL:
166 EndDialog(hDlg, IDCANCEL);
167 return TRUE;
168 }
169 break;
170
171 case WM_CONTEXTMENU:
173 break;
174
175 case WM_HELP:
176 {
178
179 if (info->iContextType == HELPINFO_WINDOW) {
180 ShowHelpWindow(hDlg, info->iCtrlId);
181 }
182 }
183 return TRUE;
184 }
185
186 return FALSE;
187}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static VOID ShowContextMenu(HWND hwndDlg, HWND hwndTreeView, PHOTPLUG_DATA pHotplugData)
Definition: hotplug.c:110
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define MAKELONG(a, b)
Definition: typedefs.h:249
static DWORD OnOK(HWND hDlg)
Definition: vfdguisave.c:475
static void OnInit(HWND hDlg, PCSAVE_PARAM pParam)
Definition: vfdguisave.c:192
static void OnOverwrite(HWND hDlg, HWND hCheck)
Definition: vfdguisave.c:449
static void OnTruncate(HWND hDlg, HWND hCheck)
Definition: vfdguisave.c:464
static void OnBrowse(HWND hDlg)
Definition: vfdguisave.c:401
void ShowHelpWindow(HWND hDlg, UINT nCtl)
Definition: vfdguiut.c:507
struct tagHELPINFO * LPHELPINFO
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_INITDIALOG
Definition: winuser.h:1742
#define HELPINFO_WINDOW
Definition: winuser.h:1175
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define EN_CHANGE
Definition: winuser.h:2025

Referenced by GuiSaveParam().

◆ VfdGuiSave()

DWORD WINAPI VfdGuiSave ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 58 of file vfdguisave.c.

61{
64 DWORD ret;
65
66 // open the source device
67
68 param.hDevice = VfdOpenDevice(nDevice);
69
70 if (param.hDevice == INVALID_HANDLE_VALUE) {
71 return GetLastError();
72 }
73
74 // get current image information
75
76 param.ImageName = path;
77
79 param.hDevice,
80 param.ImageName,
81 &param.DiskType,
82 &param.MediaType,
83 &param.MediaFlags,
84 &param.FileType,
85 &param.ImageSize);
86
87 if (ret == ERROR_SUCCESS) {
88
89 // show dialog box
90
91 ret = GuiSaveParam(hParent, &param);
92 }
93
94 // close the source device
95
96 CloseHandle(param.hDevice);
97
98 return ret;
99}
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
DWORD WINAPI VfdGetImageInfo(HANDLE hDevice, PSTR sFileName, PVFD_DISKTYPE pDiskType, PVFD_MEDIA pMediaType, PVFD_FLAGS pMediaFlags, PVFD_FILETYPE pFileType, PULONG pImageSize)
Definition: vfdctl.c:1839
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
DWORD GuiSaveParam(HWND hParent, PCSAVE_PARAM pParam)
Definition: vfdguisave.c:101

Referenced by CVfdShExt::DoVfdSave().