From 5644cdc1f5677efa1b5d9e4e9aa70c98b0e61e31 Mon Sep 17 00:00:00 2001
From: Andreas Mohr <a.mohr@mailto.de>
Date: Tue, 26 Sep 2000 22:46:36 +0000
Subject: [PATCH] Started some basic work on the more or less undocumented
 SETUPX functions.

---
 dlls/setupapi/Makefile.in   |  1 +
 dlls/setupapi/infparse.c    | 93 +++++++++++++++++++++++++++++++++++++
 dlls/setupapi/setupx.spec   | 20 ++++----
 dlls/setupapi/setupx16.h    | 42 +++++++++++++++++
 dlls/setupapi/setupx_main.c | 57 ++++++++++++++++++++++-
 5 files changed, 201 insertions(+), 12 deletions(-)
 create mode 100644 dlls/setupapi/infparse.c
 create mode 100644 dlls/setupapi/setupx16.h

diff --git a/dlls/setupapi/Makefile.in b/dlls/setupapi/Makefile.in
index 6efa6dc4647..6b4ee79f32d 100644
--- a/dlls/setupapi/Makefile.in
+++ b/dlls/setupapi/Makefile.in
@@ -8,6 +8,7 @@ ALTNAMES  = setupx
 IMPORTS   = advapi32 kernel32
 
 C_SRCS = \
+	infparse.c \
 	setupx_main.c \
 	stubs.c
 
diff --git a/dlls/setupapi/infparse.c b/dlls/setupapi/infparse.c
new file mode 100644
index 00000000000..9efad74531a
--- /dev/null
+++ b/dlls/setupapi/infparse.c
@@ -0,0 +1,93 @@
+/*
+ * SetupX .inf file parsing functions
+ *
+ * FIXME: return values ???
+ */
+
+#include "debugtools.h"
+#include "windef.h"
+#include "winbase.h"
+#include "wine/winbase16.h"
+#include "setupx16.h"
+
+DEFAULT_DEBUG_CHANNEL(setupx);
+
+WORD InfNumEntries = 0;
+INF_HANDLE *InfList = NULL;
+
+#define GET_INF_ENTRY(x) ((InfList - x)/4)
+
+RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf)
+{
+    HFILE16 hFile = _lopen16(lpInfFileName, OF_READ);
+
+    if (!lphInf)
+	return IP_ERROR;
+
+    if (hFile != HFILE_ERROR16)
+    {
+	InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1);
+	InfList[InfNumEntries].hInfFile = hFile;
+	InfList[InfNumEntries].lpInfFileName = lpInfFileName;
+	InfNumEntries++;
+        *lphInf = &InfList[InfNumEntries-1] - InfList;
+	return OK;
+    }
+    *lphInf = 0xffff;
+    return ERR_IP_INVALID_INFFILE;
+}
+
+LPCSTR IP_GetFileName(HINF16 hInf)
+{
+    if ((hInf <= (InfNumEntries*sizeof(INF_HANDLE *)))
+    && ((hInf & 3) == 0)) /* aligned ? */
+    {
+	return InfList[hInf/4].lpInfFileName;
+    }
+    return NULL;
+}
+
+RETERR16 IP_CloseInf(HINF16 hInf)
+{
+    int i;
+    HFILE16 res = ERR_IP_INVALID_HINF;
+
+    if ((hInf <= (InfNumEntries*sizeof(INF_HANDLE *)))
+    && ((hInf & 3) == 0)) /* aligned ? */
+    {
+	_lclose16(InfList[hInf/4].hInfFile);
+	res = OK;
+	for (i=hInf/4; i < InfNumEntries-1; i++)
+	    InfList[i] = InfList[i+1];
+	InfNumEntries--;
+	InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries);
+    }
+    return res;
+}
+
+/***********************************************************************
+ *		IpOpen16
+ *
+ */
+RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf)
+{
+    TRACE("('%s', %p)\n", lpInfFileName, lphInf);
+    return IP_OpenInf(lpInfFileName, lphInf);
+}
+
+/***********************************************************************
+ *		IpClose16
+ */
+RETERR16 WINAPI IpClose16(HINF16 hInf)
+{
+    return IP_CloseInf(hInf);
+}
+
+/***********************************************************************
+ *		IpGetProfileString16
+ */
+RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen) 
+{
+    GetPrivateProfileString16(section, entry, "", buffer, buflen, IP_GetFileName(hInf));
+    return 0;
+}
diff --git a/dlls/setupapi/setupx.spec b/dlls/setupapi/setupx.spec
index b8003ccb6f7..4b2f90ded0a 100644
--- a/dlls/setupapi/setupx.spec
+++ b/dlls/setupapi/setupx.spec
@@ -3,9 +3,9 @@ type    win16
 owner	setupapi
 
 1    stub     WEP
-2    stub     IPOPEN
+2    pascal16 IpOpen(str ptr) IpOpen16
 3    stub     IPOPENAPPEND
-4    stub     IPCLOSE
+4    pascal16 IpClose(word) IpClose16
 5    stub     IPGETLONGFIELD
 6    stub     IPGETSTRINGFIELD
 7    stub     IPFINDFIRSTLINE
@@ -39,7 +39,7 @@ owner	setupapi
 35   stub     CTLFINDLDD
 36   stub     CTLADDLDD
 37   stub     CTLDELLDD
-38   stub     CTLGETLDDPATH
+38   pascal16 CtlGetLddPath(word ptr) CtlGetLddPath16
 39   stub     SUREGCLOSEKEY
 40   stub     SUREGCREATEKEY
 41   stub     SUREGDELETEKEY
@@ -48,7 +48,7 @@ owner	setupapi
 44   stub     SUREGENUMVALUE
 45   stub     SUREGFLUSH
 46   stub     SUREGINIT
-47   pascal   SUregOpenKey(word str ptr) SURegOpenKey
+47   pascal   SURegOpenKey(word str ptr) SURegOpenKey
 48   stub     SUREGQUERYVALUE
 49   stub     SUREGQUERYVALUE16
 50   pascal   SURegQueryValueEx(long str ptr ptr ptr ptr) SURegQueryValueEx
@@ -64,9 +64,9 @@ owner	setupapi
 63   stub     SURPLSETUP
 64   stub     SUSTORELDIDPATH
 65   stub     WILDCARDSTRCMPI
-101  stub     GENINSTALL
+101  pascal16 GenInstall(word str word) GenInstall16
 102  stub     GENWININITRENAME
-103  stub     GENFORMSTRWITHOUTPLACEHOLDERS
+103  pascal   GenFormStrWithoutPlaceHolders(str str word) GenFormStrWithoutPlaceHolders16
 104  stub     SETUPX
 105  stub     CFGSETUPMERGE
 106  stub     INITDEPENDANTLDIDS
@@ -113,8 +113,8 @@ owner	setupapi
 160  stub     SXUPDATEDS
 170  stub     SUSETMEM
 171  stub     WRITEDMFBOOTDATA
-200  stub     VCPOPEN
-201  stub     VCPCLOSE
+200  pascal   vcpOpen(ptr str) vcpOpen16
+201  pascal   vcpClose(word word word) vcpClose16
 202  stub     VCPDEFCALLBACKPROC
 203  stub     VCPENUMFILES
 204  stub     VCPQUEUERENAME
@@ -123,7 +123,7 @@ owner	setupapi
 207  stub     VSMSTRINGADD
 208  stub     VSMGETSTRINGRAWNAME
 209  stub     IPSAVERESTOREPOSITION
-210  stub     IPGETPROFILESTRING
+210  pascal16 IpGetProfileString(word str str ptr word) IpGetProfileString16
 211  stub     IPOPENEX
 212  stub     IPOPENAPPENDEX
 213  stub     VCPUICALLBACKPROC
@@ -204,7 +204,7 @@ owner	setupapi
 504  stub     SXOCPAGEDLG
 506  stub     SXOCBATCHSETTINGS
 507  stub     SXOCFIXNEEDS
-508  stub     CTLSETLDDPATH
+508  pascal16 CtlSetLddPath(word str) CtlSetLddPath16
 509  stub     SXCALLOCPROC
 520  stub     DIBUILDCLASSDRVINFOLIST
 521  stub     DIBUILDCOMPATDRVINFOLIST
diff --git a/dlls/setupapi/setupx16.h b/dlls/setupapi/setupx16.h
new file mode 100644
index 00000000000..43845a3d2c0
--- /dev/null
+++ b/dlls/setupapi/setupx16.h
@@ -0,0 +1,42 @@
+#ifndef __WINE_SETUPX16_H
+#define __WINE_SETUPX16_H
+
+#include "wine/windef16.h"
+
+typedef UINT16 HINF16;
+typedef UINT16 LOGDISKID16;
+
+/* error codes stuff */
+
+typedef UINT16 RETERR16;
+#define OK		0
+#define IP_ERROR	(UINT16)100
+
+enum _IP_ERR {
+	ERR_IP_INVALID_FILENAME = IP_ERROR+1,
+	ERR_IP_ALLOC_ERR,
+	ERR_IP_INVALID_SECT_NAME,
+	ERR_IP_OUT_OF_HANDLES,
+	ERR_IP_INF_NOT_FOUND,
+	ERR_IP_INVALID_INFFILE,
+	ERR_IP_INVALID_HINF,
+	ERR_IP_INVALID_FIELD,
+	ERR_IP_SECTION_NOT_FOUND,
+	ERR_IP_END_OF_SECTION,
+	ERR_IP_PROFILE_NOT_FOUND,
+	ERR_IP_LINE_NOT_FOUND,
+	ERR_IP_FILEREAD,
+	ERR_IP_TOOMANYINFFILES,
+	ERR_IP_INVALID_SAVERESTORE,
+	ERR_IP_INVALID_INFTYPE
+};
+
+typedef struct {
+    HFILE16 hInfFile;
+    LPCSTR lpInfFileName;
+} INF_HANDLE;
+
+extern INF_HANDLE *InfList;
+extern WORD InfNumEntries;
+
+#endif /* __WINE_SETUPX16_H */
diff --git a/dlls/setupapi/setupx_main.c b/dlls/setupapi/setupx_main.c
index 9643f16bfe4..4131c1b6844 100644
--- a/dlls/setupapi/setupx_main.c
+++ b/dlls/setupapi/setupx_main.c
@@ -1,13 +1,23 @@
 /*
  *      SETUPX library
  *
- *      Copyright 1998  Andreas Mohr
+ *      Copyright 1998,2000  Andreas Mohr
  *
  * FIXME: Rather non-functional functions for now.
+ *
+ * See:
+ * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
+ * http://www.microsoft.com/ddk/ddkdocs/win98ddk/devinst_12uw.htm
+ * DDK: setupx.h
+ * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
+ * http://www.rdrop.com/~cary/html/inf_faq.html
+ *
+ * Stuff tested with rs405deu.exe (German Acroread 4.05 setup)
  */
 
 #include "winreg.h"
 #include "wine/winuser16.h"
+#include "setupx16.h"
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(setupx);
@@ -48,5 +58,48 @@ DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
 DWORD WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
 {
 	FIXME("(%04x, %04x, %s, %d), stub.\n", hwnd, hinst, lpszCmdLine, nCmdShow);
-	return 0;
+    return 0;
+}
+
+
+/*
+ * GenFormStrWithoutPlaceholders
+ *
+ * Any real docu ?
+ */
+void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
+{
+    FIXME("(%p, '%s', %04x), stub.\n", szDst, szSrc, hInf);
+    strcpy(szDst, szSrc);
+}
+
+RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
+{
+    FIXME("(%04x, %p), stub.\n", ldid, szPath);
+    strcpy(szPath, "FIXME_BogusLddPath");
+    return OK;
+}
+
+RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
+{
+    FIXME("(%04x, '%s'), stub.\n", ldid, szPath);
+    return OK;
+}
+
+RETERR16 WINAPI vcpOpen16(LPWORD p1, LPWORD p2)
+{
+    FIXME("(%p, %p, stub.\n", p1, p2);
+    return OK;
+}
+
+RETERR16 WINAPI vcpClose16(WORD w1, WORD w2, WORD w3)
+{
+    FIXME("(%04x, %04x %04x), stub.\n", w1, w2, w3);
+    return OK;
+}
+
+RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
+{
+    FIXME("(%04x, '%s', %04x), stub. This doesn't install anything yet !\n", hInfFile, szInstallSection, wFlags);
+    return OK;
 }
-- 
GitLab