[SETUPLIB] Some INI support refactoring: function/struct names, duplicated code (#6815)

And convert ANSI strings to UNICODE in a better way instead of
zero-extending them.
This commit is contained in:
Hermès Bélusca-Maïto 2024-04-23 21:09:36 +02:00
parent cb6fc76b8b
commit 817c27a54e
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 291 additions and 444 deletions

View file

@ -232,7 +232,7 @@ InstallSetupInfFile(
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
#endif #endif
PINICACHESECTION IniSection; PINI_SECTION IniSection;
WCHAR PathBuffer[MAX_PATH]; WCHAR PathBuffer[MAX_PATH];
WCHAR UnattendInfPath[MAX_PATH]; WCHAR UnattendInfPath[MAX_PATH];
@ -241,35 +241,31 @@ InstallSetupInfFile(
if (!IniCache) if (!IniCache)
return; return;
IniSection = IniCacheAppendSection(IniCache, L"SetupParams"); IniSection = IniAddSection(IniCache, L"SetupParams");
if (IniSection) if (IniSection)
{ {
/* Key "skipmissingfiles" */ /* Key "skipmissingfiles" */
// RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), // RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
// L"\"%s\"", L"WinNt5.2"); // L"\"%s\"", L"WinNt5.2");
// IniCacheInsertKey(IniSection, NULL, INSERT_LAST, // IniAddKey(IniSection, L"Version", PathBuffer);
// L"Version", PathBuffer);
} }
IniSection = IniCacheAppendSection(IniCache, L"Data"); IniSection = IniAddSection(IniCache, L"Data");
if (IniSection) if (IniSection)
{ {
RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no"); L"\"%s\"", IsUnattendedSetup ? L"yes" : L"no");
IniCacheInsertKey(IniSection, NULL, INSERT_LAST, IniAddKey(IniSection, L"UnattendedInstall", PathBuffer);
L"UnattendedInstall", PathBuffer);
// "floppylessbootpath" (yes/no) // "floppylessbootpath" (yes/no)
RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
L"\"%s\"", L"winnt"); L"\"%s\"", L"winnt");
IniCacheInsertKey(IniSection, NULL, INSERT_LAST, IniAddKey(IniSection, L"ProductType", PathBuffer);
L"ProductType", PathBuffer);
RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
L"\"%s\\\"", pSetupData->SourceRootPath.Buffer); L"\"%s\\\"", pSetupData->SourceRootPath.Buffer);
IniCacheInsertKey(IniSection, NULL, INSERT_LAST, IniAddKey(IniSection, L"SourcePath", PathBuffer);
L"SourcePath", PathBuffer);
// "floppyless" ("0") // "floppyless" ("0")
} }

View file

@ -79,8 +79,8 @@ typedef struct _BOOT_STORE_INI_CONTEXT
PVOID ViewBase; PVOID ViewBase;
PINICACHE IniCache; PINICACHE IniCache;
PINICACHESECTION OptionsIniSection; PINI_SECTION OptionsIniSection;
PINICACHESECTION OsIniSection; PINI_SECTION OsIniSection;
} BOOT_STORE_INI_CONTEXT, *PBOOT_STORE_INI_CONTEXT; } BOOT_STORE_INI_CONTEXT, *PBOOT_STORE_INI_CONTEXT;
// TODO! // TODO!
@ -208,56 +208,41 @@ static VOID
CreateCommonFreeLdrSections( CreateCommonFreeLdrSections(
IN OUT PBOOT_STORE_INI_CONTEXT BootStore) IN OUT PBOOT_STORE_INI_CONTEXT BootStore)
{ {
PINICACHESECTION IniSection; PINI_SECTION IniSection;
/* /*
* Cache the "FREELOADER" section for our future usage. * Cache the "FREELOADER" section for our future usage.
*/ */
/* Get the "FREELOADER" section */ /* Get or create the "FREELOADER" section */
IniSection = IniCacheGetSection(BootStore->IniCache, L"FREELOADER"); IniSection = IniGetSection(BootStore->IniCache, L"FREELOADER");
if (!IniSection) if (!IniSection)
{ IniSection = IniAddSection(BootStore->IniCache, L"FREELOADER");
/* It does not exist yet, so create it */ if (!IniSection)
IniSection = IniCacheAppendSection(BootStore->IniCache, L"FREELOADER"); DPRINT1("CreateCommonFreeLdrSections: Failed to create 'FREELOADER' section!\n");
if (!IniSection)
{
DPRINT1("CreateCommonFreeLdrSections: Failed to create 'FREELOADER' section!\n");
}
}
BootStore->OptionsIniSection = IniSection; BootStore->OptionsIniSection = IniSection;
/* TimeOut */ /* TimeOut */
IniCacheInsertKey(BootStore->OptionsIniSection, NULL, INSERT_LAST, IniAddKey(BootStore->OptionsIniSection, L"TimeOut", L"0");
L"TimeOut", L"0");
/* Create "Display" section */ /* Create "Display" section */
IniSection = IniCacheAppendSection(BootStore->IniCache, L"Display"); IniSection = IniAddSection(BootStore->IniCache, L"Display");
/* TitleText */ /* TitleText and MinimalUI */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST, IniAddKey(IniSection, L"TitleText", L"ReactOS Boot Manager");
L"TitleText", L"ReactOS Boot Manager"); IniAddKey(IniSection, L"MinimalUI", L"Yes");
/* MinimalUI */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
L"MinimalUI", L"Yes");
/* /*
* Cache the "Operating Systems" section for our future usage. * Cache the "Operating Systems" section for our future usage.
*/ */
/* Get the "Operating Systems" section */ /* Get or create the "Operating Systems" section */
IniSection = IniCacheGetSection(BootStore->IniCache, L"Operating Systems"); IniSection = IniGetSection(BootStore->IniCache, L"Operating Systems");
if (!IniSection) if (!IniSection)
{ IniSection = IniAddSection(BootStore->IniCache, L"Operating Systems");
/* It does not exist yet, so create it */ if (!IniSection)
IniSection = IniCacheAppendSection(BootStore->IniCache, L"Operating Systems"); DPRINT1("CreateCommonFreeLdrSections: Failed to create 'Operating Systems' section!\n");
if (!IniSection)
{
DPRINT1("CreateCommonFreeLdrSections: Failed to create 'Operating Systems' section!\n");
}
}
BootStore->OsIniSection = IniSection; BootStore->OsIniSection = IniSection;
} }
@ -352,7 +337,7 @@ OpenIniBootLoaderStore(
} }
else else
{ {
PINICACHESECTION IniSection; PINI_SECTION IniSection;
/* /*
* Check whether the loader configuration INI file exists, * Check whether the loader configuration INI file exists,
@ -401,17 +386,12 @@ OpenIniBootLoaderStore(
* Cache the "FREELOADER" section for our future usage. * Cache the "FREELOADER" section for our future usage.
*/ */
/* Get the "FREELOADER" section */ /* Get or create the "FREELOADER" section */
IniSection = IniCacheGetSection(BootStore->IniCache, L"FREELOADER"); IniSection = IniGetSection(BootStore->IniCache, L"FREELOADER");
if (!IniSection) if (!IniSection)
{ IniSection = IniAddSection(BootStore->IniCache, L"FREELOADER");
/* It does not exist yet, so create it */ if (!IniSection)
IniSection = IniCacheAppendSection(BootStore->IniCache, L"FREELOADER"); DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'FREELOADER' section!\n");
if (!IniSection)
{
DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'FREELOADER' section!\n");
}
}
BootStore->OptionsIniSection = IniSection; BootStore->OptionsIniSection = IniSection;
@ -419,17 +399,12 @@ OpenIniBootLoaderStore(
* Cache the "Operating Systems" section for our future usage. * Cache the "Operating Systems" section for our future usage.
*/ */
/* Get the "Operating Systems" section */ /* Get or create the "Operating Systems" section */
IniSection = IniCacheGetSection(BootStore->IniCache, L"Operating Systems"); IniSection = IniGetSection(BootStore->IniCache, L"Operating Systems");
if (!IniSection) if (!IniSection)
{ IniSection = IniAddSection(BootStore->IniCache, L"Operating Systems");
/* It does not exist yet, so create it */ if (!IniSection)
IniSection = IniCacheAppendSection(BootStore->IniCache, L"Operating Systems"); DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'Operating Systems' section!\n");
if (!IniSection)
{
DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'Operating Systems' section!\n");
}
}
BootStore->OsIniSection = IniSection; BootStore->OsIniSection = IniSection;
} }
@ -476,28 +451,26 @@ OpenIniBootLoaderStore(
*/ */
/* Get the "boot loader" section */ /* Get the "boot loader" section */
IniSection = IniCacheGetSection(BootStore->IniCache, L"boot loader"); IniSection = IniGetSection(BootStore->IniCache, L"boot loader");
if (!IniSection) if (!IniSection)
{ {
/* Fall back to "flexboot" */ /* Fall back to "flexboot" */
IniSection = IniCacheGetSection(BootStore->IniCache, L"flexboot"); IniSection = IniGetSection(BootStore->IniCache, L"flexboot");
if (!IniSection) if (!IniSection)
{ {
/* Fall back to "multiboot" */ /* Fall back to "multiboot" */
IniSection = IniCacheGetSection(BootStore->IniCache, L"multiboot"); IniSection = IniGetSection(BootStore->IniCache, L"multiboot");
} }
} }
#if 0 #if 0
if (!IniSection) if (!IniSection)
{ {
/* It does not exist yet, so create it */ /* It does not exist yet, so create it */
IniSection = IniCacheAppendSection(BootStore->IniCache, L"boot loader"); IniSection = IniAddSection(BootStore->IniCache, L"boot loader");
if (!IniSection)
{
DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'boot loader' section!\n");
}
} }
#endif #endif
if (!IniSection)
DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'boot loader' section!\n");
BootStore->OptionsIniSection = IniSection; BootStore->OptionsIniSection = IniSection;
@ -506,18 +479,16 @@ OpenIniBootLoaderStore(
*/ */
/* Get the "Operating Systems" section */ /* Get the "Operating Systems" section */
IniSection = IniCacheGetSection(BootStore->IniCache, L"operating systems"); IniSection = IniGetSection(BootStore->IniCache, L"operating systems");
#if 0
if (!IniSection) if (!IniSection)
{ {
#if 0
/* It does not exist yet, so create it */ /* It does not exist yet, so create it */
IniSection = IniCacheAppendSection(BootStore->IniCache, L"operating systems"); IniSection = IniAddSection(BootStore->IniCache, L"operating systems");
if (!IniSection)
{
DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'operating systems' section!\n");
}
#endif
} }
#endif
if (!IniSection)
DPRINT1("OpenIniBootLoaderStore: Failed to retrieve 'operating systems' section!\n");
BootStore->OsIniSection = IniSection; BootStore->OsIniSection = IniSection;
} }
@ -785,15 +756,14 @@ CreateNTOSEntry(
IN ULONG_PTR BootEntryKey, IN ULONG_PTR BootEntryKey,
IN PBOOT_STORE_ENTRY BootEntry) IN PBOOT_STORE_ENTRY BootEntry)
{ {
PINICACHESECTION IniSection; PINI_SECTION IniSection;
PWCHAR Section = (PWCHAR)BootEntryKey; PCWSTR Section = (PCWSTR)BootEntryKey;
/* Insert the entry into the "Operating Systems" section */ /* Insert the entry into the "Operating Systems" section */
IniCacheInsertKey(BootStore->OsIniSection, NULL, INSERT_LAST, IniAddKey(BootStore->OsIniSection, Section, BootEntry->FriendlyName);
Section, (PWSTR)BootEntry->FriendlyName);
/* Create a new section */ /* Create a new section */
IniSection = IniCacheAppendSection(BootStore->IniCache, Section); IniSection = IniAddSection(BootStore->IniCache, Section);
if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) && if (BootEntry->OsOptionsLength >= sizeof(NTOS_OPTIONS) &&
RtlCompareMemory(&BootEntry->OsOptions /* Signature */, RtlCompareMemory(&BootEntry->OsOptions /* Signature */,
@ -803,17 +773,10 @@ CreateNTOSEntry(
{ {
PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions; PNTOS_OPTIONS Options = (PNTOS_OPTIONS)&BootEntry->OsOptions;
/* BootType */ /* BootType, SystemPath and Options */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST, IniAddKey(IniSection, L"BootType", L"Windows2003");
L"BootType", L"Windows2003"); IniAddKey(IniSection, L"SystemPath", Options->OsLoadPath);
IniAddKey(IniSection, L"Options", Options->OsLoadOptions);
/* SystemPath */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
L"SystemPath", (PWSTR)Options->OsLoadPath);
/* Options */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
L"Options", (PWSTR)Options->OsLoadOptions);
} }
else else
if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) && if (BootEntry->OsOptionsLength >= sizeof(BOOT_SECTOR_OPTIONS) &&
@ -824,21 +787,11 @@ CreateNTOSEntry(
{ {
PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions; PBOOT_SECTOR_OPTIONS Options = (PBOOT_SECTOR_OPTIONS)&BootEntry->OsOptions;
/* BootType */ /* BootType, BootDrive, BootPartition and BootSector */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST, IniAddKey(IniSection, L"BootType", L"BootSector");
L"BootType", L"BootSector"); IniAddKey(IniSection, L"BootDrive", Options->Drive);
IniAddKey(IniSection, L"BootPartition", Options->Partition);
/* BootDrive */ IniAddKey(IniSection, L"BootSectorFile", Options->BootSectorFileName);
IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
L"BootDrive", (PWSTR)Options->Drive);
/* BootPartition */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
L"BootPartition", (PWSTR)Options->Partition);
/* BootSector */
IniCacheInsertKey(IniSection, NULL, INSERT_LAST,
L"BootSectorFile", (PWSTR)Options->BootSectorFileName);
} }
else else
{ {
@ -935,8 +888,8 @@ AddBootStoreEntry(
} }
/* Insert the entry into the "Operating Systems" section */ /* Insert the entry into the "Operating Systems" section */
IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OsIniSection, NULL, INSERT_LAST, IniAddKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OsIniSection,
(PWSTR)Options->OsLoadPath, Buffer); Options->OsLoadPath, Buffer);
RtlFreeHeap(ProcessHeap, 0, Buffer); RtlFreeHeap(ProcessHeap, 0, Buffer);
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -1087,13 +1040,13 @@ QueryBootStoreOptions(
{ {
BootOptions->Version = FreeLdr; BootOptions->Version = FreeLdr;
Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, Status = IniGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
L"DefaultOS", (PWCHAR*)&BootOptions->CurrentBootEntryKey); L"DefaultOS", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
BootOptions->CurrentBootEntryKey = 0; BootOptions->CurrentBootEntryKey = 0;
Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, Status = IniGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
L"TimeOut", &TimeoutStr); L"TimeOut", &TimeoutStr);
if (NT_SUCCESS(Status) && TimeoutStr) if (NT_SUCCESS(Status) && TimeoutStr)
BootOptions->Timeout = _wtoi(TimeoutStr); BootOptions->Timeout = _wtoi(TimeoutStr);
else else
@ -1103,13 +1056,13 @@ QueryBootStoreOptions(
{ {
BootOptions->Version = NtLdr; BootOptions->Version = NtLdr;
Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, Status = IniGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
L"default", (PWCHAR*)&BootOptions->CurrentBootEntryKey); L"default", (PWCHAR*)&BootOptions->CurrentBootEntryKey);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
BootOptions->CurrentBootEntryKey = 0; BootOptions->CurrentBootEntryKey = 0;
Status = IniCacheGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, Status = IniGetKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
L"timeout", &TimeoutStr); L"timeout", &TimeoutStr);
if (NT_SUCCESS(Status) && TimeoutStr) if (NT_SUCCESS(Status) && TimeoutStr)
BootOptions->Timeout = _wtoi(TimeoutStr); BootOptions->Timeout = _wtoi(TimeoutStr);
else else
@ -1157,14 +1110,13 @@ SetBootStoreOptions(
// TODO: Depending on the flags set in 'FieldsToChange', // TODO: Depending on the flags set in 'FieldsToChange',
// change either one or both these bootloader options. // change either one or both these bootloader options.
// //
IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, IniAddKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
NULL, INSERT_LAST, L"DefaultOS", (PCWSTR)BootOptions->CurrentBootEntryKey);
L"DefaultOS", (PWCHAR)BootOptions->CurrentBootEntryKey);
RtlStringCchPrintfW(TimeoutStr, ARRAYSIZE(TimeoutStr), L"%d", BootOptions->Timeout); RtlStringCchPrintfW(TimeoutStr, ARRAYSIZE(TimeoutStr), L"%d", BootOptions->Timeout);
IniCacheInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection, IniInsertKey(((PBOOT_STORE_INI_CONTEXT)BootStore)->OptionsIniSection,
NULL, INSERT_FIRST, // INSERT_LAST, // FIXME!! There is a bug in the INI parser where a given key can be inserted twice in the same section... NULL, INSERT_FIRST, // INSERT_LAST, // FIXME!! There is a bug in the INI parser where a given key can be inserted twice in the same section...
L"TimeOut", TimeoutStr); L"TimeOut", TimeoutStr);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -1180,7 +1132,7 @@ FreeLdrEnumerateBootEntries(
{ {
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
PINICACHEITERATOR Iterator; PINICACHEITERATOR Iterator;
PINICACHESECTION OsIniSection; PINI_SECTION OsIniSection;
PWCHAR SectionName, KeyData; PWCHAR SectionName, KeyData;
UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) + UCHAR xxBootEntry[FIELD_OFFSET(BOOT_STORE_ENTRY, OsOptions) +
max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))]; max(sizeof(NTOS_OPTIONS), sizeof(BOOT_SECTOR_OPTIONS))];
@ -1188,7 +1140,7 @@ FreeLdrEnumerateBootEntries(
PWCHAR Buffer; PWCHAR Buffer;
/* Enumerate all the valid installations listed in the "Operating Systems" section */ /* Enumerate all the valid installations listed in the "Operating Systems" section */
Iterator = IniCacheFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData); Iterator = IniFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData);
if (!Iterator) return STATUS_SUCCESS; if (!Iterator) return STATUS_SUCCESS;
do do
{ {
@ -1243,13 +1195,13 @@ FreeLdrEnumerateBootEntries(
BootEntry->OsOptionsLength = 0; BootEntry->OsOptionsLength = 0;
/* Search for an existing boot entry section */ /* Search for an existing boot entry section */
OsIniSection = IniCacheGetSection(BootStore->IniCache, SectionName); OsIniSection = IniGetSection(BootStore->IniCache, SectionName);
if (!OsIniSection) if (!OsIniSection)
goto DoEnum; goto DoEnum;
/* Check for supported boot type "Windows2003" */ /* Check for supported boot type "Windows2003" */
Status = IniCacheGetKey(OsIniSection, L"BootType", &KeyData); Status = IniGetKey(OsIniSection, L"BootType", &KeyData);
if (!NT_SUCCESS(Status) || (KeyData == NULL)) if (!NT_SUCCESS(Status) || !KeyData)
{ {
/* Certainly not a ReactOS installation */ /* Certainly not a ReactOS installation */
DPRINT1("No BootType value present!\n"); DPRINT1("No BootType value present!\n");
@ -1273,18 +1225,16 @@ FreeLdrEnumerateBootEntries(
// BootEntry->BootFilePath = NULL; // BootEntry->BootFilePath = NULL;
/* Check its SystemPath */ /* Check its SystemPath */
Status = IniCacheGetKey(OsIniSection, L"SystemPath", &KeyData); Options->OsLoadPath = NULL;
if (!NT_SUCCESS(Status)) Status = IniGetKey(OsIniSection, L"SystemPath", &KeyData);
Options->OsLoadPath = NULL; if (NT_SUCCESS(Status))
else
Options->OsLoadPath = KeyData; Options->OsLoadPath = KeyData;
// KeyData == SystemRoot; // KeyData == SystemRoot;
/* Check the optional Options */ /* Check the optional Options */
Status = IniCacheGetKey(OsIniSection, L"Options", &KeyData); Options->OsLoadOptions = NULL;
if (!NT_SUCCESS(Status)) Status = IniGetKey(OsIniSection, L"Options", &KeyData);
Options->OsLoadOptions = NULL; if (NT_SUCCESS(Status))
else
Options->OsLoadOptions = KeyData; Options->OsLoadOptions = KeyData;
} }
else else
@ -1304,24 +1254,21 @@ FreeLdrEnumerateBootEntries(
// BootEntry->BootFilePath = NULL; // BootEntry->BootFilePath = NULL;
/* Check its BootDrive */ /* Check its BootDrive */
Status = IniCacheGetKey(OsIniSection, L"BootDrive", &KeyData); Options->Drive = NULL;
if (!NT_SUCCESS(Status)) Status = IniGetKey(OsIniSection, L"BootDrive", &KeyData);
Options->Drive = NULL; if (NT_SUCCESS(Status))
else
Options->Drive = KeyData; Options->Drive = KeyData;
/* Check its BootPartition */ /* Check its BootPartition */
Status = IniCacheGetKey(OsIniSection, L"BootPartition", &KeyData); Options->Partition = NULL;
if (!NT_SUCCESS(Status)) Status = IniGetKey(OsIniSection, L"BootPartition", &KeyData);
Options->Partition = NULL; if (NT_SUCCESS(Status))
else
Options->Partition = KeyData; Options->Partition = KeyData;
/* Check its BootSector */ /* Check its BootSector */
Status = IniCacheGetKey(OsIniSection, L"BootSectorFile", &KeyData); Options->BootSectorFileName = NULL;
if (!NT_SUCCESS(Status)) Status = IniGetKey(OsIniSection, L"BootSectorFile", &KeyData);
Options->BootSectorFileName = NULL; if (NT_SUCCESS(Status))
else
Options->BootSectorFileName = KeyData; Options->BootSectorFileName = KeyData;
} }
else else
@ -1342,9 +1289,9 @@ DoEnum:
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
break; break;
} }
while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData)); while (IniFindNextValue(Iterator, &SectionName, &KeyData));
IniCacheFindClose(Iterator); IniFindClose(Iterator);
return Status; return Status;
} }
@ -1365,7 +1312,7 @@ NtLdrEnumerateBootEntries(
ULONG BufferLength; ULONG BufferLength;
/* Enumerate all the valid installations */ /* Enumerate all the valid installations */
Iterator = IniCacheFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData); Iterator = IniFindFirstValue(BootStore->OsIniSection, &SectionName, &KeyData);
if (!Iterator) return STATUS_SUCCESS; if (!Iterator) return STATUS_SUCCESS;
do do
{ {
@ -1476,9 +1423,9 @@ NtLdrEnumerateBootEntries(
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
break; break;
} }
while (IniCacheFindNextValue(Iterator, &SectionName, &KeyData)); while (IniFindNextValue(Iterator, &SectionName, &KeyData));
IniCacheFindClose(Iterator); IniFindClose(Iterator);
return Status; return Status;
} }

View file

@ -17,11 +17,11 @@
/* PRIVATE FUNCTIONS ********************************************************/ /* PRIVATE FUNCTIONS ********************************************************/
static static
PINICACHEKEY PINI_KEYWORD
IniCacheFreeKey( IniCacheFreeKey(
PINICACHEKEY Key) PINI_KEYWORD Key)
{ {
PINICACHEKEY Next; PINI_KEYWORD Next;
if (Key == NULL) if (Key == NULL)
return NULL; return NULL;
@ -44,13 +44,12 @@ IniCacheFreeKey(
return Next; return Next;
} }
static static
PINICACHESECTION PINI_SECTION
IniCacheFreeSection( IniCacheFreeSection(
PINICACHESECTION Section) PINI_SECTION Section)
{ {
PINICACHESECTION Next; PINI_SECTION Next;
if (Section == NULL) if (Section == NULL)
return NULL; return NULL;
@ -73,15 +72,14 @@ IniCacheFreeSection(
return Next; return Next;
} }
static static
PINICACHEKEY PINI_KEYWORD
IniCacheFindKey( IniCacheFindKey(
PINICACHESECTION Section, PINI_SECTION Section,
PWCHAR Name, PWCHAR Name,
ULONG NameLength) ULONG NameLength)
{ {
PINICACHEKEY Key; PINI_KEYWORD Key;
Key = Section->FirstKey; Key = Section->FirstKey;
while (Key != NULL) while (Key != NULL)
@ -98,20 +96,19 @@ IniCacheFindKey(
return Key; return Key;
} }
static static
PINICACHEKEY PINI_KEYWORD
IniCacheAddKey( IniCacheAddKeyAorW(
PINICACHESECTION Section, _In_ PINI_SECTION Section,
PCHAR Name, _In_ PINI_KEYWORD AnchorKey,
ULONG NameLength, _In_ INSERTION_TYPE InsertionType,
PCHAR Data, _In_ const VOID* Name,
ULONG DataLength) _In_ ULONG NameLength,
_In_ const VOID* Data,
_In_ ULONG DataLength,
_In_ BOOLEAN IsUnicode)
{ {
PINICACHEKEY Key; PINI_KEYWORD Key = NULL;
ULONG i;
Key = NULL;
if (Section == NULL || if (Section == NULL ||
Name == NULL || Name == NULL ||
@ -123,16 +120,18 @@ IniCacheAddKey(
return NULL; return NULL;
} }
Key = (PINICACHEKEY)RtlAllocateHeap(ProcessHeap, /* Allocate key buffer */
Key = (PINI_KEYWORD)RtlAllocateHeap(ProcessHeap,
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(INICACHEKEY)); sizeof(INI_KEYWORD));
if (Key == NULL) if (Key == NULL)
{ {
DPRINT("RtlAllocateHeap() failed\n"); DPRINT("RtlAllocateHeap() failed\n");
return NULL; return NULL;
} }
Key->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap, /* Allocate name buffer */
Key->Name = (PWCHAR)RtlAllocateHeap(ProcessHeap,
0, 0,
(NameLength + 1) * sizeof(WCHAR)); (NameLength + 1) * sizeof(WCHAR));
if (Key->Name == NULL) if (Key->Name == NULL)
@ -142,14 +141,15 @@ IniCacheAddKey(
return NULL; return NULL;
} }
/* Copy value name */ /* Copy value name (ANSI or UNICODE) */
for (i = 0; i < NameLength; i++) if (IsUnicode)
{ wcsncpy(Key->Name, (PCWCH)Name, NameLength);
Key->Name[i] = (WCHAR)Name[i]; else
} _snwprintf(Key->Name, NameLength, L"%.*S", NameLength, (PCCH)Name);
Key->Name[NameLength] = 0; Key->Name[NameLength] = UNICODE_NULL;
Key->Data = (WCHAR*)RtlAllocateHeap(ProcessHeap, /* Allocate data buffer */
Key->Data = (PWCHAR)RtlAllocateHeap(ProcessHeap,
0, 0,
(DataLength + 1) * sizeof(WCHAR)); (DataLength + 1) * sizeof(WCHAR));
if (Key->Data == NULL) if (Key->Data == NULL)
@ -160,39 +160,65 @@ IniCacheAddKey(
return NULL; return NULL;
} }
/* Copy value data */ /* Copy value data (ANSI or UNICODE) */
for (i = 0; i < DataLength; i++) if (IsUnicode)
{ wcsncpy(Key->Data, (PCWCH)Data, DataLength);
Key->Data[i] = (WCHAR)Data[i]; else
} _snwprintf(Key->Data, DataLength, L"%.*S", DataLength, (PCCH)Data);
Key->Data[DataLength] = 0; Key->Data[DataLength] = UNICODE_NULL;
/* Insert key into section */
if (Section->FirstKey == NULL) if (Section->FirstKey == NULL)
{ {
Section->FirstKey = Key; Section->FirstKey = Key;
Section->LastKey = Key; Section->LastKey = Key;
} }
else else if ((InsertionType == INSERT_FIRST) ||
((InsertionType == INSERT_BEFORE) &&
((AnchorKey == NULL) || (AnchorKey == Section->FirstKey))))
{
/* Insert at the head of the list */
Section->FirstKey->Prev = Key;
Key->Next = Section->FirstKey;
Section->FirstKey = Key;
}
else if ((InsertionType == INSERT_BEFORE) && (AnchorKey != NULL))
{
/* Insert before the anchor key */
Key->Next = AnchorKey;
Key->Prev = AnchorKey->Prev;
AnchorKey->Prev->Next = Key;
AnchorKey->Prev = Key;
}
else if ((InsertionType == INSERT_LAST) ||
((InsertionType == INSERT_AFTER) &&
((AnchorKey == NULL) || (AnchorKey == Section->LastKey))))
{ {
Section->LastKey->Next = Key; Section->LastKey->Next = Key;
Key->Prev = Section->LastKey; Key->Prev = Section->LastKey;
Section->LastKey = Key; Section->LastKey = Key;
} }
else if ((InsertionType == INSERT_AFTER) && (AnchorKey != NULL))
{
/* Insert after the anchor key */
Key->Next = AnchorKey->Next;
Key->Prev = AnchorKey;
AnchorKey->Next->Prev = Key;
AnchorKey->Next = Key;
}
return Key; return Key;
} }
static static
PINICACHESECTION PINI_SECTION
IniCacheAddSection( IniCacheAddSectionAorW(
PINICACHE Cache, _In_ PINICACHE Cache,
PCHAR Name, _In_ const VOID* Name,
ULONG NameLength) _In_ ULONG NameLength,
_In_ BOOLEAN IsUnicode)
{ {
PINICACHESECTION Section = NULL; PINI_SECTION Section = NULL;
ULONG i;
if (Cache == NULL || Name == NULL || NameLength == 0) if (Cache == NULL || Name == NULL || NameLength == 0)
{ {
@ -200,9 +226,9 @@ IniCacheAddSection(
return NULL; return NULL;
} }
Section = (PINICACHESECTION)RtlAllocateHeap(ProcessHeap, Section = (PINI_SECTION)RtlAllocateHeap(ProcessHeap,
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
sizeof(INICACHESECTION)); sizeof(INI_SECTION));
if (Section == NULL) if (Section == NULL)
{ {
DPRINT("RtlAllocateHeap() failed\n"); DPRINT("RtlAllocateHeap() failed\n");
@ -210,7 +236,7 @@ IniCacheAddSection(
} }
/* Allocate and initialize section name */ /* Allocate and initialize section name */
Section->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap, Section->Name = (PWCHAR)RtlAllocateHeap(ProcessHeap,
0, 0,
(NameLength + 1) * sizeof(WCHAR)); (NameLength + 1) * sizeof(WCHAR));
if (Section->Name == NULL) if (Section->Name == NULL)
@ -220,12 +246,12 @@ IniCacheAddSection(
return NULL; return NULL;
} }
/* Copy section name */ /* Copy section name (ANSI or UNICODE) */
for (i = 0; i < NameLength; i++) if (IsUnicode)
{ wcsncpy(Section->Name, (PCWCH)Name, NameLength);
Section->Name[i] = (WCHAR)Name[i]; else
} _snwprintf(Section->Name, NameLength, L"%.*S", NameLength, (PCCH)Name);
Section->Name[NameLength] = 0; Section->Name[NameLength] = UNICODE_NULL;
/* Append section */ /* Append section */
if (Cache->FirstSection == NULL) if (Cache->FirstSection == NULL)
@ -243,7 +269,6 @@ IniCacheAddSection(
return Section; return Section;
} }
static static
PCHAR PCHAR
IniCacheSkipWhitespace( IniCacheSkipWhitespace(
@ -255,7 +280,6 @@ IniCacheSkipWhitespace(
return (*Ptr == 0) ? NULL : Ptr; return (*Ptr == 0) ? NULL : Ptr;
} }
static static
PCHAR PCHAR
IniCacheSkipToNextSection( IniCacheSkipToNextSection(
@ -274,7 +298,6 @@ IniCacheSkipToNextSection(
return (*Ptr == 0) ? NULL : Ptr; return (*Ptr == 0) ? NULL : Ptr;
} }
static static
PCHAR PCHAR
IniCacheGetSectionName( IniCacheGetSectionName(
@ -283,7 +306,6 @@ IniCacheGetSectionName(
PULONG NameSize) PULONG NameSize)
{ {
ULONG Size = 0; ULONG Size = 0;
CHAR Name[256];
*NamePtr = NULL; *NamePtr = NULL;
*NameSize = 0; *NameSize = 0;
@ -311,15 +333,11 @@ IniCacheGetSectionName(
*NameSize = Size; *NameSize = Size;
strncpy(Name, *NamePtr, Size); DPRINT("SectionName: '%.*s'\n", Size, *NamePtr);
Name[Size] = 0;
DPRINT("SectionName: '%s'\n", Name);
return Ptr; return Ptr;
} }
static static
PCHAR PCHAR
IniCacheGetKeyName( IniCacheGetKeyName(
@ -372,7 +390,6 @@ IniCacheGetKeyName(
return Ptr; return Ptr;
} }
static static
PCHAR PCHAR
IniCacheGetKeyValue( IniCacheGetKeyValue(
@ -457,8 +474,8 @@ IniCacheLoadFromMemory(
{ {
PCHAR Ptr; PCHAR Ptr;
PINICACHESECTION Section; PINI_SECTION Section;
PINICACHEKEY Key; PINI_KEYWORD Key;
PCHAR SectionName; PCHAR SectionName;
ULONG SectionNameSize; ULONG SectionNameSize;
@ -499,12 +516,13 @@ IniCacheLoadFromMemory(
DPRINT("[%.*s]\n", SectionNameSize, SectionName); DPRINT("[%.*s]\n", SectionNameSize, SectionName);
Section = IniCacheAddSection(*Cache, Section = IniCacheAddSectionAorW(*Cache,
SectionName, SectionName,
SectionNameSize); SectionNameSize,
FALSE);
if (Section == NULL) if (Section == NULL)
{ {
DPRINT("IniCacheAddSection() failed\n"); DPRINT("IniCacheAddSectionAorW() failed\n");
Ptr = IniCacheSkipToNextSection(Ptr); Ptr = IniCacheSkipToNextSection(Ptr);
continue; continue;
} }
@ -528,14 +546,17 @@ IniCacheLoadFromMemory(
DPRINT("'%.*s' = '%.*s'\n", KeyNameSize, KeyName, KeyValueSize, KeyValue); DPRINT("'%.*s' = '%.*s'\n", KeyNameSize, KeyName, KeyValueSize, KeyValue);
Key = IniCacheAddKey(Section, Key = IniCacheAddKeyAorW(Section,
KeyName, NULL,
KeyNameSize, INSERT_LAST,
KeyValue, KeyName,
KeyValueSize); KeyNameSize,
KeyValue,
KeyValueSize,
FALSE);
if (Key == NULL) if (Key == NULL)
{ {
DPRINT("IniCacheAddKey() failed\n"); DPRINT("IniCacheAddKeyAorW() failed\n");
} }
} }
} }
@ -575,7 +596,7 @@ IniCacheLoadByHandle(
DPRINT("File size: %lu\n", FileLength); DPRINT("File size: %lu\n", FileLength);
/* Allocate file buffer with NULL-terminator */ /* Allocate file buffer with NULL-terminator */
FileBuffer = (CHAR*)RtlAllocateHeap(ProcessHeap, FileBuffer = (PCHAR)RtlAllocateHeap(ProcessHeap,
0, 0,
FileLength + 1); FileLength + 1);
if (FileBuffer == NULL) if (FileBuffer == NULL)
@ -661,7 +682,6 @@ IniCacheLoad(
return Status; return Status;
} }
VOID VOID
IniCacheDestroy( IniCacheDestroy(
PINICACHE Cache) PINICACHE Cache)
@ -679,12 +699,12 @@ IniCacheDestroy(
} }
PINICACHESECTION PINI_SECTION
IniCacheGetSection( IniGetSection(
PINICACHE Cache, PINICACHE Cache,
PWCHAR Name) PWCHAR Name)
{ {
PINICACHESECTION Section = NULL; PINI_SECTION Section = NULL;
if (Cache == NULL || Name == NULL) if (Cache == NULL || Name == NULL)
{ {
@ -711,14 +731,13 @@ IniCacheGetSection(
return NULL; return NULL;
} }
NTSTATUS NTSTATUS
IniCacheGetKey( IniGetKey(
PINICACHESECTION Section, PINI_SECTION Section,
PWCHAR KeyName, PWCHAR KeyName,
PWCHAR *KeyData) PWCHAR *KeyData)
{ {
PINICACHEKEY Key; PINI_KEYWORD Key;
if (Section == NULL || KeyName == NULL || KeyData == NULL) if (Section == NULL || KeyName == NULL || KeyData == NULL)
{ {
@ -741,13 +760,13 @@ IniCacheGetKey(
PINICACHEITERATOR PINICACHEITERATOR
IniCacheFindFirstValue( IniFindFirstValue(
PINICACHESECTION Section, PINI_SECTION Section,
PWCHAR *KeyName, PWCHAR *KeyName,
PWCHAR *KeyData) PWCHAR *KeyData)
{ {
PINICACHEITERATOR Iterator; PINICACHEITERATOR Iterator;
PINICACHEKEY Key; PINI_KEYWORD Key;
if (Section == NULL || KeyName == NULL || KeyData == NULL) if (Section == NULL || KeyName == NULL || KeyData == NULL)
{ {
@ -780,14 +799,13 @@ IniCacheFindFirstValue(
return Iterator; return Iterator;
} }
BOOLEAN BOOLEAN
IniCacheFindNextValue( IniFindNextValue(
PINICACHEITERATOR Iterator, PINICACHEITERATOR Iterator,
PWCHAR *KeyName, PWCHAR *KeyName,
PWCHAR *KeyData) PWCHAR *KeyData)
{ {
PINICACHEKEY Key; PINI_KEYWORD Key;
if (Iterator == NULL || KeyName == NULL || KeyData == NULL) if (Iterator == NULL || KeyName == NULL || KeyData == NULL)
{ {
@ -810,9 +828,8 @@ IniCacheFindNextValue(
return TRUE; return TRUE;
} }
VOID VOID
IniCacheFindClose( IniFindClose(
PINICACHEITERATOR Iterator) PINICACHEITERATOR Iterator)
{ {
if (Iterator == NULL) if (Iterator == NULL)
@ -822,106 +839,46 @@ IniCacheFindClose(
} }
PINICACHEKEY PINI_SECTION
IniCacheInsertKey( IniAddSection(
PINICACHESECTION Section, _In_ PINICACHE Cache,
PINICACHEKEY AnchorKey, _In_ PCWSTR Name)
INSERTION_TYPE InsertionType,
PWCHAR Name,
PWCHAR Data)
{ {
PINICACHEKEY Key; if (!Cache || !Name || !*Name)
Key = NULL;
if (Section == NULL ||
Name == NULL ||
*Name == 0 ||
Data == NULL ||
*Data == 0)
{ {
DPRINT("Invalid parameter\n"); DPRINT("Invalid parameter\n");
return NULL; return NULL;
} }
return IniCacheAddSectionAorW(Cache, Name, wcslen(Name), TRUE);
}
/* Allocate key buffer */ PINI_KEYWORD
Key = (PINICACHEKEY)RtlAllocateHeap(ProcessHeap, IniInsertKey(
HEAP_ZERO_MEMORY, _In_ PINI_SECTION Section,
sizeof(INICACHEKEY)); _In_ PINI_KEYWORD AnchorKey,
if (Key == NULL) _In_ INSERTION_TYPE InsertionType,
_In_ PCWSTR Name,
_In_ PCWSTR Data)
{
if (!Section || !Name || !*Name || !Data || !*Data)
{ {
DPRINT("RtlAllocateHeap() failed\n"); DPRINT("Invalid parameter\n");
return NULL; return NULL;
} }
return IniCacheAddKeyAorW(Section,
AnchorKey, InsertionType,
Name, wcslen(Name),
Data, wcslen(Data),
TRUE);
}
/* Allocate name buffer */ PINI_KEYWORD
Key->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap, IniAddKey(
0, _In_ PINI_SECTION Section,
(wcslen(Name) + 1) * sizeof(WCHAR)); _In_ PCWSTR Name,
if (Key->Name == NULL) _In_ PCWSTR Data)
{ {
DPRINT("RtlAllocateHeap() failed\n"); return IniInsertKey(Section, NULL, INSERT_LAST, Name, Data);
RtlFreeHeap(ProcessHeap, 0, Key);
return NULL;
}
/* Copy value name */
wcscpy(Key->Name, Name);
/* Allocate data buffer */
Key->Data = (WCHAR*)RtlAllocateHeap(ProcessHeap,
0,
(wcslen(Data) + 1) * sizeof(WCHAR));
if (Key->Data == NULL)
{
DPRINT("RtlAllocateHeap() failed\n");
RtlFreeHeap(ProcessHeap, 0, Key->Name);
RtlFreeHeap(ProcessHeap, 0, Key);
return NULL;
}
/* Copy value data */
wcscpy(Key->Data, Data);
/* Insert key into section */
if (Section->FirstKey == NULL)
{
Section->FirstKey = Key;
Section->LastKey = Key;
}
else if ((InsertionType == INSERT_FIRST) ||
((InsertionType == INSERT_BEFORE) && ((AnchorKey == NULL) || (AnchorKey == Section->FirstKey))))
{
/* Insert at the head of the list */
Section->FirstKey->Prev = Key;
Key->Next = Section->FirstKey;
Section->FirstKey = Key;
}
else if ((InsertionType == INSERT_BEFORE) && (AnchorKey != NULL))
{
/* Insert before the anchor key */
Key->Next = AnchorKey;
Key->Prev = AnchorKey->Prev;
AnchorKey->Prev->Next = Key;
AnchorKey->Prev = Key;
}
else if ((InsertionType == INSERT_LAST) ||
((InsertionType == INSERT_AFTER) && ((AnchorKey == NULL) || (AnchorKey == Section->LastKey))))
{
Section->LastKey->Next = Key;
Key->Prev = Section->LastKey;
Section->LastKey = Key;
}
else if ((InsertionType == INSERT_AFTER) && (AnchorKey != NULL))
{
/* Insert after the anchor key */
Key->Next = AnchorKey->Next;
Key->Prev = AnchorKey;
AnchorKey->Next->Prev = Key;
AnchorKey->Next = Key;
}
return Key;
} }
@ -943,15 +900,14 @@ IniCacheCreate(VOID)
return Cache; return Cache;
} }
NTSTATUS NTSTATUS
IniCacheSaveByHandle( IniCacheSaveByHandle(
PINICACHE Cache, PINICACHE Cache,
HANDLE FileHandle) HANDLE FileHandle)
{ {
NTSTATUS Status; NTSTATUS Status;
PINICACHESECTION Section; PINI_SECTION Section;
PINICACHEKEY Key; PINI_KEYWORD Key;
ULONG BufferSize; ULONG BufferSize;
PCHAR Buffer; PCHAR Buffer;
PCHAR Ptr; PCHAR Ptr;
@ -984,7 +940,7 @@ IniCacheSaveByHandle(
DPRINT("BufferSize: %lu\n", BufferSize); DPRINT("BufferSize: %lu\n", BufferSize);
/* Allocate file buffer with NULL-terminator */ /* Allocate file buffer with NULL-terminator */
Buffer = (CHAR*)RtlAllocateHeap(ProcessHeap, Buffer = (PCHAR)RtlAllocateHeap(ProcessHeap,
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
BufferSize + 1); BufferSize + 1);
if (Buffer == NULL) if (Buffer == NULL)
@ -1083,57 +1039,4 @@ IniCacheSave(
return Status; return Status;
} }
PINICACHESECTION
IniCacheAppendSection(
PINICACHE Cache,
PWCHAR Name)
{
PINICACHESECTION Section = NULL;
if (Cache == NULL || Name == NULL || *Name == 0)
{
DPRINT("Invalid parameter\n");
return NULL;
}
Section = (PINICACHESECTION)RtlAllocateHeap(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(INICACHESECTION));
if (Section == NULL)
{
DPRINT("RtlAllocateHeap() failed\n");
return NULL;
}
/* Allocate and initialize section name */
Section->Name = (WCHAR*)RtlAllocateHeap(ProcessHeap,
0,
(wcslen(Name) + 1) * sizeof(WCHAR));
if (Section->Name == NULL)
{
DPRINT("RtlAllocateHeap() failed\n");
RtlFreeHeap(ProcessHeap, 0, Section);
return NULL;
}
/* Copy section name */
wcscpy(Section->Name, Name);
/* Append section */
if (Cache->FirstSection == NULL)
{
Cache->FirstSection = Section;
Cache->LastSection = Section;
}
else
{
Cache->LastSection->Next = Section;
Section->Prev = Cache->LastSection;
Cache->LastSection = Section;
}
return Section;
}
/* EOF */ /* EOF */

View file

@ -7,42 +7,38 @@
#pragma once #pragma once
typedef struct _INICACHEKEY typedef struct _INI_KEYWORD
{ {
PWCHAR Name; PWCHAR Name;
PWCHAR Data; PWCHAR Data;
struct _INICACHEKEY *Next; struct _INI_KEYWORD *Next;
struct _INICACHEKEY *Prev; struct _INI_KEYWORD *Prev;
} INICACHEKEY, *PINICACHEKEY; } INI_KEYWORD, *PINI_KEYWORD;
typedef struct _INI_SECTION
typedef struct _INICACHESECTION
{ {
PWCHAR Name; PWCHAR Name;
PINICACHEKEY FirstKey; PINI_KEYWORD FirstKey;
PINICACHEKEY LastKey; PINI_KEYWORD LastKey;
struct _INICACHESECTION *Next;
struct _INICACHESECTION *Prev;
} INICACHESECTION, *PINICACHESECTION;
struct _INI_SECTION *Next;
struct _INI_SECTION *Prev;
} INI_SECTION, *PINI_SECTION;
typedef struct _INICACHE typedef struct _INICACHE
{ {
PINICACHESECTION FirstSection; PINI_SECTION FirstSection;
PINICACHESECTION LastSection; PINI_SECTION LastSection;
} INICACHE, *PINICACHE; } INICACHE, *PINICACHE;
typedef struct _PINICACHEITERATOR typedef struct _PINICACHEITERATOR
{ {
PINICACHESECTION Section; PINI_SECTION Section;
PINICACHEKEY Key; PINI_KEYWORD Key;
} INICACHEITERATOR, *PINICACHEITERATOR; } INICACHEITERATOR, *PINICACHEITERATOR;
typedef enum typedef enum
{ {
INSERT_FIRST, INSERT_FIRST,
@ -76,41 +72,51 @@ VOID
IniCacheDestroy( IniCacheDestroy(
PINICACHE Cache); PINICACHE Cache);
PINICACHESECTION PINI_SECTION
IniCacheGetSection( IniGetSection(
PINICACHE Cache, PINICACHE Cache,
PWCHAR Name); PWCHAR Name);
NTSTATUS NTSTATUS
IniCacheGetKey( IniGetKey(
PINICACHESECTION Section, PINI_SECTION Section,
PWCHAR KeyName, PWCHAR KeyName,
PWCHAR *KeyData); PWCHAR *KeyData);
PINICACHEITERATOR PINICACHEITERATOR
IniCacheFindFirstValue( IniFindFirstValue(
PINICACHESECTION Section, PINI_SECTION Section,
PWCHAR *KeyName, PWCHAR *KeyName,
PWCHAR *KeyData); PWCHAR *KeyData);
BOOLEAN BOOLEAN
IniCacheFindNextValue( IniFindNextValue(
PINICACHEITERATOR Iterator, PINICACHEITERATOR Iterator,
PWCHAR *KeyName, PWCHAR *KeyName,
PWCHAR *KeyData); PWCHAR *KeyData);
VOID VOID
IniCacheFindClose( IniFindClose(
PINICACHEITERATOR Iterator); PINICACHEITERATOR Iterator);
PINI_SECTION
IniAddSection(
_In_ PINICACHE Cache,
_In_ PCWSTR Name);
PINICACHEKEY PINI_KEYWORD
IniCacheInsertKey( IniInsertKey(
PINICACHESECTION Section, _In_ PINI_SECTION Section,
PINICACHEKEY AnchorKey, _In_ PINI_KEYWORD AnchorKey,
INSERTION_TYPE InsertionType, _In_ INSERTION_TYPE InsertionType,
PWCHAR Name, _In_ PCWSTR Name,
PWCHAR Data); _In_ PCWSTR Data);
PINI_KEYWORD
IniAddKey(
_In_ PINI_SECTION Section,
_In_ PCWSTR Name,
_In_ PCWSTR Data);
PINICACHE PINICACHE
IniCacheCreate(VOID); IniCacheCreate(VOID);
@ -125,9 +131,4 @@ IniCacheSave(
PINICACHE Cache, PINICACHE Cache,
PWCHAR FileName); PWCHAR FileName);
PINICACHESECTION
IniCacheAppendSection(
PINICACHE Cache,
PWCHAR Name);
/* EOF */ /* EOF */