Author: hbelusca
Date: Wed May 31 00:23:53 2017
New Revision: 74711
URL:
http://svn.reactos.org/svn/reactos?rev=74711&view=rev
Log:
[SETUPLIB]: Additions to inicache.c: Split IniCacheLoad() and IniCacheSave() into:
themselves & IniCacheLoadByHandle() and IniCacheSaveByHandle(), respectively, so that
we can load & save INI files if we already have an opened handle to them.
Modified:
branches/setup_improvements/base/setup/lib/inicache.c
branches/setup_improvements/base/setup/lib/inicache.h
Modified: branches/setup_improvements/base/setup/lib/inicache.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/inicache.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/inicache.c [iso-8859-1] Wed May 31 00:23:53
2017
@@ -546,45 +546,19 @@
}
NTSTATUS
-IniCacheLoad(
+IniCacheLoadByHandle(
PINICACHE *Cache,
- PWCHAR FileName,
+ HANDLE FileHandle,
BOOLEAN String)
{
- UNICODE_STRING Name;
- OBJECT_ATTRIBUTES ObjectAttributes;
+ NTSTATUS Status;
+ IO_STATUS_BLOCK IoStatusBlock;
FILE_STANDARD_INFORMATION FileInfo;
- IO_STATUS_BLOCK IoStatusBlock;
- HANDLE FileHandle;
- NTSTATUS Status;
PCHAR FileBuffer;
ULONG FileLength;
LARGE_INTEGER FileOffset;
*Cache = NULL;
-
- /* Open ini file */
- RtlInitUnicodeString(&Name, FileName);
-
- InitializeObjectAttributes(&ObjectAttributes,
- &Name,
- 0,
- NULL,
- NULL);
-
- Status = NtOpenFile(&FileHandle,
- GENERIC_READ | SYNCHRONIZE,
- &ObjectAttributes,
- &IoStatusBlock,
- FILE_SHARE_READ,
- FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
- return Status;
- }
-
- DPRINT("NtOpenFile() successful\n");
/* Query file size */
Status = NtQueryInformationFile(FileHandle,
@@ -595,7 +569,6 @@
if (!NT_SUCCESS(Status))
{
DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
return Status;
}
@@ -610,7 +583,6 @@
if (FileBuffer == NULL)
{
DPRINT1("RtlAllocateHeap() failed\n");
- NtClose(FileHandle);
return STATUS_INSUFFICIENT_RESOURCES;
}
@@ -629,8 +601,6 @@
/* Append NULL-terminator */
FileBuffer[FileLength] = 0;
- NtClose(FileHandle);
-
if (!NT_SUCCESS(Status))
{
DPRINT("NtReadFile() failed (Status %lx)\n", Status);
@@ -646,6 +616,50 @@
Quit:
/* Free the file buffer, and return */
RtlFreeHeap(ProcessHeap, 0, FileBuffer);
+ return Status;
+}
+
+NTSTATUS
+IniCacheLoad(
+ PINICACHE *Cache,
+ PWCHAR FileName,
+ BOOLEAN String)
+{
+ NTSTATUS Status;
+ UNICODE_STRING Name;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ HANDLE FileHandle;
+
+ *Cache = NULL;
+
+ /* Open the INI file */
+ RtlInitUnicodeString(&Name, FileName);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &Name,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ FILE_GENERIC_READ | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_READ,
+ FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NtOpenFile() failed (Status %lx)\n", Status);
+ return Status;
+ }
+
+ DPRINT("NtOpenFile() successful\n");
+
+ Status = IniCacheLoadByHandle(Cache, FileHandle, String);
+
+ /* Close the INI file */
+ NtClose(FileHandle);
return Status;
}
@@ -933,24 +947,19 @@
NTSTATUS
-IniCacheSave(
+IniCacheSaveByHandle(
PINICACHE Cache,
- PWCHAR FileName)
-{
- UNICODE_STRING Name;
+ HANDLE FileHandle)
+{
+ NTSTATUS Status;
PINICACHESECTION Section;
PINICACHEKEY Key;
ULONG BufferSize;
PCHAR Buffer;
PCHAR Ptr;
ULONG Len;
- NTSTATUS Status;
-
- OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
LARGE_INTEGER Offset;
- HANDLE FileHandle;
-
/* Calculate required buffer size */
BufferSize = 0;
@@ -1010,33 +1019,7 @@
}
}
- /* Create ini file */
- RtlInitUnicodeString(&Name, FileName);
-
- InitializeObjectAttributes(&ObjectAttributes,
- &Name,
- 0,
- NULL,
- NULL);
-
- Status = NtCreateFile(&FileHandle,
- GENERIC_WRITE | SYNCHRONIZE,
- &ObjectAttributes,
- &IoStatusBlock,
- NULL,
- FILE_ATTRIBUTE_NORMAL,
- 0,
- FILE_SUPERSEDE,
- FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY,
- NULL,
- 0);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
- RtlFreeHeap(ProcessHeap, 0, Buffer);
- return Status;
- }
-
+ /* Write to the INI file */
Offset.QuadPart = 0LL;
Status = NtWriteFile(FileHandle,
NULL,
@@ -1049,17 +1032,57 @@
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
- RtlFreeHeap(ProcessHeap, 0, Buffer);
- return Status;
- }
-
+ DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
+ RtlFreeHeap(ProcessHeap, 0, Buffer);
+ return Status;
+ }
+
+ RtlFreeHeap(ProcessHeap, 0, Buffer);
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+IniCacheSave(
+ PINICACHE Cache,
+ PWCHAR FileName)
+{
+ NTSTATUS Status;
+ UNICODE_STRING Name;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ HANDLE FileHandle;
+
+ /* Create the INI file */
+ RtlInitUnicodeString(&Name, FileName);
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &Name,
+ 0,
+ NULL,
+ NULL);
+
+ Status = NtCreateFile(&FileHandle,
+ FILE_GENERIC_WRITE | SYNCHRONIZE,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ NULL,
+ FILE_ATTRIBUTE_NORMAL,
+ 0,
+ FILE_SUPERSEDE,
+ FILE_SYNCHRONOUS_IO_NONALERT | FILE_SEQUENTIAL_ONLY |
FILE_NON_DIRECTORY_FILE,
+ NULL,
+ 0);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ return Status;
+ }
+
+ Status = IniCacheSaveByHandle(Cache, FileHandle);
+
+ /* Close the INI file */
NtClose(FileHandle);
-
- RtlFreeHeap(ProcessHeap, 0, Buffer);
-
- return STATUS_SUCCESS;
+ return Status;
}
Modified: branches/setup_improvements/base/setup/lib/inicache.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/inicache.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/inicache.h [iso-8859-1] Wed May 31 00:23:53
2017
@@ -63,6 +63,12 @@
BOOLEAN String);
NTSTATUS
+IniCacheLoadByHandle(
+ PINICACHE *Cache,
+ HANDLE FileHandle,
+ BOOLEAN String);
+
+NTSTATUS
IniCacheLoad(
PINICACHE *Cache,
PWCHAR FileName,
@@ -112,6 +118,11 @@
IniCacheCreate(VOID);
NTSTATUS
+IniCacheSaveByHandle(
+ PINICACHE Cache,
+ HANDLE FileHandle);
+
+NTSTATUS
IniCacheSave(
PINICACHE Cache,
PWCHAR FileName);