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 |
|
|
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 KB"); |
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 |
|
|
_snprintf (buf, sizeof (buf)-1, "%d KB", st.st_size/1024); |
400 |
|
|
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)buf); |
401 |
|
|
} |
402 |
|
|
else |
403 |
|
|
SendMessage (statbar, SB_SETTEXT, 1, (LPARAM)"0 KB"); |
404 |
|
|
} |
405 |
|
|
|
406 |
|
|
|
407 |
twoaday |
105 |
/* Subclass procedure to detect common hotkeys. */ |
408 |
werner |
36 |
static BOOL CALLBACK |
409 |
|
|
filelist_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
410 |
|
|
{ |
411 |
|
|
switch (msg) { |
412 |
|
|
case WM_KEYUP: |
413 |
|
|
int virt_key = (int)wparam; |
414 |
|
|
if (virt_key == VK_DELETE) |
415 |
|
|
send_cmd_id (filelist_proc.dlg, ID_FILEMISC_WIPE); |
416 |
|
|
break; |
417 |
|
|
} |
418 |
|
|
return CallWindowProc (filelist_proc.old, dlg, msg, wparam, lparam); |
419 |
|
|
} |
420 |
|
|
|
421 |
|
|
|
422 |
twoaday |
88 |
/* Enable or disabled menu entries from the dialog window @hwnd. |
423 |
|
|
@lv is used to find out the state of the selected file entry. */ |
424 |
|
|
static void |
425 |
|
|
update_ui_items (HWND hwnd, listview_ctrl_t lv) |
426 |
|
|
{ |
427 |
|
|
HMENU hm; |
428 |
|
|
int pos; |
429 |
|
|
|
430 |
|
|
hm = GetMenu (hwnd); |
431 |
|
|
|
432 |
|
|
pos = listview_get_curr_pos (lv); |
433 |
|
|
if (fm_check_file_type (lv, pos, FM_ENCRYPT)) { |
434 |
|
|
set_menu_state (hm, ID_FILEMISC_DECRYPT, MF_GRAYED|MF_DISABLED); |
435 |
|
|
set_menu_state (hm, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED); |
436 |
|
|
} |
437 |
|
|
if (fm_check_file_type (lv, pos, FM_DECRYPT)) { |
438 |
|
|
set_menu_state (hm, ID_FILEMISC_ENCRYPT, MF_GRAYED|MF_DISABLED); |
439 |
|
|
set_menu_state (hm, ID_FILEMISC_SIGN, MF_GRAYED|MF_DISABLED); |
440 |
|
|
set_menu_state (hm, ID_FILEMISC_SIGNENC, MF_GRAYED|MF_DISABLED); |
441 |
|
|
} |
442 |
|
|
if (fm_check_file_type (lv, pos, FM_VERIFY)) { |
443 |
|
|
set_menu_state (hm, ID_FILEMISC_VERIFY, MF_ENABLED); |
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 |
|
|
} |
448 |
|
|
|
449 |
|
|
|
450 |
twoaday |
105 |
/* Dialog box procedure for the File Manager. */ |
451 |
werner |
36 |
BOOL CALLBACK |
452 |
|
|
file_manager_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
453 |
|
|
{ |
454 |
|
|
static HWND statbar; |
455 |
|
|
static listview_ctrl_t lv = NULL; |
456 |
|
|
static HMENU menu = NULL; |
457 |
twoaday |
85 |
static int always_ontop = 0; |
458 |
werner |
36 |
HWND fl; |
459 |
|
|
|
460 |
|
|
switch (msg) { |
461 |
|
|
case WM_INITDIALOG: |
462 |
twoaday |
85 |
always_ontop = get_reg_winpt_flag ("AlwaysOnTop"); |
463 |
|
|
if (always_ontop == -1) |
464 |
|
|
always_ontop = 0; |
465 |
|
|
SetWindowText (dlg, _("File Manager (use drag & drop to add files)")); |
466 |
werner |
36 |
menu = LoadMenu (glob_hinst, (LPCSTR)IDR_WINPT_FILEMISC); |
467 |
twoaday |
85 |
set_menu_text_bypos (menu, 0, _("File")); |
468 |
|
|
set_menu_text_bypos (menu, 1, _("Edit")); |
469 |
|
|
set_menu_text_bypos (menu, 2, _("View")); |
470 |
werner |
36 |
set_menu_text (menu, ID_FILEMISC_OPEN, _("&Open...") ); |
471 |
|
|
set_menu_text (menu, ID_FILEMISC_ENCRYPT, _("&Encrypt") ); |
472 |
twoaday |
88 |
set_menu_text (menu, ID_FILEMISC_ENCRYPT_ZIP, _("Encrypt into ZIP")); |
473 |
werner |
36 |
set_menu_text (menu, ID_FILEMISC_DECRYPT, _("&Decrypt") ); |
474 |
|
|
set_menu_text (menu, ID_FILEMISC_SIGN, _("&Sign") ); |
475 |
|
|
set_menu_text (menu, ID_FILEMISC_SIGNENC, _("Sign && Encrypt") ); |
476 |
|
|
set_menu_text (menu, ID_FILEMISC_VERIFY, _("&Verify") ); |
477 |
|
|
set_menu_text (menu, ID_FILEMISC_SYMENC, _("S&ymmetric") ); |
478 |
|
|
set_menu_text (menu, ID_FILEMISC_IMPORT, _("&Import") ); |
479 |
|
|
set_menu_text (menu, ID_FILEMISC_EXPORT, _("E&xport") ); |
480 |
|
|
set_menu_text (menu, ID_FILEMISC_QUIT, _("Exit")); |
481 |
|
|
set_menu_text (menu, ID_FILEMISC_CLEAR, _("&Reset") ); |
482 |
|
|
set_menu_text (menu, ID_FILEMISC_ONTOP, _("Always on Top")); |
483 |
|
|
set_menu_text (menu, ID_FILEMISC_PASTE, _("&Paste")); |
484 |
|
|
set_menu_text (menu, ID_FILEMISC_SELALL, _("&Select All")); |
485 |
|
|
set_menu_text (menu, ID_FILEMISC_PREFS, _("&Preferences")); |
486 |
|
|
set_menu_text (menu, ID_FILEMISC_SEND, _("Send as Mail")); |
487 |
|
|
set_menu_text (menu, ID_FILEMISC_LIST, _("&List Packets")); |
488 |
|
|
set_menu_text (menu, ID_FILEMISC_WIPE_FREES, _("Wipe Free Space")); |
489 |
|
|
set_menu_text (menu, ID_FILEMISC_WIPE, _("&Wipe")); |
490 |
|
|
|
491 |
|
|
fl = GetDlgItem (dlg, IDC_FILE_LIST); |
492 |
|
|
filelist_proc.dlg = dlg; |
493 |
|
|
filelist_proc.current = (WNDPROC)filelist_subclass_proc; |
494 |
|
|
filelist_proc.old = (WNDPROC)GetWindowLong (fl, GWL_WNDPROC); |
495 |
|
|
if (filelist_proc.old) { |
496 |
|
|
if (!SetWindowLong (fl, GWL_WNDPROC, (LONG)filelist_proc.current)) { |
497 |
twoaday |
141 |
msg_box (dlg, "Could not set filelist window procedure.", |
498 |
twoaday |
105 |
_("File Manager"), MB_ERR); |
499 |
werner |
36 |
BUG (NULL); |
500 |
|
|
} |
501 |
|
|
} |
502 |
|
|
SetMenu (dlg, menu); |
503 |
twoaday |
85 |
if (!always_ontop) |
504 |
|
|
set_menu_state (menu, ID_FILEMISC_ONTOP, MFS_UNCHECKED); |
505 |
werner |
36 |
fm_build (&lv, GetDlgItem (dlg, IDC_FILE_LIST)); |
506 |
|
|
center_window2 (dlg, NULL, HWND_TOPMOST); |
507 |
|
|
center_window (dlg, NULL); |
508 |
|
|
SetForegroundWindow (dlg); |
509 |
|
|
statbar = setup_status_bar (dlg); |
510 |
|
|
filelist_proc.opaque = (void*)statbar; |
511 |
|
|
return TRUE; |
512 |
|
|
|
513 |
|
|
case WM_DESTROY: |
514 |
|
|
if (lv) { |
515 |
|
|
fm_delete (lv); |
516 |
|
|
lv = NULL; |
517 |
|
|
} |
518 |
|
|
if (menu) { |
519 |
|
|
DestroyMenu (menu); |
520 |
|
|
menu = NULL; |
521 |
|
|
} |
522 |
twoaday |
85 |
set_reg_winpt_flag ("AlwaysOnTop", always_ontop); |
523 |
werner |
36 |
return FALSE; |
524 |
|
|
|
525 |
|
|
case WM_DROPFILES: |
526 |
|
|
fm_add_dropped_files (lv, (HDROP)wparam); |
527 |
|
|
return TRUE; |
528 |
|
|
|
529 |
|
|
case WM_NOTIFY: |
530 |
|
|
NMHDR *notify; |
531 |
|
|
int pos; |
532 |
|
|
HMENU hm; |
533 |
|
|
|
534 |
|
|
notify = (NMHDR *)lparam; |
535 |
|
|
if (notify && notify->code == NM_CLICK && |
536 |
|
|
notify->idFrom == IDC_FILE_LIST) |
537 |
|
|
update_status_bar (statbar, lv); |
538 |
|
|
if (notify && notify->code == NM_RCLICK |
539 |
|
|
&& notify->idFrom == IDC_FILE_LIST) { |
540 |
|
|
POINT p; |
541 |
|
|
HMENU popup; |
542 |
|
|
|
543 |
|
|
GetCursorPos (&p); |
544 |
|
|
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_FILEMISC_CTX)); |
545 |
|
|
popup = GetSubMenu (hm, 0); |
546 |
twoaday |
88 |
set_menu_text (popup, ID_FILECTX_ENCRYPT_ZIP, _("Encrypt into ZIP")); |
547 |
werner |
36 |
set_menu_text (popup, ID_FILECTX_ENCRYPT, _("Encrypt")); |
548 |
|
|
set_menu_text (popup, ID_FILECTX_DECRYPT, _("Decrypt")); |
549 |
|
|
set_menu_text (popup, ID_FILECTX_SIGN, _("Sign")); |
550 |
|
|
set_menu_text (popup, ID_FILECTX_SIGNENC, _("Sign && Encrypt")); |
551 |
|
|
set_menu_text (popup, ID_FILECTX_VERIFY, _("Verify")); |
552 |
|
|
set_menu_text (popup, ID_FILECTX_WIPE, _("Wipe")); |
553 |
|
|
set_menu_text (popup, ID_FILECTX_SEND, _("Send as Mail")); |
554 |
twoaday |
88 |
set_menu_text (popup, ID_FILECTX_LIST, _("List Packets")); |
555 |
werner |
36 |
pos = listview_get_curr_pos (lv); |
556 |
|
|
if (fm_check_file_type (lv, pos, FM_DECRYPT)) |
557 |
|
|
set_menu_state (popup, ID_FILECTX_SEND, MF_ENABLED); |
558 |
|
|
if (fm_check_file_type (lv, pos, FM_ENCRYPT)) { |
559 |
|
|
set_menu_state (popup, ID_FILECTX_DECRYPT, MF_GRAYED|MF_DISABLED); |
560 |
|
|
set_menu_state (popup, ID_FILECTX_VERIFY, MF_GRAYED|MF_DISABLED); |
561 |
|
|
} |
562 |
|
|
if (fm_check_file_type (lv, pos, FM_DECRYPT)) { |
563 |
|
|
set_menu_state (popup, ID_FILECTX_ENCRYPT, MF_GRAYED|MF_DISABLED); |
564 |
|
|
set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED); |
565 |
|
|
set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED); |
566 |
|
|
} |
567 |
|
|
if (fm_check_file_type (lv, pos, FM_VERIFY)) { |
568 |
|
|
set_menu_state (popup, ID_FILECTX_VERIFY, MF_ENABLED); |
569 |
|
|
set_menu_state (popup, ID_FILECTX_SIGN, MF_GRAYED|MF_DISABLED); |
570 |
|
|
set_menu_state (popup, ID_FILECTX_SIGNENC, MF_GRAYED|MF_DISABLED); |
571 |
|
|
} |
572 |
|
|
|
573 |
twoaday |
88 |
TrackPopupMenu (popup, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
574 |
werner |
36 |
DestroyMenu (popup); |
575 |
|
|
DestroyMenu (hm); |
576 |
|
|
} |
577 |
|
|
if (notify && notify->code == NM_CLICK |
578 |
|
|
&& notify->idFrom == IDC_FILE_LIST) { |
579 |
|
|
hm = GetMenu (dlg); |
580 |
|
|
pos = listview_get_curr_pos (lv); |
581 |
|
|
if (!fm_check_file_type (lv, pos, FM_DECRYPT)) |
582 |
|
|
set_menu_state (hm, ID_FILEMISC_SEND, MF_GRAYED|MF_DISABLED); |
583 |
|
|
else |
584 |
|
|
set_menu_state (hm, ID_FILEMISC_SEND, MF_ENABLED); |
585 |
|
|
} |
586 |
twoaday |
88 |
if (notify && notify->code == LVN_ITEMCHANGED && |
587 |
|
|
((LPNMLISTVIEW)lparam)->uNewState) /* item selected? */ |
588 |
|
|
update_ui_items (dlg, lv); |
589 |
werner |
36 |
return TRUE; |
590 |
|
|
|
591 |
|
|
case WM_SYSCOMMAND: |
592 |
twoaday |
88 |
if (LOWORD (wparam) == SC_CLOSE) |
593 |
|
|
EndDialog (dlg, TRUE); |
594 |
werner |
36 |
return FALSE; |
595 |
|
|
|
596 |
twoaday |
88 |
case WM_INITMENUPOPUP: |
597 |
|
|
if ((UINT)LOWORD (lparam) == 0 && |
598 |
|
|
GetMenuItemCount ((HMENU)wparam) == 19) /* XXX: do not hard code values */ |
599 |
|
|
set_menu_text_bypos ((HMENU)wparam, 2, _("&Calc Digest")); |
600 |
werner |
36 |
return FALSE; |
601 |
|
|
|
602 |
|
|
case WM_COMMAND: |
603 |
|
|
switch( LOWORD( wparam ) ) { |
604 |
|
|
case ID_FILEMISC_QUIT: |
605 |
|
|
EndDialog (dlg, TRUE); |
606 |
|
|
return TRUE; |
607 |
|
|
|
608 |
|
|
case ID_FILEMISC_WIPE_FREES: |
609 |
twoaday |
105 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SPACE_SECDEL, |
610 |
|
|
dlg, space_wipefrees_dlg_proc, 0); |
611 |
werner |
36 |
break; |
612 |
|
|
|
613 |
|
|
case ID_FILEMISC_SELALL: |
614 |
|
|
listview_select_all (lv); |
615 |
|
|
break; |
616 |
|
|
|
617 |
|
|
case ID_FILEMISC_PASTE: |
618 |
|
|
fm_verify_pasted_detsig (lv, dlg); |
619 |
|
|
break; |
620 |
|
|
|
621 |
|
|
case ID_FILEMISC_ONTOP: |
622 |
|
|
always_ontop ^= 1; |
623 |
|
|
set_menu_state (menu, ID_FILEMISC_ONTOP, |
624 |
|
|
always_ontop == 0? MFS_UNCHECKED : MFS_CHECKED); |
625 |
twoaday |
105 |
center_window2 (dlg, NULL, |
626 |
|
|
always_ontop == 0? HWND_NOTOPMOST : HWND_TOPMOST); |
627 |
werner |
36 |
break; |
628 |
|
|
|
629 |
|
|
case ID_FILEMISC_SEND: |
630 |
|
|
fm_send_file (lv); |
631 |
|
|
break; |
632 |
|
|
|
633 |
|
|
case ID_FILEMISC_PREFS: |
634 |
|
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_FILE_PREFS, dlg, |
635 |
twoaday |
65 |
file_preferences_dlg_proc, 0); |
636 |
werner |
36 |
break; |
637 |
|
|
|
638 |
|
|
case ID_FILEMISC_LIST: |
639 |
|
|
case ID_FILEMISC_ENCRYPT: |
640 |
|
|
case ID_FILEMISC_SYMENC: |
641 |
|
|
case ID_FILEMISC_DECRYPT: |
642 |
|
|
case ID_FILEMISC_SIGN: |
643 |
|
|
case ID_FILEMISC_SIGNENC: |
644 |
|
|
case ID_FILEMISC_VERIFY: |
645 |
|
|
case ID_FILEMISC_WIPE: |
646 |
twoaday |
77 |
case ID_FILEMISC_ENCRYPT_ZIP: |
647 |
werner |
36 |
fm_parse_files (lv, dlg, LOWORD (wparam)); |
648 |
|
|
SetForegroundWindow (dlg); |
649 |
|
|
return TRUE; |
650 |
|
|
|
651 |
|
|
case ID_FILEMISC_MD_MD5: |
652 |
|
|
case ID_FILEMISC_MD_SHA1: |
653 |
|
|
case ID_FILEMISC_MD_RMD160: |
654 |
|
|
case ID_FILEMISC_MD_SHA256: |
655 |
|
|
int algo; |
656 |
|
|
|
657 |
|
|
switch (LOWORD (wparam)) { |
658 |
twoaday |
105 |
case ID_FILEMISC_MD_MD5: algo = GPGME_MD_MD5; break; |
659 |
|
|
case ID_FILEMISC_MD_SHA1: algo = GPGME_MD_SHA1; break; |
660 |
werner |
36 |
case ID_FILEMISC_MD_RMD160: algo = GPGME_MD_RMD160; break; |
661 |
twoaday |
105 |
case ID_FILEMISC_MD_SHA256: algo = GPGME_MD_SHA256; break; |
662 |
|
|
default: algo = GPGME_MD_SHA1; break; |
663 |
werner |
36 |
} |
664 |
|
|
fm_print_md (lv, dlg, algo); |
665 |
|
|
SetForegroundWindow (dlg); |
666 |
|
|
return TRUE; |
667 |
|
|
|
668 |
|
|
case ID_FILEMISC_CLEAR: |
669 |
twoaday |
150 |
listview_del_all_items (lv); |
670 |
werner |
36 |
return TRUE; |
671 |
|
|
|
672 |
|
|
case ID_FILEMISC_OPEN: |
673 |
|
|
fm_add_opened_files( lv, dlg ); |
674 |
|
|
return TRUE; |
675 |
|
|
|
676 |
|
|
/* context menu entries */ |
677 |
twoaday |
105 |
case ID_FILECTX_ENCRYPT: send_cmd_id (dlg, ID_FILEMISC_ENCRYPT); break; |
678 |
|
|
case ID_FILECTX_DECRYPT: send_cmd_id (dlg, ID_FILEMISC_DECRYPT);break; |
679 |
|
|
case ID_FILECTX_SIGN: send_cmd_id (dlg, ID_FILEMISC_SIGN); break; |
680 |
|
|
case ID_FILECTX_SIGNENC: send_cmd_id (dlg, ID_FILEMISC_SIGNENC);break; |
681 |
|
|
case ID_FILECTX_VERIFY: send_cmd_id (dlg, ID_FILEMISC_VERIFY); break; |
682 |
|
|
case ID_FILECTX_WIPE: send_cmd_id (dlg, ID_FILEMISC_WIPE); break; |
683 |
|
|
case ID_FILECTX_LIST: send_cmd_id (dlg, ID_FILEMISC_LIST); break; |
684 |
|
|
case ID_FILECTX_SEND: send_cmd_id (dlg, ID_FILEMISC_SEND); break; |
685 |
twoaday |
77 |
case ID_FILECTX_ENCRYPT_ZIP:send_cmd_id (dlg, ID_FILEMISC_ENCRYPT_ZIP); break; |
686 |
werner |
36 |
} |
687 |
|
|
break; |
688 |
|
|
} |
689 |
|
|
|
690 |
|
|
return FALSE; |
691 |
twoaday |
105 |
} |
692 |
werner |
36 |
|
693 |
|
|
|
694 |
twoaday |
105 |
/* Dialog box procedure for the FM preferences. */ |
695 |
werner |
36 |
BOOL CALLBACK |
696 |
|
|
file_preferences_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
697 |
|
|
{ |
698 |
|
|
switch (msg) { |
699 |
|
|
case WM_INITDIALOG: |
700 |
twoaday |
105 |
CheckDlgButton (dlg, IDC_FPREFS_PROGRESS, |
701 |
|
|
reg_prefs.fm.progress? BST_CHECKED : BST_UNCHECKED); |
702 |
werner |
36 |
SetForegroundWindow (dlg); |
703 |
|
|
center_window (dlg, NULL); |
704 |
|
|
break; |
705 |
|
|
|
706 |
|
|
case WM_COMMAND: |
707 |
|
|
switch (LOWORD (wparam)) { |
708 |
|
|
case IDOK: |
709 |
|
|
reg_prefs.fm.progress = IsDlgButtonChecked (dlg, IDC_FPREFS_PROGRESS)? 1 : 0; |
710 |
|
|
set_reg_winpt_prefs (®_prefs); |
711 |
|
|
EndDialog (dlg, TRUE); |
712 |
|
|
break; |
713 |
|
|
|
714 |
|
|
case IDCANCEL: |
715 |
|
|
EndDialog (dlg, FALSE); |
716 |
|
|
break; |
717 |
|
|
} |
718 |
|
|
break; |
719 |
|
|
} |
720 |
|
|
|
721 |
|
|
return FALSE; |
722 |
twoaday |
105 |
} |
723 |
werner |
36 |
|
724 |
|
|
|
725 |
twoaday |
105 |
/* Add the selected items from @lv into the combo box. */ |
726 |
werner |
36 |
static void |
727 |
|
|
add_files_from_lv (HWND dlg, listview_ctrl_t lv) |
728 |
|
|
{ |
729 |
|
|
char fname[384+1]; |
730 |
|
|
int i; |
731 |
|
|
|
732 |
|
|
for (i = 0; i < listview_count_items (lv, 0); i++) { |
733 |
|
|
if (!listview_get_item_state (lv, i)) |
734 |
|
|
continue; |
735 |
|
|
listview_get_item_text (lv, i, 1, fname, sizeof (fname)-1); |
736 |
|
|
SendDlgItemMessage (dlg, IDC_SECDEL_FILES, LB_ADDSTRING, |
737 |
twoaday |
68 |
0, (WPARAM)(char *)fname); |
738 |
werner |
36 |
} |
739 |
|
|
} |
740 |
|
|
|
741 |
|
|
|
742 |
|
|
/* Dialog box procedure to confirm that files shall be deleted. */ |
743 |
|
|
BOOL CALLBACK |
744 |
|
|
file_secdel_confirm_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
745 |
|
|
{ |
746 |
|
|
static secdel_confirm_s * ctx; |
747 |
|
|
|
748 |
|
|
switch (msg) { |
749 |
|
|
case WM_INITDIALOG: |
750 |
|
|
ctx = (struct secdel_confirm_s *)lparam; |
751 |
|
|
if (!ctx) |
752 |
|
|
BUG (NULL); |
753 |
|
|
add_files_from_lv (dlg, ctx->lv_files); |
754 |
|
|
SetWindowText (dlg, _("Are you sure you want to secure delete these files?")); |
755 |
|
|
SetDlgItemText (dlg, IDYES, _("&Yes")); |
756 |
|
|
SetDlgItemText (dlg, IDNO, _("&No")); |
757 |
|
|
break; |
758 |
|
|
|
759 |
|
|
case WM_COMMAND: |
760 |
|
|
switch (LOWORD (wparam)) { |
761 |
|
|
case IDYES: |
762 |
|
|
ctx->yes = 1; |
763 |
|
|
EndDialog (dlg, TRUE); |
764 |
|
|
break; |
765 |
|
|
|
766 |
|
|
case IDNO: |
767 |
|
|
ctx->yes = 0; |
768 |
|
|
EndDialog (dlg, FALSE); |
769 |
|
|
break; |
770 |
|
|
} |
771 |
|
|
break; |
772 |
|
|
} |
773 |
|
|
|
774 |
|
|
return FALSE; |
775 |
|
|
} |
776 |
|
|
|
777 |
|
|
|
778 |
|
|
/* Wipe callback. @ctx is a window handle @off is the current offset |
779 |
|
|
and @n is the total size. */ |
780 |
|
|
static void |
781 |
|
|
wipe_cb (void *ctx, ui64 off, ui64 n) |
782 |
|
|
{ |
783 |
|
|
SendDlgItemMessage ((HWND)ctx, IDC_SPACE_PROGRESS, PBM_SETPOS, |
784 |
|
|
(WPARAM) (off*100/n), 0); |
785 |
|
|
SetDlgItemInt ((HWND)ctx, IDC_SPACE_OFF, (UINT)(off/1024), FALSE); |
786 |
|
|
SetDlgItemInt ((HWND)ctx, IDC_SPACE_N, (UINT)(n/1024), FALSE); |
787 |
|
|
} |
788 |
|
|
|
789 |
|
|
|
790 |
|
|
/* Call the wipe free space method asynchron. */ |
791 |
|
|
static DWORD WINAPI |
792 |
|
|
wipe_thread (void *ctx) |
793 |
|
|
{ |
794 |
|
|
thread_ctx_t a = (thread_ctx_t)ctx; |
795 |
|
|
int rc; |
796 |
|
|
|
797 |
|
|
rc = wipe_freespace (a->drive, &a->fd, wipe_cb, a->dlg); |
798 |
|
|
SetDlgItemText (a->dlg, IDC_SPACE_INFO, |
799 |
|
|
rc? _("Operation Status: Error") : |
800 |
|
|
_("Operation Status: Done.")); |
801 |
|
|
if (rc) |
802 |
|
|
msg_box (a->dlg, winpt_strerror (rc), _("Wipe Free Space"), MB_ERR); |
803 |
|
|
else |
804 |
|
|
MessageBeep (MB_OK); |
805 |
|
|
ExitThread (0); |
806 |
|
|
return 0; |
807 |
|
|
} |
808 |
|
|
|
809 |
|
|
|
810 |
|
|
static void |
811 |
|
|
fill_drive_combobox (HWND dlg) |
812 |
|
|
{ |
813 |
|
|
char buf[384], p[16]; |
814 |
|
|
int n, i, j = 0; |
815 |
|
|
|
816 |
|
|
n = GetLogicalDriveStrings (DIM (buf)-1, buf); |
817 |
|
|
while (j < n) { |
818 |
|
|
for (i = 0; buf[j] != '\0'; i++, j++) |
819 |
|
|
p[i] = buf[j]; |
820 |
|
|
p[i] = '\0'; |
821 |
|
|
j++; |
822 |
|
|
if (GetDriveType (p) != DRIVE_CDROM) |
823 |
|
|
SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_ADDSTRING, |
824 |
|
|
0, (LPARAM)(const char *)p); |
825 |
|
|
} |
826 |
|
|
SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_SETCURSEL, 0, 0); |
827 |
|
|
} /* fill_drive_combobox */ |
828 |
|
|
|
829 |
|
|
|
830 |
|
|
static void |
831 |
|
|
update_disc_stats (HWND dlg) |
832 |
|
|
{ |
833 |
|
|
ULARGE_INTEGER caller = {0}, total = {0}, free = {0}; |
834 |
|
|
char buf[128], drive[32], a_total[64] = {0}, a_free[64] = {0}; |
835 |
|
|
int idx; |
836 |
|
|
|
837 |
|
|
idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0); |
838 |
|
|
GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1); |
839 |
|
|
if (GetDiskFreeSpaceEx (drive, &caller, &total, &free)) { |
840 |
|
|
_ui64toa (total.QuadPart/1024, a_total, 10); |
841 |
|
|
_ui64toa (free.QuadPart/1024, a_free, 10); |
842 |
|
|
} |
843 |
|
|
_snprintf (buf, DIM (buf)-1, _("Total Capacity: %12sk\n" |
844 |
|
|
"Free Space : %12sk"), a_total, a_free); |
845 |
|
|
SetDlgItemText(dlg, IDC_SPACE_DISC_INFO, buf); |
846 |
|
|
SetDlgItemInt (dlg, IDC_SPACE_OFF, 0, FALSE); |
847 |
|
|
SetDlgItemInt (dlg, IDC_SPACE_N, 0, FALSE); |
848 |
|
|
} /* update_disc_stats */ |
849 |
|
|
|
850 |
|
|
|
851 |
|
|
BOOL CALLBACK |
852 |
|
|
space_wipefrees_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
853 |
|
|
{ |
854 |
|
|
static HANDLE thread_hd = NULL; |
855 |
|
|
static thread_ctx_s ctx; |
856 |
|
|
char drive[32], * p; |
857 |
|
|
int idx; |
858 |
|
|
DWORD tid; |
859 |
|
|
|
860 |
|
|
switch (msg) { |
861 |
|
|
case WM_INITDIALOG: |
862 |
|
|
fill_drive_combobox (dlg); |
863 |
|
|
update_disc_stats (dlg); |
864 |
|
|
center_window (dlg, NULL); |
865 |
|
|
SetForegroundWindow (dlg); |
866 |
|
|
break; |
867 |
|
|
|
868 |
|
|
case WM_DESTROY: |
869 |
|
|
thread_hd = NULL; |
870 |
|
|
free_if_alloc (ctx.drive); |
871 |
|
|
memset (&ctx, 0, sizeof ctx); |
872 |
|
|
break; |
873 |
|
|
|
874 |
|
|
case WM_COMMAND: |
875 |
|
|
if (HIWORD (wparam) == CBN_SELCHANGE) |
876 |
|
|
update_disc_stats (dlg); |
877 |
|
|
switch (LOWORD (wparam)) { |
878 |
|
|
case IDOK: |
879 |
|
|
idx = SendDlgItemMessage (dlg, IDC_SPACE_DRIVES, CB_GETCURSEL, 0, 0); |
880 |
|
|
if (idx != CB_ERR && !thread_hd) { |
881 |
|
|
GetDlgItemText (dlg, IDC_SPACE_DRIVES, drive, DIM (drive)-1); |
882 |
|
|
ctx.dlg = dlg; |
883 |
|
|
ctx.drive = m_strdup (drive); |
884 |
|
|
ctx.fd = NULL; |
885 |
|
|
thread_hd = CreateThread (NULL, 0, wipe_thread, &ctx, 0, &tid); |
886 |
|
|
} |
887 |
|
|
if (WaitForSingleObject (thread_hd, 0) == WAIT_OBJECT_0) { |
888 |
|
|
CloseHandle (thread_hd); |
889 |
|
|
thread_hd = NULL; |
890 |
|
|
EndDialog (dlg, TRUE); |
891 |
|
|
} |
892 |
|
|
break; |
893 |
|
|
|
894 |
|
|
case IDCANCEL: |
895 |
|
|
if (thread_hd) { |
896 |
|
|
WaitForSingleObject (thread_hd, 2000); |
897 |
|
|
TerminateThread (thread_hd, 1); |
898 |
|
|
CloseHandle (thread_hd); |
899 |
|
|
CloseHandle (ctx.fd); |
900 |
|
|
p = make_filename (ctx.drive, "temp_winpt.tmp", NULL); |
901 |
|
|
if (p && !file_exist_check (p)) |
902 |
werner |
47 |
remove (p); |
903 |
werner |
36 |
free_if_alloc (p); |
904 |
|
|
} |
905 |
|
|
EndDialog( dlg, FALSE ); |
906 |
|
|
break; |
907 |
|
|
} |
908 |
|
|
break; |
909 |
|
|
} |
910 |
|
|
|
911 |
|
|
return FALSE; |
912 |
|
|
} /* space_wipefrees_dlg_proc */ |