17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
|
|
|
20 |
#include <windows.h> |
#include <windows.h> |
21 |
|
|
22 |
#include "../resource.h" |
#include "../resource.h" |
40 |
LOCK mo_file; |
LOCK mo_file; |
41 |
int scard_support = 0; |
int scard_support = 0; |
42 |
int debug = 0; |
int debug = 0; |
43 |
|
int mobile = 0; |
44 |
int gpg_read_only = 0; |
int gpg_read_only = 0; |
45 |
char gpgver[3]; |
char gpgver[3]; |
46 |
|
|
47 |
|
/* Internal IPC */ |
48 |
|
int start_keymanager = 0; |
49 |
|
|
50 |
static void |
static void |
51 |
update_keycache (HWND hwnd) |
update_keycache (HWND hwnd) |
158 |
ma, mi, pa); |
ma, mi, pa); |
159 |
return rc; |
return rc; |
160 |
} |
} |
161 |
/* We enable smartcard support for GPG: 1.9.x and >= 1.3.90 */ |
/* We enable smartcard support for GPG: 1.9.x or >= 1.4.0 */ |
162 |
if (ma > 1 || mi >= 9 || mi > 3) |
if (ma >= 1 && mi >= 4) |
163 |
scard_support = 1; |
scard_support = 1; |
164 |
|
|
165 |
gpgver[0] = ma; |
gpgver[0] = ma; |
188 |
} |
} |
189 |
|
|
190 |
|
|
191 |
|
static void |
192 |
|
enable_mobile_mode (void) |
193 |
|
{ |
194 |
|
memset (®_prefs, 0, sizeof (reg_prefs)); |
195 |
|
reg_prefs.always_trust = 0; |
196 |
|
reg_prefs.auto_backup = 0; |
197 |
|
reg_prefs.cache_time = 0; |
198 |
|
reg_prefs.expert = 0; |
199 |
|
reg_prefs.keylist_mode = 1; |
200 |
|
reg_prefs.kserv_conf = m_strdup ("keyserver.conf"); |
201 |
|
reg_prefs.no_zip_mmedia = 1; |
202 |
|
reg_prefs.use_tmpfiles = 1; |
203 |
|
reg_prefs.word_wrap = 80; |
204 |
|
reg_prefs.use_viewer = 0; /* XXX */ |
205 |
|
} |
206 |
|
|
207 |
|
char* get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid); |
208 |
|
|
209 |
int WINAPI |
int WINAPI |
210 |
|
#ifndef WINPT_IPC |
211 |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
WinMain (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
212 |
|
#else |
213 |
|
win_main (HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int showcmd) |
214 |
|
#endif |
215 |
{ |
{ |
216 |
WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME}; |
WNDCLASS wc = {0, winpt_main_proc, 0, 0, hinst, 0, 0, 0, 0, PGM_NAME}; |
217 |
HACCEL accel_tab; |
HACCEL accel_tab; |
230 |
gpgme_set_pgm_string ("WinPT "PGM_VERSION); |
gpgme_set_pgm_string ("WinPT "PGM_VERSION); |
231 |
|
|
232 |
s = PTD_get_version (); |
s = PTD_get_version (); |
233 |
if (strcmp (s, "0.8.0")) |
if (strcmp (s, "0.8.0")) { |
|
{ |
|
234 |
log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR, |
log_box (_("Privacy Tray Dynamic (PTD)"), MB_ERR, |
235 |
_("Please update your PTD.dll to the newest version, " |
_("Please update your PTD.dll to the newest version, " |
236 |
"the version (%s) you use is too old."), s); |
"the version (%s) you use is too old."), s); |
237 |
return 0; |
return 0; |
238 |
} |
} |
239 |
|
|
240 |
if (gpg_md_selftest ()) |
if (gpg_md_selftest ()) { |
|
{ |
|
241 |
msg_box (NULL, _("Cryptographic selftest failed."), |
msg_box (NULL, _("Cryptographic selftest failed."), |
242 |
_("WinPT Error"), MB_ERR); |
_("WinPT Error"), MB_ERR); |
243 |
return 0; |
return 0; |
244 |
} |
} |
245 |
|
|
246 |
|
if (cmdline && stristr (cmdline, "--mobile")) { |
247 |
|
msg_box (NULL, "WARNING: mobile modus is not fully implemented yet!", "WinPT", MB_INFO); |
248 |
|
mobile = 1; |
249 |
|
} |
250 |
|
|
251 |
set_default_kserver (); |
set_default_kserver (); |
252 |
regist_inst_gnupg (1); |
|
253 |
regist_inst_winpt (1, &created); |
if (!mobile) { |
254 |
if (!created) |
regist_inst_gnupg (1); |
255 |
{ |
regist_inst_winpt (1, &created); |
256 |
|
} |
257 |
|
else { |
258 |
|
enable_mobile_mode (); |
259 |
|
/* XXX: ask for GPG path */ |
260 |
|
created = 1; /* Disable registry writing */ |
261 |
|
} |
262 |
|
|
263 |
|
if (!created) { |
264 |
memset (®_prefs, 0, sizeof (reg_prefs)); |
memset (®_prefs, 0, sizeof (reg_prefs)); |
265 |
reg_prefs.use_tmpfiles = 1; /* default */ |
reg_prefs.use_tmpfiles = 1; /* default */ |
266 |
|
reg_prefs.fm.progress = 0; /* XXX: fix the bug and enable it again */ |
267 |
get_reg_winpt_prefs (®_prefs); |
get_reg_winpt_prefs (®_prefs); |
268 |
if (!reg_prefs.no_hotkeys) |
if (!reg_prefs.no_hotkeys) |
269 |
hotkeys_modify (); |
hotkeys_modify (); |
270 |
} |
} |
271 |
|
|
272 |
rc = gnupg_check_homedir (); |
rc = gnupg_check_homedir (); |
273 |
if (rc) |
if (rc) { |
|
{ |
|
274 |
log_box (_("WinPT Error"), MB_ERR, |
log_box (_("WinPT Error"), MB_ERR, |
275 |
_("GPG home directory is not set correctly.\n" |
_("GPG home directory is not set correctly.\n" |
276 |
"Please check the GPG registry settings:\n%s."), |
"Please check the GPG registry settings:\n%s."), |
299 |
gnupg_check_homedir (); /* change gpgProgram if needed */ |
gnupg_check_homedir (); /* change gpgProgram if needed */ |
300 |
} |
} |
301 |
} |
} |
302 |
else |
else { |
|
{ |
|
303 |
msg_box (NULL, _("GPG home directory could not be determited."), |
msg_box (NULL, _("GPG home directory could not be determited."), |
304 |
_("WinPT Error"), MB_ERR); |
_("WinPT Error"), MB_ERR); |
305 |
goto start; |
goto start; |
307 |
} |
} |
308 |
|
|
309 |
rc = check_gnupg_prog (); |
rc = check_gnupg_prog (); |
310 |
if (rc) |
if (rc) { |
|
{ |
|
311 |
if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n" |
if (msg_box (NULL, _("Could not find the GPG binary (gpg.exe).\n" |
312 |
"Do you want to start the GPG preferences to " |
"Do you want to start the GPG preferences to " |
313 |
"correct this problem?"), _("WinPT Error"), |
"correct this problem?"), _("WinPT Error"), |
365 |
} |
} |
366 |
|
|
367 |
load_keyserver_conf (cmdline? 1 : 0); |
load_keyserver_conf (cmdline? 1 : 0); |
368 |
|
if (start_keymanager) { |
369 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
370 |
|
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
371 |
|
_("Key Manager"), IDS_WINPT_KEYMISC); |
372 |
|
keycache_release (); |
373 |
|
free_gnupg_table (); |
374 |
|
return 0; |
375 |
|
} |
376 |
|
|
377 |
if (cmdline && (stristr (cmdline, "--keymanager") |
if (cmdline && (stristr (cmdline, "--keymanager") |
378 |
|| stristr (cmdline, "--cardmanager"))) { |
|| stristr (cmdline, "--cardmanager"))) { |
379 |
update_keycache (GetDesktopWindow ()); |
update_keycache (GetDesktopWindow ()); |
380 |
if (stristr (cmdline, "keymanager")) |
if (stristr (cmdline, "keymanager")) |
381 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYMISC, |
382 |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
GetDesktopWindow(), keymanager_dlg_proc, NULL, |
383 |
_("Key Manager"), IDS_WINPT_KEYMISC); |
_("Key Manager"), IDS_WINPT_KEYMISC); |
384 |
else { |
else { |
385 |
gpgme_card_t crd = smartcard_init (); |
gpgme_card_t crd = smartcard_init (); |
386 |
if (crd) |
if (crd) |
401 |
return 0; |
return 0; |
402 |
} |
} |
403 |
|
|
404 |
/*if (file_exist_check ("loadimage.exe")) |
if (cmdline) { |
405 |
PTD_create_loadimage (NULL);*/ |
if (stristr (cmdline, "--enable-debug") || stristr (cmdline, "--debug")) { |
406 |
|
gpgme_set_debug_mode (1); |
407 |
if (cmdline && stristr (cmdline, "--enable-debug")) { |
winpt_debug_msg (); |
408 |
gpgme_set_debug_mode (1); |
debug = 1; |
409 |
winpt_debug_msg (); |
} |
|
debug = 1; |
|
410 |
} |
} |
411 |
|
|
412 |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT)); |