[Winpt-commits] r417 - trunk/Src
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Feb 16 20:50:32 CET 2012
Author: twoaday
Date: 2012-02-16 20:50:32 +0100 (Thu, 16 Feb 2012)
New Revision: 417
Modified:
trunk/Src/ChangeLog
trunk/Src/WinPT.cpp
trunk/Src/wptErrors.cpp
Log:
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2012-02-12 18:29:29 UTC (rev 416)
+++ trunk/Src/ChangeLog 2012-02-16 19:50:32 UTC (rev 417)
@@ -1,3 +1,10 @@
+2012-02-16 Timo Schulz <twoaday at gmx.net>
+
+ * wptErrors.cpp (setup_logfile): New. Factored out the
+ code to create the debug logging file.
+ (log_debug): Use it here and disable debugging in case
+ of any file problems.
+
2012-02-11 Timo Schulz <twoaday at gmx.net>
* wptCurrWnd.cpp (get_current_wnd): store thread ID
Modified: trunk/Src/WinPT.cpp
===================================================================
--- trunk/Src/WinPT.cpp 2012-02-12 18:29:29 UTC (rev 416)
+++ trunk/Src/WinPT.cpp 2012-02-16 19:50:32 UTC (rev 417)
@@ -1,5 +1,5 @@
/* WinPT.cpp - Windows Privacy Tray (WinPT)
- * Copyright (C) 2000-2009 Timo Schulz
+ * Copyright (C) 2000-2009, 2012 Timo Schulz
*
* This file is part of WinPT.
*
@@ -315,11 +315,8 @@
static bool
check_for_empty_keyrings (bool pub_only)
{
- char *p;
- int n;
-
- n=0;
- p = get_gnupg_keyring (1, 0);
+ int n = 0;
+ char *p = get_gnupg_keyring (1, 0);
if (file_exist_check (p) == 0 && get_file_size (p) == 0)
n++;
free_if_alloc (p);
@@ -329,7 +326,7 @@
if (file_exist_check (p) == 0 && get_file_size (p) == 0)
n++;
free_if_alloc (p);
- return n==2? true : false;
+ return n == 2? true : false;
}
@@ -344,7 +341,7 @@
GetTempPath (DIM (temp) - 1, temp);
_snprintf (output, DIM (output)-1,
"The GPGME output file is %sgpgme.dbg\n"
- "The WinPT output file is %swinpt.log\n", temp, temp);
+ "The WinPT output file is %swinpt-%08lx.log\n", temp, temp, GetCurrentProcessId());
MessageBox (NULL, output, "WinPT now runs in DEBUG MODE", MB_INFO);
}
@@ -354,11 +351,10 @@
static int
count_insecure_elgkeys (void)
{
- gpg_keycache_t pc;
gpgme_key_t key;
int n = 0;
- pc = keycache_get_ctx (1);
+ gpg_keycache_t pc = keycache_get_ctx (1);
while (!gpg_keycache_next_key (pc, 0, &key)) {
if (key->subkeys->pubkey_algo == GPGME_PK_ELG)
n++;
@@ -412,20 +408,31 @@
glob_hinst = hinst;
+ /* Check as early as possible for debug flags and activate
+ the debug mode if requested */
+ if (cmdline && (stristr (cmdline, "--enable-debug") ||
+ stristr (cmdline, "--debug"))) {
+ //gpg_set_debug_mode (1);
+ winpt_debug_msg ();
+ debug = 1;
+ }
+
/* Allow to shutdown the process, for instance by an installer */
if (cmdline && stristr (cmdline, "--stop")) {
hwnd = FindWindow ("WinPT", "WinPT");
if (hwnd != NULL) {
- log_debug("shutdown an existing WinPT process");
+ log_debug ("shutdown an existing WinPT process");
PostMessage (hwnd, WM_DESTROY, 0, 0);
}
return 0;
}
/* KLUDGE: test if the hooking is causing problems with some AV programs */
- if (cmdline && stristr (cmdline, "--disable-hook"))
+ if (cmdline && stristr (cmdline, "--disable-hook")) {
+ log_debug ("disable current window hooks");
disable_hook = 1;
-
+ }
+
log_debug("check PTD and GPGME version");
get_file_version ("winpt.exe", &ver[0], &ver[1], &ver[2], &ver[3]);
@@ -447,8 +454,10 @@
}
CreateMutex (NULL, TRUE, PGM_NAME);
- if (GetLastError () == ERROR_ALREADY_EXISTS)
+ if (GetLastError () == ERROR_ALREADY_EXISTS) {
+ log_debug ("Found running WinPT instance");
winpt_inst_found = 1;
+ }
gettext_set_user_domain ();
@@ -468,7 +477,7 @@
}
if (is_gpg4win_installed ()) {
- log_debug("gpg4win: load gpg environment");
+ log_debug ("gpg4win: load gpg environment");
load_gpg_env (); /* TODO: check return code. */
}
@@ -529,8 +538,10 @@
return 0;
}
}
- if (check_for_empty_keyrings (false))
+ if (check_for_empty_keyrings (false)) {
+ log_debug ("found empty keyrings, assume first start");
first_start = 1;
+ }
if (!first_start) {
rc = gpg_check_permissions (1);
@@ -543,6 +554,7 @@
init_gnupg_table ();
if (fm_parse_command_line (cmdline) > 0) {
+ log_debug ("processed arguments with File Manager, exiting...");
free_gnupg_table ();
return 0;
}
@@ -575,14 +587,7 @@
free_gnupg_table ();
return 0;
}
-
- if (cmdline && (stristr (cmdline, "--enable-debug") ||
- stristr (cmdline, "--debug"))) {
- gpg_set_debug_mode (1);
- winpt_debug_msg ();
- debug = 1;
- }
-
+
wc.hIcon = LoadIcon (glob_hinst, MAKEINTRESOURCE (IDI_WINPT));
rc = RegisterClass (&wc);
if (rc == FALSE) {
Modified: trunk/Src/wptErrors.cpp
===================================================================
--- trunk/Src/wptErrors.cpp 2012-02-12 18:29:29 UTC (rev 416)
+++ trunk/Src/wptErrors.cpp 2012-02-16 19:50:32 UTC (rev 417)
@@ -42,7 +42,6 @@
_snprintf (buf, DIM (buf) - 1,
_("Could not locate GPG.exe in %s."), path);
break;
-
case WPTERR_GPG_OPT_KEYRINGS:
case WPTERR_GPG_KEYRINGS:
_snprintf (buf, DIM (buf) - 1,
@@ -168,27 +167,43 @@
#endif
}
+/* Create a log file in the temporary folder
+ and use the PID as a unique identifier */
+static int
+setup_logfile (void)
+{
+ char tmpdir[384];
+ char file[128];
+
+ snprintf (file, sizeof(file)-1, "\\WinPT-%08lX.LOG",
+ GetCurrentProcessId ());
+ GetTempPath (sizeof (tmpdir) - strlen (file) - 2, tmpdir);
+ strcat (tmpdir, file);
+ log_fp = fopen (tmpdir, "w+b");
+ if (!log_fp)
+ return -1;
+ return 0;
+}
/* Log a message into the log file. */
void
log_debug (const char *format, ...)
-{
- char tmpdir[384];
+{
va_list arg_ptr;
if (!debug)
return;
-
+
if (log_fp == NULL) {
- GetTempPath (sizeof (tmpdir) - 32, tmpdir);
- strcat (tmpdir, "\\WinPT.LOG");
- log_fp = fopen (tmpdir, "a+b");
- if (!log_fp)
- return;
+ /* In case of problems, disable debug to avoid loops */
+ if (setup_logfile ())
+ debug = 0;
}
+
va_start (arg_ptr, format);
vfprintf (log_fp, format, arg_ptr);
va_end (arg_ptr);
+ fprintf(log_fp, "\r\n");
fflush (log_fp);
}
More information about the Winpt-commits
mailing list