Index: trunk/src/version/VERSION.DEF
===================================================================
--- trunk/src/version/VERSION.DEF	(revision 367)
+++ trunk/src/version/VERSION.DEF	(revision 369)
@@ -1,3 +1,3 @@
-; $Id: VERSION.DEF,v 1.3 1999-06-10 16:29:00 phaller Exp $
+; $Id: VERSION.DEF,v 1.4 1999-07-23 07:30:48 sandervl Exp $
 
 ;Created by BLAST for IBM's compiler
@@ -17,5 +17,6 @@
     VerLanguageNameW           = _VERSION_VerLanguageNameW@12        @10
     VerQueryValueA             = _VERSION_VerQueryValueA@16          @11
-;   VerQueryValueIndexA        = _VERSION_VerQueryValueIndexA@16     @12
-;   VerQueryValueIndexW        = _VERSION_VerQueryValueIndexW@16     @13
-    VerQueryValueW             = _VERSION_VerQueryValueW@16          @14
+    VerQueryValueW             = _VERSION_VerQueryValueW@16          @12
+;    VerQueryValueIndexA        = _VERSION_VerQueryValueIndexA@16     @12
+;    VerQueryValueIndexW        = _VERSION_VerQueryValueIndexW@16     @13
+;    VerQueryValueW             = _VERSION_VerQueryValueW@16          @14
Index: trunk/src/version/version.cpp
===================================================================
--- trunk/src/version/version.cpp	(revision 367)
+++ trunk/src/version/version.cpp	(revision 369)
@@ -1,3 +1,3 @@
-/* $Id: version.cpp,v 1.3 1999-06-10 16:29:00 phaller Exp $ */
+/* $Id: version.cpp,v 1.4 1999-07-23 07:30:49 sandervl Exp $ */
 
 /*
@@ -24,10 +24,4 @@
 
 
-/*
-#include "winver.h"
-#include "windef.h"
-*/
-
-
 /******************************************************************************/
 /******************************************************************************/
@@ -99,36 +93,167 @@
 /******************************************************************************/
 /******************************************************************************/
-BOOL WIN32API VERSION_VerQueryValueA(const LPVOID pBlock,
-                                     LPTSTR       lpSubBlock,
-                                     LPVOID       lplpBuffer,
-                                     PUINT        puLen)
-{
-  dprintf(("VERSION: VerQueryValueA(%08xh,%08xh,%08xh,%08xh) not implemented\n",
-           pBlock,
-           lpSubBlock,
-           lplpBuffer,
-           puLen));
-
-   return TRUE;
-}
-/******************************************************************************/
-/******************************************************************************/
-/*KSO Sun 24.05.1998*/
-BOOL WIN32API VERSION_VerQueryValueW(const LPVOID pBlock,
-                                     LPWSTR       lpSubBlock,
-                                     LPVOID       lplpBuffer,
-                                     PUINT        puLen)
-{
-   dprintf(("VERSION: VerQueryValueW(%08xh,%08xh,%08xh,%08xh) not implemented\n",
-            pBlock,
-            lpSubBlock,
-            lplpBuffer,
-            puLen));
-
-   return TRUE;
-}
-/******************************************************************************/
-/******************************************************************************/
-
+INT WIN32API lstrncmpiW( LPCWSTR str1, LPCWSTR str2, INT n )
+{
+    INT res;
+
+    if (!n) return 0;
+    while ((--n > 0) && *str1)
+    {
+        if ((res = towupper(*str1) - towupper(*str2)) != 0) return res;
+        str1++;
+        str2++;
+    }
+    return towupper(*str1) - towupper(*str2);
+}
+/***********************************************************************
+ *           VersionInfo16_FindChild             [internal]
+ */
+VS_VERSION_INFO_STRUCT16 *VersionInfo16_FindChild( VS_VERSION_INFO_STRUCT16 *info, 
+                                            LPCSTR szKey, UINT cbKey )
+{
+    VS_VERSION_INFO_STRUCT16 *child = VersionInfo16_Children( info );
+
+    while ( (DWORD)child < (DWORD)info + info->wLength )
+    {
+        if ( !strnicmp( child->szKey, szKey, cbKey ) )
+            return child;
+
+	if (!(child->wLength)) return NULL;
+        child = VersionInfo16_Next( child );
+    }
+
+    return NULL;
+}
+/***********************************************************************
+ *           VersionInfo32_FindChild             [internal]
+ */
+VS_VERSION_INFO_STRUCT32 *VersionInfo32_FindChild( VS_VERSION_INFO_STRUCT32 *info, 
+                                            LPCWSTR szKey, UINT cbKey )
+{
+    VS_VERSION_INFO_STRUCT32 *child = VersionInfo32_Children( info );
+
+    while ( (DWORD)child < (DWORD)info + info->wLength )
+    {
+        if ( !lstrncmpiW( child->szKey, szKey, cbKey ) )
+            return child;
+
+        child = VersionInfo32_Next( child );
+    }
+
+    return NULL;
+}
+/******************************************************************************/
+/******************************************************************************
+ *           VerQueryValue32W              [VERSION.13]
+ */
+BOOL WIN32API VERSION_VerQueryValueW( LPVOID pBlock, LPCWSTR lpSubBlock,
+                                      LPVOID *lplpBuffer, UINT *puLen )
+{
+    VS_VERSION_INFO_STRUCT32 *info = (VS_VERSION_INFO_STRUCT32 *)pBlock;
+    if ( VersionInfoIs16( info ) )
+    {
+        dprintf(("VERSION: called on NE resource!\n"));
+        return FALSE;
+    }
+
+    dprintf(("VERSION: (%p,%s,%p,%p)\n",
+             pBlock, lpSubBlock, lplpBuffer, puLen ));
+
+    while ( *lpSubBlock )
+    {
+        /* Find next path component */
+        LPCWSTR lpNextSlash;
+        for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
+            if ( *lpNextSlash == '\\' )
+                break;
+
+        /* Skip empty components */
+        if ( lpNextSlash == lpSubBlock )
+        {
+            lpSubBlock++;
+            continue;
+        }
+
+        /* We have a non-empty component: search info for key */
+        info = VersionInfo32_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
+        if ( !info ) return FALSE;
+
+        /* Skip path component */
+        lpSubBlock = lpNextSlash;
+    }
+
+    /* Return value */
+    *lplpBuffer = VersionInfo32_Value( info );
+    *puLen = info->wValueLength;
+
+    return TRUE;
+}
+/******************************************************************************/
+/******************************************************************************/
+/***********************************************************************
+ *           VerQueryValue32A              [VERSION.12]
+ */
+BOOL WIN32API VERSION_VerQueryValueA( LPVOID pBlock, LPCSTR lpSubBlock,
+                                      LPVOID *lplpBuffer, UINT *puLen )
+{
+    VS_VERSION_INFO_STRUCT16 *info = (VS_VERSION_INFO_STRUCT16 *)pBlock;
+    if ( !VersionInfoIs16( info ) )
+    {
+        // this is a quick hack, not much tested 
+        WCHAR *ustring = (WCHAR *)malloc(strlen((char *)lpSubBlock)*2+1);
+        LPVOID ubuffer;
+        char *abuffer;
+        UINT len = *puLen * 2;
+        BOOL rc;
+
+        dprintf(("VERSION: called on PE unicode resource!\n" ));
+
+        AsciiToUnicode((char *)lpSubBlock, ustring);
+        rc = VERSION_VerQueryValueW( pBlock, (LPCWSTR)ustring, &ubuffer, &len);
+        if(lpSubBlock[0] == '\\' && lpSubBlock[1] == 0)
+          *lplpBuffer = ubuffer;
+        else
+        {
+          *lplpBuffer = malloc(len+1); // no free, memory leak
+          UnicodeToAsciiN((WCHAR *)ubuffer, (char *)*lplpBuffer, len);
+        }
+        *puLen = len;
+        free(ustring);
+        return rc;
+    }
+
+    dprintf(("VERSION: (%p,%s,%p,%p)\n",
+             pBlock, lpSubBlock, lplpBuffer, puLen ));
+
+    while ( *lpSubBlock )
+    {
+        /* Find next path component */
+        LPCSTR lpNextSlash;
+        for ( lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++ )
+            if ( *lpNextSlash == '\\' )
+                break;
+
+        /* Skip empty components */
+        if ( lpNextSlash == lpSubBlock )
+        {
+            lpSubBlock++;
+            continue;
+        }
+
+        /* We have a non-empty component: search info for key */
+        info = VersionInfo16_FindChild( info, lpSubBlock, lpNextSlash-lpSubBlock );
+        if ( !info ) return FALSE;
+
+        /* Skip path component */
+        lpSubBlock = lpNextSlash;
+    }
+
+    /* Return value */
+    *lplpBuffer = VersionInfo16_Value( info );
+    *puLen = info->wValueLength;
+
+    return TRUE;
+}
+/******************************************************************************/
 
 
Index: trunk/src/version/version.h
===================================================================
--- trunk/src/version/version.h	(revision 367)
+++ trunk/src/version/version.h	(revision 369)
@@ -1,3 +1,3 @@
-/* $Id: version.h,v 1.2 1999-06-10 16:29:00 phaller Exp $ */
+/* $Id: version.h,v 1.3 1999-07-23 07:30:49 sandervl Exp $ */
 
 /* Definitions for the VERsion infolibrary (VER.DLL)
@@ -9,5 +9,6 @@
 #define __ODIN_VERSION_H
 
-#include "windef.h"
+#include <windef.h>
+#include <wctype.h>
 
 /* resource ids for different version infos */
@@ -137,4 +138,54 @@
 } VS_FIXEDFILEINFO;
 
+/***********************************************************************
+ * Version Info Structure
+ */
+
+typedef struct
+{
+    WORD  wLength;
+    WORD  wValueLength;
+    CHAR  szKey[1];
+#if 0   /* variable length structure */
+    /* DWORD aligned */
+    BYTE  Value[];
+    /* DWORD aligned */
+    VS_VERSION_INFO_STRUCT16 Children[];
+#endif
+} VS_VERSION_INFO_STRUCT16;
+
+typedef struct
+{
+    WORD  wLength;
+    WORD  wValueLength;
+    WORD  bText;
+    WCHAR szKey[1];
+#if 0   /* variable length structure */
+    /* DWORD aligned */
+    BYTE  Value[];
+    /* DWORD aligned */
+    VS_VERSION_INFO_STRUCT32 Children[];
+#endif
+} VS_VERSION_INFO_STRUCT32;
+
+#define VersionInfoIs16( ver ) \
+    ( ((VS_VERSION_INFO_STRUCT16 *)ver)->szKey[0] >= ' ' )
+
+#define VersionInfo16_Value( ver )  \
+    (LPBYTE)( ((DWORD)((ver)->szKey) + (lstrlenA((ver)->szKey)+1) + 3) & ~3 )
+#define VersionInfo32_Value( ver )  \
+    (LPBYTE)( ((DWORD)((ver)->szKey) + 2*(lstrlenW((ver)->szKey)+1) + 3) & ~3 )
+
+#define VersionInfo16_Children( ver )  \
+    (VS_VERSION_INFO_STRUCT16 *)( VersionInfo16_Value( ver ) + \
+                           ( ( (ver)->wValueLength + 3 ) & ~3 ) )
+#define VersionInfo32_Children( ver )  \
+    (VS_VERSION_INFO_STRUCT32 *)( VersionInfo32_Value( ver ) + \
+                           ( ( (ver)->wValueLength * \
+                               ((ver)->bText? 2 : 1) + 3 ) & ~3 ) )
+#define VersionInfo16_Next( ver ) \
+    (VS_VERSION_INFO_STRUCT16 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
+#define VersionInfo32_Next( ver ) \
+    (VS_VERSION_INFO_STRUCT32 *)( (LPBYTE)ver + (((ver)->wLength + 3) & ~3) )
 
 #ifndef RC_INVOKED
