[Gpg4win-commits] r572 - in trunk: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Oct 18 16:10:02 CEST 2007


Author: marcus
Date: 2007-10-18 16:10:02 +0200 (Thu, 18 Oct 2007)
New Revision: 572

Modified:
   trunk/ChangeLog
   trunk/src/g4wihelp.c
   trunk/src/gpg4win.nsi
   trunk/src/installer.nsi
Log:
2007-10-18  Marcus Brinkmann  <marcus at g10code.de>

	* src/g4wihelp.c (read_w32_registry_string): New function.
	(ENV_HK, ENV_REG): New macros.
	(path_add, path_remove): New functions.
	* src/gpg4win.nsi: Remove GpgEX from light installer.
	* src/installer.nsi (AddToPath, RemoveFromPath): Rewritten.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-10-17 15:12:12 UTC (rev 571)
+++ trunk/ChangeLog	2007-10-18 14:10:02 UTC (rev 572)
@@ -1,3 +1,11 @@
+2007-10-18  Marcus Brinkmann  <marcus at g10code.de>
+
+	* src/g4wihelp.c (read_w32_registry_string): New function.
+	(ENV_HK, ENV_REG): New macros.
+	(path_add, path_remove): New functions.
+	* src/gpg4win.nsi: Remove GpgEX from light installer.
+	* src/installer.nsi (AddToPath, RemoveFromPath): Rewritten.
+
 2007-10-17  Marcus Brinkmann  <marcus at g10code.de>
 
 	* src/inst-kleopatra.nsi: Add DESC_Menu_kleopatra language string.

Modified: trunk/src/g4wihelp.c
===================================================================
--- trunk/src/g4wihelp.c	2007-10-17 15:12:12 UTC (rev 571)
+++ trunk/src/g4wihelp.c	2007-10-18 14:10:02 UTC (rev 572)
@@ -896,3 +896,232 @@
   setuservariable (INST_R0, result == 0 ? "0" : "1");
   return;
 }
+
+
+/* Return a string from the Win32 Registry or NULL in case of error.
+   Caller must release the return value.  A NULL for root is an alias
+   for HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE in turn.  */
+char *
+read_w32_registry_string (HKEY root, const char *dir, const char *name)
+{
+  HKEY root_key;
+  HKEY key_handle;
+  DWORD n1, nbytes, type;
+  char *result = NULL;
+
+  root_key = root;
+  if (! root_key)
+    root_key = HKEY_CURRENT_USER;
+
+  if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) )
+    {
+      if (root)
+	return NULL; /* no need for a RegClose, so return direct */
+      /* It seems to be common practise to fall back to HKLM. */
+      if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) )
+	return NULL; /* still no need for a RegClose, so return direct */
+    }
+
+  nbytes = 1;
+  if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) {
+    if (root)
+      goto leave;
+    /* Try to fallback to HKLM also vor a missing value.  */
+    RegCloseKey (key_handle);
+    if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) )
+      return NULL; /* Nope.  */
+    if (RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes))
+      goto leave;
+  }
+
+  result = malloc( (n1=nbytes+1) );
+
+  if( !result )
+    goto leave;
+  if( RegQueryValueEx( key_handle, name, 0, &type, result, &n1 ) ) {
+    free(result); result = NULL;
+    goto leave;
+  }
+  result[nbytes] = 0; /* make sure it is really a string  */
+
+ leave:
+  RegCloseKey( key_handle );
+  return result;
+}
+
+
+#define ENV_HK HKEY_LOCAL_MACHINE
+#define ENV_REG "SYSTEM\\CurrentControlSet\\Control\\" \
+    "Session Manager\\Environment"
+  /* The following setting can be used for a per-user setting.  */
+#if 0
+#define ENV_HK HKEY_CURRENT_USER
+#define ENV_REG "Environment"
+#endif
+
+
+void __declspec(dllexport) 
+path_add (HWND hwndParent, int string_size, char *variables, 
+	  stack_t **stacktop, extra_parameters_t *extra)
+{
+#ifndef PATH_MAX
+#define PATH_MAX 8192
+#endif
+  char dir[PATH_MAX];
+  char *path;
+  char *path_new;
+  int path_new_size;
+  char *comp;
+  const char delims[] = ";";
+  HKEY key_handle = 0;
+
+  g_hwndParent = hwndParent;
+  EXDLL_INIT();
+
+  setuservariable (INST_R0, "0");
+
+  MessageBox (g_hwndParent, "XXX 1", 0, MB_OK);
+
+  /* The expected stack layout: path component.  */
+  if (popstring (dir, sizeof (dir)))
+    return;
+
+  MessageBox (g_hwndParent, "XXX 2", 0, MB_OK);
+
+  path = read_w32_registry_string (ENV_HK, ENV_REG, "Path");
+  if (! path)
+    {
+      MessageBox (g_hwndParent, "No PATH variable found", 0, MB_OK);
+      return;
+    }
+
+  MessageBox (g_hwndParent, "XXX 3", 0, MB_OK);
+
+  /* Old path plus semicolon plus dir plus terminating nul.  */
+  path_new_size = strlen (path) + 1 + strlen (dir) + 1;
+  if (path_new_size > PATH_MAX)
+    {
+      MessageBox (g_hwndParent, "PATH env variable too big", 0, MB_OK);
+      free (path);
+      return;
+    }
+
+  MessageBox (g_hwndParent, "XXX 4", 0, MB_OK);
+
+  path_new = malloc (path_new_size);
+  if (!path_new)
+    {
+      free (path);
+      return;
+    }
+
+  MessageBox (g_hwndParent, "XXX 5", 0, MB_OK);
+
+  strcpy (path_new, path);
+  strcat (path_new, ";");
+  strcat (path_new, dir);
+
+  MessageBox (g_hwndParent, "XXX 6", 0, MB_OK);
+  MessageBox (g_hwndParent, dir, 0, MB_OK);
+  MessageBox (g_hwndParent, "XXX 7", 0, MB_OK);
+
+  /* Check if the directory already exists in the path.  */
+  comp = strtok (path, delims);
+  do
+    {
+      MessageBox (g_hwndParent, comp, 0, MB_OK);
+
+      if (!strcmp (comp, dir))
+	{
+	  free (path);
+	  free (path_new);
+	  return;
+	}
+      comp = strtok (NULL, delims);
+    }
+  while (comp);
+  free (path);
+
+  MessageBox (g_hwndParent, "XXX 8", 0, MB_OK);
+
+  /* Set a key for our CLSID.  */
+  RegCreateKey (ENV_HK, ENV_REG, &key_handle);
+  RegSetValueEx (key_handle, "Path", 0, REG_EXPAND_SZ,
+		 path_new, path_new_size);
+  RegCloseKey (key_handle);
+  free (path_new);
+
+  MessageBox (g_hwndParent, "XXX 9", 0, MB_OK);
+
+  setuservariable (INST_R0, "1");
+}
+
+
+void __declspec(dllexport) 
+path_remove (HWND hwndParent, int string_size, char *variables, 
+	     stack_t **stacktop, extra_parameters_t *extra)
+{
+#ifndef PATH_MAX
+#define PATH_MAX 8192
+#endif
+  char dir[PATH_MAX];
+  char *path;
+  char *path_new;
+  int path_new_size;
+  char *comp;
+  const char delims[] = ";";
+  HKEY key_handle = 0;
+  int changed = 0;
+  int count = 0;
+
+  g_hwndParent = hwndParent;
+  EXDLL_INIT();
+
+  setuservariable (INST_R0, "0");
+
+  /* The expected stack layout: path component.  */
+  if (popstring (dir, sizeof (dir)))
+    return;
+
+  path = read_w32_registry_string (ENV_HK, ENV_REG, "Path");
+  /* Old path plus semicolon plus dir plus terminating nul.  */
+  path_new_size = strlen (path) + 1;
+  path_new = malloc (path_new_size);
+  if (!path_new)
+    {
+      free (path);
+      return;
+    }
+  path_new[0] = '\0';
+
+  /* Compose the new path.  */
+  comp = strtok (path, delims);
+  do
+    {
+      if (strcmp (comp, dir))
+	{
+	  if (count != 0)
+	    strcat (path_new, ";");
+	  strcat (path_new, comp);
+	  count++;
+	}
+      else
+	changed = 1;
+
+      comp = strtok (NULL, delims);
+    }
+  while (comp);
+  free (path);
+
+  if (! changed)
+    return;
+
+  /* Set a key for our CLSID.  */
+  RegCreateKey (ENV_HK, ENV_REG, &key_handle);
+  RegSetValueEx (key_handle, "Path", 0, REG_EXPAND_SZ,
+		 path_new, path_new_size);
+  RegCloseKey (key_handle);
+  free (path_new);
+
+  setuservariable (INST_R0, "1");
+}

Modified: trunk/src/gpg4win.nsi
===================================================================
--- trunk/src/gpg4win.nsi	2007-10-17 15:12:12 UTC (rev 571)
+++ trunk/src/gpg4win.nsi	2007-10-18 14:10:02 UTC (rev 572)
@@ -33,6 +33,9 @@
 !ifdef HAVE_PKG_KLEOPATRA
 !undef HAVE_PKG_KLEOPATRA
 !endif
+!ifdef HAVE_PKG_GPGEX
+!undef HAVE_PKG_GPGEX
+!endif
 !ifdef HAVE_PKG_KDELIBS
 !undef HAVE_PKG_KDELIBS
 !endif

Modified: trunk/src/installer.nsi
===================================================================
--- trunk/src/installer.nsi	2007-10-17 15:12:12 UTC (rev 571)
+++ trunk/src/installer.nsi	2007-10-18 14:10:02 UTC (rev 572)
@@ -616,110 +616,26 @@
 FunctionEnd
 
 
-#
 # AddToPath - Adds the given dir to the search path.
 #        Input - head of the stack
-# (Taken from Kichik's code at the NSIS Wiki)
-#
 Function AddToPath
   Exch $0
-  Push $1
-  Push $2
-  Push $3
- 
-  # Don't add if the path doesn't exist
-  IfFileExists "$0\*.*" "" AddToPath_done
- 
-  ReadEnvStr $1 PATH
-  Push "$1;"
-  Push "$0;"
-  Call StrStr
-  Pop $2
-  StrCmp $2 "" "" AddToPath_done
-  Push "$1;"
-  Push "$0\;"
-  Call StrStr
-  Pop $2
-  StrCmp $2 "" "" AddToPath_done
-  GetFullPathName /SHORT $3 $0
-  Push "$1;"
-  Push "$3;"
-  Call StrStr
-  Pop $2
-  StrCmp $2 "" "" AddToPath_done
-  Push "$1;"
-  Push "$3\;"
-  Call StrStr
-  Pop $2
-  StrCmp $2 "" "" AddToPath_done
- 
-  ReadRegStr $1 ${Regkey_for_Env} "PATH"
-  StrCmp $1 "" AddToPath_NTdoIt
-    Push $1
-    #  We do not need the follwing call
-    #  Call Trim
-    Pop $1
-    StrCpy $0 "$1;$0"
-  AddToPath_NTdoIt:
-    WriteRegExpandStr ${Regkey_for_Env} "PATH" $0
-    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
- 
-  AddToPath_done:
-    Pop $3
-    Pop $2
-    Pop $1
-    Pop $0
+  g4wihelp::path_add "$0"
+  StrCmp $R5 "0" add_to_path_done
+  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+  add_to_path_done:
+  Pop $0
 FunctionEnd
  
-#
 # RemoveFromPath - Remove a given dir from the path
 #     Input: head of the stack
-# (Taken from Kichik's code at the NSIS Wiki)
-# 
 Function un.RemoveFromPath
   Exch $0
-  Push $1
-  Push $2
-  Push $3
-  Push $4
-  Push $5
-  Push $6
- 
-  IntFmt $6 "%c" 26 # DOS EOF
- 
-  ReadRegStr $1 ${Regkey_for_Env} "PATH"
-  StrCpy $5 $1 1 -1 # copy last char
-  StrCmp $5 ";" +2 # if last char != ;
-    StrCpy $1 "$1;" # append ;
-  Push $1
-  Push "$0;"
-  Call un.StrStr # Find `$0;` in $1
-  Pop $2 ; pos of our dir
-  StrCmp $2 "" unRemoveFromPath_done
-    # else, it is in path
-    # $0 - path to add
-    # $1 - path var
-    StrLen $3 "$0;"
-    StrLen $4 $2
-    StrCpy $5 $1 -$4   # $5 is now the part before the path to remove
-    StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
-    StrCpy $3 $5$6
- 
-    StrCpy $5 $3 1 -1  # copy last char
-    StrCmp $5 ";" 0 +2 # if last char == ;
-      StrCpy $3 $3 -1  # remove last char
- 
-    WriteRegExpandStr ${Regkey_for_Env} "PATH" $3
-    SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
- 
-  unRemoveFromPath_done:
-    Pop $6
-    Pop $5
-    Pop $4
-    Pop $3
-    Pop $2
-    Pop $1
-    Pop $0
+  g4wihelp::path_remove "$0"
+  StrCmp $R5 "0" remove_from_path_done
+  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+  remove_from_path_done:
+  Pop $0
 FunctionEnd
  
  



More information about the Gpg4win-commits mailing list