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 |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
23 |
#endif |
24 |
|
25 |
#include <windows.h> |
26 |
#include <commctrl.h> |
27 |
#include <sys/stat.h> |
28 |
#include <stdio.h> |
29 |
|
30 |
#include "resource.h" |
31 |
#include "wptCommonCtl.h" |
32 |
#include "wptGPG.h" |
33 |
#include "wptW32API.h" |
34 |
#include "wptKeylist.h" |
35 |
#include "wptErrors.h" |
36 |
#include "wptContext.h" /* for passphrase_s */ |
37 |
#include "wptDlgs.h" |
38 |
#include "wptTypes.h" |
39 |
#include "wptNLS.h" |
40 |
#include "wptVersion.h" |
41 |
#include "wptFileManager.h" |
42 |
#include "wptRegistry.h" |
43 |
#include "wptCrypto.h" |
44 |
|
45 |
#define FM_SEPARATOR_ID 10001 |
46 |
|
47 |
#define send_cmd_id(hwnd, id) \ |
48 |
PostMessage ((hwnd), WM_COMMAND, MAKEWPARAM( (id), 0), 0) |
49 |
|
50 |
static subclass_s filelist_proc; |
51 |
|
52 |
struct thread_ctx_s { |
53 |
HWND dlg; |
54 |
HANDLE fd; |
55 |
char *drive; |
56 |
}; |
57 |
typedef struct thread_ctx_s *thread_ctx_t; |
58 |
|
59 |
|
60 |
/* Dialog procedure for selecting recipients for encryption. */ |
61 |
BOOL CALLBACK |
62 |
file_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
63 |
{ |
64 |
static listview_ctrl_t lv = NULL; |
65 |
static fm_state_t c; |
66 |
static keylist_t list = NULL; |
67 |
gpg_keycache_t kc; |
68 |
gpgme_ctx_t ctx; |
69 |
int force_trust = 0; |
70 |
|
71 |
switch (msg) { |
72 |
case WM_INITDIALOG: |
73 |
c = (fm_state_t)lparam; |
74 |
if (!c) |
75 |
dlg_fatal_error( dlg, "Could not get dialog state!" ); |
76 |
kc = keycache_get_ctx (KEYCACHE_PUB); |
77 |
SetWindowText (dlg, _("File Encrypt")); |
78 |
SetDlgItemText (dlg, IDC_ENCRYPT_ARMOR, _("&Text Output")); |
79 |
SetDlgItemText (dlg, IDC_ENCRYPT_WIPE, _("&Wipe Original")); |
80 |
SetDlgItemText (dlg, IDC_ENCRYPT_ANON, _("Anonymize (throw keyid)")); |
81 |
SetDlgItemText (dlg, IDC_ENCRYPT_SIGN, _("&Select Key for signing")); |
82 |
SetDlgItemText (dlg, IDC_ENCRYPT_OPTINF, _("Options")); |
83 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
84 |
|
85 |
/* XXX: support --hidden-recipient */ |
86 |
EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_ANON), FALSE); |
87 |
|
88 |
if (c->req_signer) { |
89 |
EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_SIGN), TRUE); |
90 |
seclist_init (dlg, IDC_ENCRYPT_SECLIST, KEYLIST_FLAG_SHORT, &list); |
91 |
} |
92 |
lv = keylist_load (GetDlgItem (dlg, IDC_ENCRYPT_LIST), kc, NULL, |
93 |
KEYLIST_ENCRYPT_MIN|KEYLIST_FLAG_FILE, |
94 |
KEY_SORT_USERID); |
95 |
SetForegroundWindow (dlg); |
96 |
return TRUE; |
97 |
|
98 |
case WM_DESTROY: |
99 |
seclist_destroy (&list); |
100 |
if (lv) { |
101 |
keylist_delete (lv); |
102 |
lv = NULL; |
103 |
} |
104 |
return FALSE; |
105 |
|
106 |
case WM_NOTIFY: |
107 |
NMHDR *notify; |
108 |
notify = (NMHDR *)lparam; |
109 |
if (notify && notify->code == LVN_COLUMNCLICK |
110 |
&& notify->idFrom == IDC_ENCRYPT_LIST) { |
111 |
NMLISTVIEW *p = (LPNMLISTVIEW) lparam; |
112 |
int sortby = 0; |
113 |
|
114 |
switch (p->iSubItem) { |
115 |
case 0: sortby = KEY_SORT_USERID; break; |
116 |
case 1: sortby = KEY_SORT_KEYID; break; |
117 |
case 2: sortby = KEY_SORT_LEN; break; |
118 |
case 4: sortby = KEY_SORT_VALIDITY; break; |
119 |
default:sortby = KEY_SORT_USERID; break; |
120 |
} |
121 |
keylist_sort (lv, sortby); |
122 |
} |
123 |
|
124 |
case WM_SYSCOMMAND: |
125 |
if (LOWORD (wparam) == SC_CLOSE) { |
126 |
c->cancel = 1; |
127 |
EndDialog (dlg, TRUE); |
128 |
} |
129 |
return FALSE; |
130 |
|
131 |
case WM_COMMAND: |
132 |
if (HIWORD (wparam) == BN_CLICKED |
133 |
&& LOWORD (wparam) == IDC_ENCRYPT_SIGN) { |
134 |
int req_signer = IsDlgButtonChecked (dlg, IDC_ENCRYPT_SIGN); |
135 |
EnableWindow (GetDlgItem (dlg, IDC_ENCRYPT_SECLIST), |
136 |
req_signer? TRUE : FALSE); |
137 |
} |
138 |
switch( LOWORD( wparam ) ) { |
139 |
case IDOK: |
140 |
ctx = c->ctx; |
141 |
safe_free (c->recp); |
142 |
c->recp = keylist_get_recipients (lv, &force_trust, &c->n_recp); |
143 |
if (!c->n_recp) { |
144 |
msg_box (dlg, _("Please select at least one recipient."), |
145 |
_("File Encrypt"), MB_ERR); |
146 |
safe_free (c->recp); |
147 |
c->recp = NULL; |
148 |
c->cancel = 1; |
149 |
return TRUE; |
150 |
} |
151 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_SIGN)) { |
152 |
gpgme_key_t key; |
153 |
|
154 |
if (seclist_select_key (dlg, IDC_ENCRYPT_SECLIST, &key)) |
155 |
return TRUE; |
156 |
else |
157 |
gpgme_signers_add (c->ctx, key); |
158 |
} |
159 |
|
160 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_ARMOR)) |
161 |
gpgme_set_armor (ctx, 1); |
162 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_WIPE)) |
163 |
c->wipe = 1; |
164 |
/* XXX: implement this |
165 |
if (IsDlgButtonChecked (dlg, IDC_ENCRYPT_ANON)) |
166 |
; |
167 |
*/ |
168 |
c->cancel = 0; |
169 |
EndDialog (dlg, TRUE); |
170 |
return TRUE; |
171 |
|
172 |
case IDCANCEL: |
173 |
c->cancel = 1; |
174 |
EndDialog (dlg, FALSE); |
175 |
return TRUE; |
176 |
} |
177 |
return TRUE; |
178 |
} |
179 |
|
180 |
return FALSE; |
181 |
} |
182 |
|
183 |
|
184 |
/* Dialog box procedure for importing keys. */ |
185 |
BOOL CALLBACK |
186 |
file_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
187 |
{ |
188 |
static listview_ctrl_t lv = NULL; |
189 |
static fm_state_t c; |
190 |
static int is_revcert = 0, has_seckeys = 0; |
191 |
|
192 |
switch (msg) { |
193 |
case WM_INITDIALOG: |
194 |
c = (fm_state_s *)lparam; |
195 |
if (!c) |
196 |
dlg_fatal_error( dlg, "Could not get dialog param!" ); |
197 |
ShowWindow (GetDlgItem( dlg, IDC_IMPORT_KEYMNGT ), WS_DISABLED); |
198 |
implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
199 |
implist_load (lv, c->import.is_clip? NULL: c->opaque, |
200 |
&is_revcert, &has_seckeys); |
201 |
if (!listview_count_items (lv, 0)) { |
202 |
msg_box (dlg, _("No valid OpenPGP data found."), _("Key Import"), MB_ERR); |
203 |
c->cancel = 1; |
204 |
EndDialog (dlg, FALSE); |
205 |
} |
206 |
else { |
207 |
const char *s = _("%s contain(s) %d key(s)."); |
208 |
char *p = new char[strlen (s) + 32]; |
209 |
if (!p) |
210 |
BUG (NULL); |
211 |
sprintf (p, s, c->import.is_clip? _("Clipboard") : _("File"), |
212 |
listview_count_items (lv, 0)); |
213 |
SetDlgItemText (dlg, IDC_IMPORT_INFO, p); |
214 |
free_if_alloc (p); |
215 |
} |
216 |
SetWindowText (dlg, _("Key Import")); |
217 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
218 |
center_window (dlg, NULL); |
219 |
SetForegroundWindow (dlg); |
220 |
return TRUE; |
221 |
|
222 |
case WM_DESTROY: |
223 |
if (lv) { |
224 |
listview_release (lv); |
225 |
lv = NULL; |
226 |
} |
227 |
return FALSE; |
228 |
|
229 |
case WM_SYSCOMMAND: |
230 |
if (LOWORD (wparam) == SC_CLOSE) { |
231 |
c->cancel = 1; |
232 |
EndDialog (dlg, FALSE); |
233 |
} |
234 |
return FALSE; |
235 |
|
236 |
case WM_COMMAND: |
237 |
switch (LOWORD (wparam)) { |
238 |
case IDC_IMPORT_DOIT: |
239 |
if (has_seckeys > 0) { |
240 |
msg_box (dlg, _("Some of the imported keys are secret keys.\n\n" |
241 |
"The ownertrust values of these keys must be\n" |
242 |
"set manually via the Key Properties dialog."), |
243 |
_("Import"), MB_INFO); |
244 |
} |
245 |
c->cancel = 0; |
246 |
c->import.revcert = is_revcert? 1 : 0; |
247 |
c->import.has_seckey = has_seckeys? 1 : 0; |
248 |
EndDialog (dlg, TRUE); |
249 |
return TRUE; |
250 |
|
251 |
case IDCANCEL: |
252 |
c->cancel = 1; |
253 |
EndDialog (dlg, FALSE); |
254 |
return FALSE; |
255 |
} |
256 |
break; |
257 |
} |
258 |
|
259 |
return FALSE; |
260 |
} |
261 |
|
262 |
|
263 |
/* Dialog box procedure for file signing. */ |
264 |
BOOL CALLBACK |
265 |
file_sign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
266 |
{ |
267 |
static fm_state_t c; |
268 |
static listview_ctrl_t lv; |
269 |
gpg_keycache_t kc, sec_kc; |
270 |
gpgme_key_t key; |
271 |
int lv_idx; |
272 |
char signer[32]; |
273 |
|
274 |
switch (msg) { |
275 |
case WM_INITDIALOG: |
276 |
c = (fm_state_s *)lparam; |
277 |
if (c == NULL) |
278 |
dlg_fatal_error (dlg, "Could not get dialog state!"); |
279 |
SetWindowText (dlg, _("File Sign")); |
280 |
SetDlgItemText (dlg, IDC_FILE_SIG_ARMOR, _("&Text Output") ); |
281 |
SetDlgItemText (dlg, IDC_FILE_SIG_NORMAL, _("&Normal Signature")); |
282 |
SetDlgItemText (dlg, IDC_FILE_SIG_DETACH, _("&Detached Signature")); |
283 |
SetDlgItemText (dlg, IDC_FILE_SIG_CLEAR, _("&Cleartext Signature")); |
284 |
SetDlgItemText (dlg, IDC_FILE_SIG_SIGINF, _("Signature mode")); |
285 |
SetDlgItemText (dlg, IDC_FILE_SIG_OPTINF, _("Options")); |
286 |
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
287 |
CheckDlgButton (dlg, IDC_FILE_SIG_DETACH, BST_CHECKED); |
288 |
kc = keycache_get_ctx (KEYCACHE_PUB); |
289 |
if (!kc) |
290 |
BUG (dlg); |
291 |
sec_kc = keycache_get_ctx (KEYCACHE_PRV); |
292 |
if (!sec_kc) |
293 |
BUG (dlg); |
294 |
lv = keylist_load (GetDlgItem (dlg, IDC_FILE_SIG_LIST), kc, sec_kc, |
295 |
KEYLIST_SIGN, KEY_SORT_USERID); |
296 |
SetForegroundWindow (dlg); |
297 |
return TRUE; |
298 |
|
299 |
case WM_DESTROY: |
300 |
if (lv) { |
301 |
listview_release (lv); |
302 |
lv = NULL; |
303 |
} |
304 |
return FALSE; |
305 |
|
306 |
case WM_SYSCOMMAND: |
307 |
if (LOWORD (wparam) == SC_CLOSE) |
308 |
EndDialog (dlg, TRUE); |
309 |
return FALSE; |
310 |
|
311 |
case WM_COMMAND: |
312 |
switch (LOWORD (wparam)) { |
313 |
case IDOK: |
314 |
if (IsDlgButtonChecked (dlg, IDC_FILE_SIG_ARMOR)) |
315 |
gpgme_set_armor (c->ctx, 1); |
316 |
if (IsDlgButtonChecked (dlg, IDC_FILE_SIG_NORMAL)) |
317 |
c->sigmode = GPGME_SIG_MODE_NORMAL; |
318 |
else if (IsDlgButtonChecked (dlg, IDC_FILE_SIG_DETACH)) |
319 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
320 |
else if (IsDlgButtonChecked( dlg, IDC_FILE_SIG_CLEAR)) |
321 |
c->sigmode = GPGME_SIG_MODE_CLEAR; |
322 |
else { |
323 |
/* default is to produce detached signatures */ |
324 |
c->sigmode = GPGME_SIG_MODE_DETACH; |
325 |
} |
326 |
lv_idx = listview_get_selected_item (lv); |
327 |
if (lv_idx == -1) { |
328 |
if (listview_count_items (lv, 0) == 1) |
329 |
lv_idx = 0; |
330 |
else { |
331 |
msg_box (dlg, _("Please select a key."), _("File Sign"), MB_ERR); |
332 |
return FALSE; |
333 |
} |
334 |
} |
335 |
listview_get_item_text( lv, lv_idx, 1, signer, sizeof signer-1 ); |
336 |
if( get_seckey( signer, &key ) ) |
337 |
BUG( NULL ); |
338 |
gpgme_signers_clear (c->ctx); |
339 |
gpgme_signers_add (c->ctx, key); |
340 |
free_if_alloc (c->opaque); |
341 |
c->opaque = m_strdup (signer); /* store for later use */ |
342 |
c->cancel = 0; |
343 |
if (!c->opaque) |
344 |
BUG (0); |
345 |
EndDialog (dlg, TRUE); |
346 |
return TRUE; |
347 |
|
348 |
case IDCANCEL: |
349 |
c->cancel = 1; |
350 |
EndDialog (dlg, FALSE); |
351 |
return FALSE; |
352 |
} |
353 |
break; |
354 |
} |
355 |
|
356 |
return FALSE; |
357 |
} |
358 |
|
359 |
|
360 |
/* Setup status bar for the main window @dlg. */ |
361 |
static HWND |
362 |
setup_status_bar (HWND dlg) |
363 |
{ |
364 |
HWND statbar; |
365 |
RECT r; |
366 |
int partpos[3]; |
367 |
int i; |
368 |
|
369 |
GetClientRect (dlg, &r); |
370 |
for (i=1; i <= 3; i++) |
371 |
partpos[i-1] = r.right/3*i; |
372 |
|
373 |
statbar = CreateStatusWindow (WS_CHILD | WS_VISIBLE | CCS_BOTTOM, |
374 |
"", dlg, FM_SEPARATOR_ID); |
375 |
ShowWindow (statbar, SW_SHOW); |
376 |
SendMessage (statbar, SB_SETPARTS, (WPARAM)3, (LPARAM)partpos); |
377 |
return statbar; |
378 |
} |
379 |
|
380 |
|
381 |
/* Refresh the status bar text with the selected item from @lv. */ |
382 |
static void |
383 |
update_status_bar (HWND statbar, listview_ctrl_t lv) |
384 |
{ |
385 |
struct stat st; |
386 |
char buf[128]; |
387 |
int n; |
388 |
|
389 |
if (!lv) { /* flush */ |
390 |
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 Byte"); |
391 |
SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)_("0 Objects marked")); |
392 |
return; |
393 |
} |
394 |
n = listview_count_items (lv, 1); |
395 |
_snprintf (buf, sizeof (buf)-1, _("%d Object(s) marked"), n); |
396 |
SendMessage (statbar, SB_SETTEXT, 0, (LPARAM)buf); |
397 |
listview_get_item_text (lv, listview_get_curr_pos (lv), 1, buf, 127); |
398 |
if (stat (buf, &st) == 0) { |
399 |
if (st.st_size < 1024) |
400 |
_snprintf (buf, sizeof (buf)-1, "%d Byte", st.st_size); |
401 |
else if (st.st_size < 1048576) |
402 |
_snprintf (buf, sizeof (buf)-1, "%d KB", st.st_size/1024); |
403 |
else |
404 |
_snprintf (buf, sizeof (buf)-1, "%d MB", st.st_size/1024/1024); |
405 |
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf); |
406 |
} |
407 |
else |
408 |
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 Byte"); |
409 |
} |
410 |
|
411 |
|
412 |
/* Subclass procedure to detect common hotkeys. */ |
413 |
static BOOL CALLBACK |
414 |
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
415 |
{ |
416 |
switch (msg) { |
417 |
case WM_KEYUP: |
418 |
int virt_key = (int)wparam; |
419 |
if (virt_key == VK_DELETE) |
420 |
send_cmd_id (filelist_proc.dlg, ID_FILEMISC_WIPE); |
421 |
break; |
422 |
} |
423 |
return CallWindowProc (filelist_proc.old, dlg, msg, wparam, lparam); |
424 |
} |
425 |
|
426 |
|
427 |
/* Enable or disabled menu entries from the dialog window @hwnd. |
428 |
@lv is used to find out the state of the selected file entry. */ |
429 |
static void |
430 |
update_ui_items (HWND hwnd, listview_ctrl_t lv) |
431 |
{ |
432 |
HMENU hm; |
433 |
int pos; |
434 |
|
435 |
hm = GetMenu (hwnd); |
436 |
|
437 |
pos = listview_get_curr_pos (lv); |
438 |
if (fm_check_file_type (lv, pos, FM_ENCRYPT)) { |
439 |
set_menu_state (hm, ID_FILEMISC_DECRYPT, MF_GRAYED|MF_DISABLED); |
440 |
set_menu_state (hm, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED); |
441 |
} |
442 |
if (fm_check_file_type (lv, pos, FM_DECRYPT)) { |
443 |
set_menu_state (hm, ID_FILEMISC_ENCRYPT, MF_GRAYED|MF_DISABLED); |
444 |
set_menu_state (hm, ID_FILEMISC_SIGN, MF_GRAYED|MF_DISABLED); |
445 |
set_menu_state (hm, ID_FILEMISC_SIGNENC, MF_GRAYED|MF_DISABLED); |
446 |
} |
447 |
if (fm_check_file_type (lv, pos, FM_VERIFY)) { |
448 |
set_menu_state (hm, ID_FILEMISC_VERIFY, MF_ENABLED); |
449 |
set_menu_state (hm, ID_FILEMISC_SIGN, MF_GRAYED|MF_DISABLED); |
450 |
set_menu_state (hm, ID_FILEMISC_SIGNENC, MF_GRAYED|MF_DISABLED); |
451 |
} |
452 |
} |
453 |
|
454 |
|
455 |
/* Dialog box procedure for the File Manager. */ |
456 |
BOOL CALLBACK |
457 |
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
458 |
{ |
459 |
static HWND statbar; |
460 |
static listview_ctrl_t lv = NULL; |
461 |
static HMENU menu = NULL; |
462 |
static int always_ontop = 0; |
463 |
HWND fl; |
464 |
|
465 |
switch (msg) { |
466 |
case WM_INITDIALOG: |
467 |
always_ontop = get_reg_winpt_flag ("AlwaysOnTop"); |
468 |
if (always_ontop == -1) |
469 |
always_ontop = 0; |
470 |
SetWindowText (dlg, _("File Manager (use drag & drop to add files)")); |
471 |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
472 |
set_menu_text_bypos (menu, 0, _("File")); |
473 |
set_menu_text_bypos (menu, 1, _("Edit")); |
474 |
set_menu_text_bypos (menu, 2, _("View")); |
475 |
set_menu_text (menu, ID_FILEMISC_OPEN, _("&Open...") ); |
476 |
set_menu_text (menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
477 |
set_menu_text (menu, ID_FILEMISC_ENCRYPT_ZIP, _("Encrypt into ZIP")); |
478 |
set_menu_text (menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
479 |
set_menu_text (menu, ID_FILEMISC_SIGN, _("&Sign") ); |
480 |
set_menu_text (menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
481 |
set_menu_text (menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
482 |
set_menu_text (menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
483 |
set_menu_text (menu, ID_FILEMISC_IMPORT, _("&Import") ); |
484 |
set_menu_text (menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
485 |
set_menu_text (menu, ID_FILEMISC_QUIT, _("Exit")); |
486 |
set_menu_text (menu, ID_FILEMISC_CLEAR, _("&Reset") ); |
487 |
set_menu_text (menu, ID_FILEMISC_ONTOP, _("Always on Top")); |
488 |
set_menu_text (menu, ID_FILEMISC_PASTE, _("&Paste")); |
489 |
set_menu_text (menu, ID_FILEMISC_SELALL, _("&Select All")); |
490 |
set_menu_text (menu, ID_FILEMISC_PREFS, _("&Preferences")); |
491 |
set_menu_text (menu, ID_FILEMISC_SEND, _("Send as Mail")); |
492 |
set_menu_text (menu, ID_FILEMISC_LIST, _("&List Packets")); |
493 |
set_menu_text (menu, ID_FILEMISC_WIPE_FREES, _("Wipe Free Space")); |
494 |
set_menu_text (menu, ID_FILEMISC_WIPE, _("&Wipe")); |
495 |
|
496 |
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
497 |
filelist_proc.dlg = dlg; |
498 |
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
499 |
filelist_proc.old = (WNDPROC)GetWindowLong (fl, GWL_WNDPROC); |
500 |
if (filelist_proc.old) { |
501 |
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
502 |
msg_box (dlg, "Could not set filelist window procedure.", |
503 |
_("File Manager"), MB_ERR); |
504 |
BUG (NULL); |
505 |
} |
506 |
} |
507 |
SetMenu (dlg, menu); |
508 |
if (!always_ontop) |
509 |
set_menu_state (menu, ID_FILEMISC_ONTOP, MFS_UNCHECKED); |
510 |
else |
511 |
center_window2 (dlg, NULL, HWND_TOPMOST); |
512 |
fm_build (&lv, GetDlgItem (dlg, IDC_FILE_LIST)); |
513 |
center_window (dlg, NULL); |
514 |
SetForegroundWindow (dlg); |
515 |
statbar = setup_status_bar (dlg); |
516 |
filelist_proc.opaque = (void*)statbar; |
517 |
return TRUE; |
518 |
|
519 |
case WM_DESTROY: |
520 |
if (lv) { |
521 |
fm_delete (lv); |
522 |
lv = NULL; |
523 |
} |
524 |
if (menu) { |
525 |
DestroyMenu (menu); |
526 |
menu = NULL; |
527 |
} |
528 |
set_reg_winpt_flag ("AlwaysOnTop", always_ontop); |
529 |
return FALSE; |
530 |
|
531 |
case WM_DROPFILES: |
532 |
fm_add_dropped_files (lv, (HDROP)wparam); |
533 |
return TRUE; |
534 |
|
535 |
case WM_NOTIFY: |
536 |
NMHDR *notify; |
537 |
int pos; |
538 |
HMENU hm; |
539 |
|
540 |
notify = (NMHDR *)lparam; |
541 |
if (notify && notify->code == NM_CLICK && |
542 |
notify->idFrom == IDC_FILE_LIST) |
543 |
update_status_bar (statbar, lv); |
544 |
if (notify && notify->code == NM_RCLICK |
545 |
&& notify->idFrom == IDC_FILE_LIST) { |
546 |
POINT p; |
547 |
HMENU popup; |
548 |
|
549 |
GetCursorPos (&p); |
550 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_FILEMISC_CTX)); |
551 |
popup = GetSubMenu (hm, 0); |
552 |
set_menu_text (popup, ID_FILECTX_ENCRYPT_ZIP, _("Encrypt into ZIP")); |
553 |
set_menu_text (popup, ID_FILECTX_ENCRYPT, _("Encrypt")); |
554 |
set_menu_text (popup, ID_FILECTX_DECRYPT, _("Decrypt")); |
555 |
set_menu_text (popup, ID_FILECTX_SIGN, _("Sign")); |
556 |
set_menu_text (popup, ID_FILECTX_SIGNENC, _("Sign && Encrypt")); |
557 |
set_menu_text (popup, ID_FILECTX_VERIFY, _("Verify")); |
558 |
set_menu_text (popup, ID_FILECTX_WIPE, _("Wipe")); |
559 |
set_menu_text (popup, ID_FILECTX_SEND, _("Send as Mail")); |
560 |
set_menu_text (popup, ID_FILECTX_LIST, _("List Packets")); |
561 |
pos = listview_get_curr_pos (lv); |
562 |
if (fm_check_file_type (lv, pos, FM_DECRYPT)) |
563 |
set_menu_state (popup, ID_FILECTX_SEND, MF_ENABLED); |
564 |
if (fm_check_file_type (lv, pos, FM_ENCRYPT)) { |
565 |
set_menu_state (popup, ID_FILECTX_DECRYPT, MF_GRAYED|MF_DISABLED); |
566 |
set_menu_state (popup, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED); |
567 |
} |
568 |
if (fm_check_file_type (lv, pos, FM_DECRYPT)) { |
569 |
set_menu_state (popup, ID_FILECTX_ENCRYPT_ZIP, MF_GRAYED|MF_DISABLED); |
570 |
set_menu_state (popup, ID_FILECTX_ENCRYPT, MF_GRAYED|MF_DISABLED); |
571 |
set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED); |
572 |
set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED); |
573 |
} |
574 |
if (fm_check_file_type (lv, pos, FM_VERIFY)) { |
575 |
set_menu_state (popup, ID_FILECTX_VERIFY, MF_ENABLED); |
576 |
set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED); |
577 |
set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED); |
578 |
} |
579 |
|
580 |
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
581 |
DestroyMenu (popup); |
582 |
DestroyMenu (hm); |
583 |
} |
584 |
if (notify && notify->code == NM_CLICK |
585 |
&& notify->idFrom == IDC_FILE_LIST) { |
586 |
hm = GetMenu (dlg); |
587 |
pos = listview_get_curr_pos (lv); |
588 |
if (!fm_check_file_type (lv, pos, FM_DECRYPT)) |
589 |
set_menu_state (hm, ID_FILEMISC_SEND, MF_GRAYED|MF_DISABLED); |
590 |
else |
591 |
set_menu_state (hm, ID_FILEMISC_SEND, MF_ENABLED); |
592 |
} |
593 |
if (notify && notify->code == LVN_ITEMCHANGED && |
594 |
((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */ |
595 |
update_ui_items (dlg, lv); |
596 |
return TRUE; |
597 |
|
598 |
case WM_SYSCOMMAND: |
599 |
if (LOWORD (wparam) == SC_CLOSE) |
600 |
EndDialog (dlg, TRUE); |
601 |
return FALSE; |
602 |
|
603 |
case WM_INITMENUPOPUP: |
604 |
if ((UINT)LOWORD (lparam) == 0 && |
605 |
GetMenuItemCount ((HMENU)wparam) == 19) /* XXX: do not hard code values */ |
606 |
set_menu_text_bypos ((HMENU)wparam, 2, _("&Calc Digest")); |
607 |
return FALSE; |
608 |
|
609 |
case WM_COMMAND: |
610 |
switch (LOWORD (wparam)) { |
611 |
case IDCANCEL: |
612 |
EndDialog (dlg, FALSE); |
613 |
return TRUE; |
614 |
|
615 |
case ID_FILEMISC_QUIT: |
616 |
EndDialog (dlg, TRUE); |
617 |
return TRUE; |
618 |
|
619 |
case ID_FILEMISC_WIPE_FREES: |
620 |
if (!admin_user) { |
621 |
msg_box (dlg, _("This command requires admin privileges.\n"), |
622 |
_("File Manager"), MB_ERR); |
623 |
break; |
624 |
} |
625 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL, |
626 |
dlg, space_wipefrees_dlg_proc, 0); |
627 |
break; |
628 |
|
629 |
case ID_FILEMISC_SELALL: |
630 |
listview_select_all (lv); |
631 |
break; |
632 |
|
633 |
case ID_FILEMISC_PASTE: |
634 |
fm_verify_pasted_detsig (lv, dlg); |
635 |
break; |
636 |
|
637 |
case ID_FILEMISC_ONTOP: |
638 |
always_ontop ^= 1; |
639 |
set_menu_state (menu, ID_FILEMISC_ONTOP, |
640 |
always_ontop == 0? MFS_UNCHECKED : MFS_CHECKED); |
641 |
center_window2 (dlg, NULL, |
642 |
always_ontop == 0? HWND_NOTOPMOST : HWND_TOPMOST); |
643 |
break; |
644 |
|
645 |
case ID_FILEMISC_SEND: |
646 |
fm_send_file (lv); |
647 |
break; |
648 |
|
649 |
case ID_FILEMISC_PREFS: |
650 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_FILE_PREFS, dlg, |
651 |
file_preferences_dlg_proc, 0); |
652 |
break; |
653 |
|
654 |
case ID_FILEMISC_LIST: |
655 |
case ID_FILEMISC_ENCRYPT: |
656 |
case ID_FILEMISC_SYMENC: |
657 |
case ID_FILEMISC_DECRYPT: |
658 |
case ID_FILEMISC_SIGN: |
659 |
case ID_FILEMISC_SIGNENC: |
660 |
case ID_FILEMISC_VERIFY: |
661 |
case ID_FILEMISC_WIPE: |
662 |
case ID_FILEMISC_ENCRYPT_ZIP: |
663 |
fm_parse_files (lv, dlg, LOWORD (wparam)); |
664 |
SetForegroundWindow (dlg); |
665 |
return TRUE; |
666 |
|
667 |
case ID_FILEMISC_MD_MD5: |
668 |
case ID_FILEMISC_MD_SHA1: |
669 |
case ID_FILEMISC_MD_RMD160: |
670 |
case ID_FILEMISC_MD_SHA256: |
671 |
int algo; |
672 |
|
673 |
switch (LOWORD (wparam)) { |
674 |
case ID_FILEMISC_MD_MD5: algo = GPGME_MD_MD5; break; |
675 |
case ID_FILEMISC_MD_SHA1: algo = GPGME_MD_SHA1; break; |
676 |
case ID_FILEMISC_MD_RMD160: algo = GPGME_MD_RMD160; break; |
677 |
case ID_FILEMISC_MD_SHA256: algo = GPGME_MD_SHA256; break; |
678 |
default: algo = GPGME_MD_SHA1; break; |
679 |
} |
680 |
fm_print_md (lv, dlg, algo); |
681 |
SetForegroundWindow (dlg); |
682 |
return TRUE; |
683 |
|
684 |
case ID_FILEMISC_CLEAR: |
685 |
listview_del_all_items (lv); |
686 |
return TRUE; |
687 |
|
688 |
case ID_FILEMISC_OPEN: |
689 |
fm_add_opened_files( lv, dlg ); |
690 |
return TRUE; |
691 |
|
692 |
/* context menu entries */ |
693 |
case ID_FILECTX_ENCRYPT: send_cmd_id (dlg, ID_FILEMISC_ENCRYPT); break; |
694 |
case ID_FILECTX_DECRYPT: send_cmd_id (dlg, ID_FILEMISC_DECRYPT);break; |
695 |
case ID_FILECTX_SIGN: send_cmd_id (dlg, ID_FILEMISC_SIGN); break; |
696 |
case ID_FILECTX_SIGNENC: send_cmd_id (dlg, ID_FILEMISC_SIGNENC);break; |
697 |
case ID_FILECTX_VERIFY: send_cmd_id (dlg, ID_FILEMISC_VERIFY); break; |
698 |
case ID_FILECTX_WIPE: send_cmd_id (dlg, ID_FILEMISC_WIPE); break; |
699 |
case ID_FILECTX_LIST: send_cmd_id (dlg, ID_FILEMISC_LIST); break; |
700 |
case ID_FILECTX_SEND: send_cmd_id (dlg, ID_FILEMISC_SEND); break; |
701 |
case ID_FILECTX_ENCRYPT_ZIP:send_cmd_id (dlg, ID_FILEMISC_ENCRYPT_ZIP); break; |
702 |
} |
703 |
break; |
704 |
} |
705 |
|
706 |
return FALSE; |
707 |
} |
708 |
|
709 |
|
710 |
/* Dialog box procedure for the FM preferences. */ |
711 |
BOOL CALLBACK |
712 |
file_preferences_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
713 |
{ |
714 |
switch (msg) { |
715 |
case WM_INITDIALOG: |
716 |
CheckDlgButton (dlg, IDC_FPREFS_PROGRESS, |
717 |
reg_prefs.fm.progress? BST_CHECKED : BST_UNCHECKED); |
718 |
SetForegroundWindow (dlg); |
719 |
center_window (dlg, NULL); |
720 |
break; |
721 |
|
722 |
case WM_COMMAND: |
723 |
switch (LOWORD (wparam)) { |
724 |
case IDOK: |
725 |
reg_prefs.fm.progress = IsDlgButtonChecked (dlg, IDC_FPREFS_PROGRESS)? 1 : 0; |
726 |
set_reg_winpt_prefs (®_prefs); |
727 |
EndDialog (dlg, TRUE); |
728 |
break; |
729 |
|
730 |
case IDCANCEL: |
731 |
EndDialog (dlg, FALSE); |
732 |
break; |
733 |
} |
734 |
break; |
735 |
} |
736 |
|
737 |
return FALSE; |
738 |
} |
739 |
|
740 |
|
741 |
/* Add the selected items from @lv into the combo box. */ |
742 |
static void |
743 |
add_files_from_lv (HWND dlg, listview_ctrl_t lv) |
744 |
{ |
745 |
char fname[384+1]; |
746 |
int i; |
747 |
|
748 |
for (i = 0; i < listview_count_items (lv, 0); i++) { |
749 |
if (!listview_get_item_state (lv, i)) |
750 |
continue; |
751 |
listview_get_item_text (lv, i, 1, fname, sizeof (fname)-1); |
752 |
SendDlgItemMessage (dlg, IDC_SECDEL_FILES, LB_ADDSTRING, |
753 |
0, (WPARAM)(char *)fname); |
754 |
} |
755 |
} |
756 |
|
757 |
|
758 |
/* Dialog box procedure to confirm that files shall be deleted. */ |
759 |
BOOL CALLBACK |
760 |
file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
761 |
{ |
762 |
static secdel_confirm_s * ctx; |
763 |
|
764 |
switch (msg) { |
765 |
case WM_INITDIALOG: |
766 |
ctx = (struct secdel_confirm_s *)lparam; |
767 |
if (!ctx) |
768 |
BUG (NULL); |
769 |
add_files_from_lv (dlg, ctx->lv_files); |
770 |
SetWindowText (dlg, _("Are you sure you want to secure delete these files?")); |
771 |
SetDlgItemText (dlg, IDYES, _("&Yes")); |
772 |
SetDlgItemText (dlg, IDNO, _("&No")); |
773 |
break; |
774 |
|
775 |
case WM_COMMAND: |
776 |
switch (LOWORD (wparam)) { |
777 |
case IDYES: |
778 |
ctx->yes = 1; |
779 |
EndDialog (dlg, TRUE); |
780 |
break; |
781 |
|
782 |
case IDNO: |
783 |
ctx->yes = 0; |
784 |
EndDialog (dlg, FALSE); |
785 |
break; |
786 |
} |
787 |
break; |
788 |
} |
789 |
|
790 |
return FALSE; |
791 |
} |
792 |
|
793 |
|
794 |
/* Wipe callback. @ctx is a window handle @off is the current offset |
795 |
and @n is the total size. */ |
796 |
static void |
797 |
wipe_cb (void *ctx, ui64 off, ui64 n) |
798 |
{ |
799 |
SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS, |
800 |
(WPARAM) (off*100/n), 0); |
801 |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE); |
802 |
SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE); |
803 |
} |
804 |
|
805 |
|
806 |
/* Call the wipe free space method asynchron. */ |
807 |
static DWORD WINAPI |
808 |
wipe_thread (void *ctx) |
809 |
{ |
810 |
thread_ctx_t a = (thread_ctx_t)ctx; |
811 |
int rc; |
812 |
|
813 |
rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg); |
814 |
SetDlgItemText (a->dlg, IDC_SPACE_INFO, |
815 |
rc? _("Operation Status: Error") : |
816 |
_("Operation Status: Done.")); |
817 |
if (rc) |
818 |
msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR); |
819 |
else |
820 |
MessageBeep (MB_OK); |
821 |
ExitThread (0); |
822 |
return 0; |
823 |
} |
824 |
|
825 |
|
826 |
static void |
827 |
fill_drive_combobox (HWND dlg) |
828 |
{ |
829 |
char buf[384], p[16]; |
830 |
int n, i, j = 0; |
831 |
|
832 |
n = GetLogicalDriveStrings (DIM (buf)-1, buf); |
833 |
while (j < n) { |
834 |
for (i = 0; buf[j] != '\0'; i++, j++) |
835 |
p[i] = buf[j]; |
836 |
p[i] = '\0'; |
837 |
j++; |
838 |
if (GetDriveType (p) != DRIVE_CDROM) |
839 |
SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_ADDSTRING, |
840 |
0, (LPARAM)(const char *)p); |
841 |
} |
842 |
SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_SETCURSEL, 0, 0); |
843 |
} /* fill_drive_combobox */ |
844 |
|
845 |
|
846 |
static void |
847 |
update_disc_stats (HWND dlg) |
848 |
{ |
849 |
ULARGE_INTEGER caller = {0}, total = {0}, free = {0}; |
850 |
char buf[128], drive[32], a_total[64] = {0}, a_free[64] = {0}; |
851 |
int idx; |
852 |
|
853 |
idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0); |
854 |
GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1); |
855 |
if (GetDiskFreeSpaceEx (drive, &caller, &total, &free)) { |
856 |
_ui64toa (total.QuadPart/1024, a_total, 10); |
857 |
_ui64toa (free.QuadPart/1024, a_free, 10); |
858 |
} |
859 |
_snprintf (buf, DIM (buf)-1, _("Total Capacity: %12sk\n" |
860 |
"Free Space : %12sk"), a_total, a_free); |
861 |
SetDlgItemText(dlg, IDC_SPACE_DISC_INFO, buf); |
862 |
SetDlgItemInt (dlg, IDC_SPACE_OFF, 0, FALSE); |
863 |
SetDlgItemInt (dlg, IDC_SPACE_N, 0, FALSE); |
864 |
} /* update_disc_stats */ |
865 |
|
866 |
|
867 |
BOOL CALLBACK |
868 |
space_wipefrees_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
869 |
{ |
870 |
static HANDLE thread_hd = NULL; |
871 |
static thread_ctx_s ctx; |
872 |
char drive[32], * p; |
873 |
int idx; |
874 |
DWORD tid; |
875 |
|
876 |
switch (msg) { |
877 |
case WM_INITDIALOG: |
878 |
fill_drive_combobox (dlg); |
879 |
update_disc_stats (dlg); |
880 |
center_window (dlg, NULL); |
881 |
SetForegroundWindow (dlg); |
882 |
break; |
883 |
|
884 |
case WM_DESTROY: |
885 |
thread_hd = NULL; |
886 |
free_if_alloc (ctx.drive); |
887 |
memset (&ctx, 0, sizeof ctx); |
888 |
break; |
889 |
|
890 |
case WM_COMMAND: |
891 |
if (HIWORD (wparam) == CBN_SELCHANGE) |
892 |
update_disc_stats (dlg); |
893 |
switch (LOWORD (wparam)) { |
894 |
case IDOK: |
895 |
idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0); |
896 |
if (idx != CB_ERR && !thread_hd) { |
897 |
GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1); |
898 |
ctx.dlg = dlg; |
899 |
ctx.drive = m_strdup (drive); |
900 |
ctx.fd = NULL; |
901 |
thread_hd = CreateThread (NULL, 0, wipe_thread, &ctx, 0, &tid); |
902 |
} |
903 |
if (WaitForSingleObject (thread_hd, 0) == WAIT_OBJECT_0) { |
904 |
CloseHandle (thread_hd); |
905 |
thread_hd = NULL; |
906 |
EndDialog (dlg, TRUE); |
907 |
} |
908 |
break; |
909 |
|
910 |
case IDCANCEL: |
911 |
if (thread_hd) { |
912 |
WaitForSingleObject (thread_hd, 2000); |
913 |
TerminateThread (thread_hd, 1); |
914 |
CloseHandle (thread_hd); |
915 |
CloseHandle (ctx.fd); |
916 |
p = make_filename (ctx.drive, "temp_winpt.tmp", NULL); |
917 |
if (p && !file_exist_check (p)) |
918 |
remove (p); |
919 |
free_if_alloc (p); |
920 |
} |
921 |
EndDialog( dlg, FALSE ); |
922 |
break; |
923 |
} |
924 |
break; |
925 |
} |
926 |
|
927 |
return FALSE; |
928 |
} /* space_wipefrees_dlg_proc */ |