https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c8ea82d67b7bd65b63316…
commit c8ea82d67b7bd65b633164d94e577c9dddd54bb6
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun May 21 23:48:09 2017 +0000
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun May 27 20:18:53 2018 +0200
[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
---
base/setup/usetup/inicache.c | 182 +++++++++++++++++++++++--------------------
base/setup/usetup/inicache.h | 7 ++
2 files changed, 106 insertions(+), 83 deletions(-)
diff --git a/base/setup/usetup/inicache.c b/base/setup/usetup/inicache.c
index 16f3e2e4e0..f509e59606 100644
--- a/base/setup/usetup/inicache.c
+++ b/base/setup/usetup/inicache.c
@@ -467,21 +467,13 @@ IniCacheGetKeyValue(
/* PUBLIC FUNCTIONS *********************************************************/
NTSTATUS
-IniCacheLoad(
+IniCacheLoadFromMemory(
PINICACHE *Cache,
- PWCHAR FileName,
+ PCHAR FileBuffer,
+ ULONG FileLength,
BOOLEAN String)
{
- UNICODE_STRING Name;
- OBJECT_ATTRIBUTES ObjectAttributes;
- FILE_STANDARD_INFORMATION FileInfo;
- IO_STATUS_BLOCK IoStatusBlock;
- HANDLE FileHandle;
- NTSTATUS Status;
- PCHAR FileBuffer;
- ULONG FileLength;
PCHAR Ptr;
- LARGE_INTEGER FileOffset;
PINICACHESECTION Section;
PINICACHEKEY Key;
@@ -495,6 +487,96 @@ IniCacheLoad(
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
+IniCacheLoad(
+ PINICACHE *Cache,
+ PWCHAR FileName,
+ BOOLEAN String)
+{
+ UNICODE_STRING Name;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ FILE_STANDARD_INFORMATION FileInfo;
+ IO_STATUS_BLOCK IoStatusBlock;
+ HANDLE FileHandle;
+ NTSTATUS Status;
+ PCHAR FileBuffer;
+ ULONG FileLength;
+ LARGE_INTEGER FileOffset;
+
*Cache = NULL;
/* Open ini file */
@@ -568,84 +650,18 @@ IniCacheLoad(
if (!NT_SUCCESS(Status))
{
DPRINT("NtReadFile() failed (Status %lx)\n", Status);
- RtlFreeHeap(ProcessHeap, 0, FileBuffer);
- return Status;
+ goto Quit;
}
- /* 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)
+ Status = IniCacheLoadFromMemory(Cache, FileBuffer, FileLength, String);
+ if (!NT_SUCCESS(Status))
{
- 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");
- }
- }
+ DPRINT1("IniCacheLoadFromMemory() failed (Status %lx)\n", Status);
}
- /* Free file buffer */
+Quit:
+ /* Free the file buffer, and return */
RtlFreeHeap(ProcessHeap, 0, FileBuffer);
-
return Status;
}
diff --git a/base/setup/usetup/inicache.h b/base/setup/usetup/inicache.h
index 3a26332ab9..8e12103e28 100644
--- a/base/setup/usetup/inicache.h
+++ b/base/setup/usetup/inicache.h
@@ -73,6 +73,13 @@ typedef enum
/* FUNCTIONS ****************************************************************/
+NTSTATUS
+IniCacheLoadFromMemory(
+ PINICACHE *Cache,
+ PCHAR FileBuffer,
+ ULONG FileLength,
+ BOOLEAN String);
+
NTSTATUS
IniCacheLoad(
PINICACHE *Cache,