1 |
/* wptKeygenDlg.cpp - Key callback generation dialog |
2 |
* Copyright (C) 2001, 2002, 2003, 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 |
#ifdef HAVE_CONFIG_H |
21 |
#include <config.h> |
22 |
#endif |
23 |
|
24 |
#include <windows.h> |
25 |
|
26 |
#include "resource.h" |
27 |
#include "wptTypes.h" |
28 |
#include "wptW32API.h" |
29 |
#include "wptVersion.h" |
30 |
#include "wptNLS.h" |
31 |
#include "wptErrors.h" |
32 |
|
33 |
/* Handle to the progress dialog. */ |
34 |
static HWND dlg_hwnd = NULL; |
35 |
|
36 |
|
37 |
/* Dialog box param for the keygen progress. */ |
38 |
static BOOL CALLBACK |
39 |
keygen_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
40 |
{ |
41 |
switch (msg) { |
42 |
case WM_INITDIALOG: |
43 |
SetDlgItemText (dlg, IDC_KEYPROG_CB, ""); |
44 |
SetForegroundWindow (dlg); |
45 |
SetWindowText (dlg, _("Key Generation - Progress Dialog")); |
46 |
center_window (dlg, NULL); |
47 |
dlg_hwnd = dlg; |
48 |
return TRUE; |
49 |
|
50 |
case WM_DESTROY: |
51 |
dlg_hwnd = NULL; |
52 |
break; |
53 |
} |
54 |
|
55 |
return FALSE; |
56 |
} |
57 |
|
58 |
|
59 |
/* Thread to start the progress dialog (async). */ |
60 |
static DWORD WINAPI |
61 |
keygen_cb_thread (void *opaque) |
62 |
{ |
63 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROG, |
64 |
GetActiveWindow (), keygen_cb_dlg_proc, 0); |
65 |
ExitThread (0); |
66 |
return 0; |
67 |
} |
68 |
|
69 |
|
70 |
/* Create the progress thread. */ |
71 |
int |
72 |
keygen_cb_dlg_create (void) |
73 |
{ |
74 |
DWORD tid; |
75 |
HANDLE thread_hd; |
76 |
SECURITY_ATTRIBUTES sec_attr; |
77 |
|
78 |
memset (&sec_attr, 0, sizeof sec_attr); |
79 |
sec_attr.bInheritHandle = FALSE; |
80 |
sec_attr.lpSecurityDescriptor = NULL; |
81 |
sec_attr.nLength = sizeof sec_attr; |
82 |
thread_hd = CreateThread (&sec_attr, 0, keygen_cb_thread, NULL, 0, &tid); |
83 |
if (!thread_hd) { |
84 |
msg_box (NULL, "Could not create key generation thread", |
85 |
_("Key Generation"), MB_ERR); |
86 |
return WPTERR_GENERAL; |
87 |
} |
88 |
|
89 |
return 0; |
90 |
} |
91 |
|
92 |
|
93 |
/* Destroy the progress dialog and cleanup. */ |
94 |
void |
95 |
keygen_cb_dlg_destroy (void) |
96 |
{ |
97 |
if (dlg_hwnd) { |
98 |
EndDialog (dlg_hwnd, TRUE); |
99 |
dlg_hwnd = NULL; |
100 |
} |
101 |
} |
102 |
|
103 |
|
104 |
/* GPGME progress callback function. */ |
105 |
void |
106 |
keygen_cb (void * opaque, const char * what, int type, int curretn, int total) |
107 |
{ |
108 |
static char cb[8192] = {0}; |
109 |
static int cb_pos = 0; |
110 |
|
111 |
if (!opaque && !what && !type && !curretn && !total) { |
112 |
memset (cb, 0, sizeof cb); |
113 |
cb_pos = 0; |
114 |
return; |
115 |
} |
116 |
|
117 |
if (cb_pos >= (DIM (cb)-1)) { |
118 |
SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, ""); |
119 |
cb_pos = 0; |
120 |
} |
121 |
cb[cb_pos] = (char)type; |
122 |
cb_pos++; |
123 |
cb[cb_pos] = '\0'; |
124 |
|
125 |
SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, cb); |
126 |
} |