- reorganized DInput DLL
[wine] / dlls / setupapi / setupx_main.c
1 /*
2  *      SETUPX library
3  *
4  *      Copyright 1998,2000  Andreas Mohr
5  *
6  * FIXME: Rather non-functional functions for now.
7  *
8  * See:
9  * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
10  * http://willemer.de/informatik/windows/inf_info.htm (German)
11  * http://www.microsoft.com/ddk/ddkdocs/win98ddk/devinst_12uw.htm
12  * DDK: setupx.h
13  * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
14  * http://www.rdrop.com/~cary/html/inf_faq.html
15  *
16  * Stuff tested with rs405deu.exe (German Acroread 4.05 setup)
17  */
18
19 #include <stdlib.h>
20 #include "winreg.h"
21 #include "wine/winuser16.h"
22 #include "setupx16.h"
23 #include "winerror.h"
24 #include "debugtools.h"
25
26 DEFAULT_DEBUG_CHANNEL(setupx);
27
28 /***********************************************************************
29  *              SURegOpenKey
30  */
31 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, LPHKEY retkey )
32 {
33     FIXME("(%x,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
34     return RegOpenKeyA( hkey, lpszSubKey, retkey );
35 }
36
37 /***********************************************************************
38  *              SURegQueryValueEx
39  */
40 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
41                                 LPDWORD lpdwReserved, LPDWORD lpdwType,
42                                 LPBYTE lpbData, LPDWORD lpcbData )
43 {
44     FIXME("(%x,%s,%p,%p,%p,%ld), semi-stub.\n",hkey,debugstr_a(lpszValueName),
45           lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
46     return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
47                                lpbData, lpcbData );
48 }
49
50 /*
51  * hwnd = parent window
52  * hinst = instance of SETUPX.DLL
53  * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
54  * Here "DefaultInstall" is the .inf file section to be installed (optional).
55  * 132 is the standard parameter, it seems.
56  * 133 means don't prompt user for reboot.
57  * 
58  * nCmdShow = nCmdShow of CreateProcess
59  * FIXME: is the return type correct ?
60  */
61 DWORD WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
62 {
63     FIXME("(%04x, %04x, %s, %d), stub.\n", hwnd, hinst, lpszCmdLine, nCmdShow);
64     return 0;
65 }
66
67 typedef struct
68 {
69     LPCSTR RegValName;
70     LPCSTR StdString; /* fallback string; sub dir of windows directory */
71 } LDID_DATA;
72
73 static LDID_DATA LDID_Data[34] =
74 {
75     { /* 0 (LDID_NULL) -- not defined */
76         NULL,
77         NULL
78     },
79     { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
80         "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
81         NULL
82     },
83     { /* 2 (LDID_SETUPTEMP) = setup temp dir */
84         "SetupTempDir",
85         NULL
86     },
87     { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
88         "UninstallDir",
89         NULL
90     },
91     { /* 4 (LDID_BACKUP) = backup dir */
92         "BackupDir",
93         NULL
94     },
95     { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
96         "SetupScratchDir",
97         NULL
98     },
99     { /* 6 -- not defined */
100         NULL,
101         NULL
102     },
103     { /* 7 -- not defined */
104         NULL,
105         NULL
106     },
107     { /* 8 -- not defined */
108         NULL,
109         NULL
110     },
111     { /* 9 -- not defined */
112         NULL,
113         NULL
114     },
115     { /* 10 (LDID_WIN) = windows dir */
116         "WinDir",
117         ""
118     },
119     { /* 11 (LDID_SYS) = system dir */
120         "SysDir",
121         NULL /* call GetSystemDirectory() instead */
122     },
123     { /* 12 (LDID_IOS) = IOSubSys dir */
124         NULL, /* FIXME: registry string ? */
125         "SYSTEM\\IOSUBSYS"
126     },
127     { /* 13 (LDID_CMD) = COMMAND dir */
128         NULL, /* FIXME: registry string ? */
129         "COMMAND"
130     },
131     { /* 14 (LDID_CPL) = control panel dir */
132         NULL,
133         ""
134     },
135     { /* 15 (LDID_PRINT) = windows printer dir */
136         NULL,
137         "SYSTEM" /* correct ?? */
138     },
139     { /* 16 (LDID_MAIL) = destination mail dir */
140         NULL,
141         ""
142     },
143     { /* 17 (LDID_INF) = INF dir */
144         "SetupScratchDir", /* correct ? */
145         "INF"
146     },
147     { /* 18 (LDID_HELP) = HELP dir */
148         NULL, /* ??? */
149         "HELP"
150     },
151     { /* 19 (LDID_WINADMIN) = Admin dir */
152         "WinAdminDir",
153         ""
154     },
155     { /* 20 (LDID_FONTS) = Fonts dir */
156         NULL, /* ??? */
157         "FONTS"
158     },
159     { /* 21 (LDID_VIEWERS) = Viewers */
160         NULL, /* ??? */
161         "SYSTEM\\VIEWERS"
162     },
163     { /* 22 (LDID_VMM32) = VMM32 dir */
164         NULL, /* ??? */
165         "SYSTEM\\VMM32"
166     },
167     { /* 23 (LDID_COLOR) = ICM dir */
168         "ICMPath",
169         "SYSTEM\\COLOR"
170     },
171     { /* 24 (LDID_APPS) = root of boot drive ? */
172         "AppsDir",
173         "C:\\"
174     },
175     { /* 25 (LDID_SHARED) = shared dir */
176         "SharedDir",
177         ""
178     },
179     { /* 26 (LDID_WINBOOT) = Windows boot dir */
180         "WinBootDir",
181         ""
182     },
183     { /* 27 (LDID_MACHINE) = machine specific files */
184         "MachineDir",
185         NULL
186     },
187     { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
188         "HostWinBootDir",
189         NULL
190     },
191     { /* 29 -- not defined */
192         NULL,
193         NULL
194     },
195     { /* 30 (LDID_BOOT) = Root of boot drive */
196         "BootDir",
197         NULL
198     },
199     { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
200         "BootHost",
201         NULL
202     },
203     { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
204         "OldWinBootDir",
205         NULL
206     },
207     { /* 33 (LDID_OLD_WIN) = old win dir */
208         "OldWinDir",
209         NULL
210     }
211     /* the rest (34-38) isn't too interesting, so I'll forget about it */
212 };
213
214 /*
215  * Translate a logical disk identifier (LDID) into its string representation
216  */
217 BOOL SETUPX_TranslateLDID(int ldid, LPSTR buffer, WORD buflen)
218 {
219     BOOL handled = FALSE;
220
221     if ((ldid >= LDID_SRCPATH) && (ldid <= LDID_OLD_WIN))
222     {
223         if (LDID_Data[ldid].RegValName)
224         {
225             HKEY hKey;
226
227             if (RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey) == ERROR_SUCCESS)
228             {
229                 DWORD type, len = buflen;
230
231                 if ( (RegQueryValueExA(hKey, LDID_Data[ldid].RegValName,
232                         NULL, &type, buffer, &len) == ERROR_SUCCESS)
233                 &&   (type == REG_SZ) )
234                 {
235                     TRACE("found value '%s' for LDID %d\n", buffer, ldid);
236                     handled = TRUE;
237                 }
238
239                 RegCloseKey(hKey);
240             }
241         }
242     }
243     if (!handled)
244     {
245         switch(ldid)
246         {
247             case LDID_SRCPATH:
248                 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
249                 break;
250             case LDID_SYS:
251                 GetSystemDirectoryA(buffer, buflen);
252                 handled = TRUE;
253                 break;
254             case LDID_APPS:
255             case LDID_MACHINE:
256             case LDID_HOST_WINBOOT:
257             case LDID_BOOT:
258             case LDID_BOOT_HOST:
259                 strncpy(buffer, "C:\\", buflen);
260                 buffer[buflen-1] = '\0';
261                 handled = TRUE;
262                 break;
263             case 49001: /* what's this ???
264                            does this have to pop up a dialog or what ? */
265                 strncpy(buffer, "C:\\Program Files", buflen);
266                 buffer[buflen-1] = '\0';
267                 FIXME("what is LDID 49001 ?? returning %s for now.\n", buffer);
268                 handled = TRUE;
269                 break;
270             default:
271                 if (LDID_Data[ldid].StdString)
272                 {
273                     UINT len = GetWindowsDirectoryA(buffer, buflen);
274                     if (len <= buflen-1)
275                     {
276                         buffer += len;
277                         buflen -= len;
278                         *buffer++ = '\\';
279                         buflen--;
280                         strncpy(buffer, LDID_Data[ldid].StdString, buflen);
281                         buffer[buflen-1] = '\0';
282                     }
283                     handled = TRUE;
284                 }
285                 break;
286         }
287     }
288
289     if (!handled)
290         FIXME("unimplemented LDID %d\n", ldid);
291
292     return handled;
293 }
294
295 /*
296  * GenFormStrWithoutPlaceHolders
297  */
298 void WINAPI GenFormStrWithoutPlaceHolders16( LPSTR szDst, LPCSTR szSrc, HINF16 hInf)
299 {
300     LPCSTR pSrc = szSrc, pSrcEnd = szSrc + strlen(szSrc);
301     LPSTR pDst = szDst, p, pPHBegin;
302     int count;
303     
304     FIXME("(%p, '%s', %04x), semi stub.\n", szDst, szSrc, hInf);
305     while (pSrc < pSrcEnd)
306     {
307         p = strchr(pSrc, '%');
308         if (p)
309         {
310             count = (int)p - (int)pSrc;
311             strncpy(pDst, pSrc, count);
312             pSrc += count;
313             pDst += count;
314             pPHBegin = p+1;
315             p = strchr(pPHBegin, '%');
316             if (p)
317             {
318                 char placeholder[80]; /* that really ought to be enough ;) */
319                 int ldid;
320                 BOOL done = TRUE;
321                 count = (int)p - (int)pPHBegin;
322                 strncpy(placeholder, pPHBegin, count);
323                 placeholder[count] = '\0';
324                 ldid = atoi(placeholder);
325                 if (ldid)
326                 {
327                     done = SETUPX_TranslateLDID(ldid, pDst, 256);
328                     if (done)
329                         pDst += strlen(pDst);
330                 }
331                 else
332                 { /* hmm, string placeholder. Need to look up
333                      in the [strings] section of the hInf */
334                     DWORD ret;
335                     char buf[256]; /* long enough ? */
336                     
337                     ret = GetPrivateProfileStringA("strings", placeholder, "",
338                                         buf, 256, IP_GetFileName(hInf));
339                     if (ret)
340                     {
341                         strcpy(pDst, buf);
342                         pDst += strlen(buf);
343                     }
344                     else
345                     {
346                         ERR("placeholder string '%s' not found !\n", placeholder);
347                         done = FALSE;
348                     }
349                 }
350                 if (!done)
351                 { /* copy raw placeholder string over */
352                     count = (int)p - (int)pPHBegin + 2;
353                     strncpy(pDst, pPHBegin-1, count);
354                     pDst += count;
355                     
356                 }
357                 pSrc = p+1;
358                 continue;
359             }
360         }
361
362         /* copy the remaining source string over */
363         strncpy(pDst, pSrc, (int)pSrcEnd - (int)pSrc + 1);
364         break;
365     }
366     TRACE("ret '%s'\n", szDst);
367 }
368
369 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
370 {
371     FIXME("(%04x, %p), stub.\n", ldid, szPath);
372     strcpy(szPath, "FIXME_BogusLddPath");
373     return OK;
374 }
375
376 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
377 {
378     FIXME("(%04x, '%s'), stub.\n", ldid, szPath);
379     return OK;
380 }
381
382 RETERR16 WINAPI vcpOpen16(LPWORD p1, LPWORD p2)
383 {
384     FIXME("(%p, %p), stub.\n", p1, p2);
385     return OK;
386 }
387
388 RETERR16 WINAPI vcpClose16(WORD w1, WORD w2, WORD w3)
389 {
390     FIXME("(%04x, %04x %04x), stub.\n", w1, w2, w3);
391     return OK;
392 }
393
394 RETERR16 WINAPI GenInstall16(HINF16 hInfFile, LPCSTR szInstallSection, WORD wFlags)
395 {
396     FIXME("(%04x, '%s', %04x), stub. This doesn't install anything yet !\n", hInfFile, szInstallSection, wFlags);
397     return OK;
398 }