| 1 | /* | 
|---|
| 2 | * SetupX .inf file parsing functions | 
|---|
| 3 | * | 
|---|
| 4 | * FIXME: | 
|---|
| 5 | * - return values ??? | 
|---|
| 6 | * - this should be reimplemented at some point to have its own | 
|---|
| 7 | *   file parsing instead of using profile functions, | 
|---|
| 8 | *   as some SETUPX exports probably demand that | 
|---|
| 9 | *   (IpSaveRestorePosition, IpFindNextMatchLine, ...). | 
|---|
| 10 | */ | 
|---|
| 11 |  | 
|---|
| 12 | #include "debugtools.h" | 
|---|
| 13 | #include "windef.h" | 
|---|
| 14 | #include "winbase.h" | 
|---|
| 15 | #include "heap.h" | 
|---|
| 16 | #include "wine/winbase16.h" | 
|---|
| 17 | #include "setupx16.h" | 
|---|
| 18 | #include "setupx_private.h" | 
|---|
| 19 |  | 
|---|
| 20 | DEFAULT_DEBUG_CHANNEL(setupx); | 
|---|
| 21 |  | 
|---|
| 22 | WORD InfNumEntries = 0; | 
|---|
| 23 | INF_FILE *InfList = NULL; | 
|---|
| 24 | HINF16 IP_curr_handle = 0; | 
|---|
| 25 |  | 
|---|
| 26 | RETERR16 IP_OpenInf(LPCSTR lpInfFileName, HINF16 *lphInf) | 
|---|
| 27 | { | 
|---|
| 28 | HFILE hFile = _lopen(lpInfFileName, OF_READ); | 
|---|
| 29 |  | 
|---|
| 30 | if (!lphInf) | 
|---|
| 31 | return IP_ERROR; | 
|---|
| 32 |  | 
|---|
| 33 | /* this could be improved by checking for already freed handles */ | 
|---|
| 34 | if (IP_curr_handle == 0xffff) | 
|---|
| 35 | return ERR_IP_OUT_OF_HANDLES; | 
|---|
| 36 |  | 
|---|
| 37 | if (hFile != HFILE_ERROR) | 
|---|
| 38 | { | 
|---|
| 39 | InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries+1); | 
|---|
| 40 | InfList[InfNumEntries].hInf = IP_curr_handle++; | 
|---|
| 41 | InfList[InfNumEntries].hInfFile = hFile; | 
|---|
| 42 | InfList[InfNumEntries].lpInfFileName = HeapAlloc( GetProcessHeap(), 0, | 
|---|
| 43 | strlen(lpInfFileName)+1); | 
|---|
| 44 | strcpy( InfList[InfNumEntries].lpInfFileName, lpInfFileName ); | 
|---|
| 45 | *lphInf = InfList[InfNumEntries].hInf; | 
|---|
| 46 | InfNumEntries++; | 
|---|
| 47 | TRACE("ret handle %d.\n", *lphInf); | 
|---|
| 48 | return OK; | 
|---|
| 49 | } | 
|---|
| 50 | *lphInf = 0xffff; | 
|---|
| 51 | return ERR_IP_INVALID_INFFILE; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | BOOL IP_FindInf(HINF16 hInf, WORD *ret) | 
|---|
| 55 | { | 
|---|
| 56 | WORD n; | 
|---|
| 57 |  | 
|---|
| 58 | for (n=0; n < InfNumEntries; n++) | 
|---|
| 59 | if (InfList[n].hInf == hInf) | 
|---|
| 60 | { | 
|---|
| 61 | *ret = n; | 
|---|
| 62 | return TRUE; | 
|---|
| 63 | } | 
|---|
| 64 | return FALSE; | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 | LPCSTR IP_GetFileName(HINF16 hInf) | 
|---|
| 69 | { | 
|---|
| 70 | WORD n; | 
|---|
| 71 | if (IP_FindInf(hInf, &n)) | 
|---|
| 72 | { | 
|---|
| 73 | return InfList[n].lpInfFileName; | 
|---|
| 74 | } | 
|---|
| 75 | return NULL; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | RETERR16 IP_CloseInf(HINF16 hInf) | 
|---|
| 79 | { | 
|---|
| 80 | int i; | 
|---|
| 81 | WORD n; | 
|---|
| 82 | RETERR16 res = ERR_IP_INVALID_HINF; | 
|---|
| 83 |  | 
|---|
| 84 | if (IP_FindInf(hInf, &n)) | 
|---|
| 85 | { | 
|---|
| 86 | _lclose(InfList[n].hInfFile); | 
|---|
| 87 | HeapFree(GetProcessHeap(), 0, InfList[n].lpInfFileName); | 
|---|
| 88 | for (i=n; i < InfNumEntries-1; i++) | 
|---|
| 89 | InfList[i] = InfList[i+1]; | 
|---|
| 90 | InfNumEntries--; | 
|---|
| 91 | InfList = HeapReAlloc(GetProcessHeap(), 0, InfList, InfNumEntries); | 
|---|
| 92 | res = OK; | 
|---|
| 93 | } | 
|---|
| 94 | return res; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | /*********************************************************************** | 
|---|
| 98 | *              IpOpen16 | 
|---|
| 99 | * | 
|---|
| 100 | */ | 
|---|
| 101 | RETERR16 WINAPI IpOpen16(LPCSTR lpInfFileName, HINF16 *lphInf) | 
|---|
| 102 | { | 
|---|
| 103 | TRACE("('%s', %p)\n", lpInfFileName, lphInf); | 
|---|
| 104 | return IP_OpenInf(lpInfFileName, lphInf); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | /*********************************************************************** | 
|---|
| 108 | *              IpClose16 | 
|---|
| 109 | */ | 
|---|
| 110 | RETERR16 WINAPI IpClose16(HINF16 hInf) | 
|---|
| 111 | { | 
|---|
| 112 | return IP_CloseInf(hInf); | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | /*********************************************************************** | 
|---|
| 116 | *              IpGetProfileString16 | 
|---|
| 117 | */ | 
|---|
| 118 | RETERR16 WINAPI IpGetProfileString16(HINF16 hInf, LPCSTR section, LPCSTR entry, LPSTR buffer, WORD buflen) | 
|---|
| 119 | { | 
|---|
| 120 | TRACE("'%s': section '%s' entry '%s'\n", IP_GetFileName(hInf), section, entry); | 
|---|
| 121 | GetPrivateProfileStringA(section, entry, "", buffer, buflen, IP_GetFileName(hInf)); | 
|---|
| 122 | return 0; | 
|---|
| 123 | } | 
|---|