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