Add support for specific EOI PIC command.
[wine] / dlls / setupapi / setupx_main.c
1 /*
2  *      SETUPX library
3  *
4  *      Copyright 1998,2000  Andreas Mohr
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * FIXME: Rather non-functional functions for now.
21  *
22  * See:
23  * http://www.geocities.com/SiliconValley/Network/5317/drivers.html
24  * http://willemer.de/informatik/windows/inf_info.htm (German)
25  * http://www.microsoft.com/ddk/ddkdocs/win98ddk/devinst_12uw.htm
26  * DDK: setupx.h
27  * http://mmatrix.tripod.com/customsystemfolder/infsysntaxfull.html
28  * http://www.rdrop.com/~cary/html/inf_faq.html
29  * http://support.microsoft.com/support/kb/articles/q194/6/40.asp
30  *
31  * Stuff tested with:
32  * - rs405deu.exe (German Acroread 4.05 setup)
33  * - ie5setup.exe
34  * - Netmeeting
35  *
36  * FIXME:
37  * - string handling is... weird ;) (buflen etc.)
38  * - memory leaks ?
39  * - separate that mess (but probably only when it's done completely)
40  *
41  * SETUPX consists of several parts with the following acronyms/prefixes:
42  * Di   device installer (devinst.c ?)
43  * Gen  generic installer (geninst.c ?)
44  * Ip   .INF parsing (infparse.c)
45  * LDD  logical device descriptor (ldd.c ?)
46  * LDID logical device ID
47  * SU   setup (setup.c ?)
48  * Tp   text processing (textproc.c ?)
49  * Vcp  virtual copy module (vcp.c ?)
50  * ...
51  *
52  * The SETUPX DLL is NOT thread-safe. That's why many installers urge you to
53  * "close all open applications".
54  * All in all the design of it seems to be a bit weak.
55  * Not sure whether my implementation of it is better, though ;-)
56  */
57
58 #include <stdlib.h>
59 #include <stdio.h>
60 #include <string.h>
61 #include "winreg.h"
62 #include "winerror.h"
63 #include "wine/winuser16.h"
64 #include "wownt32.h"
65 #include "setupapi.h"
66 #include "setupx16.h"
67 #include "setupapi_private.h"
68 #include "winerror.h"
69 #include "wine/debug.h"
70
71 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
72
73 /***********************************************************************
74  *              SURegOpenKey (SETUPX.47)
75  */
76 DWORD WINAPI SURegOpenKey( HKEY hkey, LPCSTR lpszSubKey, PHKEY retkey )
77 {
78     FIXME("(%p,%s,%p), semi-stub.\n",hkey,debugstr_a(lpszSubKey),retkey);
79     return RegOpenKeyA( hkey, lpszSubKey, retkey );
80 }
81
82 /***********************************************************************
83  *              SURegQueryValueEx (SETUPX.50)
84  */
85 DWORD WINAPI SURegQueryValueEx( HKEY hkey, LPSTR lpszValueName,
86                                 LPDWORD lpdwReserved, LPDWORD lpdwType,
87                                 LPBYTE lpbData, LPDWORD lpcbData )
88 {
89     FIXME("(%p,%s,%p,%p,%p,%ld), semi-stub.\n",hkey,debugstr_a(lpszValueName),
90           lpdwReserved,lpdwType,lpbData,lpcbData?*lpcbData:0);
91     return RegQueryValueExA( hkey, lpszValueName, lpdwReserved, lpdwType,
92                                lpbData, lpcbData );
93 }
94
95 /*
96  * Returns pointer to a string list with the first entry being number
97  * of strings.
98  *
99  * Hmm. Should this be InitSubstrData(), GetFirstSubstr() and GetNextSubstr()
100  * instead?
101  */
102 static LPSTR *SETUPX_GetSubStrings(LPSTR start, char delimiter)
103 {
104     LPSTR p, q;
105     LPSTR *res = NULL;
106     DWORD count = 0;
107     int len;
108
109     p = start;
110
111     while (1)
112     {
113         /* find beginning of real substring */
114         while ( (*p == ' ') || (*p == '\t') || (*p == '"') ) p++;
115
116         /* find end of real substring */
117         q = p;
118         while ( (*q)
119              && (*q != ' ') && (*q != '\t') && (*q != '"')
120              && (*q != ';') && (*q != delimiter) ) q++;
121         if (q == p)
122             break;
123         len = (int)q - (int)p;
124
125         /* alloc entry for new substring in steps of 32 units and copy over */
126         if (count % 32 == 0)
127         { /* 1 for count field + current count + 32 */
128             res = HeapReAlloc(GetProcessHeap(), 0, res, (1+count+32)*sizeof(LPSTR));
129         }
130         *(res+1+count) = HeapAlloc(GetProcessHeap(), 0, len+1);
131         strncpy(*(res+1+count), p, len);
132         (*(res+1+count))[len] = '\0';
133         count++;
134
135         /* we are still within last substring (before delimiter),
136          * so get out of it */
137         while ((*q) && (*q != ';') && (*q != delimiter)) q++;
138         if ((!*q) || (*q == ';'))
139             break;
140         p = q+1;
141     }
142
143     /* put number of entries at beginning of list */
144     *(DWORD *)res = count;
145     return res;
146 }
147
148 static void SETUPX_FreeSubStrings(LPSTR *substr)
149 {
150     DWORD count = *(DWORD *)substr;
151     LPSTR *pStrings = substr+1;
152     DWORD n;
153
154     for (n=0; n < count; n++)
155         HeapFree(GetProcessHeap(), 0, *pStrings++);
156
157     HeapFree(GetProcessHeap(), 0, substr);
158 }
159
160
161 /***********************************************************************
162  *              InstallHinfSection (SETUPX.527)
163  *
164  * hwnd = parent window
165  * hinst = instance of SETUPX.DLL
166  * lpszCmdLine = e.g. "DefaultInstall 132 C:\MYINSTALL\MYDEV.INF"
167  * Here "DefaultInstall" is the .inf file section to be installed (optional).
168  * The 132 value is made of the HOW_xxx flags and sometimes 128 (-> setupx16.h).
169  *
170  * nCmdShow = nCmdShow of CreateProcess
171  */
172 RETERR16 WINAPI InstallHinfSection16( HWND16 hwnd, HINSTANCE16 hinst, LPCSTR lpszCmdLine, INT16 nCmdShow)
173 {
174     LPSTR *pSub;
175     DWORD count;
176     HINF16 hInf = 0;
177     RETERR16 res = OK, tmp;
178     WORD wFlags;
179     BOOL reboot = FALSE;
180
181     TRACE("(%04x, %04x, %s, %d);\n", hwnd, hinst, lpszCmdLine, nCmdShow);
182
183     pSub = SETUPX_GetSubStrings((LPSTR)lpszCmdLine, ' ');
184
185     count = *(DWORD *)pSub;
186     if (count < 2) /* invalid number of arguments ? */
187         goto end;
188     if (IpOpen16(*(pSub+count), &hInf) != OK)
189     {
190         res = ERROR_FILE_NOT_FOUND; /* yes, correct */
191         goto end;
192     }
193     if (VcpOpen16(NULL, 0))
194         goto end;
195     if (GenInstall16(hInf, *(pSub+count-2), GENINSTALL_DO_ALL) != OK)
196         goto end;
197     wFlags = atoi(*(pSub+count-1)) & ~128;
198     switch (wFlags)
199     {
200         case HOW_ALWAYS_SILENT_REBOOT:
201         case HOW_SILENT_REBOOT:
202             reboot = TRUE;
203             break;
204         case HOW_ALWAYS_PROMPT_REBOOT:
205         case HOW_PROMPT_REBOOT:
206             if (MessageBoxA(HWND_32(hwnd), "You must restart Wine before the new settings will take effect.\n\nDo you want to exit Wine now ?", "Systems Settings Change", MB_YESNO|MB_ICONQUESTION) == IDYES)
207                 reboot = TRUE;
208             break;
209         default:
210             ERR("invalid flags %d !\n", wFlags);
211             goto end;
212     }
213
214     res = OK;
215 end:
216     tmp = VcpClose16(VCPFL_ALL, NULL);
217     if (tmp != OK)
218         res = tmp;
219     tmp = IpClose16(hInf);
220     if (tmp != OK)
221         res = tmp;
222     SETUPX_FreeSubStrings(pSub);
223     if (reboot)
224     {
225         /* FIXME: we should have a means of terminating all wine + wineserver */
226         MESSAGE("Program or user told me to restart. Exiting Wine...\n");
227         ExitProcess(1);
228     }
229
230     return res;
231 }
232
233 typedef struct
234 {
235     LPCSTR RegValName;
236     LPCSTR StdString; /* fallback string; sub dir of windows directory */
237 } LDID_DATA;
238
239 static const LDID_DATA LDID_Data[34] =
240 {
241     { /* 0 (LDID_NULL) -- not defined */
242         NULL,
243         NULL
244     },
245     { /* 1 (LDID_SRCPATH) = source of installation. hmm, what to do here ? */
246         "SourcePath", /* hmm, does SETUPX have to care about updating it ?? */
247         NULL
248     },
249     { /* 2 (LDID_SETUPTEMP) = setup temp dir */
250         "SetupTempDir",
251         NULL
252     },
253     { /* 3 (LDID_UNINSTALL) = uninstall backup dir */
254         "UninstallDir",
255         NULL
256     },
257     { /* 4 (LDID_BACKUP) = backup dir */
258         "BackupDir",
259         NULL
260     },
261     { /* 5 (LDID_SETUPSCRATCH) = setup scratch dir */
262         "SetupScratchDir",
263         NULL
264     },
265     { /* 6 -- not defined */
266         NULL,
267         NULL
268     },
269     { /* 7 -- not defined */
270         NULL,
271         NULL
272     },
273     { /* 8 -- not defined */
274         NULL,
275         NULL
276     },
277     { /* 9 -- not defined */
278         NULL,
279         NULL
280     },
281     { /* 10 (LDID_WIN) = windows dir */
282         "WinDir",
283         ""
284     },
285     { /* 11 (LDID_SYS) = system dir */
286         "SysDir",
287         NULL /* call GetSystemDirectory() instead */
288     },
289     { /* 12 (LDID_IOS) = IOSubSys dir */
290         NULL, /* FIXME: registry string ? */
291         "SYSTEM\\IOSUBSYS"
292     },
293     { /* 13 (LDID_CMD) = COMMAND dir */
294         NULL, /* FIXME: registry string ? */
295         "COMMAND"
296     },
297     { /* 14 (LDID_CPL) = control panel dir */
298         NULL,
299         ""
300     },
301     { /* 15 (LDID_PRINT) = windows printer dir */
302         NULL,
303         "SYSTEM" /* correct ?? */
304     },
305     { /* 16 (LDID_MAIL) = destination mail dir */
306         NULL,
307         ""
308     },
309     { /* 17 (LDID_INF) = INF dir */
310         "SetupScratchDir", /* correct ? */
311         "INF"
312     },
313     { /* 18 (LDID_HELP) = HELP dir */
314         NULL, /* ??? */
315         "HELP"
316     },
317     { /* 19 (LDID_WINADMIN) = Admin dir */
318         "WinAdminDir",
319         ""
320     },
321     { /* 20 (LDID_FONTS) = Fonts dir */
322         NULL, /* ??? */
323         "FONTS"
324     },
325     { /* 21 (LDID_VIEWERS) = Viewers */
326         NULL, /* ??? */
327         "SYSTEM\\VIEWERS"
328     },
329     { /* 22 (LDID_VMM32) = VMM32 dir */
330         NULL, /* ??? */
331         "SYSTEM\\VMM32"
332     },
333     { /* 23 (LDID_COLOR) = ICM dir */
334         "ICMPath",
335         "SYSTEM\\COLOR"
336     },
337     { /* 24 (LDID_APPS) = root of boot drive ? */
338         "AppsDir",
339         "C:\\"
340     },
341     { /* 25 (LDID_SHARED) = shared dir */
342         "SharedDir",
343         ""
344     },
345     { /* 26 (LDID_WINBOOT) = Windows boot dir */
346         "WinBootDir",
347         ""
348     },
349     { /* 27 (LDID_MACHINE) = machine specific files */
350         "MachineDir",
351         NULL
352     },
353     { /* 28 (LDID_HOST_WINBOOT) = Host Windows boot dir */
354         "HostWinBootDir",
355         NULL
356     },
357     { /* 29 -- not defined */
358         NULL,
359         NULL
360     },
361     { /* 30 (LDID_BOOT) = Root of boot drive */
362         "BootDir",
363         NULL
364     },
365     { /* 31 (LDID_BOOT_HOST) = Root of boot drive host */
366         "BootHost",
367         NULL
368     },
369     { /* 32 (LDID_OLD_WINBOOT) = subdir of root */
370         "OldWinBootDir",
371         NULL
372     },
373     { /* 33 (LDID_OLD_WIN) = old win dir */
374         "OldWinDir",
375         NULL
376     }
377     /* the rest (34-38) isn't too interesting, so I'll forget about it */
378 };
379
380 /*
381  * LDD  == Logical Device Descriptor
382  * LDID == Logical Device ID
383  *
384  * The whole LDD/LDID business might go into a separate file named
385  * ldd.c.
386  * At the moment I don't know what the hell these functions are really doing.
387  * That's why I added reporting stubs.
388  * The only thing I do know is that I need them for the LDD/LDID infrastructure.
389  * That's why I implemented them in a way that's suitable for my purpose.
390  */
391 static LDD_LIST *pFirstLDD = NULL;
392
393 static BOOL std_LDDs_done = FALSE;
394
395 void SETUPX_CreateStandardLDDs(void)
396 {
397     HKEY hKey = 0;
398     WORD n;
399     DWORD type, len;
400     LOGDISKDESC_S ldd;
401     char buffer[MAX_PATH];
402
403     /* has to be here, otherwise loop */
404     std_LDDs_done = TRUE;
405
406     RegOpenKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup", &hKey);
407
408     for (n=0; n < sizeof(LDID_Data)/sizeof(LDID_DATA); n++)
409     {
410         buffer[0] = '\0';
411
412         len = MAX_PATH;
413         if ( (hKey) && (LDID_Data[n].RegValName)
414         &&   (RegQueryValueExA(hKey, LDID_Data[n].RegValName,
415                 NULL, &type, buffer, &len) == ERROR_SUCCESS)
416         &&   (type == REG_SZ) )
417         {
418             TRACE("found value '%s' for LDID %d\n", buffer, n);
419         }
420         else
421         switch(n)
422         {
423             case LDID_SRCPATH:
424                 FIXME("LDID_SRCPATH: what exactly do we have to do here ?\n");
425                 strcpy(buffer, "X:\\FIXME");
426                 break;
427             case LDID_SYS:
428                 GetSystemDirectoryA(buffer, MAX_PATH);
429                 break;
430             case LDID_APPS:
431             case LDID_MACHINE:
432             case LDID_HOST_WINBOOT:
433             case LDID_BOOT:
434             case LDID_BOOT_HOST:
435                 strcpy(buffer, "C:\\");
436                 break;
437             default:
438                 if (LDID_Data[n].StdString)
439                 {
440                     DWORD len = GetWindowsDirectoryA(buffer, MAX_PATH);
441                     LPSTR p;
442                     p = buffer + len;
443                     *p++ = '\\';
444                     strcpy(p, LDID_Data[n].StdString);
445                 }
446                 break;
447         }
448         if (buffer[0])
449         {
450             INIT_LDD(ldd, n);
451             ldd.pszPath = buffer;
452             TRACE("LDID %d -> '%s'\n", ldd.ldid, ldd.pszPath);
453             CtlSetLdd16(&ldd);
454         }
455     }
456     if (hKey) RegCloseKey(hKey);
457 }
458
459 /***********************************************************************
460  * CtlDelLdd            (SETUPX.37)
461  *
462  * RETURN
463  *   ERR_VCP_LDDINVALID if ldid < LDID_ASSIGN_START.
464  */
465 RETERR16 SETUPX_DelLdd(LOGDISKID16 ldid)
466 {
467     LDD_LIST *pCurr, *pPrev = NULL;
468
469     TRACE("(%d)\n", ldid);
470
471     if (!std_LDDs_done)
472         SETUPX_CreateStandardLDDs();
473
474     if (ldid < LDID_ASSIGN_START)
475         return ERR_VCP_LDDINVALID;
476
477     pCurr = pFirstLDD;
478     /* search until we find the appropriate LDD or hit the end */
479     while ((pCurr != NULL) && (ldid > pCurr->pldd->ldid))
480     {
481          pPrev = pCurr;
482          pCurr = pCurr->next;
483     }
484     if ( (pCurr == NULL) /* hit end of list */
485       || (ldid != pCurr->pldd->ldid) )
486         return ERR_VCP_LDDFIND; /* correct ? */
487
488     /* ok, found our victim: eliminate it */
489
490     if (pPrev)
491         pPrev->next = pCurr->next;
492
493     if (pCurr == pFirstLDD)
494         pFirstLDD = NULL;
495     HeapFree(GetProcessHeap(), 0, pCurr);
496
497     return OK;
498 }
499
500 /***********************************************************************
501  *              CtlDelLdd (SETUPX.37)
502  */
503 RETERR16 WINAPI CtlDelLdd16(LOGDISKID16 ldid)
504 {
505     FIXME("(%d); - please report this!\n", ldid);
506     return SETUPX_DelLdd(ldid);
507 }
508
509 /***********************************************************************
510  * CtlFindLdd           (SETUPX.35)
511  *
512  * doesn't check pldd ptr validity: crash (W98SE)
513  *
514  * RETURN
515  *   ERR_VCP_LDDINVALID if pldd->cbSize != structsize
516  *   1 in all other cases ??
517  *
518  */
519 RETERR16 WINAPI CtlFindLdd16(LPLOGDISKDESC pldd)
520 {
521     LDD_LIST *pCurr, *pPrev = NULL;
522
523     TRACE("(%p)\n", pldd);
524
525     if (!std_LDDs_done)
526         SETUPX_CreateStandardLDDs();
527
528     if (pldd->cbSize != sizeof(LOGDISKDESC_S))
529         return ERR_VCP_LDDINVALID;
530
531     pCurr = pFirstLDD;
532     /* search until we find the appropriate LDD or hit the end */
533     while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
534     {
535         pPrev = pCurr;
536         pCurr = pCurr->next;
537     }
538     if ( (pCurr == NULL) /* hit end of list */
539       || (pldd->ldid != pCurr->pldd->ldid) )
540         return ERR_VCP_LDDFIND; /* correct ? */
541
542     memcpy(pldd, pCurr->pldd, pldd->cbSize);
543     /* hmm, we probably ought to strcpy() the string ptrs here */
544
545     return 1; /* what is this ?? */
546 }
547
548 /***********************************************************************
549  * CtlSetLdd                    (SETUPX.33)
550  *
551  * Set an LDD entry.
552  *
553  * RETURN
554  *   ERR_VCP_LDDINVALID if pldd.cbSize != sizeof(LOGDISKDESC_S)
555  *
556  */
557 RETERR16 WINAPI CtlSetLdd16(LPLOGDISKDESC pldd)
558 {
559     LDD_LIST *pCurr, *pPrev = NULL;
560     LPLOGDISKDESC pCurrLDD;
561     HANDLE heap;
562     BOOL is_new = FALSE;
563
564     TRACE("(%p)\n", pldd);
565
566     if (!std_LDDs_done)
567         SETUPX_CreateStandardLDDs();
568
569     if (pldd->cbSize != sizeof(LOGDISKDESC_S))
570         return ERR_VCP_LDDINVALID;
571
572     heap = GetProcessHeap();
573     pCurr = pFirstLDD;
574     /* search until we find the appropriate LDD or hit the end */
575     while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
576     {
577          pPrev = pCurr;
578          pCurr = pCurr->next;
579     }
580     if (!pCurr || pldd->ldid != pCurr->pldd->ldid)
581     {
582         is_new = TRUE;
583         pCurr = HeapAlloc(heap, 0, sizeof(LDD_LIST));
584         pCurr->pldd = HeapAlloc(heap, 0, sizeof(LOGDISKDESC_S));
585         pCurr->next = NULL;
586         pCurrLDD = pCurr->pldd;
587     }
588     else
589     {
590         pCurrLDD = pCurr->pldd;
591         if (pCurrLDD->pszPath)          HeapFree(heap, 0, pCurrLDD->pszPath);
592         if (pCurrLDD->pszVolLabel)      HeapFree(heap, 0, pCurrLDD->pszVolLabel);
593         if (pCurrLDD->pszDiskName)      HeapFree(heap, 0, pCurrLDD->pszDiskName);
594     }
595
596     memcpy(pCurrLDD, pldd, sizeof(LOGDISKDESC_S));
597
598     if (pldd->pszPath)
599     {
600         pCurrLDD->pszPath = HeapAlloc( heap, 0, strlen(pldd->pszPath)+1 );
601         strcpy( pCurrLDD->pszPath, pldd->pszPath );
602     }
603     if (pldd->pszVolLabel)
604     {
605         pCurrLDD->pszVolLabel = HeapAlloc( heap, 0, strlen(pldd->pszVolLabel)+1 );
606         strcpy( pCurrLDD->pszVolLabel, pldd->pszVolLabel );
607     }
608     if (pldd->pszDiskName)
609     {
610         pCurrLDD->pszDiskName = HeapAlloc( heap, 0, strlen(pldd->pszDiskName)+1 );
611         strcpy( pCurrLDD->pszDiskName, pldd->pszDiskName );
612     }
613
614     if (is_new) /* link into list */
615     {
616         if (pPrev)
617         {
618             pCurr->next = pPrev->next;
619             pPrev->next = pCurr;
620         }
621         if (!pFirstLDD)
622             pFirstLDD = pCurr;
623     }
624
625     return OK;
626 }
627
628
629 /***********************************************************************
630  * CtlAddLdd            (SETUPX.36)
631  *
632  * doesn't check pldd ptr validity: crash (W98SE)
633  *
634  */
635 static LOGDISKID16 ldid_to_add = LDID_ASSIGN_START;
636 RETERR16 WINAPI CtlAddLdd16(LPLOGDISKDESC pldd)
637 {
638     pldd->ldid = ldid_to_add++;
639     return CtlSetLdd16(pldd);
640 }
641
642 /***********************************************************************
643  * CtlGetLdd            (SETUPX.34)
644  *
645  * doesn't check pldd ptr validity: crash (W98SE)
646  * What the !@#$%&*( is the difference between CtlFindLdd() and CtlGetLdd() ??
647  *
648  * RETURN
649  *   ERR_VCP_LDDINVALID if pldd->cbSize != structsize
650  *
651  */
652 static RETERR16 SETUPX_GetLdd(LPLOGDISKDESC pldd)
653 {
654     LDD_LIST *pCurr, *pPrev = NULL;
655
656     if (!std_LDDs_done)
657         SETUPX_CreateStandardLDDs();
658
659     if (pldd->cbSize != sizeof(LOGDISKDESC_S))
660         return ERR_VCP_LDDINVALID;
661
662     pCurr = pFirstLDD;
663     /* search until we find the appropriate LDD or hit the end */
664     while ((pCurr != NULL) && (pldd->ldid > pCurr->pldd->ldid))
665     {
666          pPrev = pCurr;
667          pCurr = pCurr->next;
668     }
669     if (pCurr == NULL) /* hit end of list */
670         return ERR_VCP_LDDFIND; /* correct ? */
671
672     memcpy(pldd, pCurr->pldd, pldd->cbSize);
673     /* hmm, we probably ought to strcpy() the string ptrs here */
674
675     return OK;
676 }
677
678 /**********************************************************************/
679
680 RETERR16 WINAPI CtlGetLdd16(LPLOGDISKDESC pldd)
681 {
682     FIXME("(%p); - please report this!\n", pldd);
683     return SETUPX_GetLdd(pldd);
684 }
685
686 /***********************************************************************
687  *              CtlGetLddPath           (SETUPX.38)
688  *
689  * Gets the path of an LDD.
690  * No crash if szPath == NULL.
691  * szPath has to be at least MAX_PATH_LEN bytes long.
692  * RETURN
693  *   ERR_VCP_LDDUNINIT if LDD for LDID not found.
694  */
695 RETERR16 WINAPI CtlGetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
696 {
697     TRACE("(%d, %p);\n", ldid, szPath);
698
699     if (szPath)
700     {
701         LOGDISKDESC_S ldd;
702         INIT_LDD(ldd, ldid);
703         if (CtlFindLdd16(&ldd) == ERR_VCP_LDDFIND)
704             return ERR_VCP_LDDUNINIT;
705         SETUPX_GetLdd(&ldd);
706         strcpy(szPath, ldd.pszPath);
707         TRACE("ret '%s' for LDID %d\n", szPath, ldid);
708     }
709     return OK;
710 }
711
712 /***********************************************************************
713  *              CtlSetLddPath           (SETUPX.508)
714  *
715  * Sets the path of an LDD.
716  * Creates LDD for LDID if not existing yet.
717  */
718 RETERR16 WINAPI CtlSetLddPath16(LOGDISKID16 ldid, LPSTR szPath)
719 {
720     LOGDISKDESC_S ldd;
721     TRACE("(%d, '%s');\n", ldid, szPath);
722
723     SetupSetDirectoryIdA( 0, ldid, szPath );
724     INIT_LDD(ldd, ldid);
725     ldd.pszPath = szPath;
726     return CtlSetLdd16(&ldd);
727 }