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