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