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