ReactOS 0.4.16-dev-597-gdbf7844
ini_init.c
Go to the documentation of this file.
1/*
2 * FreeLoader
3 * Copyright (C) 2009 Hervé Poussineau <hpoussin@reactos.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <freeldr.h>
21
22#include <debug.h>
24
26{
28 ULONG FileId; // File handle for freeldr.ini
29 PCHAR FreeLoaderIniFileData;
30 ULONG FreeLoaderIniFileSize, Count;
33
34 TRACE("IniFileInitialize()\n");
35
36 /* Try to open freeldr.ini */
37 Status = FsOpenFile("freeldr.ini", FrLdrBootPath, OpenReadOnly, &FileId);
38 if (Status != ESUCCESS)
39 {
40 ERR("Error while opening freeldr.ini, Status: %d\n", Status);
41
42 /* Try to open boot.ini */
43 Status = FsOpenFile("boot.ini", FrLdrBootPath, OpenReadOnly, &FileId);
44 if (Status != ESUCCESS)
45 {
46 ERR("Error while opening boot.ini, Status: %d\n", Status);
47 UiMessageBoxCritical("Error opening freeldr.ini/boot.ini or file not found.\nYou need to re-install FreeLoader.");
48 return FALSE;
49 }
50 }
51
52 /* Get the file size */
54 if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
55 {
56 UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
57 ArcClose(FileId);
58 return FALSE;
59 }
60 FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
61
62 /* Allocate memory to cache the whole freeldr.ini */
63 FreeLoaderIniFileData = FrLdrTempAlloc(FreeLoaderIniFileSize, TAG_INI_FILE);
64 if (!FreeLoaderIniFileData)
65 {
66 UiMessageBoxCritical("Out of memory while loading freeldr.ini.");
67 ArcClose(FileId);
68 return FALSE;
69 }
70
71 /* Load freeldr.ini from the disk */
72 Status = ArcRead(FileId, FreeLoaderIniFileData, FreeLoaderIniFileSize, &Count);
73 if (Status != ESUCCESS || Count != FreeLoaderIniFileSize)
74 {
75 ERR("Error while reading freeldr.ini, Status: %d\n", Status);
76 UiMessageBoxCritical("Error while reading freeldr.ini.");
77 ArcClose(FileId);
78 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
79 return FALSE;
80 }
81
82 /* Parse the .ini file data */
83 Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
84
85 /* Do some cleanup, and return */
86 ArcClose(FileId);
87 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
88
89 return Success;
90}
unsigned char BOOLEAN
#define ERR(fmt,...)
Definition: precomp.h:57
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
ARC_STATUS ArcGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: fs.c:462
ARC_STATUS FsOpenFile(IN PCSTR FileName, IN PCSTR DefaultPath OPTIONAL, IN OPENMODE OpenMode, OUT PULONG FileId)
Definition: fs.c:478
ARC_STATUS ArcClose(_In_ ULONG FileId)
Definition: fs.c:409
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:448
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
VOID UiMessageBoxCritical(_In_ PCSTR MessageText)
Definition: ui.c:372
#define FALSE
Definition: types.h:117
@ Success
Definition: eventcreate.c:712
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:29
Status
Definition: gdiplustypes.h:25
BOOLEAN IniFileInitialize(VOID)
Definition: ini_init.c:25
#define TAG_INI_FILE
Definition: inifile.h:24
BOOLEAN IniParseFile(PCHAR IniFileData, ULONG IniFileSize)
Definition: parse.c:31
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
int Count
Definition: noreturn.cpp:7
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
@ OpenReadOnly
Definition: arc.h:65
#define TRACE(s)
Definition: solgame.cpp:4
@ INIFILE
Definition: tnconfig.cpp:129
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51