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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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, ...).
32 #include "wine/winbase16.h"
35 #include "setupapi_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(setupapi
);
40 #define MAX_HANDLES 16384
41 #define FIRST_HANDLE 32
43 static HINF handles
[MAX_HANDLES
];
46 static RETERR16
alloc_hinf16( HINF hinf
, HINF16
*hinf16
)
49 for (i
= 0; i
< MAX_HANDLES
; i
++)
54 *hinf16
= i
+ FIRST_HANDLE
;
58 return ERR_IP_OUT_OF_HANDLES
;
61 static HINF
get_hinf( HINF16 hinf16
)
63 int idx
= hinf16
- FIRST_HANDLE
;
64 if (idx
< 0 || idx
>= MAX_HANDLES
) return 0;
69 static HINF
free_hinf16( HINF16 hinf16
)
72 int idx
= hinf16
- FIRST_HANDLE
;
74 if (idx
< 0 || idx
>= MAX_HANDLES
) return 0;
80 /* convert last error code to a RETERR16 value */
81 static RETERR16
get_last_error(void)
83 switch(GetLastError())
85 case ERROR_EXPECTED_SECTION_NAME
:
86 case ERROR_BAD_SECTION_NAME_LINE
:
87 case ERROR_SECTION_NAME_TOO_LONG
: return ERR_IP_INVALID_SECT_NAME
;
88 case ERROR_SECTION_NOT_FOUND
: return ERR_IP_SECT_NOT_FOUND
;
89 case ERROR_LINE_NOT_FOUND
: return ERR_IP_LINE_NOT_FOUND
;
90 default: return IP_ERROR
; /* FIXME */
95 /***********************************************************************
99 RETERR16 WINAPI
IpOpen16( LPCSTR filename
, HINF16
*hinf16
)
101 HINF hinf
= SetupOpenInfFileA( filename
, NULL
, INF_STYLE_WIN4
, NULL
);
102 if (hinf
== (HINF
)INVALID_HANDLE_VALUE
) return get_last_error();
103 return alloc_hinf16( hinf
, hinf16
);
107 /***********************************************************************
110 RETERR16 WINAPI
IpClose16( HINF16 hinf16
)
112 HINF hinf
= free_hinf16( hinf16
);
113 if (!hinf
) return ERR_IP_INVALID_HINF
;
114 SetupCloseInfFile( hinf
);
119 /***********************************************************************
120 * IpGetProfileString (SETUPX.210)
122 RETERR16 WINAPI
IpGetProfileString16( HINF16 hinf16
, LPCSTR section
, LPCSTR entry
,
123 LPSTR buffer
, WORD buflen
)
126 HINF hinf
= get_hinf( hinf16
);
128 if (!hinf
) return ERR_IP_INVALID_HINF
;
129 if (!SetupGetLineTextA( NULL
, hinf
, section
, entry
, buffer
, buflen
, &required_size
))
130 return get_last_error();
131 TRACE("%p: section %s entry %s ret %s\n",
132 hinf
, debugstr_a(section
), debugstr_a(entry
), debugstr_a(buffer
) );
137 /***********************************************************************
138 * GenFormStrWithoutPlaceHolders (SETUPX.103)
140 * ought to be pretty much implemented, I guess...
142 void WINAPI
GenFormStrWithoutPlaceHolders16( LPSTR dst
, LPCSTR src
, HINF16 hinf16
)
145 HINF hinf
= get_hinf( hinf16
);
149 if (!RtlCreateUnicodeStringFromAsciiz( &srcW
, src
)) return;
150 PARSER_string_substA( hinf
, srcW
.Buffer
, dst
, MAX_INF_STRING_LENGTH
);
151 RtlFreeUnicodeString( &srcW
);
152 TRACE( "%s -> %s\n", debugstr_a(src
), debugstr_a(dst
) );
155 /***********************************************************************
156 * GenInstall (SETUPX.101)
158 * generic installer function for .INF file sections
160 * This is not perfect - patch whenever you can !
162 * wFlags == GENINSTALL_DO_xxx
164 * first call GENINSTALL_DO_REGSRCPATH | GENINSTALL_DO_FILES,
165 * second call GENINSTALL_DO_LOGCONFIG | CFGAUTO | INI2REG | REG | INI
167 RETERR16 WINAPI
GenInstall16( HINF16 hinf16
, LPCSTR section
, WORD genflags
)
170 HINF hinf
= get_hinf( hinf16
);
174 if (!hinf
) return ERR_IP_INVALID_HINF
;
176 if (genflags
& GENINSTALL_DO_FILES
) flags
|= SPINST_FILES
;
177 if (genflags
& GENINSTALL_DO_INI
) flags
|= SPINST_INIFILES
;
178 if (genflags
& GENINSTALL_DO_REG
) flags
|= SPINST_REGISTRY
;
179 if (genflags
& GENINSTALL_DO_INI2REG
) flags
|= SPINST_INI2REG
;
180 if (genflags
& GENINSTALL_DO_LOGCONFIG
) flags
|= SPINST_LOGCONFIG
;
181 if (genflags
& GENINSTALL_DO_REGSRCPATH
) FIXME( "unsupported flag: GENINSTALL_DO_REGSRCPATH\n" );
182 if (genflags
& GENINSTALL_DO_CFGAUTO
) FIXME( "unsupported flag: GENINSTALL_DO_CFGAUTO\n" );
183 if (genflags
& GENINSTALL_DO_PERUSER
) FIXME( "unsupported flag: GENINSTALL_DO_PERUSER\n" );
185 context
= SetupInitDefaultQueueCallback( 0 );
186 if (!SetupInstallFromInfSectionA( 0, hinf
, section
, flags
, 0, NULL
, 0,
187 SetupDefaultQueueCallbackA
, context
, 0, 0 ))
188 ret
= get_last_error();
190 SetupTermDefaultQueueCallback( context
);