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