1 |
/* wptFileMangerDlg.cpp - File Manager |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
3 |
* |
4 |
* This file is part of WinPT. |
5 |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* WinPT 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 |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
20 |
|
21 |
#include <windows.h> |
22 |
#include <commctrl.h> |
23 |
|
24 |
#include "../resource.h" |
25 |
#include "wptCommonCtl.h" |
26 |
#include "wptGPG.h" |
27 |
#include "wptW32API.h" |
28 |
#include "wptKeylist.h" |
29 |
#include "wptErrors.h" |
30 |
#include "wptContext.h" /* for passphrase_s */ |
31 |
#include "wptDlgs.h" |
32 |
#include "wptTypes.h" |
33 |
#include "wptNLS.h" |
34 |
#include "wptVersion.h" |
35 |
#include "wptFileManager.h" |
36 |
|
37 |
#define send_cmd_id(hwnd, id) \ |
38 |
PostMessage( (hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0 ) |
39 |
|
40 |
static subclass_s filelist_proc; |
41 |
|
42 |
struct thread_ctx_s { |
43 |
HWND dlg; |
44 |
HANDLE fd; |
45 |
char * drive; |
46 |
}; |
47 |
typedef struct thread_ctx_s * thread_ctx_t; |
48 |
|
49 |
|
50 |
BOOL CALLBACK |
51 |
file_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
52 |
{ |
53 |
static listview_ctrl_t lv = NULL; |
54 |
static fm_state_t c; |
55 |
static int req_signer = 0; |
56 |
static keylist_t list = NULL; |
57 |
gpgme_keycache_t kc; |
58 |
gpgme_ctx_t ctx; |
59 |
int force_trust = 0, count = 0; |
60 |
|
61 |
switch (msg) { |
62 |
case WM_INITDIALOG: |
63 |
req_signer = 0; |
64 |
c = (fm_state_t)lparam; |
65 |
if (!c) |
66 |
dlg_fatal_error( dlg, "Could not get dialog state!" ); |
67 |
kc = keycache_get_ctx (KEYCACHE_PUB); |
68 |
if (!kc) |
69 |
BUG (dlg); |
70 |
#ifndef LANG_DE |
71 |
SetWindowText( dlg, _("File Encrypt") ); |
72 |
SetDlgItemText( dlg, IDC_ENCRYPT_ARMOR, _("&Text Output") ); |
73 |
SetDlgItemText( dlg, IDC_ENCRYPT_WIPE, _("&Wipe Original") ); |
74 |
#endif |
75 |
if (c->req_signer) { |
76 |
EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_SIGN), TRUE); |
77 |
seclist_init (dlg, IDC_ENCRYPT_SECLIST, KEYLIST_FLAG_SHORT, &list); |
78 |
} |
79 |
lv = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_LIST), kc, NULL, |
80 |
KEYLIST_ENCRYPT|KEYLIST_FLAG_FILE, GPGME_ATTR_USERID); |
81 |
SetForegroundWindow (dlg); |
82 |
return TRUE; |
83 |
|
84 |
case WM_DESTROY: |
85 |
seclist_destroy (&list); |
86 |
if (lv) { |
87 |
keylist_delete (lv); |
88 |
lv = NULL; |
89 |
} |
90 |
return FALSE; |
91 |
|
92 |
case WM_NOTIFY: |
93 |
NMHDR *notify; |
94 |
notify = (NMHDR *)lparam; |
95 |
if( notify && notify->code == LVN_COLUMNCLICK |
96 |
&& notify->idFrom == IDC_ENCRYPT_LIST ) { |
97 |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
98 |
int sortby = 0; |
99 |
|
100 |
switch( p->iSubItem ) { |
101 |
case 0: sortby = GPGME_ATTR_USERID; break; |
102 |
case 1: sortby = GPGME_ATTR_KEYID; break; |
103 |
case 2: sortby = GPGME_ATTR_LEN; break; |
104 |
case 4: sortby = GPGME_ATTR_VALIDITY; break; |
105 |
default:sortby = GPGME_ATTR_USERID; break; |
106 |
} |
107 |
keylist_sort( lv, sortby ); |
108 |
} |
109 |
|
110 |
case WM_SYSCOMMAND: |
111 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
112 |
c->cancel = 1; |
113 |
EndDialog( dlg, TRUE ); |
114 |
} |
115 |
return FALSE; |
116 |
|
117 |
case WM_COMMAND: |
118 |
if (HIWORD (wparam) == BN_CLICKED |
119 |
&& LOWORD (wparam) == IDC_ENCRYPT_SIGN) { |
120 |
req_signer ^= 1; |
121 |
EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_SECLIST), |
122 |
req_signer? TRUE : FALSE); |
123 |
} |
124 |
switch( LOWORD( wparam ) ) { |
125 |
case IDOK: |
126 |
ctx = c->ctx; |
127 |
gpgme_recipients_release (c->recp); |
128 |
c->recp = keylist_get_recipients (lv, &force_trust, &count); |
129 |
if( !gpgme_recipients_count (c->recp) ) { |
130 |
msg_box (dlg, _("Please select at least one recipient."), |
131 |
_("File Encrypt"), MB_ERR); |
132 |
gpgme_recipients_release(c->recp); |
133 |
c->recp = NULL; |
134 |
c->cancel = 1; |
135 |
return FALSE; |
136 |
} |
137 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_SIGN)) { |
138 |
gpgme_key_t key; |
139 |
|
140 |
if (seclist_select_key (dlg, IDC_ENCRYPT_SECLIST, &key)) |
141 |
return FALSE; |
142 |
else |
143 |
gpgme_signers_add (c->ctx, key); |
144 |
} |
145 |
|
146 |
gpgme_control( ctx, GPGME_CTRL_FORCETRUST, force_trust ); |
147 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_ARMOR)) |
148 |
gpgme_control (ctx, GPGME_CTRL_ARMOR, 1); |
149 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_WIPE)) |
150 |
c->wipe = 1; |
151 |
if (force_trust) |
152 |
gpgme_control (ctx, GPGME_CTRL_FORCETRUST, 1); |
153 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_ANON)) |
154 |
gpgme_control (ctx, GPGME_CTRL_THROWKEYID, 1); |
155 |
c->cancel = 0; |
156 |
EndDialog (dlg, TRUE); |
157 |
return TRUE; |
158 |
|
159 |
case IDCANCEL: |
160 |
c->cancel = 1; |
161 |
EndDialog (dlg, FALSE); |
162 |
return FALSE; |
163 |
} |
164 |
return TRUE; |
165 |
} |
166 |
|
167 |
return FALSE; |
168 |
} /* file_encrypt_dlg_proc */ |
169 |
|
170 |
|
171 |
BOOL CALLBACK |
172 |
file_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
173 |
{ |
174 |
static listview_ctrl_t lv = NULL; |
175 |
static fm_state_t c; |
176 |
static int is_revcert = 0, has_seckeys = 0; |
177 |
|
178 |
switch( msg ) { |
179 |
case WM_INITDIALOG: |
180 |
c = (fm_state_s *)lparam; |
181 |
if (!c) |
182 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
183 |
#ifndef LANG_DE |
184 |
SetWindowText (dlg, _("File Import")); |
185 |
#endif |
186 |
ShowWindow( GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED ); |
187 |
/* fixme: use the new code */ |
188 |
implist_build( &lv, GetDlgItem( dlg, IDC_IMPORT_KEYLIST ) ); |
189 |
implist_load( lv, c->opaque, &is_revcert, &has_seckeys ); |
190 |
SetForegroundWindow( dlg ); |
191 |
if( !listview_count_items( lv, 0 ) ) { |
192 |
msg_box( dlg, _("No valid OpenPGP data found."), _("File Import"), MB_ERR ); |
193 |
c->cancel = 1; |
194 |
EndDialog( dlg, FALSE ); |
195 |
} |
196 |
return TRUE; |
197 |
|
198 |
case WM_DESTROY: |
199 |
if( lv ) { |
200 |
listview_release( lv ); |
201 |
lv = NULL; |
202 |
} |
203 |
return FALSE; |
204 |
|
205 |
case WM_SYSCOMMAND: |
206 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
207 |
c->cancel = 1; |
208 |
EndDialog( dlg, FALSE ); |
209 |
} |
210 |
return FALSE; |
211 |
|
212 |
case WM_COMMAND: |
213 |
switch( LOWORD( wparam ) ) { |
214 |
case IDC_IMPORT_DOIT: |
215 |
c->cancel = 0; |
216 |
c->implist_revcert = is_revcert? 1 : 0; |
217 |
EndDialog( dlg, TRUE ); |
218 |
return TRUE; |
219 |
|
220 |
case IDCANCEL: |
221 |
c->cancel = 1; |
222 |
EndDialog( dlg, FALSE ); |
223 |
return FALSE; |
224 |
} |
225 |
break; |
226 |
} |
227 |
|
228 |
return FALSE; |
229 |
} /* file_import_dlg_proc */ |
230 |
|
231 |
|
232 |
BOOL CALLBACK |
233 |
file_sign_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
234 |
{ |
235 |
static fm_state_t c; |
236 |
static listview_ctrl_t lv; |
237 |
gpgme_keycache_t kc, sec_kc; |
238 |
gpgme_key_t key; |
239 |
int lv_idx; |
240 |
char signer[32]; |
241 |
|
242 |
switch( msg ) { |
243 |
case WM_INITDIALOG: |
244 |
c = (fm_state_s *)lparam; |
245 |
if( c == NULL ) |
246 |
dlg_fatal_error( dlg, "Could not get dialog state!" ); |
247 |
#ifndef LANG_DE |
248 |
SetWindowText (dlg, _("File Sign")); |
249 |
SetDlgItemText (dlg, IDC_FILE_SIG_ARMOR, _("&Text Output") ); |
250 |
SetDlgItemText (dlg, IDC_FILE_SIG_NORMAL, _("&Normal Signature")); |
251 |
SetDlgItemText (dlg, IDC_FILE_SIG_DETACH, _("&Detached Signature")); |
252 |
SetDlgItemText (dlg, IDC_FILE_SIG_CLEAR, _("&Cleartext Signature")); |
253 |
#endif |
254 |
CheckDlgButton (dlg, IDC_FILE_SIG_DETACH, BST_CHECKED); |
255 |
kc = keycache_get_ctx (KEYCACHE_PUB); |
256 |
if (!kc) |
257 |
BUG (dlg); |
258 |
sec_kc = keycache_get_ctx (KEYCACHE_PRV); |
259 |
if (!sec_kc) |
260 |
BUG( dlg ); |
261 |
lv = keylist_load( GetDlgItem(dlg, IDC_FILE_SIG_LIST), kc, sec_kc, |
262 |
KEYLIST_SIGN, GPGME_ATTR_USERID ); |
263 |
SetForegroundWindow( dlg ); |
264 |
return TRUE; |
265 |
|
266 |
case WM_DESTROY: |
267 |
if( lv ) { |
268 |
listview_release( lv ); |
269 |
lv = NULL; |
270 |
} |
271 |
return FALSE; |
272 |
|
273 |
case WM_SYSCOMMAND: |
274 |
if( LOWORD (wparam) == SC_CLOSE ) |
275 |
EndDialog( dlg, TRUE ); |
276 |
return FALSE; |
277 |
|
278 |
case WM_COMMAND: |
279 |
switch( LOWORD( wparam ) ) { |
280 |
case IDOK: |
281 |
if( IsDlgButtonChecked( dlg, IDC_FILE_SIG_ARMOR ) ) |
282 |
gpgme_control( c->ctx, GPGME_CTRL_ARMOR, 1 ); |
283 |
if( IsDlgButtonChecked( dlg, IDC_FILE_SIG_NORMAL ) ) |
284 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
285 |
else if( IsDlgButtonChecked( dlg, IDC_FILE_SIG_DETACH ) ) |
286 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
287 |
else if( IsDlgButtonChecked( dlg, IDC_FILE_SIG_CLEAR ) ) |
288 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
289 |
else { |
290 |
/* default is to produce detached signatures */ |
291 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
292 |
} |
293 |
lv_idx = listview_get_curr_pos( lv ); |
294 |
if (lv_idx == -1) { |
295 |
if (listview_count_items (lv, 0) == 1) |
296 |
lv_idx = 0; |
297 |
else { |
298 |
msg_box (dlg, _("Please select a key."), _("Sign"), MB_ERR); |
299 |
return FALSE; |
300 |
} |
301 |
} |
302 |
listview_get_item_text( lv, lv_idx, 1, signer, sizeof signer-1 ); |
303 |
if( get_seckey( signer, &key ) ) |
304 |
BUG( NULL ); |
305 |
gpgme_signers_clear (c->ctx); |
306 |
gpgme_signers_add (c->ctx, key); |
307 |
free_if_alloc (c->opaque); |
308 |
c->opaque = m_strdup (signer); /* store for later use */ |
309 |
c->cancel = 0; |
310 |
if (!c->opaque) |
311 |
BUG (0); |
312 |
EndDialog (dlg, TRUE); |
313 |
return TRUE; |
314 |
|
315 |
case IDCANCEL: |
316 |
c->cancel = 1; |
317 |
EndDialog (dlg, FALSE); |
318 |
return FALSE; |
319 |
} |
320 |
break; |
321 |
} |
322 |
|
323 |
return FALSE; |
324 |
} /* file_sign_dlg_proc */ |
325 |
|
326 |
|
327 |
|
328 |
BOOL CALLBACK |
329 |
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
330 |
{ |
331 |
switch (msg) |
332 |
{ |
333 |
case WM_KEYUP: |
334 |
int virt_key = (int)wparam; |
335 |
if (virt_key == VK_DELETE) |
336 |
send_cmd_id (filelist_proc.dlg, ID_FILEMISC_WIPE); |
337 |
break; |
338 |
} |
339 |
return CallWindowProc (filelist_proc.old, dlg, msg, wparam, lparam); |
340 |
} |
341 |
|
342 |
|
343 |
BOOL CALLBACK |
344 |
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
345 |
{ |
346 |
static listview_ctrl_t lv = NULL; |
347 |
static HMENU menu = NULL; |
348 |
static int always_ontop = 1; |
349 |
HWND fl; |
350 |
|
351 |
switch (msg) |
352 |
{ |
353 |
case WM_INITDIALOG: |
354 |
always_ontop = 1; |
355 |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
356 |
SetWindowText( dlg, _("File Manager (use drag & drop to add files)") ); |
357 |
set_menu_text( menu, ID_FILEMISC_OPEN, _("&Open...") ); |
358 |
set_menu_text( menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
359 |
set_menu_text( menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
360 |
set_menu_text( menu, ID_FILEMISC_SIGN, _("&Sign") ); |
361 |
set_menu_text( menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
362 |
set_menu_text( menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
363 |
set_menu_text( menu, ID_FILEMISC_WIPE, _("&Wipe") ); |
364 |
set_menu_text( menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
365 |
set_menu_text( menu, ID_FILEMISC_IMPORT, _("&Import") ); |
366 |
set_menu_text( menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
367 |
set_menu_text( menu, ID_FILEMISC_QUIT, _("Exit")); |
368 |
set_menu_text( menu, ID_FILEMISC_PREFS, _("Preferences") ); |
369 |
set_menu_text( menu, ID_FILEMISC_CLEAR, _("Clear List") ); |
370 |
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
371 |
filelist_proc.dlg = dlg; |
372 |
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
373 |
filelist_proc.old = (WNDPROC)GetWindowLong (fl, GWL_WNDPROC); |
374 |
if (filelist_proc.old) { |
375 |
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
376 |
msg_box (dlg, _("Could not set filelist window procedure."), _("Key Manager"), MB_ERR); |
377 |
BUG (0); |
378 |
} |
379 |
} |
380 |
SetMenu (dlg, menu); |
381 |
fm_build (&lv, GetDlgItem (dlg, IDC_FILE_LIST)); |
382 |
center_window2 (dlg, HWND_TOPMOST); |
383 |
center_window (dlg); |
384 |
SetForegroundWindow (dlg); |
385 |
return TRUE; |
386 |
|
387 |
case WM_DESTROY: |
388 |
if (lv) { |
389 |
fm_delete (lv); |
390 |
lv = NULL; |
391 |
} |
392 |
if (menu) { |
393 |
DestroyMenu (menu); |
394 |
menu = NULL; |
395 |
} |
396 |
return FALSE; |
397 |
|
398 |
case WM_DROPFILES: |
399 |
fm_add_dropped_files (lv, (HDROP)wparam); |
400 |
return TRUE; |
401 |
|
402 |
case WM_NOTIFY: |
403 |
NMHDR *notify; |
404 |
int pos; |
405 |
HMENU hm; |
406 |
|
407 |
notify = (NMHDR *)lparam; |
408 |
if (notify && notify->code == NM_RCLICK |
409 |
&& notify->idFrom == IDC_FILE_LIST) { |
410 |
POINT p; |
411 |
HMENU popup; |
412 |
|
413 |
GetCursorPos (&p); |
414 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_FILEMISC_CTX)); |
415 |
popup = GetSubMenu (hm, 0); |
416 |
set_menu_text (popup, ID_FILECTX_ENCRYPT, _("Encrypt")); |
417 |
set_menu_text (popup, ID_FILECTX_DECRYPT, _("Decrypt")); |
418 |
set_menu_text (popup, ID_FILECTX_SIGN, _("Sign")); |
419 |
set_menu_text (popup, ID_FILECTX_SIGNENC, _("Sign && Encrypt")); |
420 |
set_menu_text (popup, ID_FILECTX_VERIFY, _("Verify")); |
421 |
set_menu_text (popup, ID_FILECTX_WIPE, _("Wipe")); |
422 |
set_menu_text (popup, ID_FILECTX_SEND, _("Send as Mail")); |
423 |
pos = listview_get_curr_pos (lv); |
424 |
if (fm_check_file_type (lv, pos, FM_DECRYPT)) |
425 |
set_menu_state (popup, ID_FILECTX_SEND, MF_ENABLED); |
426 |
if (fm_check_file_type (lv, listview_get_curr_pos (lv), FM_ENCRYPT)) { |
427 |
set_menu_state (popup, ID_FILECTX_DECRYPT, MF_GRAYED|MF_DISABLED); |
428 |
set_menu_state (popup, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED); |
429 |
} |
430 |
if (fm_check_file_type (lv, pos, FM_DECRYPT)) { |
431 |
set_menu_state (popup, ID_FILECTX_ENCRYPT, MF_GRAYED|MF_DISABLED); |
432 |
set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED); |
433 |
set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED); |
434 |
} |
435 |
if (fm_check_file_type (lv, pos, FM_VERIFY)) { |
436 |
set_menu_state (popup, ID_FILECTX_VERIFY, MF_ENABLED); |
437 |
set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED); |
438 |
set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED); |
439 |
} |
440 |
|
441 |
TrackPopupMenu(popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
442 |
DestroyMenu (popup); |
443 |
DestroyMenu (hm); |
444 |
} |
445 |
if (notify && notify->code == NM_CLICK |
446 |
&& notify->idFrom == IDC_FILE_LIST) { |
447 |
hm = GetMenu (dlg); |
448 |
pos = listview_get_curr_pos (lv); |
449 |
if (!fm_check_file_type (lv, pos, FM_DECRYPT)) |
450 |
set_menu_state (hm, ID_FILEMISC_SEND, MF_GRAYED|MF_DISABLED); |
451 |
else |
452 |
set_menu_state (hm, ID_FILEMISC_SEND, MF_ENABLED); |
453 |
} |
454 |
return TRUE; |
455 |
|
456 |
case WM_SYSCOMMAND: |
457 |
if( LOWORD( wparam ) == SC_CLOSE ) |
458 |
EndDialog( dlg, TRUE ); |
459 |
return FALSE; |
460 |
|
461 |
case WM_COMMAND: |
462 |
switch( LOWORD( wparam ) ) { |
463 |
case ID_FILEMISC_QUIT: |
464 |
EndDialog( dlg, TRUE ); |
465 |
return TRUE; |
466 |
|
467 |
case ID_FILEMISC_WIPE_FREES: |
468 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL, dlg, |
469 |
space_wipefrees_dlg_proc, NULL); |
470 |
break; |
471 |
|
472 |
case ID_FILEMISC_SELALL: |
473 |
listview_select_all (lv); |
474 |
break; |
475 |
|
476 |
case ID_FILEMISC_PASTE: |
477 |
fm_verify_pasted_detsig (lv, dlg); |
478 |
break; |
479 |
|
480 |
case ID_FILEMISC_ONTOP: |
481 |
always_ontop ^= 1; |
482 |
set_menu_state (menu, ID_FILEMISC_ONTOP, |
483 |
always_ontop == 0? MFS_UNCHECKED : MFS_CHECKED); |
484 |
center_window2 (dlg, always_ontop == 0? HWND_NOTOPMOST : HWND_TOPMOST); |
485 |
break; |
486 |
|
487 |
case ID_FILEMISC_SEND: |
488 |
fm_send_file (lv); |
489 |
break; |
490 |
|
491 |
case ID_FILEMISC_LIST: |
492 |
case ID_FILEMISC_ENCRYPT: |
493 |
case ID_FILEMISC_SYMENC: |
494 |
case ID_FILEMISC_DECRYPT: |
495 |
case ID_FILEMISC_SIGN: |
496 |
case ID_FILEMISC_SIGNENC: |
497 |
case ID_FILEMISC_VERIFY: |
498 |
case ID_FILEMISC_WIPE: |
499 |
fm_parse_files (lv, dlg, LOWORD (wparam)); |
500 |
SetForegroundWindow (dlg); |
501 |
return TRUE; |
502 |
|
503 |
case ID_FILEMISC_MD_MD5: |
504 |
case ID_FILEMISC_MD_SHA1: |
505 |
case ID_FILEMISC_MD_RMD160: |
506 |
fm_print_md (lv, dlg, LOWORD (wparam)-40136); |
507 |
SetForegroundWindow (dlg); |
508 |
return TRUE; |
509 |
|
510 |
case ID_FILEMISC_CLEAR: |
511 |
listview_del_all( lv ); |
512 |
return TRUE; |
513 |
|
514 |
case ID_FILEMISC_OPEN: |
515 |
fm_add_opened_files( lv, dlg ); |
516 |
return TRUE; |
517 |
|
518 |
/* context menu entries */ |
519 |
case ID_FILECTX_ENCRYPT: send_cmd_id( dlg, ID_FILEMISC_ENCRYPT); break; |
520 |
case ID_FILECTX_DECRYPT: send_cmd_id( dlg, ID_FILEMISC_DECRYPT );break; |
521 |
case ID_FILECTX_SIGN: send_cmd_id( dlg, ID_FILEMISC_SIGN ); break; |
522 |
case ID_FILECTX_SIGNENC: send_cmd_id( dlg, ID_FILEMISC_SIGNENC );break; |
523 |
case ID_FILECTX_VERIFY: send_cmd_id( dlg, ID_FILEMISC_VERIFY ); break; |
524 |
case ID_FILECTX_WIPE: send_cmd_id( dlg, ID_FILEMISC_WIPE ); break; |
525 |
case ID_FILECTX_LIST: send_cmd_id( dlg, ID_FILEMISC_LIST ); break; |
526 |
case ID_FILECTX_SEND: send_cmd_id( dlg, ID_FILEMISC_SEND ); break; |
527 |
} |
528 |
break; |
529 |
} |
530 |
|
531 |
return FALSE; |
532 |
} /* file_manager_dlg_proc */ |
533 |
|
534 |
|
535 |
BOOL CALLBACK |
536 |
file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
537 |
{ |
538 |
static secdel_confirm_s * ctx; |
539 |
const char * s; |
540 |
void * tmp; |
541 |
|
542 |
switch (msg) { |
543 |
case WM_INITDIALOG: |
544 |
ctx = (struct secdel_confirm_s *)lparam; |
545 |
if( !ctx ) |
546 |
BUG( NULL ); |
547 |
gpgme_recipients_enum_open( ctx->rset, &tmp ); |
548 |
while( (s =gpgme_recipients_enum_read( ctx->rset, &tmp )) ) |
549 |
SendDlgItemMessage( dlg, IDC_SECDEL_FILES, LB_ADDSTRING, |
550 |
NULL, (WPARAM)(char *)s ); |
551 |
break; |
552 |
|
553 |
case WM_COMMAND: |
554 |
switch( LOWORD( wparam ) ) { |
555 |
case IDYES: |
556 |
ctx->yes = 1; |
557 |
EndDialog( dlg, TRUE ); |
558 |
break; |
559 |
|
560 |
case IDNO: |
561 |
ctx->yes = 0; |
562 |
EndDialog( dlg, FALSE ); |
563 |
break; |
564 |
} |
565 |
break; |
566 |
} |
567 |
|
568 |
return FALSE; |
569 |
} /* file_secdel_confirm_dlg_proc */ |
570 |
|
571 |
|
572 |
static void |
573 |
wipe_cb (void * ctx, ui64 off, ui64 n) |
574 |
{ |
575 |
SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS, |
576 |
(WPARAM) (off*100/n), 0); |
577 |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE); |
578 |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE); |
579 |
} /* wipe_cb */ |
580 |
|
581 |
|
582 |
static DWORD WINAPI |
583 |
wipe_thread (void * ctx) |
584 |
{ |
585 |
thread_ctx_t a = (thread_ctx_t)ctx; |
586 |
int rc; |
587 |
|
588 |
rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg); |
589 |
SetDlgItemText (a->dlg, IDC_SPACE_INFO, |
590 |
rc? _("Operation Status: Error") : _("Operation Status: Done.")); |
591 |
if (rc) |
592 |
msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR); |
593 |
else |
594 |
MessageBeep (MB_OK); |
595 |
ExitThread (0); |
596 |
return 0; |
597 |
} /* wipe_thread */ |
598 |
|
599 |
|
600 |
static void |
601 |
fill_drive_combobox (HWND dlg) |
602 |
{ |
603 |
char buf[384], p[16]; |
604 |
int n, i, j = 0; |
605 |
|
606 |
n = GetLogicalDriveStrings (DIM (buf)-1, buf); |
607 |
while (j < n) { |
608 |
for (i = 0; buf[j] != '\0'; i++, j++) |
609 |
p[i] = buf[j]; |
610 |
p[i] = '\0'; |
611 |
j++; |
612 |
if (GetDriveType (p) != DRIVE_CDROM) |
613 |
SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_ADDSTRING, |
614 |
0, (LPARAM)(const char *)p); |
615 |
} |
616 |
SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_SETCURSEL, 0, 0); |
617 |
} /* fill_drive_combobox */ |
618 |
|
619 |
|
620 |
static void |
621 |
update_disc_stats (HWND dlg) |
622 |
{ |
623 |
ULARGE_INTEGER caller = {0}, total = {0}, free = {0}; |
624 |
char buf[128], drive[32], a_total[64] = {0}, a_free[64] = {0}; |
625 |
int idx; |
626 |
|
627 |
idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0); |
628 |
GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1); |
629 |
if (GetDiskFreeSpaceEx (drive, &caller, &total, &free)) { |
630 |
_ui64toa (total.QuadPart/1024, a_total, 10); |
631 |
_ui64toa (free.QuadPart/1024, a_free, 10); |
632 |
} |
633 |
_snprintf (buf, DIM (buf)-1, _("Total Capacity: %12sk\n" |
634 |
"Free Space : %12sk"), a_total, a_free); |
635 |
SetDlgItemText(dlg, IDC_SPACE_DISC_INFO, buf); |
636 |
SetDlgItemInt (dlg, IDC_SPACE_OFF, 0, FALSE); |
637 |
SetDlgItemInt (dlg, IDC_SPACE_N, 0, FALSE); |
638 |
} /* update_disc_stats */ |
639 |
|
640 |
|
641 |
BOOL CALLBACK |
642 |
space_wipefrees_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
643 |
{ |
644 |
static HANDLE thread_hd = NULL; |
645 |
static thread_ctx_s ctx; |
646 |
char drive[32], * p; |
647 |
int idx; |
648 |
DWORD tid; |
649 |
|
650 |
switch (msg) { |
651 |
case WM_INITDIALOG: |
652 |
fill_drive_combobox (dlg); |
653 |
update_disc_stats (dlg); |
654 |
center_window (dlg); |
655 |
SetForegroundWindow (dlg); |
656 |
break; |
657 |
|
658 |
case WM_DESTROY: |
659 |
thread_hd = NULL; |
660 |
free_if_alloc (ctx.drive); |
661 |
memset (&ctx, 0, sizeof ctx); |
662 |
break; |
663 |
|
664 |
case WM_COMMAND: |
665 |
if (HIWORD (wparam) == CBN_SELCHANGE) |
666 |
update_disc_stats (dlg); |
667 |
switch (LOWORD (wparam)) |
668 |
{ |
669 |
case IDOK: |
670 |
idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0); |
671 |
if (idx != CB_ERR && !thread_hd) { |
672 |
GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1); |
673 |
ctx.dlg = dlg; |
674 |
ctx.drive = m_strdup (drive); |
675 |
ctx.fd = NULL; |
676 |
thread_hd = CreateThread (NULL, 0, wipe_thread, &ctx, 0, &tid); |
677 |
} |
678 |
if (WaitForSingleObject (thread_hd, 0) == WAIT_OBJECT_0) { |
679 |
CloseHandle (thread_hd); |
680 |
thread_hd = NULL; |
681 |
EndDialog (dlg, TRUE); |
682 |
} |
683 |
break; |
684 |
|
685 |
case IDCANCEL: |
686 |
if (thread_hd) { |
687 |
WaitForSingleObject (thread_hd, 2000); |
688 |
TerminateThread (thread_hd, 1); |
689 |
CloseHandle (thread_hd); |
690 |
CloseHandle (ctx.fd); |
691 |
p = make_filename (ctx.drive, "temp_winpt.tmp", NULL); |
692 |
if (p && !file_exist_check (p)) |
693 |
unlink (p); |
694 |
free_if_alloc (p); |
695 |
} |
696 |
EndDialog( dlg, FALSE ); |
697 |
break; |
698 |
} |
699 |
break; |
700 |
} |
701 |
|
702 |
return FALSE; |
703 |
} /* space_wipefrees_dlg_proc */ |