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