20 |
|
|
21 |
#include <windows.h> |
#include <windows.h> |
22 |
#include <commctrl.h> |
#include <commctrl.h> |
23 |
|
#include <sys/stat.h> |
24 |
|
|
25 |
#include "../resource.h" |
#include "../resource.h" |
26 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
36 |
#include "wptFileManager.h" |
#include "wptFileManager.h" |
37 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
38 |
|
|
39 |
|
#define FM_SEPARATOR_ID 10001 |
40 |
|
|
41 |
#define send_cmd_id(hwnd, id) \ |
#define send_cmd_id(hwnd, id) \ |
42 |
PostMessage( (hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0 ) |
PostMessage( (hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0 ) |
43 |
|
|
46 |
struct thread_ctx_s { |
struct thread_ctx_s { |
47 |
HWND dlg; |
HWND dlg; |
48 |
HANDLE fd; |
HANDLE fd; |
49 |
char * drive; |
char *drive; |
50 |
}; |
}; |
51 |
typedef struct thread_ctx_s * thread_ctx_t; |
typedef struct thread_ctx_s *thread_ctx_t; |
52 |
|
|
53 |
|
|
54 |
/* Dialog procedure for selecting recipients for encryption. */ |
/* Dialog procedure for selecting recipients for encryption. */ |
59 |
static fm_state_t c; |
static fm_state_t c; |
60 |
static int req_signer = 0; |
static int req_signer = 0; |
61 |
static keylist_t list = NULL; |
static keylist_t list = NULL; |
62 |
gpgme_keycache_t kc; |
gpg_keycache_t kc; |
63 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
64 |
int force_trust = 0, count = 0; |
int force_trust = 0, count = 0; |
65 |
|
|
131 |
ctx = c->ctx; |
ctx = c->ctx; |
132 |
if (c->recp) |
if (c->recp) |
133 |
free (c->recp); |
free (c->recp); |
134 |
c->recp = keylist_get_recipients (lv, &force_trust, &count); |
c->recp = keylist_get_recipients (lv, &force_trust, &c->n_recp); |
135 |
if (!count) { |
if (!c->n_recp) { |
136 |
msg_box (dlg, _("Please select at least one recipient."), |
msg_box (dlg, _("Please select at least one recipient."), |
137 |
_("File Encrypt"), MB_ERR); |
_("File Encrypt"), MB_ERR); |
138 |
free (c->recp); |
free (c->recp); |
186 |
if (!c) |
if (!c) |
187 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
188 |
#ifndef LANG_DE |
#ifndef LANG_DE |
189 |
SetWindowText (dlg, _("File Import")); |
SetWindowText (dlg, _("Key Import")); |
190 |
#endif |
#endif |
191 |
ShowWindow( GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED ); |
ShowWindow( GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED ); |
192 |
/* XXX: use the new code */ |
/* XXX: use the new code */ |
193 |
implist_build (&lv, GetDlgItem( dlg, IDC_IMPORT_KEYLIST)); |
implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
194 |
implist_load (lv, c->opaque, &is_revcert, &has_seckeys); |
implist_load (lv, c->opaque, &is_revcert, &has_seckeys); |
195 |
if (!listview_count_items (lv, 0)) { |
if (!listview_count_items (lv, 0)) { |
196 |
msg_box (dlg, _("No valid OpenPGP data found."), _("File Import"), MB_ERR); |
msg_box (dlg, _("No valid OpenPGP data found."), _("Key Import"), MB_ERR); |
197 |
c->cancel = 1; |
c->cancel = 1; |
198 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
199 |
} |
} |
200 |
else { |
else { |
|
/* XXX: add more information (public keys, secret key...) */ |
|
201 |
const char *s = "File contain(s) %d key(s)."; |
const char *s = "File contain(s) %d key(s)."; |
202 |
char *p = new char[strlen (s) + 32]; |
char *p = new char[strlen (s) + 32]; |
203 |
if (!p) |
if (!p) |
217 |
return FALSE; |
return FALSE; |
218 |
|
|
219 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
220 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
if (LOWORD (wparam) == SC_CLOSE) { |
221 |
c->cancel = 1; |
c->cancel = 1; |
222 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
223 |
} |
} |
224 |
return FALSE; |
return FALSE; |
225 |
|
|
226 |
case WM_COMMAND: |
case WM_COMMAND: |
227 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
228 |
case IDC_IMPORT_DOIT: |
case IDC_IMPORT_DOIT: |
229 |
c->cancel = 0; |
c->cancel = 0; |
230 |
c->implist_revcert = is_revcert? 1 : 0; |
c->import.revcert = is_revcert? 1 : 0; |
231 |
EndDialog( dlg, TRUE ); |
c->import.has_seckey = has_seckeys? 1 : 0; |
232 |
|
EndDialog (dlg, TRUE); |
233 |
return TRUE; |
return TRUE; |
234 |
|
|
235 |
case IDCANCEL: |
case IDCANCEL: |
236 |
c->cancel = 1; |
c->cancel = 1; |
237 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
238 |
return FALSE; |
return FALSE; |
239 |
} |
} |
240 |
break; |
break; |
249 |
{ |
{ |
250 |
static fm_state_t c; |
static fm_state_t c; |
251 |
static listview_ctrl_t lv; |
static listview_ctrl_t lv; |
252 |
gpgme_keycache_t kc, sec_kc; |
gpg_keycache_t kc, sec_kc; |
253 |
gpgme_key_t key; |
gpgme_key_t key; |
254 |
int lv_idx; |
int lv_idx; |
255 |
char signer[32]; |
char signer[32]; |
340 |
|
|
341 |
|
|
342 |
|
|
343 |
BOOL CALLBACK |
static BOOL CALLBACK |
344 |
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
345 |
{ |
{ |
346 |
switch (msg) |
switch (msg) { |
|
{ |
|
347 |
case WM_KEYUP: |
case WM_KEYUP: |
348 |
int virt_key = (int)wparam; |
int virt_key = (int)wparam; |
349 |
if (virt_key == VK_DELETE) |
if (virt_key == VK_DELETE) |
354 |
} |
} |
355 |
|
|
356 |
|
|
357 |
|
/* Setup status bar for the main window @dlg. */ |
358 |
|
static HWND |
359 |
|
setup_status_bar (HWND dlg) |
360 |
|
{ |
361 |
|
HWND statbar; |
362 |
|
RECT r; |
363 |
|
int partpos[3]; |
364 |
|
int i; |
365 |
|
|
366 |
|
GetClientRect (dlg, &r); |
367 |
|
for (i=1; i <= 3; i++) |
368 |
|
partpos[i-1] = r.right/3*i; |
369 |
|
|
370 |
|
statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM, |
371 |
|
"", dlg, FM_SEPARATOR_ID); |
372 |
|
ShowWindow (statbar, SW_SHOW); |
373 |
|
SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos); |
374 |
|
return statbar; |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
|
/* Refresh the status bar text with the selected item from @lv. */ |
379 |
|
static void |
380 |
|
update_status_bar (HWND statbar, listview_ctrl_t lv) |
381 |
|
{ |
382 |
|
struct stat st; |
383 |
|
char buf[128]; |
384 |
|
int n = listview_count_items (lv, 1); |
385 |
|
_snprintf (buf, sizeof (buf)-1, "%d Object(s) marked", n); |
386 |
|
SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)buf); |
387 |
|
listview_get_item_text (lv, listview_get_curr_pos (lv), 1, buf, 127); |
388 |
|
if (stat (buf, &st) == 0) { |
389 |
|
_snprintf (buf, sizeof (buf)-1, "%d KB", st.st_size/1024); |
390 |
|
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf); |
391 |
|
} |
392 |
|
} |
393 |
|
|
394 |
|
|
395 |
BOOL CALLBACK |
BOOL CALLBACK |
396 |
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
397 |
{ |
{ |
398 |
|
static HWND statbar; |
399 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
400 |
static HMENU menu = NULL; |
static HMENU menu = NULL; |
401 |
static int always_ontop = 1; |
static int always_ontop = 1; |
402 |
HWND fl; |
HWND fl; |
403 |
|
|
404 |
switch (msg) |
switch (msg) { |
|
{ |
|
405 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
406 |
always_ontop = 1; |
always_ontop = 1; |
407 |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
408 |
SetWindowText( dlg, _("File Manager (use drag & drop to add files)") ); |
SetWindowText (dlg, _("File Manager (use drag & drop to add files)")); |
409 |
set_menu_text( menu, ID_FILEMISC_OPEN, _("&Open...") ); |
set_menu_text (menu, ID_FILEMISC_OPEN, _("&Open...") ); |
410 |
set_menu_text( menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
set_menu_text (menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
411 |
set_menu_text( menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
set_menu_text (menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
412 |
set_menu_text( menu, ID_FILEMISC_SIGN, _("&Sign") ); |
set_menu_text (menu, ID_FILEMISC_SIGN, _("&Sign") ); |
413 |
set_menu_text( menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
set_menu_text (menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
414 |
set_menu_text( menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
set_menu_text (menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
415 |
set_menu_text( menu, ID_FILEMISC_WIPE, _("&Wipe") ); |
set_menu_text (menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
416 |
set_menu_text( menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
set_menu_text (menu, ID_FILEMISC_IMPORT, _("&Import") ); |
417 |
set_menu_text( menu, ID_FILEMISC_IMPORT, _("&Import") ); |
set_menu_text (menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
418 |
set_menu_text( menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
set_menu_text (menu, ID_FILEMISC_QUIT, _("Exit")); |
419 |
set_menu_text( menu, ID_FILEMISC_QUIT, _("Exit")); |
set_menu_text (menu, ID_FILEMISC_CLEAR, _("&Reset") ); |
420 |
set_menu_text( menu, ID_FILEMISC_PREFS, _("Preferences") ); |
set_menu_text (menu, ID_FILEMISC_ONTOP, _("Always on Top")); |
421 |
set_menu_text( menu, ID_FILEMISC_CLEAR, _("&Reset") ); |
set_menu_text (menu, ID_FILEMISC_PASTE, _("&Paste")); |
422 |
|
set_menu_text (menu, ID_FILEMISC_SELALL, _("&Select All")); |
423 |
|
set_menu_text (menu, ID_FILEMISC_PREFS, _("&Preferences")); |
424 |
|
set_menu_text (menu, ID_FILEMISC_SEND, _("Send as Mail")); |
425 |
|
set_menu_text (menu, ID_FILEMISC_LIST, _("&List Packets")); |
426 |
|
set_menu_text (menu, ID_FILEMISC_WIPE_FREES, _("Wipe Free Space")); |
427 |
|
set_menu_text (menu, ID_FILEMISC_WIPE, _("&Wipe")); |
428 |
|
|
429 |
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
430 |
filelist_proc.dlg = dlg; |
filelist_proc.dlg = dlg; |
431 |
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
433 |
if (filelist_proc.old) { |
if (filelist_proc.old) { |
434 |
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
435 |
msg_box (dlg, _("Could not set filelist window procedure."), _("Key Manager"), MB_ERR); |
msg_box (dlg, _("Could not set filelist window procedure."), _("Key Manager"), MB_ERR); |
436 |
BUG (0); |
BUG (NULL); |
437 |
} |
} |
438 |
} |
} |
439 |
SetMenu (dlg, menu); |
SetMenu (dlg, menu); |
441 |
center_window2 (dlg, NULL, HWND_TOPMOST); |
center_window2 (dlg, NULL, HWND_TOPMOST); |
442 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
443 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
444 |
|
statbar = setup_status_bar (dlg); |
445 |
return TRUE; |
return TRUE; |
446 |
|
|
447 |
case WM_DESTROY: |
case WM_DESTROY: |
465 |
HMENU hm; |
HMENU hm; |
466 |
|
|
467 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
468 |
|
if (notify && notify->code == NM_CLICK && |
469 |
|
notify->idFrom == IDC_FILE_LIST) |
470 |
|
update_status_bar (statbar, lv); |
471 |
if (notify && notify->code == NM_RCLICK |
if (notify && notify->code == NM_RCLICK |
472 |
&& notify->idFrom == IDC_FILE_LIST) { |
&& notify->idFrom == IDC_FILE_LIST) { |
473 |
POINT p; |
POINT p; |
521 |
EndDialog( dlg, TRUE ); |
EndDialog( dlg, TRUE ); |
522 |
return FALSE; |
return FALSE; |
523 |
|
|
524 |
|
case WM_INITMENUPOPUP: |
525 |
|
if ((UINT)LOWORD (lparam) == 0) { |
526 |
|
HMENU hm = (HMENU)wparam; |
527 |
|
set_menu_text_bypos (hm, 2, _("&Calc Digest")); |
528 |
|
} |
529 |
|
return FALSE; |
530 |
|
|
531 |
case WM_COMMAND: |
case WM_COMMAND: |
532 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
533 |
case ID_FILEMISC_QUIT: |
case ID_FILEMISC_QUIT: |
661 |
} |
} |
662 |
|
|
663 |
|
|
664 |
|
/* Dialog box procedure to confirm that files shall be deleted. */ |
665 |
BOOL CALLBACK |
BOOL CALLBACK |
666 |
file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
667 |
{ |
{ |
673 |
if (!ctx) |
if (!ctx) |
674 |
BUG (NULL); |
BUG (NULL); |
675 |
add_files_from_lv (dlg, ctx->lv_files); |
add_files_from_lv (dlg, ctx->lv_files); |
676 |
|
SetWindowText (dlg, _("Are you sure you want to secure delete these files?")); |
677 |
|
SetDlgItemText (dlg, IDYES, _("&Yes")); |
678 |
|
SetDlgItemText (dlg, IDNO, _("&No")); |
679 |
break; |
break; |
680 |
|
|
681 |
case WM_COMMAND: |
case WM_COMMAND: |
682 |
switch( LOWORD( wparam ) ) { |
switch (LOWORD (wparam)) { |
683 |
case IDYES: |
case IDYES: |
684 |
ctx->yes = 1; |
ctx->yes = 1; |
685 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, TRUE); |
686 |
break; |
break; |
687 |
|
|
688 |
case IDNO: |
case IDNO: |
689 |
ctx->yes = 0; |
ctx->yes = 0; |
690 |
EndDialog( dlg, FALSE ); |
EndDialog (dlg, FALSE); |
691 |
break; |
break; |
692 |
} |
} |
693 |
break; |
break; |
694 |
} |
} |
695 |
|
|
696 |
return FALSE; |
return FALSE; |
697 |
} /* file_secdel_confirm_dlg_proc */ |
} |
698 |
|
|
699 |
|
|
700 |
|
/* Wipe callback. @ctx is a window handle @off is the current offset |
701 |
|
and @n is the total size. */ |
702 |
static void |
static void |
703 |
wipe_cb (void * ctx, ui64 off, ui64 n) |
wipe_cb (void *ctx, ui64 off, ui64 n) |
704 |
{ |
{ |
705 |
SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS, |
SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS, |
706 |
(WPARAM) (off*100/n), 0); |
(WPARAM) (off*100/n), 0); |
707 |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE); |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE); |
708 |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE); |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE); |
709 |
} /* wipe_cb */ |
} |
710 |
|
|
711 |
|
|
712 |
|
/* Call the wipe free space method asynchron. */ |
713 |
static DWORD WINAPI |
static DWORD WINAPI |
714 |
wipe_thread (void * ctx) |
wipe_thread (void *ctx) |
715 |
{ |
{ |
716 |
thread_ctx_t a = (thread_ctx_t)ctx; |
thread_ctx_t a = (thread_ctx_t)ctx; |
717 |
int rc; |
int rc; |
718 |
|
|
719 |
rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg); |
rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg); |
720 |
SetDlgItemText (a->dlg, IDC_SPACE_INFO, |
SetDlgItemText (a->dlg, IDC_SPACE_INFO, |
721 |
rc? _("Operation Status: Error") : _("Operation Status: Done.")); |
rc? _("Operation Status: Error") : |
722 |
|
_("Operation Status: Done.")); |
723 |
if (rc) |
if (rc) |
724 |
msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR); |
msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR); |
725 |
else |
else |
726 |
MessageBeep (MB_OK); |
MessageBeep (MB_OK); |
727 |
ExitThread (0); |
ExitThread (0); |
728 |
return 0; |
return 0; |
729 |
} /* wipe_thread */ |
} |
730 |
|
|
731 |
|
|
732 |
static void |
static void |