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