[Gpg4win-commits] [git] Gpg4win - branch, master, updated. gpg4win-2.3.0-102-g929d94b

by Andre Heinecke cvs at cvs.gnupg.org
Mon Feb 29 15:56:26 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG for Windows".

The branch, master has been updated
       via  929d94bd192ddb8ddc8f9ee45e9168b066488459 (commit)
       via  929ebdc5698fdea951a35cd4bc23f8c20d678f8a (commit)
      from  b5ee6db6017547777c8178185e3e750b91757968 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 929d94bd192ddb8ddc8f9ee45e9168b066488459
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Mon Feb 29 15:55:03 2016 +0100

    Kill Kleo and GPA on uninstall / install
    
    * src/installer.nsi (PrintCloseOtherApps): Just kill them.
     (un.CloseApps): New.
    * MUI_UNPAGE_INSTFILES: Call CloseApps in pre function.

diff --git a/src/installer.nsi b/src/installer.nsi
index fdc4298..2de7f5b 100644
--- a/src/installer.nsi
+++ b/src/installer.nsi
@@ -210,6 +210,7 @@ LangString T_RunGPA ${LANG_ENGLISH} \
 
 !insertmacro MUI_UNPAGE_WELCOME
 !insertmacro MUI_UNPAGE_CONFIRM
+!define MUI_PAGE_CUSTOMFUNCTION_PRE un.CloseApps
 !insertmacro MUI_UNPAGE_INSTFILES
 #!insertmacro MUI_UNPAGE_FINISH
 
@@ -421,13 +422,18 @@ FunctionEnd
 # Check whether this is a reinstall and popup a message box to explain
 # that it is better to close other apps before continuing
 Function PrintCloseOtherApps
-    # TODO Look for running processes instead.
-    IfFileExists $INSTDIR\gpa.exe   print_warning
-    IfFileExists $INSTDIR\gpgol.dll print_warning
-    Return
+   g4wihelp::KillProc "kleopatra.exe"
+   g4wihelp::KillProc "gpa.exe"
+goto leave
+# TODO check for running outlook and offer to kill it.
    print_warning:
     MessageBox MB_OK|MB_ICONEXCLAMATION "$(T_CloseOtherApps)"
-   leave:
+leave:
+FunctionEnd
+
+Function un.CloseApps
+   g4wihelp::KillProc "kleopatra.exe"
+   g4wihelp::KillProc "gpa.exe"
 FunctionEnd
 
 # Called right before installation

commit 929ebdc5698fdea951a35cd4bc23f8c20d678f8a
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Mon Feb 29 15:50:21 2016 +0100

    Add simple KillProc function
    
    * src/desktopshellrun.cpp, src/exdll.h (ERRORPRINTF),
     (acp_to_wchar): Move from destkopshellrun to exdll.h
    * src/g4wihelp.c (KillProc): New. Kill processes.

diff --git a/src/desktopshellrun.cpp b/src/desktopshellrun.cpp
index 76c4992..4ef8a9e 100644
--- a/src/desktopshellrun.cpp
+++ b/src/desktopshellrun.cpp
@@ -47,13 +47,6 @@ __CRT_UUID_DECL(IShellFolderViewDual,  0xe7a1af80, 0x4d96,
 #endif
 
 #define UNUSED(x) (void)(x)
-#define ERRORPRINTF(fmt, ...) \
-  { \
-    char buf[512]; \
-    snprintf(buf, 511, "ERROR: " fmt, ##__VA_ARGS__); \
-    buf[511] = '\0'; \
-    OutputDebugStringA(buf); \
-  }
 
 /** @brief the actual execuation call on the shell dispatcher
  *
@@ -115,37 +108,6 @@ shellexecute(IShellDispatch2 *disp, wchar_t *fName, wchar_t *param)
   return true;
 }
 
-wchar_t
-*acp_to_wchar (const char *string, size_t len)
-{
-  int n, ilen;
-  wchar_t *result;
-
-  ilen = (int) len;
-  if (ilen < 0)
-    return NULL;
-
-  n = MultiByteToWideChar (CP_ACP, 0, string, ilen, NULL, 0);
-  if (n < 0 || n + 1 < 0)
-    return NULL;
-
-  result = (wchar_t *) malloc ((size_t)(n+1) * sizeof *result);
-  if (!result)
-    {
-      ERRORPRINTF("Out of core");
-      exit(1);
-    }
-  n = MultiByteToWideChar (CP_ACP, 0, string, ilen, result, n);
-  if (n < 0)
-    {
-      if (result)
-        free (result);
-      return NULL;
-    }
-  result[n] = 0;
-  return result;
-}
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/exdll.h b/src/exdll.h
index a32ed20..0c36f28 100644
--- a/src/exdll.h
+++ b/src/exdll.h
@@ -146,6 +146,44 @@ setuservariable(const int varnum, const char *var)
     lstrcpy(g_variables + varnum*g_stringsize, var);
 }
 
+#define ERRORPRINTF(fmt, ...) \
+  { \
+    char buf[512]; \
+    snprintf(buf, 511, "ERROR: " fmt, ##__VA_ARGS__); \
+    buf[511] = '\0'; \
+    OutputDebugStringA(buf); \
+  }
+
+static wchar_t
+*acp_to_wchar (const char *string, size_t len)
+{
+  int n, ilen;
+  wchar_t *result;
+
+  ilen = (int) len;
+  if (ilen < 0)
+    return NULL;
+
+  n = MultiByteToWideChar (CP_ACP, 0, string, ilen, NULL, 0);
+  if (n < 0 || n + 1 < 0)
+    return NULL;
+
+  result = (wchar_t *) malloc ((size_t)(n+1) * sizeof *result);
+  if (!result)
+    {
+      ERRORPRINTF("Out of core");
+      exit(1);
+    }
+  n = MultiByteToWideChar (CP_ACP, 0, string, ilen, result, n);
+  if (n < 0)
+    {
+      if (result)
+        free (result);
+      return NULL;
+    }
+  result[n] = 0;
+  return result;
+}
 
 
 #endif//_EXDLL_H_
diff --git a/src/g4wihelp.c b/src/g4wihelp.c
index 7cb0679..dd2bc83 100644
--- a/src/g4wihelp.c
+++ b/src/g4wihelp.c
@@ -1,6 +1,7 @@
 /* g4wihelp.c - NSIS Helper DLL used with gpg4win. -*- coding: latin-1; -*-
  * Copyright (C) 2005 g10 Code GmbH
  * Copyright (C) 2001 Justin Frankel
+ * Copyright (C) 2016 Intevation GmbH
  *
  * This software is provided 'as-is', without any express or implied
  * warranty. In no event will the authors be held liable for any
@@ -30,6 +31,8 @@
 
 #include <windows.h>
 #include <stdio.h>
+#include <tlhelp32.h>
+#include <psapi.h>
 #include "exdll.h"
 
 static HINSTANCE g_hInstance; /* Our Instance. */
@@ -1133,3 +1136,65 @@ path_remove (HWND hwndParent, int string_size, char *variables,
 
   setuservariable (INST_R0, "1");
 }
+
+/** @brief Kill processes with the name name.
+ *
+ * This function tries to kill a process using ExitProcess.
+ *
+ * If it does not work it does not work. No return values.
+ * The intention is to make an effort to kill something during
+ * installation / uninstallation.
+ *
+ * The function signature is explained by NSIS.
+ */
+void __declspec(dllexport) __cdecl KillProc(HWND hwndParent,
+                                            int string_size,
+                                            char *variables,
+                                            stack_t **stacktop)
+{
+  HANDLE h;
+  PROCESSENTRY32 pe32;
+
+  if (!stacktop || !*stacktop || !(*stacktop)->text)
+    {
+      ERRORPRINTF ("Invalid call to KillProc.");
+      return;
+    }
+
+
+  h = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      ERRORPRINTF ("Failed to create Toolhelp snapshot");
+      return;
+    }
+  pe32.dwSize = sizeof (PROCESSENTRY32);
+
+  if (!Process32First (h, &pe32))
+    {
+      ERRORPRINTF ("Failed to get first process");
+      CloseHandle (h);
+      return;
+    }
+
+  do
+    {
+      if (!strcmp ((*stacktop)->text, pe32.szExeFile))
+        {
+          HANDLE hProc = OpenProcess (PROCESS_ALL_ACCESS, FALSE,
+                                      pe32.th32ProcessID);
+          if (!hProc)
+            {
+              ERRORPRINTF ("Failed to open process handle.");
+              continue;
+            }
+          if (!TerminateProcess (hProc, 1))
+            {
+              ERRORPRINTF ("Failed to terminate process.");
+            }
+          CloseHandle (hProc);
+        }
+    }
+  while (Process32Next (h, &pe32));
+  CloseHandle (h);
+}

-----------------------------------------------------------------------

Summary of changes:
 src/desktopshellrun.cpp | 38 -----------------------------
 src/exdll.h             | 38 +++++++++++++++++++++++++++++
 src/g4wihelp.c          | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/installer.nsi       | 16 ++++++++----
 4 files changed, 114 insertions(+), 43 deletions(-)


hooks/post-receive
-- 
GnuPG for Windows
http://git.gnupg.org



More information about the Gpg4win-commits mailing list