ReactOS 0.4.15-dev-7953-g1f49173
vfdguiut.c File Reference
#include <windows.h>
#include <stdio.h>
#include "vfdtypes.h"
#include "vfdapi.h"
#include "vfdlib.h"
#include "vfdmsg.h"
#include "vfdguirc.h"
Include dependency graph for vfdguiut.c:

Go to the source code of this file.

Macros

#define WIN32_LEAN_AND_MEAN
 
#define MB_CANCELTRYCONTINUE   0x00000006L
 
#define IDTRYAGAIN   10
 
#define IDCONTINUE   11
 

Functions

static PSTR FormatSizeBytes (ULONG size, PSTR buf)
 
static PSTR FormatSizeUnits (ULONG size, PSTR buf)
 
DWORD WINAPI VfdGuiClose (HWND hParent, ULONG nDevice)
 
DWORD WINAPI VfdGuiFormat (HWND hParent, ULONG nDevice)
 
void SetControlText (HWND hWnd, UINT nCtrl, DWORD nMsg)
 
void WINAPI VfdMakeFileDesc (PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
 
void ShowContextMenu (HWND hDlg, HWND hCtl, LPARAM lParam)
 
void ShowHelpWindow (HWND hDlg, UINT nCtl)
 

Macro Definition Documentation

◆ IDCONTINUE

#define IDCONTINUE   11

Definition at line 42 of file vfdguiut.c.

◆ IDTRYAGAIN

#define IDTRYAGAIN   10

Definition at line 38 of file vfdguiut.c.

◆ MB_CANCELTRYCONTINUE

#define MB_CANCELTRYCONTINUE   0x00000006L

Definition at line 34 of file vfdguiut.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 15 of file vfdguiut.c.

Function Documentation

◆ FormatSizeBytes()

static PSTR FormatSizeBytes ( ULONG  size,
PSTR  buf 
)
static

Definition at line 48 of file vfdguiut.c.

49{
50 ULONG comma = 1;
51 int len;
52
53 while ((comma * 1000) < size) {
54 comma *= 1000;
55 }
56
57 len = sprintf(buf, "%lu", size / comma);
58
59 while (comma > 1) {
60 size %= comma;
61 comma /= 1000;
62 len += sprintf(buf + len, ",%03lu", size / comma);
63 }
64
65 return buf;
66}
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
#define sprintf(buf, format,...)
Definition: sprintf.c:55
uint32_t ULONG
Definition: typedefs.h:59

Referenced by FormatSizeUnits(), and VfdMakeFileDesc().

◆ FormatSizeUnits()

static PSTR FormatSizeUnits ( ULONG  size,
PSTR  buf 
)
static

Definition at line 68 of file vfdguiut.c.

69{
70 static const char *name[3] = {
71 " KB", " MB", " GB"
72 };
73 int unit;
74 double dsize;
75
76 if (size < 1000) {
77#ifndef __REACTOS__
78 sprintf(buf, "%u", size);
79#else
80 sprintf(buf, "%lu", size);
81#endif
82 return buf;
83 }
84
85 dsize = size;
86 dsize /= 1024;
87 unit = 0;
88
89 while (unit < 2 && dsize >= 1000) {
90 dsize /= 1000;
91 unit++;
92 }
93
94 if (dsize < 10) {
95 sprintf(buf, "%3.2f%s", dsize, name[unit]);
96 }
97 else if (dsize < 100) {
98 sprintf(buf, "%3.1f%s", dsize, name[unit]);
99 }
100 else if (dsize < 1000) {
101 sprintf(buf, "%3.0f%s", dsize, name[unit]);
102 }
103 else {
104 FormatSizeBytes((ULONG)dsize, buf);
105 strcat(buf, name[unit]);
106 }
107
108 return buf;
109}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
png_const_structrp png_const_inforp int * unit
Definition: png.h:2159
Definition: name.c:39
static PSTR FormatSizeBytes(ULONG size, PSTR buf)
Definition: vfdguiut.c:48

Referenced by VfdMakeFileDesc().

◆ SetControlText()

void SetControlText ( HWND  hWnd,
UINT  nCtrl,
DWORD  nMsg 
)

Definition at line 350 of file vfdguiut.c.

354{
355 PSTR p = NULL;
356
357 if (nMsg) {
358 p = ModuleMessage(nMsg);
359 }
360
361 if (nCtrl) {
362 SetDlgItemText(hWnd, nCtrl, p);
363 }
364 else {
366 }
367
368 if (p) {
369 LocalFree(p);
370 }
371}
HWND hWnd
Definition: settings.c:17
#define NULL
Definition: types.h:112
GLfloat GLfloat p
Definition: glext.h:8902
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
char * PSTR
Definition: typedefs.h:51
PSTR ModuleMessage(DWORD nFormat,...)
Definition: vfdlib.c:124
#define SetWindowText
Definition: winuser.h:5857
#define SetDlgItemText
Definition: winuser.h:5849

Referenced by OnImage(), OnInit(), OnMediaType(), OnPropInit(), and OnTarget().

◆ ShowContextMenu()

void ShowContextMenu ( HWND  hDlg,
HWND  hCtl,
LPARAM  lParam 
)

Definition at line 456 of file vfdguiut.c.

460{
461 POINT pt;
462 UINT id;
463 HMENU hMenu;
464
465 pt.x = ((int)(short)LOWORD(lParam));
466 pt.y = ((int)(short)HIWORD(lParam));
467
468 if (pt.x == -1 || pt.y == -1) {
469 RECT rc;
470
471 GetWindowRect(hCtl, &rc);
472 pt.x = (rc.left + rc.right) / 2;
473 pt.y = (rc.top + rc.bottom) / 2;
474
475 id = GetDlgCtrlID(hCtl);
476 }
477 else {
478 POINT pt2 = pt;
479
480 ScreenToClient(hDlg, &pt2);
481
482 id = GetDlgCtrlID(
483 ChildWindowFromPoint(hDlg, pt2));
484 }
485
486 if (id < IDC_IMAGEFILE_LABEL ||
487 id > IDC_TRUNCATE) {
488 return;
489 }
490
491 hMenu = CreatePopupMenu();
492
493 AppendMenu(hMenu, MF_STRING, 1, "&What's This");
494
495 if (TrackPopupMenu(hMenu, TPM_RETURNCMD,
496 pt.x, pt.y, 0, hDlg, NULL))
497 {
498 ShowHelpWindow(hDlg, id);
499 }
500
501 DestroyMenu(hMenu);
502}
LPARAM lParam
Definition: combotst.c:139
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define pt(x, y)
Definition: drawing.c:79
GLuint id
Definition: glext.h:5910
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
unsigned int UINT
Definition: ndis.h:50
#define LOWORD(l)
Definition: pedump.c:82
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define HIWORD(l)
Definition: typedefs.h:247
#define IDC_TRUNCATE
Definition: vfdguirc.h:35
#define IDC_IMAGEFILE_LABEL
Definition: vfdguirc.h:13
void ShowHelpWindow(HWND hDlg, UINT nCtl)
Definition: vfdguiut.c:507
HWND WINAPI ChildWindowFromPoint(_In_ HWND, _In_ POINT)
HMENU WINAPI CreatePopupMenu(void)
Definition: menu.c:838
#define AppendMenu
Definition: winuser.h:5731
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define MF_STRING
Definition: winuser.h:138
BOOL WINAPI DestroyMenu(_In_ HMENU)
int WINAPI GetDlgCtrlID(_In_ HWND)
BOOL WINAPI TrackPopupMenu(_In_ HMENU, _In_ UINT, _In_ int, _In_ int, _Reserved_ int, _In_ HWND, _Reserved_ LPCRECT)
#define TPM_RETURNCMD
Definition: winuser.h:2387
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)

◆ ShowHelpWindow()

void ShowHelpWindow ( HWND  hDlg,
UINT  nCtl 
)

Definition at line 507 of file vfdguiut.c.

510{
511 UINT msg;
512 RECT rc;
513 PSTR help;
514
515 switch (nCtl) {
517 case IDC_IMAGEFILE:
518 msg = MSG_HELP_IMAGEFILE;
519 break;
522 msg = MSG_HELP_IMAGEDESC;
523 break;
525 case IDC_TARGETFILE:
526 msg = MSG_HELP_TARGETFILE;
527 break;
529 case IDC_DISKTYPE:
531 case IDC_DISKTYPE_RAM:
532 msg = MSG_HELP_DISKTYPE;
533 break;
535 case IDC_MEDIATYPE:
536 msg = MSG_HELP_MEDIATYPE;
537 break;
539 msg = MSG_HELP_PROTECT_NOW;
540 break;
542 msg = MSG_HELP_PROTECT_OPEN;
543 break;
544 case IDC_BROWSE:
545 msg = MSG_HELP_BROWSE;
546 break;
547 case IDC_OPEN:
548 msg = MSG_HELP_OPEN;
549 break;
550 case IDC_SAVE:
551 msg = MSG_HELP_SAVE;
552 break;
553 case IDC_CLOSE:
554 msg = MSG_HELP_CLOSE;
555 break;
556 case IDC_FORMAT:
557 msg = MSG_HELP_FORMAT;
558 break;
559 case IDC_CONTROL:
560 msg = MSG_HELP_CONTROL;
561 break;
562 case IDC_OVERWRITE:
563 msg = MSG_HELP_OVERWRITE;
564 break;
565 case IDC_TRUNCATE:
566 msg = MSG_HELP_TRUNCATE;
567 break;
568 default:
569 return;
570 }
571
572 GetWindowRect(GetDlgItem(hDlg, nCtl), &rc);
573
575
576 if (help) {
577 VfdToolTip(hDlg, help, rc.left, (rc.top + rc.bottom) / 2, TRUE);
579 }
580}
#define msg(x)
Definition: auth_time.c:54
int help
Definition: sort.c:20
#define IDC_SAVE
Definition: resource.h:16
#define IDC_OPEN
Definition: resource.h:18
#define IDC_BROWSE
Definition: resource.h:21
#define TRUE
Definition: types.h:120
#define IDC_CLOSE
Definition: resource.h:52
void WINAPI VfdToolTip(HWND hParent, PCSTR sText, int pos_x, int pos_y, BOOL stick)
Definition: vfdguitip.c:134
#define IDC_DISKTYPE_RAM
Definition: vfdguirc.h:23
#define IDC_MEDIATYPE_LABEL
Definition: vfdguirc.h:24
#define IDC_WRITE_PROTECTED
Definition: vfdguirc.h:26
#define IDC_TARGETFILE
Definition: vfdguirc.h:19
#define IDC_DISKTYPE_LABEL
Definition: vfdguirc.h:20
#define IDC_CONTROL
Definition: vfdguirc.h:33
#define IDC_DISKTYPE_FILE
Definition: vfdguirc.h:22
#define IDC_OPEN_PROTECTED
Definition: vfdguirc.h:27
#define IDC_OVERWRITE
Definition: vfdguirc.h:34
#define IDC_IMAGEFILE_DESC
Definition: vfdguirc.h:16
#define IDC_FORMAT
Definition: vfdguirc.h:32
#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
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)

Referenced by OpenDialogProc(), SaveDialogProc(), ShowContextMenu(), and VfdPageDlgProc().

◆ VfdGuiClose()

DWORD WINAPI VfdGuiClose ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 114 of file vfdguiut.c.

117{
118 HANDLE hDevice;
121 HCURSOR hourglass;
122 DWORD ret;
123 int reply;
124
125 VFDTRACE(0, ("VfdGuiClose()\n"));
126
127 hDevice = VfdOpenDevice(nDevice);
128
129 if (hDevice == INVALID_HANDLE_VALUE) {
130 return GetLastError();
131 }
132
133 // get current image information
134
136 hDevice,
137 path,
138 &param.DiskType,
139 &param.MediaType,
140 &param.MediaFlags,
141 &param.FileType,
142 &param.ImageSize);
143
144 if (ret != ERROR_SUCCESS) {
145 CloseHandle(hDevice);
146 return ret;
147 }
148
149 param.hDevice = hDevice;
150 param.ImageName = path;
151
152 // check if RAM image is modified
153
154 if (param.MediaFlags & VFD_FLAG_DATA_MODIFIED) {
155 PSTR msg = ModuleMessage(MSG_MEDIA_MODIFIED);
156
157 for (;;) {
158 reply = MessageBox(hParent, msg ? msg : "save?",
160
161 if (reply != IDYES) {
162 break;
163 }
164
165 if (GuiSaveParam(hParent, &param) == ERROR_SUCCESS) {
166 break;
167 }
168 }
169
170 if (msg) {
171 LocalFree(msg);
172 }
173
174 if (reply == IDCANCEL) {
175 CloseHandle(hDevice);
176 return ERROR_CANCELLED;
177 }
178 }
179
180 // close the image
181
182 hourglass = LoadCursor(NULL, IDC_WAIT);
183
184 for (;;) {
185
186 // show the hourglass cursor
187
188 HCURSOR original = SetCursor(hourglass);
189
190 // close the current image
191
192 ret = VfdCloseImage(hDevice, FALSE);
193
194 // restore the original cursor
195
196 SetCursor(original);
197
198 if (ret != ERROR_ACCESS_DENIED) {
199 // success or errors other than access denied
200 break;
201 }
202
203 if (IS_WINDOWS_NT()) {
204
205 // Windows NT -- cannot force close
206 // show retry / cancel message box
207
208 PSTR msg = ModuleMessage(MSG_UNMOUNT_FAILED);
209
210 reply = MessageBox(
211 hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
213
214 if (msg) {
215 LocalFree(msg);
216 }
217 }
218 else {
219
220 // Windows 2000 and later -- possible to force
221 // show cancel / retry / continue message box
222
223 PSTR msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
224
225 reply = MessageBox(
226 hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
228
229 if (msg) {
230 LocalFree(msg);
231 }
232
233 if (reply == IDCONTINUE) {
234
235 // try forced close
236
237 ret = VfdCloseImage(hDevice, TRUE);
238 }
239 }
240
241 if (reply == IDCANCEL) {
243 break;
244 }
245 else if (reply == IDCONTINUE) {
246
247 // try forced close
248
249 ret = VfdCloseImage(hDevice, TRUE);
250 break;
251 }
252 }
253
254 CloseHandle(hDevice);
255
256 return ret;
257}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat param
Definition: glext.h:5796
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
#define IS_WINDOWS_NT()
Definition: vfdcmd.c:159
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
VOID VfdCloseImage(IN PDEVICE_EXTENSION DeviceExtension)
Definition: vfdimg.c:435
DWORD GuiSaveParam(HWND hParent, PCSAVE_PARAM pParam)
Definition: vfdguisave.c:101
#define IDCONTINUE
Definition: vfdguiut.c:42
#define MB_CANCELTRYCONTINUE
Definition: vfdguiut.c:34
#define VFD_MSGBOX_TITLE
Definition: vfdlib.h:53
#define VFD_FLAG_DATA_MODIFIED
Definition: vfdtypes.h:69
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
HICON HCURSOR
Definition: windef.h:299
#define ERROR_CANCELLED
Definition: winerror.h:726
#define IDCANCEL
Definition: winuser.h:831
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
#define MB_RETRYCANCEL
Definition: winuser.h:805
#define LoadCursor
Definition: winuser.h:5812
#define MB_ICONEXCLAMATION
Definition: winuser.h:785
#define MB_ICONQUESTION
Definition: winuser.h:789
#define MessageBox
Definition: winuser.h:5822
#define IDC_WAIT
Definition: winuser.h:689
#define IDYES
Definition: winuser.h:835
#define MB_YESNOCANCEL
Definition: winuser.h:818
char CHAR
Definition: xmlstorage.h:175

Referenced by CVfdShExt::DoVfdClose().

◆ VfdGuiFormat()

DWORD WINAPI VfdGuiFormat ( HWND  hParent,
ULONG  nDevice 
)

Definition at line 262 of file vfdguiut.c.

265{
266 HANDLE hDevice;
267 ULONG ret;
268 PSTR msg;
269
270 msg = ModuleMessage(MSG_FORMAT_WARNING);
271
272 ret = MessageBox(hParent,
273 msg ? msg : "Format?",
276
277 if (msg) {
278 LocalFree(msg);
279 }
280
281 if (ret == IDCANCEL) {
282 MessageBox(hParent,
285
286 return ERROR_CANCELLED;
287 }
288
289 hDevice = VfdOpenDevice(nDevice);
290
291 if (hDevice == INVALID_HANDLE_VALUE) {
292 ret = GetLastError();
293 }
294 else {
295 HCURSOR original;
296
297retry:
298 original = SetCursor(LoadCursor(NULL, IDC_WAIT));
299
300 ret = VfdDismountVolume(hDevice, FALSE);
301
302 if (ret == ERROR_ACCESS_DENIED) {
303 PSTR msg;
304 int reply;
305
306 SetCursor(original);
307
308 msg = ModuleMessage(MSG_UNMOUNT_CONFIRM);
309
310 reply = MessageBox(
311 hParent, msg ? msg : "retry", VFD_MSGBOX_TITLE,
313
314 if (msg) {
315 LocalFree(msg);
316 }
317
318 if (reply == IDRETRY) {
319 goto retry;
320 }
321 else if (reply == IDCANCEL) {
323 }
324 else {
325 VfdDismountVolume(hDevice, TRUE);
327 }
328 }
329
330 if (ret == ERROR_SUCCESS) {
331 ret = VfdFormatMedia(hDevice);
332 }
333
334 SetCursor(original);
335
336 CloseHandle(hDevice);
337 }
338
339 MessageBox(hParent,
343
344 return ret;
345}
DWORD WINAPI VfdFormatMedia(HANDLE hDevice)
Definition: vfdctl.c:2523
DWORD WINAPI VfdDismountVolume(HANDLE hDevice, BOOL bForce)
Definition: vfdctl.c:2629
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
#define MB_OKCANCEL
Definition: winuser.h:804
#define MB_ICONINFORMATION
Definition: winuser.h:802
#define MB_ICONSTOP
Definition: winuser.h:803
#define IDRETRY
Definition: winuser.h:833

Referenced by VfdPageDlgProc().

◆ VfdMakeFileDesc()

void WINAPI VfdMakeFileDesc ( PSTR  pBuffer,
ULONG  nBufSize,
VFD_FILETYPE  nFileType,
ULONG  nFileSize,
DWORD  nFileAttr 
)

Definition at line 376 of file vfdguiut.c.

382{
383 PSTR type_str;
384 PSTR size_str;
385 PSTR attr_ro;
386 PSTR attr_enc;
388
389 ZeroMemory(pBuffer, nBufSize);
390
391 switch (nFileType) {
392 case VFD_FILETYPE_RAW:
393 type_str = ModuleMessage(MSG_FILETYPE_RAW);
394 break;
395
396 case VFD_FILETYPE_ZIP:
397 type_str = ModuleMessage(MSG_FILETYPE_ZIP);
398 break;
399
400 default:
401 type_str = NULL;
402 }
403
404 if (nFileSize == INVALID_FILE_SIZE) {
405 size_str = ModuleMessage(MSG_DESC_NEW_FILE);
406 }
407 else {
408 CHAR buf[20], buf2[20];
409 size_str = ModuleMessage(MSG_DESC_FILESIZE,
410 FormatSizeBytes(nFileSize, buf),
411 FormatSizeUnits(nFileSize, buf2));
412 }
413
414 attr_ro = NULL;
415 attr_cmp = NULL;
416 attr_enc = NULL;
417
418 if (nFileAttr != INVALID_FILE_ATTRIBUTES) {
419 if (nFileAttr & FILE_ATTRIBUTE_READONLY) {
420 attr_ro = ModuleMessage(MSG_ATTR_READONLY);
421 }
422
423 if (nFileAttr & FILE_ATTRIBUTE_COMPRESSED) {
424 attr_cmp = ModuleMessage(MSG_ATTR_COMPRESSED);
425 }
426
427 if (nFileAttr & FILE_ATTRIBUTE_ENCRYPTED) {
428 attr_enc = ModuleMessage(MSG_ATTR_ENCRYPTED);
429 }
430 }
431
432 _snprintf(pBuffer, nBufSize - 1, "%s %s %s %s %s",
433 type_str ? type_str : "",
434 size_str ? size_str : "",
435 attr_ro ? attr_ro : "",
436 attr_cmp ? attr_cmp : "",
437 attr_enc ? attr_enc : "");
438
439 if (type_str) {
440 LocalFree(type_str);
441 }
442 if (size_str) {
443 LocalFree(size_str);
444 }
445 if (attr_ro) {
446 LocalFree(attr_ro);
447 }
448 if (attr_cmp) {
450 }
451 if (attr_enc) {
452 LocalFree(attr_enc);
453 }
454}
int attr_cmp(struct attr_cache_entry *lhs, struct attr_cache_entry *rhs)
Definition: name_cache.c:113
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
PVOID pBuffer
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static PSTR FormatSizeUnits(ULONG size, PSTR buf)
Definition: vfdguiut.c:68
@ VFD_FILETYPE_RAW
Definition: vfdtypes.h:52
@ VFD_FILETYPE_ZIP
Definition: vfdtypes.h:53
#define ZeroMemory
Definition: winbase.h:1712
#define INVALID_FILE_SIZE
Definition: winbase.h:548
#define _snprintf
Definition: xmlstorage.h:200

Referenced by OnImage(), OnTarget(), PrintImageInfo(), UpdateImageInfo(), and VfdImageTip().