2 * SetupX .inf file parsing functions
4 * Copyright 2000 Andreas Mohr for CodeWeavers
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * - this should be reimplemented at some point to have its own
23 * file parsing instead of using profile functions,
24 * as some SETUPX exports probably demand that
25 * (IpSaveRestorePosition, IpFindNextMatchLine, ...).
40 #include "setupapi_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
45 #define MAX_HANDLES 16384
46 #define FIRST_HANDLE 32
48 static HINF handles
[MAX_HANDLES
];
51 static RETERR16
alloc_hinf16( HINF hinf
, HINF16
*hinf16
)
54 for (i
= 0; i
< MAX_HANDLES
; i
++)
59 *hinf16
= i
+ FIRST_HANDLE
;
63 return ERR_IP_OUT_OF_HANDLES
;
66 static HINF
get_hinf( HINF16 hinf16
)
68 int idx
= hinf16
- FIRST_HANDLE
;
69 if (idx
< 0 || idx
>= MAX_HANDLES
) return 0;
74 static HINF
free_hinf16( HINF16 hinf16
)
77 int idx
= hinf16
- FIRST_HANDLE
;
79 if (idx
< 0 || idx
>= MAX_HANDLES
) return 0;
85 /* convert last error code to a RETERR16 value */
86 static RETERR16
get_last_error(void)
88 switch(GetLastError())
90 case ERROR_EXPECTED_SECTION_NAME
:
91 case ERROR_BAD_SECTION_NAME_LINE
:
92 case ERROR_SECTION_NAME_TOO_LONG
: return ERR_IP_INVALID_SECT_NAME
;
93 case ERROR_SECTION_NOT_FOUND
: return ERR_IP_SECT_NOT_FOUND
;
94 case ERROR_LINE_NOT_FOUND
: return ERR_IP_LINE_NOT_FOUND
;
95 default: return IP_ERROR
; /* FIXME */
100 /***********************************************************************
104 RETERR16 WINAPI
IpOpen16( LPCSTR filename
, HINF16
*hinf16
)
106 HINF hinf
= SetupOpenInfFileA( filename
, NULL
, INF_STYLE_WIN4
, NULL
);
107 if (hinf
== INVALID_HANDLE_VALUE
) return get_last_error();
108 return alloc_hinf16( hinf
, hinf16
);
112 /***********************************************************************
115 RETERR16 WINAPI
IpClose16( HINF16 hinf16
)
117 HINF hinf
= free_hinf16( hinf16
);
118 if (!hinf
) return ERR_IP_INVALID_HINF
;
119 SetupCloseInfFile( hinf
);
124 /***********************************************************************
125 * IpGetProfileString (SETUPX.210)
127 RETERR16 WINAPI
IpGetProfileString16( HINF16 hinf16
, LPCSTR section
, LPCSTR entry
,
128 LPSTR buffer
, WORD buflen
)
131 HINF hinf
= get_hinf( hinf16
);
133 if (!hinf
) return ERR_IP_INVALID_HINF
;
134 if (!SetupGetLineTextA( NULL
, hinf
, section
, entry
, buffer
, buflen
, &required_size
))
135 return get_last_error();
136 TRACE("%p: section %s entry %s ret %s\n",
137 hinf
, debugstr_a(section
), debugstr_a(entry
), debugstr_a(buffer
) );
142 /***********************************************************************
143 * GenFormStrWithoutPlaceHolders (SETUPX.103)
145 * ought to be pretty much implemented, I guess...
147 void WINAPI
GenFormStrWithoutPlaceHolders16( LPSTR dst
, LPCSTR src
, HINF16 hinf16
)
150 HINF hinf
= get_hinf( hinf16
);
154 if (!RtlCreateUnicodeStringFromAsciiz( &srcW
, src
)) return;
155 PARSER_string_substA( hinf
, srcW
.Buffer
, dst
, MAX_INF_STRING_LENGTH
);
156 RtlFreeUnicodeString( &srcW
);
157 TRACE( "%s -> %s\n", debugstr_a(src
), debugstr_a(dst
) );
160 /***********************************************************************
161 * GenInstall (SETUPX.101)
163 * generic installer function for .INF file sections
165 * This is not perfect - patch whenever you can !
167 * wFlags == GENINSTALL_DO_xxx
169 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
170 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
172 RETERR16 WINAPI
GenInstall16( HINF16 hinf16
, LPCSTR section
, WORD genflags
)
175 HINF hinf
= get_hinf( hinf16
);
179 if (!hinf
) return ERR_IP_INVALID_HINF
;
181 if (genflags
& GENINSTALL_DO_FILES
) flags
|= SPINST_FILES
;
182 if (genflags
& GENINSTALL_DO_INI
) flags
|= SPINST_INIFILES
;
183 if (genflags
& GENINSTALL_DO_REG
) flags
|= SPINST_REGISTRY
;
184 if (genflags
& GENINSTALL_DO_INI2REG
) flags
|= SPINST_INI2REG
;
185 if (genflags
& GENINSTALL_DO_LOGCONFIG
) flags
|= SPINST_LOGCONFIG
;
186 if (genflags
& GENINSTALL_DO_REGSRCPATH
) FIXME( "unsupported flag: GENINSTALL_DO_REGSRCPATH\n" );
187 if (genflags
& GENINSTALL_DO_CFGAUTO
) FIXME( "unsupported flag: GENINSTALL_DO_CFGAUTO\n" );
188 if (genflags
& GENINSTALL_DO_PERUSER
) FIXME( "unsupported flag: GENINSTALL_DO_PERUSER\n" );
190 context
= SetupInitDefaultQueueCallback( 0 );
191 if (!SetupInstallFromInfSectionA( 0, hinf
, section
, flags
, 0, NULL
,
192 SP_COPY_NEWER_OR_SAME
, SetupDefaultQueueCallbackA
,
194 ret
= get_last_error();
196 SetupTermDefaultQueueCallback( context
);