mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[USETUP] Improve the inicache module.
From the existing IniCacheLoad() function, introduce a IniCacheLoadFromMemory() function that just does the same (initialize an INI file cache and parse the INI file), but takes the input from a memory buffer. Then, rewrite the IniCacheLoad() function to just open the file given in input, and then fall back to calling IniCacheLoadFromMemory. The IniCacheLoadFromMemory() function will be used later. svn path=/branches/setup_improvements/; revision=74620
This commit is contained in:
parent
38e988ace7
commit
c8ea82d67b
2 changed files with 108 additions and 85 deletions
|
@ -466,6 +466,101 @@ IniCacheGetKeyValue(
|
||||||
|
|
||||||
/* PUBLIC FUNCTIONS *********************************************************/
|
/* PUBLIC FUNCTIONS *********************************************************/
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
IniCacheLoadFromMemory(
|
||||||
|
PINICACHE *Cache,
|
||||||
|
PCHAR FileBuffer,
|
||||||
|
ULONG FileLength,
|
||||||
|
BOOLEAN String)
|
||||||
|
{
|
||||||
|
PCHAR Ptr;
|
||||||
|
|
||||||
|
PINICACHESECTION Section;
|
||||||
|
PINICACHEKEY Key;
|
||||||
|
|
||||||
|
PCHAR SectionName;
|
||||||
|
ULONG SectionNameSize;
|
||||||
|
|
||||||
|
PCHAR KeyName;
|
||||||
|
ULONG KeyNameSize;
|
||||||
|
|
||||||
|
PCHAR KeyValue;
|
||||||
|
ULONG KeyValueSize;
|
||||||
|
|
||||||
|
/* Allocate inicache header */
|
||||||
|
*Cache = (PINICACHE)RtlAllocateHeap(ProcessHeap,
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(INICACHE));
|
||||||
|
if (*Cache == NULL)
|
||||||
|
{
|
||||||
|
DPRINT("RtlAllocateHeap() failed\n");
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse ini file */
|
||||||
|
Section = NULL;
|
||||||
|
Ptr = FileBuffer;
|
||||||
|
while (Ptr != NULL && *Ptr != 0)
|
||||||
|
{
|
||||||
|
Ptr = IniCacheSkipWhitespace(Ptr);
|
||||||
|
if (Ptr == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (*Ptr == '[')
|
||||||
|
{
|
||||||
|
Section = NULL;
|
||||||
|
Ptr++;
|
||||||
|
|
||||||
|
Ptr = IniCacheGetSectionName(Ptr,
|
||||||
|
&SectionName,
|
||||||
|
&SectionNameSize);
|
||||||
|
|
||||||
|
DPRINT1("[%.*s]\n", SectionNameSize, SectionName);
|
||||||
|
|
||||||
|
Section = IniCacheAddSection(*Cache,
|
||||||
|
SectionName,
|
||||||
|
SectionNameSize);
|
||||||
|
if (Section == NULL)
|
||||||
|
{
|
||||||
|
DPRINT("IniCacheAddSection() failed\n");
|
||||||
|
Ptr = IniCacheSkipToNextSection(Ptr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Section == NULL)
|
||||||
|
{
|
||||||
|
Ptr = IniCacheSkipToNextSection(Ptr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ptr = IniCacheGetKeyName(Ptr,
|
||||||
|
&KeyName,
|
||||||
|
&KeyNameSize);
|
||||||
|
|
||||||
|
Ptr = IniCacheGetKeyValue(Ptr,
|
||||||
|
&KeyValue,
|
||||||
|
&KeyValueSize,
|
||||||
|
String);
|
||||||
|
|
||||||
|
DPRINT1("'%.*s' = '%.*s'\n", KeyNameSize, KeyName, KeyValueSize, KeyValue);
|
||||||
|
|
||||||
|
Key = IniCacheAddKey(Section,
|
||||||
|
KeyName,
|
||||||
|
KeyNameSize,
|
||||||
|
KeyValue,
|
||||||
|
KeyValueSize);
|
||||||
|
if (Key == NULL)
|
||||||
|
{
|
||||||
|
DPRINT("IniCacheAddKey() failed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
IniCacheLoad(
|
IniCacheLoad(
|
||||||
PINICACHE *Cache,
|
PINICACHE *Cache,
|
||||||
|
@ -480,21 +575,8 @@ IniCacheLoad(
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PCHAR FileBuffer;
|
PCHAR FileBuffer;
|
||||||
ULONG FileLength;
|
ULONG FileLength;
|
||||||
PCHAR Ptr;
|
|
||||||
LARGE_INTEGER FileOffset;
|
LARGE_INTEGER FileOffset;
|
||||||
|
|
||||||
PINICACHESECTION Section;
|
|
||||||
PINICACHEKEY Key;
|
|
||||||
|
|
||||||
PCHAR SectionName;
|
|
||||||
ULONG SectionNameSize;
|
|
||||||
|
|
||||||
PCHAR KeyName;
|
|
||||||
ULONG KeyNameSize;
|
|
||||||
|
|
||||||
PCHAR KeyValue;
|
|
||||||
ULONG KeyValueSize;
|
|
||||||
|
|
||||||
*Cache = NULL;
|
*Cache = NULL;
|
||||||
|
|
||||||
/* Open ini file */
|
/* Open ini file */
|
||||||
|
@ -568,84 +650,18 @@ IniCacheLoad(
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT("NtReadFile() failed (Status %lx)\n", Status);
|
DPRINT("NtReadFile() failed (Status %lx)\n", Status);
|
||||||
RtlFreeHeap(ProcessHeap, 0, FileBuffer);
|
goto Quit;
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate inicache header */
|
Status = IniCacheLoadFromMemory(Cache, FileBuffer, FileLength, String);
|
||||||
*Cache = (PINICACHE)RtlAllocateHeap(ProcessHeap,
|
if (!NT_SUCCESS(Status))
|
||||||
HEAP_ZERO_MEMORY,
|
|
||||||
sizeof(INICACHE));
|
|
||||||
if (*Cache == NULL)
|
|
||||||
{
|
{
|
||||||
DPRINT("RtlAllocateHeap() failed\n");
|
DPRINT1("IniCacheLoadFromMemory() failed (Status %lx)\n", Status);
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse ini file */
|
Quit:
|
||||||
Section = NULL;
|
/* Free the file buffer, and return */
|
||||||
Ptr = FileBuffer;
|
|
||||||
while (Ptr != NULL && *Ptr != 0)
|
|
||||||
{
|
|
||||||
Ptr = IniCacheSkipWhitespace(Ptr);
|
|
||||||
if (Ptr == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (*Ptr == '[')
|
|
||||||
{
|
|
||||||
Section = NULL;
|
|
||||||
Ptr++;
|
|
||||||
|
|
||||||
Ptr = IniCacheGetSectionName(Ptr,
|
|
||||||
&SectionName,
|
|
||||||
&SectionNameSize);
|
|
||||||
|
|
||||||
DPRINT1("[%.*s]\n", SectionNameSize, SectionName);
|
|
||||||
|
|
||||||
Section = IniCacheAddSection(*Cache,
|
|
||||||
SectionName,
|
|
||||||
SectionNameSize);
|
|
||||||
if (Section == NULL)
|
|
||||||
{
|
|
||||||
DPRINT("IniCacheAddSection() failed\n");
|
|
||||||
Ptr = IniCacheSkipToNextSection(Ptr);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Section == NULL)
|
|
||||||
{
|
|
||||||
Ptr = IniCacheSkipToNextSection(Ptr);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ptr = IniCacheGetKeyName(Ptr,
|
|
||||||
&KeyName,
|
|
||||||
&KeyNameSize);
|
|
||||||
|
|
||||||
Ptr = IniCacheGetKeyValue(Ptr,
|
|
||||||
&KeyValue,
|
|
||||||
&KeyValueSize,
|
|
||||||
String);
|
|
||||||
|
|
||||||
DPRINT1("'%.*s' = '%.*s'\n", KeyNameSize, KeyName, KeyValueSize, KeyValue);
|
|
||||||
|
|
||||||
Key = IniCacheAddKey(Section,
|
|
||||||
KeyName,
|
|
||||||
KeyNameSize,
|
|
||||||
KeyValue,
|
|
||||||
KeyValueSize);
|
|
||||||
if (Key == NULL)
|
|
||||||
{
|
|
||||||
DPRINT("IniCacheAddKey() failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free file buffer */
|
|
||||||
RtlFreeHeap(ProcessHeap, 0, FileBuffer);
|
RtlFreeHeap(ProcessHeap, 0, FileBuffer);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,13 @@ typedef enum
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
IniCacheLoadFromMemory(
|
||||||
|
PINICACHE *Cache,
|
||||||
|
PCHAR FileBuffer,
|
||||||
|
ULONG FileLength,
|
||||||
|
BOOLEAN String);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
IniCacheLoad(
|
IniCacheLoad(
|
||||||
PINICACHE *Cache,
|
PINICACHE *Cache,
|
||||||
|
|
Loading…
Reference in a new issue