mirror of
https://github.com/reactos/reactos.git
synced 2025-02-25 01:39:30 +00:00
Use Arc* infrastructure to read the .inf file
svn path=/trunk/; revision=42539
This commit is contained in:
parent
c2b74e4921
commit
945b08e99d
1 changed files with 80 additions and 64 deletions
|
@ -873,75 +873,86 @@ InfOpenFile(PHINF InfHandle,
|
||||||
PCSTR FileName,
|
PCSTR FileName,
|
||||||
PULONG ErrorLine)
|
PULONG ErrorLine)
|
||||||
{
|
{
|
||||||
PFILE FileHandle;
|
FILEINFORMATION Information;
|
||||||
|
ULONG FileId;
|
||||||
PCHAR FileBuffer;
|
PCHAR FileBuffer;
|
||||||
ULONG FileSize;
|
ULONG FileSize, Count;
|
||||||
PINFCACHE Cache;
|
PINFCACHE Cache;
|
||||||
BOOLEAN Success;
|
BOOLEAN Success;
|
||||||
|
LONG ret;
|
||||||
|
|
||||||
*InfHandle = NULL;
|
*InfHandle = NULL;
|
||||||
*ErrorLine = (ULONG)-1;
|
*ErrorLine = (ULONG)-1;
|
||||||
|
|
||||||
|
//
|
||||||
/* Open the inf file */
|
// Open the .inf file
|
||||||
FileHandle = FsOpenFile (FileName);
|
//
|
||||||
if (FileHandle == NULL)
|
FileId = FsOpenFile(FileName);
|
||||||
|
if (!FileId)
|
||||||
{
|
{
|
||||||
// DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DPRINT("NtOpenFile() successful\n");
|
//
|
||||||
|
// Query file size
|
||||||
/* Query file size */
|
//
|
||||||
FileSize = FsGetFileSize (FileHandle);
|
ret = ArcGetFileInformation(FileId, &Information);
|
||||||
if (FileSize == 0)
|
if (ret != ESUCCESS || Information.EndingAddress.HighPart != 0)
|
||||||
{
|
{
|
||||||
// DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status);
|
ArcClose(FileId);
|
||||||
FsCloseFile (FileHandle);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
FileSize = Information.EndingAddress.LowPart;
|
||||||
|
|
||||||
// DPRINT("File size: %lu\n", FileLength);
|
//
|
||||||
|
// Allocate buffer to cache the file
|
||||||
/* Allocate file buffer */
|
//
|
||||||
FileBuffer = MmHeapAlloc(FileSize + 1);
|
FileBuffer = MmHeapAlloc(FileSize + 1);
|
||||||
if (FileBuffer == NULL)
|
if (!FileBuffer)
|
||||||
{
|
{
|
||||||
// DPRINT1("RtlAllocateHeap() failed\n");
|
ArcClose(FileId);
|
||||||
FsCloseFile (FileHandle);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read file */
|
//
|
||||||
Success = FsReadFile(FileHandle, FileSize, NULL, FileBuffer);
|
// Read file into memory
|
||||||
|
//
|
||||||
FsCloseFile (FileHandle);
|
ret = ArcRead(FileId, FileBuffer, FileSize, &Count);
|
||||||
if (!Success)
|
if (ret != ESUCCESS || Count != FileSize)
|
||||||
{
|
{
|
||||||
// DPRINT("FsReadFile() failed\n");
|
ArcClose(FileId);
|
||||||
MmHeapFree(FileBuffer);
|
MmHeapFree(FileBuffer);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append string terminator */
|
//
|
||||||
|
// We don't need the file anymore. Close it
|
||||||
|
//
|
||||||
|
ArcClose(FileId);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Append string terminator
|
||||||
|
//
|
||||||
FileBuffer[FileSize] = 0;
|
FileBuffer[FileSize] = 0;
|
||||||
|
|
||||||
/* Allocate infcache header */
|
//
|
||||||
|
// Allocate infcache header
|
||||||
|
//
|
||||||
Cache = (PINFCACHE)MmHeapAlloc(sizeof(INFCACHE));
|
Cache = (PINFCACHE)MmHeapAlloc(sizeof(INFCACHE));
|
||||||
if (Cache == NULL)
|
if (!Cache)
|
||||||
{
|
{
|
||||||
// DPRINT("RtlAllocateHeap() failed\n");
|
|
||||||
MmHeapFree (FileBuffer);
|
MmHeapFree (FileBuffer);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize inicache header */
|
//
|
||||||
RtlZeroMemory(Cache,
|
// Initialize inicache header
|
||||||
sizeof(INFCACHE));
|
//
|
||||||
|
RtlZeroMemory(Cache, sizeof(INFCACHE));
|
||||||
|
|
||||||
/* Parse the inf buffer */
|
//
|
||||||
|
// Parse the inf buffer
|
||||||
|
//
|
||||||
Success = InfpParseBuffer(Cache,
|
Success = InfpParseBuffer(Cache,
|
||||||
FileBuffer,
|
FileBuffer,
|
||||||
FileBuffer + FileSize,
|
FileBuffer + FileSize,
|
||||||
|
@ -952,9 +963,14 @@ InfOpenFile(PHINF InfHandle,
|
||||||
Cache = NULL;
|
Cache = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free file buffer */
|
//
|
||||||
|
// Free file buffer, as it has been parsed
|
||||||
|
//
|
||||||
MmHeapFree(FileBuffer);
|
MmHeapFree(FileBuffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return .inf parsed contents
|
||||||
|
//
|
||||||
*InfHandle = (HINF)Cache;
|
*InfHandle = (HINF)Cache;
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
|
|
Loading…
Reference in a new issue