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