2 * PROJECT: .inf file parser
3 * LICENSE: GPL - See COPYING in the top level directory
4 * COPYRIGHT: Copyright 2005 Ge van Geldorp <gvg@reactos.org>
7 /* INCLUDES *****************************************************************/
16 InfWriteFile(HINF InfHandle
,
17 PUNICODE_STRING FileName
,
18 PUNICODE_STRING HeaderComment
)
20 OBJECT_ATTRIBUTES ObjectAttributes
;
21 IO_STATUS_BLOCK IoStatusBlock
;
28 ULONG HeaderBufferSize
;
31 InfStatus
= InfpBuildFileBuffer((PINFCACHE
) InfHandle
, &Buffer
, &BufferSize
);
32 if (! INF_SUCCESS(InfStatus
))
34 DPRINT("Failed to create buffer (Status 0x%lx)\n", InfStatus
);
38 /* Open the inf file */
39 InitializeObjectAttributes(&ObjectAttributes
,
45 Status
= NtOpenFile(&FileHandle
,
46 GENERIC_WRITE
| SYNCHRONIZE
,
50 FILE_SYNCHRONOUS_IO_NONALERT
| FILE_NON_DIRECTORY_FILE
);
51 if (!INF_SUCCESS(Status
))
53 DPRINT1("NtOpenFile() failed (Status %lx)\n", Status
);
58 DPRINT("NtOpenFile() successful\n");
60 if (NULL
!= HeaderComment
&& 0 != HeaderComment
->Length
)
62 /* This is just a comment header, don't abort on errors here */
63 HeaderBufferSize
= HeaderComment
->Length
+ 7 * sizeof(WCHAR
);
64 HeaderBuffer
= MALLOC(HeaderBufferSize
);
65 if (NULL
!= HeaderBuffer
)
67 strcpyW(HeaderBuffer
, L
"; ");
68 for (Index
= 0; Index
< HeaderComment
->Length
/ sizeof(WCHAR
); Index
++)
70 HeaderBuffer
[2 + Index
] = HeaderComment
->Buffer
[Index
];
72 strcpyW(HeaderBuffer
+ (2 + HeaderComment
->Length
/ sizeof(WCHAR
)),
74 NtWriteFile(FileHandle
,
87 /* Write main contents */
88 Status
= NtWriteFile(FileHandle
,
101 if (!INF_SUCCESS(Status
))
103 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status
);
107 return STATUS_SUCCESS
;
111 InfFindOrAddSection(HINF InfHandle
,
113 PINFCONTEXT
*Context
)
115 return INF_SUCCESS(InfpFindOrAddSection((PINFCACHE
) InfHandle
,
120 InfHostAddLine(PINFCONTEXT Context
, PCWSTR Key
)
122 return INF_SUCCESS(InfpAddLineWithKey(Context
, Key
));
126 InfHostAddField(PINFCONTEXT Context
, PCWSTR Data
)
128 return INF_SUCCESS(InfpAddField(Context
, Data
));