merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / boot / freeldr / freeldr / inifile / ini_init.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <freeldr.h>
21 #include "ini.h"
22 #include <fs.h>
23 #include <rtl.h>
24 #include <mm.h>
25 #include <debug.h>
26
27
28 BOOL IniFileInitialize(VOID)
29 {
30 PFILE Freeldr_Ini; // File handle for freeldr.ini
31 PCHAR FreeLoaderIniFileData;
32 ULONG FreeLoaderIniFileSize;
33 BOOL Success;
34
35 // Open freeldr.ini
36 Freeldr_Ini = IniOpenIniFile();
37
38 if (Freeldr_Ini == NULL)
39 {
40 printf("Error opening freeldr.ini or file not found.\n");
41 printf("You need to re-install FreeLoader.\n");
42 return FALSE;
43 }
44
45 // Get the file size & allocate enough memory for it
46 FreeLoaderIniFileSize = FsGetFileSize(Freeldr_Ini);
47 FreeLoaderIniFileData = MmAllocateMemory(FreeLoaderIniFileSize);
48
49 // If we are out of memory then return FALSE
50 if (FreeLoaderIniFileData == NULL)
51 {
52 printf("Out of memory while loading freeldr.ini.\n");
53 FsCloseFile(Freeldr_Ini);
54 return FALSE;
55 }
56
57 // Read freeldr.ini off the disk
58 if (!FsReadFile(Freeldr_Ini, FreeLoaderIniFileSize, NULL, FreeLoaderIniFileData))
59 {
60 FsCloseFile(Freeldr_Ini);
61 MmFreeMemory(FreeLoaderIniFileData);
62 return FALSE;
63 }
64
65 FsCloseFile(Freeldr_Ini);
66
67 // Parse the .ini file data
68 Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
69
70 MmFreeMemory(FreeLoaderIniFileData);
71
72 return Success;
73 }
74
75 PFILE IniOpenIniFile()
76 {
77 PFILE IniFileHandle; // File handle for freeldr.ini
78
79 // Try to open freeldr.ini
80 IniFileHandle = FsOpenFile("freeldr.ini");
81
82 return IniFileHandle;
83 }