diff cinst/nssstore_win.c @ 841:216a65d7fc4b

(issue66) Implement is_system_install and use it This has completly different implementations for linux and Windows. The commit also moves some code into util.c for better reuse.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 29 Jul 2014 18:12:57 +0200
parents 4aa33c408776
children 797aa8d9c785
line wrap: on
line diff
--- a/cinst/nssstore_win.c	Tue Jul 29 13:15:32 2014 +0200
+++ b/cinst/nssstore_win.c	Tue Jul 29 18:12:57 2014 +0200
@@ -171,114 +171,6 @@
     }
   return true;
 }
-
-/**@brief Read (and expand if necessary) a registry string.
- *
- * Reads a registry string and calls ExpandEnvironmentString
- * if necessary on it. Returns a newly allocated string array
- * with the expanded registry value converted to UTF-8
- *
- * Caller has to free return value with free.
- *
- * @param [in] root the root key (e.g. HKEY_LOCAL_MACHINE)
- * @param [in] key the key
- * @param [in] name the name of the value to read.
- *
- * @returns the expanded, null terminated utf-8 string of the value.
- *          or NULL on error.
- */
-static char*
-read_registry_string (const HKEY root, const wchar_t *key,
-                      const wchar_t *name)
-{
-  HKEY key_handle = NULL;
-  DWORD size = 0,
-        type = 0,
-        ex_size = 0,
-        dwRet = 0;
-  LONG ret = 0;
-  char *retval = NULL;
-  wchar_t *buf = NULL,
-          *ex_buf = NULL;
-  if (root == NULL || key == NULL || name == NULL)
-    {
-      ERRORPRINTF ("Invalid call to read_registry_string");
-      return NULL;
-    }
-
-  ret = RegOpenKeyExW (root, key, 0, KEY_READ, &key_handle);
-  if (ret != ERROR_SUCCESS)
-    {
-      ERRORPRINTF ("Failed to open key.");
-      return NULL;
-    }
-
-  /* Get the size */
-  ret = RegQueryValueExW (key_handle, name, 0, NULL, NULL, &size);
-  if (ret != ERROR_MORE_DATA && !(ret == ERROR_SUCCESS && size != 0))
-    {
-      ERRORPRINTF ("Failed to get required registry size.");
-      return retval;
-    }
-
-  /* Size is size in bytes not in characters */
-  buf = xmalloc (size + sizeof(wchar_t));
-
-  /* If the stored value is not zero terminated the returned value also
-     is not zero terminated. That's why we reserve more and ensure it's
-     initialized. */
-  memset (buf, 0, size + sizeof(wchar_t));
-
-  ret = RegQueryValueExW (key_handle, name, 0, &type, (LPBYTE) buf, &size);
-  if (ret != ERROR_SUCCESS)
-    {
-      ERRORPRINTF ("Failed get registry value.");
-      return retval;
-    }
-
-  if (type == REG_SZ || (type == REG_EXPAND_SZ && wcschr (buf, '%') == NULL))
-    {
-      /* Nothing to expand, we are done */
-      retval = wchar_to_utf8 (buf, wcslen (buf));
-      goto done;
-    }
-
-  if (type != REG_EXPAND_SZ)
-    {
-      ERRORPRINTF ("Unhandled registry type %i", type);
-      goto done;
-    }
-
-  /* Expand the registry string */
-  ex_size = ExpandEnvironmentStringsW (buf, NULL, 0);
-
-  if (ex_size == 0)
-    {
-      PRINTLASTERROR ("Failed to determine expanded environment size.");
-      goto done;
-    }
-
-  ex_buf = xmalloc ((ex_size + 1) * sizeof(wchar_t));
-
-  dwRet = ExpandEnvironmentStringsW (buf, ex_buf, ex_size);
-
-  ex_buf[ex_size] = '\0'; /* Make sure it's a string */
-
-  if (dwRet == 0 || dwRet != ex_size)
-    {
-      PRINTLASTERROR ("Failed to expand environment variables.");
-      goto done;
-    }
-
-  retval = wchar_to_utf8 (ex_buf, ex_size);
-
-done:
-  xfree (ex_buf);
-  xfree (buf);
-
-  RegCloseKey (key_handle);
-  return retval;
-}
 /**@brief Get the path to all users default registry hive
  *
  * Enumerates the keys in #PROFILE_LIST and retuns a

http://wald.intevation.org/projects/trustbridge/